coherent-docs-theme 1.0.1 → 1.0.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/internal-components/NavLinks.astro +58 -15
- package/package.json +12 -10
|
@@ -7,12 +7,41 @@ interface Props {
|
|
|
7
7
|
}
|
|
8
8
|
|
|
9
9
|
const { type = "header" } = Astro.props;
|
|
10
|
-
const { navLinks } = getThemeConfig();
|
|
11
|
-
const
|
|
10
|
+
const { navLinks, documentationSearchTag } = getThemeConfig();
|
|
11
|
+
const currentUrl = Astro.url;
|
|
12
|
+
|
|
13
|
+
const isLinkActive = (href: string, label: string) => {
|
|
14
|
+
try {
|
|
15
|
+
const linkUrl = new URL(href, currentUrl.origin);
|
|
16
|
+
const isLocal =
|
|
17
|
+
currentUrl.hostname === "localhost" ||
|
|
18
|
+
currentUrl.hostname === "127.0.0.1";
|
|
19
|
+
|
|
20
|
+
const normalize = (p: string) => p.replace(/\/+$/, "") || "/";
|
|
21
|
+
const currentPath = normalize(currentUrl.pathname);
|
|
22
|
+
const linkPath = normalize(linkUrl.pathname);
|
|
23
|
+
|
|
24
|
+
if (isLocal) {
|
|
25
|
+
const isCurrentProject = label === documentationSearchTag;
|
|
26
|
+
|
|
27
|
+
if (!isCurrentProject) return false;
|
|
28
|
+
|
|
29
|
+
if (linkPath === "/") return true;
|
|
30
|
+
return (
|
|
31
|
+
currentPath === linkPath ||
|
|
32
|
+
currentPath.startsWith(linkPath + "/")
|
|
33
|
+
);
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
if (linkUrl.origin !== currentUrl.origin) return false;
|
|
12
37
|
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
38
|
+
if (linkPath === "/") return currentPath === "/";
|
|
39
|
+
return (
|
|
40
|
+
currentPath === linkPath || currentPath.startsWith(linkPath + "/")
|
|
41
|
+
);
|
|
42
|
+
} catch (e) {
|
|
43
|
+
return false;
|
|
44
|
+
}
|
|
16
45
|
};
|
|
17
46
|
|
|
18
47
|
const navClasses =
|
|
@@ -20,14 +49,20 @@ const navClasses =
|
|
|
20
49
|
? "extra-links sl-hidden md:sl-flex"
|
|
21
50
|
: "extra-links mobile sidebar-mode lg:hidden";
|
|
22
51
|
|
|
23
|
-
const activeLinkObj = navLinks?.find((link) =>
|
|
52
|
+
const activeLinkObj = navLinks?.find((link) =>
|
|
53
|
+
isLinkActive(link.href, link.label),
|
|
54
|
+
);
|
|
24
55
|
const activeLabel = activeLinkObj ? activeLinkObj.label : "Documentations";
|
|
25
56
|
---
|
|
26
57
|
|
|
27
58
|
{
|
|
28
59
|
navLinks && navLinks.length > 0 && (
|
|
29
60
|
<>
|
|
30
|
-
<nav
|
|
61
|
+
<nav
|
|
62
|
+
class={"smart-nav " + navClasses}
|
|
63
|
+
id="smart-nav"
|
|
64
|
+
aria-label="Global Navigation"
|
|
65
|
+
>
|
|
31
66
|
{type === "header" && (
|
|
32
67
|
<div class="vertical-separator md:sl-flex" />
|
|
33
68
|
)}
|
|
@@ -37,7 +72,7 @@ const activeLabel = activeLinkObj ? activeLinkObj.label : "Documentations";
|
|
|
37
72
|
<li class="nav-item">
|
|
38
73
|
<a
|
|
39
74
|
href={link.href}
|
|
40
|
-
class={`nav-link ${isLinkActive(link.href) ? "active" : ""}`}
|
|
75
|
+
class={`nav-link ${isLinkActive(link.href, link.label) ? "active" : ""}`}
|
|
41
76
|
>
|
|
42
77
|
{link.label}
|
|
43
78
|
</a>
|
|
@@ -56,7 +91,7 @@ const activeLabel = activeLinkObj ? activeLinkObj.label : "Documentations";
|
|
|
56
91
|
<li>
|
|
57
92
|
<a
|
|
58
93
|
href={link.href}
|
|
59
|
-
class={`dropdown-link ${isLinkActive(link.href) ? "active" : ""}`}
|
|
94
|
+
class={`dropdown-link ${isLinkActive(link.href, link.label) ? "active" : ""}`}
|
|
60
95
|
>
|
|
61
96
|
{link.label}
|
|
62
97
|
</a>
|
|
@@ -191,9 +226,15 @@ const activeLabel = activeLinkObj ? activeLinkObj.label : "Documentations";
|
|
|
191
226
|
|
|
192
227
|
constructor(navElement: HTMLElement) {
|
|
193
228
|
this.container = navElement;
|
|
194
|
-
this.verticalSeparator = navElement.querySelector(
|
|
195
|
-
|
|
196
|
-
|
|
229
|
+
this.verticalSeparator = navElement.querySelector(
|
|
230
|
+
".vertical-separator",
|
|
231
|
+
) as HTMLElement;
|
|
232
|
+
this.fullList = navElement.querySelector(
|
|
233
|
+
".full-nav-list",
|
|
234
|
+
) as HTMLElement;
|
|
235
|
+
this.collapsedMenu = navElement.querySelector(
|
|
236
|
+
".collapsed-menu",
|
|
237
|
+
) as HTMLElement;
|
|
197
238
|
|
|
198
239
|
this.fullListWidth = this.calculateRequiredWidth();
|
|
199
240
|
|
|
@@ -230,12 +271,14 @@ const activeLabel = activeLinkObj ? activeLinkObj.label : "Documentations";
|
|
|
230
271
|
if (availableWidth === 0) return;
|
|
231
272
|
|
|
232
273
|
if (availableWidth < this.fullListWidth) {
|
|
233
|
-
if(this.verticalSeparator)
|
|
274
|
+
if (this.verticalSeparator)
|
|
275
|
+
this.verticalSeparator.style.display = "none";
|
|
234
276
|
this.container.style.flexDirection = "row-reverse";
|
|
235
277
|
this.fullList.style.display = "none";
|
|
236
278
|
this.collapsedMenu.style.display = "block";
|
|
237
279
|
} else {
|
|
238
|
-
if(this.verticalSeparator)
|
|
280
|
+
if (this.verticalSeparator)
|
|
281
|
+
this.verticalSeparator.style.display = "block";
|
|
239
282
|
this.container.style.flexDirection = "row";
|
|
240
283
|
this.fullList.style.display = "flex";
|
|
241
284
|
this.collapsedMenu.style.display = "none";
|
|
@@ -250,4 +293,4 @@ const activeLabel = activeLinkObj ? activeLinkObj.label : "Documentations";
|
|
|
250
293
|
|
|
251
294
|
document.addEventListener("astro:page-load", init);
|
|
252
295
|
document.addEventListener("DOMContentLoaded", init);
|
|
253
|
-
</script>
|
|
296
|
+
</script>
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "coherent-docs-theme",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.3",
|
|
4
4
|
"license": "MIT",
|
|
5
5
|
"description": "Theme for all the coherent documentations",
|
|
6
6
|
"author": "CoherentLabs",
|
|
@@ -16,21 +16,23 @@
|
|
|
16
16
|
"./assets/*": "./assets/*"
|
|
17
17
|
},
|
|
18
18
|
"devDependencies": {
|
|
19
|
-
"@astrojs/starlight": "
|
|
19
|
+
"@astrojs/starlight": "0.37.6",
|
|
20
|
+
"astro": "5.17.1",
|
|
20
21
|
"@types/mdast": "^4.0.4",
|
|
21
|
-
"@types/unist": "^3.0.3"
|
|
22
|
-
"astro": "^5.17.1"
|
|
22
|
+
"@types/unist": "^3.0.3"
|
|
23
23
|
},
|
|
24
24
|
"dependencies": {
|
|
25
|
-
"starlight-heading-badges": "
|
|
26
|
-
"starlight-
|
|
27
|
-
"starlight-sidebar-topics": "
|
|
28
|
-
"starlight-sidebar-topics-dropdown": "^0.5.2",
|
|
25
|
+
"starlight-heading-badges": "0.6.1",
|
|
26
|
+
"starlight-sidebar-topics": "0.6.2",
|
|
27
|
+
"starlight-sidebar-topics-dropdown": "0.5.2",
|
|
29
28
|
"gray-matter": "^4.0.3"
|
|
30
29
|
},
|
|
31
30
|
"peerDependencies": {
|
|
32
|
-
"
|
|
33
|
-
"
|
|
31
|
+
"@astrojs/starlight": ">=0.37.6",
|
|
32
|
+
"astro": ">=5.17.1"
|
|
33
|
+
},
|
|
34
|
+
"overrides": {
|
|
35
|
+
"zod": "3.25.76"
|
|
34
36
|
},
|
|
35
37
|
"engines": {
|
|
36
38
|
"node": "^18.17.1 || ^20.3.0 || >=21.0.0"
|