coherent-docs-theme 1.0.2 → 1.0.4

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/index.ts CHANGED
@@ -9,6 +9,7 @@ import type { CoherentThemeOptions } from './internal/themeConfig';
9
9
  import { fileURLToPath } from 'url';
10
10
  import { directives } from './remark-directives';
11
11
  import { getSortedCoherentReleases } from './utils/coherentReleases';
12
+ import { version } from './package.json';
12
13
 
13
14
  const __filename = fileURLToPath(import.meta.url);
14
15
  const __dirname = path.dirname(__filename);
@@ -56,7 +57,7 @@ export default function coherentThemePlugin(options: CoherentThemeOptions = { do
56
57
  name: 'coherent-docs-theme',
57
58
  hooks: {
58
59
  'config:setup'({ config, logger, updateConfig, addIntegration }) {
59
- logger.info('Initializing Coherent Theme...');
60
+ logger.info(`Initializing Coherent Theme v${version}...`);
60
61
 
61
62
  addIntegration({
62
63
  name: 'coherent-docs-theme-integration',
@@ -7,12 +7,41 @@ interface Props {
7
7
  }
8
8
 
9
9
  const { type = "header" } = Astro.props;
10
- const { navLinks } = getThemeConfig();
11
- const currentPath = Astro.url.pathname;
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
- const isLinkActive = (href: string) => {
14
- if (href === "/") return currentPath === "/";
15
- return currentPath.startsWith(href);
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) => isLinkActive(link.href));
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 class={"smart-nav " + navClasses} id="smart-nav" aria-label="Global Navigation">
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(".vertical-separator") as HTMLElement;
195
- this.fullList = navElement.querySelector(".full-nav-list") as HTMLElement;
196
- this.collapsedMenu = navElement.querySelector(".collapsed-menu") as HTMLElement;
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) this.verticalSeparator.style.display = "none";
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) this.verticalSeparator.style.display = "block";
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.2",
3
+ "version": "1.0.4",
4
4
  "license": "MIT",
5
5
  "description": "Theme for all the coherent documentations",
6
6
  "author": "CoherentLabs",