igniteui-astro-components 0.0.3 → 0.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/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "igniteui-astro-components",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.4",
|
|
4
4
|
"description": "Reusable Astro components, layouts, and integrations for Infragistics / Ignite UI documentation sites. Replaces the Starlight defaults with project-specific implementations.",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"engines": {
|
|
@@ -8,7 +8,7 @@
|
|
|
8
8
|
* Package: igniteui-webcomponents (public, MIT) — change the import path
|
|
9
9
|
* in the <script> block below to use @infragistics/igniteui-webcomponents.
|
|
10
10
|
*/
|
|
11
|
-
import { sidebar as sidebarData } from 'virtual:docs-template/site-meta';
|
|
11
|
+
import { sidebar as sidebarData, trailingSlash as configuredTrailingSlash } from 'virtual:docs-template/site-meta';
|
|
12
12
|
import SidebarFilterInput from './SidebarFilterInput.astro';
|
|
13
13
|
import './DocsSidebar.scss';
|
|
14
14
|
import SidebarLabel from './SidebarLabel.astro';
|
|
@@ -24,11 +24,18 @@ interface Props {
|
|
|
24
24
|
* Useful when consuming the component without `siteMetaIntegration`.
|
|
25
25
|
*/
|
|
26
26
|
items?: SidebarEntry[];
|
|
27
|
+
/**
|
|
28
|
+
* Append trailing slash to sidebar links.
|
|
29
|
+
* Defaults to the value derived from the site's `trailingSlash` Astro config
|
|
30
|
+
* (exposed via the virtual module). Falls back to `true` if not configured.
|
|
31
|
+
*/
|
|
32
|
+
trailingSlash?: boolean;
|
|
27
33
|
}
|
|
28
34
|
|
|
29
|
-
const
|
|
35
|
+
const useTrailingSlash = configuredTrailingSlash !== 'never';
|
|
36
|
+
const { currentSlug = '', items: itemsProp, trailingSlash = useTrailingSlash } = Astro.props;
|
|
30
37
|
const items = (itemsProp ?? sidebarData) as SidebarEntry[];
|
|
31
|
-
const nodes = toTreeNodes(items, currentSlug);
|
|
38
|
+
const nodes = toTreeNodes(items, currentSlug, { trailingSlash });
|
|
32
39
|
const activeId = normalizeSlug(currentSlug);
|
|
33
40
|
---
|
|
34
41
|
|
|
@@ -18,15 +18,21 @@ import { isGroup, isInitiallyOpen, joinPath, normalizeSlug } from '../../lib/sid
|
|
|
18
18
|
|
|
19
19
|
const base = import.meta.env.BASE_URL.replace(/\/$/, '');
|
|
20
20
|
|
|
21
|
-
const linkHref = (slug: string): string => {
|
|
21
|
+
const linkHref = (slug: string, trailingSlash: boolean): string => {
|
|
22
22
|
const normalized = normalizeSlug(slug);
|
|
23
|
-
|
|
23
|
+
const suffix = trailingSlash ? '/' : '';
|
|
24
|
+
if (!normalized) {
|
|
25
|
+
// Root (docs index): ensure href is at least '/' when base is empty.
|
|
26
|
+
return `${base}${suffix}` || '/';
|
|
27
|
+
}
|
|
28
|
+
return `${base}/${normalized}${suffix}`;
|
|
24
29
|
};
|
|
25
30
|
|
|
26
31
|
const toNode = (
|
|
27
32
|
entry: SidebarEntry,
|
|
28
33
|
ancestors: string[],
|
|
29
34
|
currentSlug: string,
|
|
35
|
+
trailingSlash: boolean,
|
|
30
36
|
): TreeNode => {
|
|
31
37
|
const path = joinPath(ancestors, entry.label);
|
|
32
38
|
|
|
@@ -36,7 +42,7 @@ const toNode = (
|
|
|
36
42
|
label: entry.label,
|
|
37
43
|
expanded: isInitiallyOpen(entry, currentSlug) || undefined,
|
|
38
44
|
children: entry.items.map((child) =>
|
|
39
|
-
toNode(child, [...ancestors, entry.label], currentSlug),
|
|
45
|
+
toNode(child, [...ancestors, entry.label], currentSlug, trailingSlash),
|
|
40
46
|
),
|
|
41
47
|
itemData: {
|
|
42
48
|
path,
|
|
@@ -49,7 +55,7 @@ const toNode = (
|
|
|
49
55
|
return {
|
|
50
56
|
id: normalizeSlug(entry.slug),
|
|
51
57
|
label: entry.label,
|
|
52
|
-
href: linkHref(entry.slug),
|
|
58
|
+
href: linkHref(entry.slug, trailingSlash),
|
|
53
59
|
itemData: {
|
|
54
60
|
path,
|
|
55
61
|
label: entry.label,
|
|
@@ -60,7 +66,13 @@ const toNode = (
|
|
|
60
66
|
};
|
|
61
67
|
};
|
|
62
68
|
|
|
69
|
+
export interface ToTreeNodesOptions {
|
|
70
|
+
/** Append trailing slash to sidebar links. Defaults to `true`. */
|
|
71
|
+
trailingSlash?: boolean;
|
|
72
|
+
}
|
|
73
|
+
|
|
63
74
|
export const toTreeNodes = (
|
|
64
75
|
entries: SidebarEntry[],
|
|
65
76
|
currentSlug: string,
|
|
66
|
-
|
|
77
|
+
{ trailingSlash = true }: ToTreeNodesOptions = {},
|
|
78
|
+
): TreeNode[] => entries.map((entry) => toNode(entry, [], currentSlug, trailingSlash));
|
package/src/integration.ts
CHANGED
|
@@ -212,20 +212,23 @@ export function siteMetaIntegration({
|
|
|
212
212
|
|
|
213
213
|
// Navigation buckets for this platform — stripped from ancestor paths during label generation.
|
|
214
214
|
const broadSections = getBroadSectionsForPlatform(effectivePlatform);
|
|
215
|
-
|
|
216
|
-
export const sidebar = ${JSON.stringify(sidebar ?? [])};
|
|
217
|
-
export const productLinks = ${JSON.stringify(productLinks)};
|
|
218
|
-
export const headEntries = ${JSON.stringify(head ?? [])};
|
|
219
|
-
`;
|
|
220
|
-
|
|
221
|
-
// Captured from astro:config:done; used to generate llms.txt content.
|
|
215
|
+
// Captured from astro:config:done; used to generate llms.txt content and virtual module.
|
|
222
216
|
let configuredSite = '';
|
|
217
|
+
// Cached virtual module source — built once in astro:config:done after
|
|
218
|
+
// trailingSlash is known and reused on every subsequent Vite load() call.
|
|
219
|
+
let siteMetaCode = '';
|
|
223
220
|
|
|
224
221
|
return {
|
|
225
222
|
name: 'docs-template:site-meta',
|
|
226
223
|
hooks: {
|
|
227
224
|
'astro:config:done'({ config }) {
|
|
228
225
|
configuredSite = (config.site?.toString() ?? '').replace(/\/$/, '');
|
|
226
|
+
siteMetaCode = `export const title = ${JSON.stringify(title)};
|
|
227
|
+
export const sidebar = ${JSON.stringify(sidebar ?? [])};
|
|
228
|
+
export const productLinks = ${JSON.stringify(productLinks)};
|
|
229
|
+
export const headEntries = ${JSON.stringify(head ?? [])};
|
|
230
|
+
export const trailingSlash = ${JSON.stringify(config.trailingSlash)};
|
|
231
|
+
`;
|
|
229
232
|
},
|
|
230
233
|
'astro:config:setup'({ updateConfig, injectRoute }) {
|
|
231
234
|
injectRoute({
|
|
@@ -283,7 +286,7 @@ export const headEntries = ${JSON.stringify(head ?? [])};
|
|
|
283
286
|
if (id === navVirtualId) return navResolvedId;
|
|
284
287
|
},
|
|
285
288
|
async load(id: string) {
|
|
286
|
-
if (id === resolvedId) return
|
|
289
|
+
if (id === resolvedId) return siteMetaCode;
|
|
287
290
|
if (id !== navResolvedId) return;
|
|
288
291
|
|
|
289
292
|
// Return cached module code — fetched at most once per build.
|
package/src/virtual-modules.d.ts
CHANGED
|
@@ -13,6 +13,8 @@ declare module 'virtual:docs-template/site-meta' {
|
|
|
13
13
|
attrs?: Record<string, string | boolean | undefined>;
|
|
14
14
|
content?: string;
|
|
15
15
|
}>;
|
|
16
|
+
/** Astro trailingSlash config value: 'always' | 'never' | 'ignore'. */
|
|
17
|
+
export const trailingSlash: 'always' | 'never' | 'ignore';
|
|
16
18
|
}
|
|
17
19
|
|
|
18
20
|
import type { NavLang, NavTheme } from './platform.ts';
|