igniteui-astro-components 0.0.6 → 0.0.7
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/README.md +9 -8
- package/package.json +4 -4
- package/src/components/DocsToc/toTreeNodes.ts +1 -1
- package/src/components/GlobalFooter/GlobalFooter.astro +12 -62
- package/src/components/GlobalFooter/README.md +7 -10
- package/src/components/GlobalNavBar/GlobalNavBar.astro +8 -193
- package/src/components/GlobalNavBar/GlobalNavBar.module.scss +0 -5
- package/src/components/GlobalNavBar/README.md +8 -15
- package/src/components/SearchAdvanced/SearchAdvanced.astro +20 -11
- package/src/components/ThemingWidget/ThemingWidget.astro +5 -10
- package/src/content.config.ts +1 -1
- package/src/integration.ts +19 -142
- package/src/layouts/DocsLayout/DocsLayout.astro +3 -4
- package/src/lib/nav-helpers.ts +11 -4
- package/src/platform.ts +9 -16
- package/src/plugins/remark-env-vars.ts +110 -0
- package/src/plugins/remark-html-transforms.ts +32 -0
- package/src/plugins/remark-md-links.ts +75 -0
- package/src/scripts/sample-widget.ts +0 -2
- package/src/sidebar.ts +6 -7
- package/src/virtual-modules.d.ts +1 -13
- package/src/plugins/remark-docfx.ts +0 -368
package/src/integration.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* integration.ts
|
|
3
3
|
*
|
|
4
|
-
* Shared configuration helpers for Astro
|
|
4
|
+
* Shared configuration helpers for Astro docs sites.
|
|
5
5
|
* All functions are independently usable; `createDocsSite` is the
|
|
6
6
|
* convenience wrapper that composes them all.
|
|
7
7
|
*
|
|
@@ -13,10 +13,10 @@
|
|
|
13
13
|
* site: 'https://my-org.github.io/my-docs',
|
|
14
14
|
* title: 'My Library',
|
|
15
15
|
* description: 'Reference docs for My Library.',
|
|
16
|
-
* platform: 'angular', // drives CDN head entries
|
|
16
|
+
* platform: 'angular', // drives CDN head entries
|
|
17
17
|
* navLang: 'en', // 'en' | 'jp' | 'kr'
|
|
18
18
|
* source: {
|
|
19
|
-
* tocPath: './my-docs/toc.
|
|
19
|
+
* tocPath: './my-docs/toc.json',
|
|
20
20
|
* docsDir: './my-docs/en/components',
|
|
21
21
|
* imagesDir: './my-docs/en/images', // omit to skip image serving
|
|
22
22
|
* },
|
|
@@ -24,10 +24,6 @@
|
|
|
24
24
|
* head: [ // extra <head> entries after platform ones
|
|
25
25
|
* { tag: 'link', attrs: { rel: 'stylesheet', href: '...' } },
|
|
26
26
|
* ],
|
|
27
|
-
* // Extra Starlight options (logo, social, editLink, customCss, …)
|
|
28
|
-
* starlight: {
|
|
29
|
-
* logo: { src: './public/favicon.svg' },
|
|
30
|
-
* },
|
|
31
27
|
* // Extra Astro options (markdown, image, build, …)
|
|
32
28
|
* markdown: { remarkPlugins: [] },
|
|
33
29
|
* });
|
|
@@ -41,7 +37,6 @@
|
|
|
41
37
|
* export default defineConfig({
|
|
42
38
|
* integrations: [
|
|
43
39
|
* siteMetaIntegration({ title: 'My Library', description: 'Reference docs.' }),
|
|
44
|
-
* starlight({ sidebar }),
|
|
45
40
|
* staticImagesIntegration('/abs/path/to/my-docs/images'),
|
|
46
41
|
* ],
|
|
47
42
|
* });
|
|
@@ -64,20 +59,18 @@ import {
|
|
|
64
59
|
type LlmsMeta, type LlmsSet, type SidebarItem,
|
|
65
60
|
} from './llms.ts';
|
|
66
61
|
import { buildSidebarFromToc } from './sidebar';
|
|
67
|
-
import {
|
|
62
|
+
import { getPlatformHead } from './platform';
|
|
68
63
|
import type { HeadEntry, PlatformKey, NavLang } from './platform.ts';
|
|
69
|
-
import {
|
|
70
|
-
import {
|
|
64
|
+
import { remarkEnvVars } from './plugins/remark-env-vars';
|
|
65
|
+
import { remarkMdLinks } from './plugins/remark-md-links';
|
|
66
|
+
import { remarkHtmlTransforms } from './plugins/remark-html-transforms';
|
|
71
67
|
|
|
72
68
|
/** Build / deployment mode. Drives env-var `DOCS_BUILD_MODE`. */
|
|
73
69
|
export type DocsMode = 'development' | 'staging' | 'production';
|
|
74
70
|
|
|
75
|
-
/** Module-level cache so the nav URL is fetched at most once per build. */
|
|
76
|
-
let _navHtmlCache: string | null = null;
|
|
77
|
-
|
|
78
71
|
/**
|
|
79
72
|
* Read `themeApiUrl` and `themingWidgetVersion` from the project's
|
|
80
|
-
* environment.json at build time.
|
|
73
|
+
* environment.json at build time. Uses the same lookup order as remark-env-vars.ts
|
|
81
74
|
* so both always resolve from the same file.
|
|
82
75
|
*/
|
|
83
76
|
function readThemingEnv(sourcePath: string | undefined, envKey: string): {
|
|
@@ -142,10 +135,6 @@ export interface SiteMetaOptions {
|
|
|
142
135
|
* module and rendered by `DocsLayout.astro`.
|
|
143
136
|
*/
|
|
144
137
|
head?: HeadEntry[];
|
|
145
|
-
/** @deprecated Use `platform` instead. */
|
|
146
|
-
prefetchNav?: boolean;
|
|
147
|
-
/** @deprecated Use `platform: 'appbuilder'` instead. */
|
|
148
|
-
prefetchAppBuilderNav?: boolean;
|
|
149
138
|
}
|
|
150
139
|
|
|
151
140
|
/**
|
|
@@ -188,8 +177,6 @@ export function siteMetaIntegration({
|
|
|
188
177
|
llmsSets = [],
|
|
189
178
|
productLinks = [],
|
|
190
179
|
head = [],
|
|
191
|
-
prefetchNav = false,
|
|
192
|
-
prefetchAppBuilderNav = false,
|
|
193
180
|
}: SiteMetaOptions = {} as SiteMetaOptions): AstroIntegration {
|
|
194
181
|
const llmsMetaMap = docsDir
|
|
195
182
|
? buildLlmsMetaMap(docsDir, sidebar ?? [])
|
|
@@ -201,17 +188,8 @@ export function siteMetaIntegration({
|
|
|
201
188
|
const navVirtualId = 'virtual:docs-template/nav-html';
|
|
202
189
|
const navResolvedId = '\0' + navVirtualId;
|
|
203
190
|
|
|
204
|
-
//
|
|
205
|
-
|
|
206
|
-
const effectivePlatform: PlatformKey | null =
|
|
207
|
-
platform ??
|
|
208
|
-
(prefetchAppBuilderNav ? 'appbuilder' : null) ??
|
|
209
|
-
(prefetchNav ? 'angular' : null);
|
|
210
|
-
|
|
211
|
-
const { navType, navUrl } = getNavConfig(effectivePlatform, navLang);
|
|
212
|
-
|
|
213
|
-
// Navigation buckets for this platform — stripped from ancestor paths during label generation.
|
|
214
|
-
const broadSections = getBroadSectionsForPlatform(effectivePlatform);
|
|
191
|
+
// Navigation buckets for this platform.
|
|
192
|
+
const broadSections = getBroadSectionsForPlatform(platform ?? null);
|
|
215
193
|
// Captured from astro:config:done; used to generate llms.txt content and virtual module.
|
|
216
194
|
let configuredSite = '';
|
|
217
195
|
// Cached virtual module source — built once in astro:config:done after
|
|
@@ -228,6 +206,7 @@ export const sidebar = ${JSON.stringify(sidebar ?? [])};
|
|
|
228
206
|
export const productLinks = ${JSON.stringify(productLinks)};
|
|
229
207
|
export const headEntries = ${JSON.stringify(head ?? [])};
|
|
230
208
|
export const trailingSlash = ${JSON.stringify(config.trailingSlash)};
|
|
209
|
+
export const navLang = ${JSON.stringify(navLang)};
|
|
231
210
|
`;
|
|
232
211
|
},
|
|
233
212
|
'astro:config:setup'({ updateConfig, injectRoute }) {
|
|
@@ -247,19 +226,6 @@ export const trailingSlash = ${JSON.stringify(config.trailingSlash)};
|
|
|
247
226
|
prerender: true,
|
|
248
227
|
});
|
|
249
228
|
|
|
250
|
-
// Vite alias: redirect @astrojs/starlight/components to our compat shim so
|
|
251
|
-
// MDX files that import Starlight UI components continue to build without the
|
|
252
|
-
// Starlight integration being active.
|
|
253
|
-
const compatIndex = fileURLToPath(new URL('./compat/starlight-components/index.ts', import.meta.url));
|
|
254
|
-
updateConfig({
|
|
255
|
-
vite: {
|
|
256
|
-
resolve: {
|
|
257
|
-
alias: [
|
|
258
|
-
{ find: '@astrojs/starlight/components', replacement: compatIndex },
|
|
259
|
-
],
|
|
260
|
-
},
|
|
261
|
-
},
|
|
262
|
-
});
|
|
263
229
|
|
|
264
230
|
// Configure Sass loadPaths so bare `highlight.js/scss/vs2015`
|
|
265
231
|
// imports in the platform theme files resolve from node_modules.
|
|
@@ -285,13 +251,10 @@ export const trailingSlash = ${JSON.stringify(config.trailingSlash)};
|
|
|
285
251
|
if (id === virtualId) return resolvedId;
|
|
286
252
|
if (id === navVirtualId) return navResolvedId;
|
|
287
253
|
},
|
|
288
|
-
|
|
254
|
+
load(id: string) {
|
|
289
255
|
if (id === resolvedId) return siteMetaCode;
|
|
290
256
|
if (id !== navResolvedId) return;
|
|
291
257
|
|
|
292
|
-
// Return cached module code — fetched at most once per build.
|
|
293
|
-
if (_navHtmlCache) return _navHtmlCache;
|
|
294
|
-
|
|
295
258
|
// ── Theming env ──────────────────────────────────────────────
|
|
296
259
|
const envKey = process.env.DOCS_ENV ?? process.env.NODE_ENV ?? 'production';
|
|
297
260
|
const { themeApiUrl, widgetVersion } = readThemingEnv(process.env.DOCS_SOURCE_PATH, envKey);
|
|
@@ -299,93 +262,11 @@ export const trailingSlash = ${JSON.stringify(config.trailingSlash)};
|
|
|
299
262
|
? `https://cdn-na.infragistics.com/igniteui/theming-widget/${widgetVersion}/igniteui-theming-widget.js`
|
|
300
263
|
: '';
|
|
301
264
|
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
let footerHtml = '';
|
|
305
|
-
|
|
306
|
-
// ── IG nav prefetch ──────────────────────────────────────────
|
|
307
|
-
if (navType === 'infragistics' && navUrl) {
|
|
308
|
-
try {
|
|
309
|
-
const res = await fetch(navUrl, {
|
|
310
|
-
credentials: 'omit',
|
|
311
|
-
signal: AbortSignal.timeout(15_000),
|
|
312
|
-
});
|
|
313
|
-
if (res.ok) {
|
|
314
|
-
const html = await res.text();
|
|
315
|
-
const igBase = navLang === 'jp' ? 'https://jp.infragistics.com' : 'https://www.infragistics.com';
|
|
316
|
-
headerHtml = absolutifyNavUrls(stripScripts(extractOuterHtml(html, '<header[^>]+id="header"')), igBase);
|
|
317
|
-
uiFooterHtml = absolutifyNavUrls(stripScripts(extractOuterHtml(html, '<footer[^>]+class="[^"]*\\bui-footer\\b')), igBase);
|
|
318
|
-
footerHtml = absolutifyNavUrls(stripScripts(extractOuterHtml(html, '<footer[^>]+id="footer"')), igBase);
|
|
319
|
-
// Strip the hello-bar promotional strip
|
|
320
|
-
headerHtml = headerHtml.replace(
|
|
321
|
-
/<div[^>]+id="hello-bar"[\s\S]*?<\/div>\s*/i, ''
|
|
322
|
-
);
|
|
323
|
-
} else {
|
|
324
|
-
console.warn(`[docs-template] Navigation fetch returned ${res.status} — falling back to empty markup.`);
|
|
325
|
-
}
|
|
326
|
-
} catch (err: unknown) {
|
|
327
|
-
console.warn(`[docs-template] Could not fetch navigation HTML: ${(err as Error).message} — falling back to empty markup.`);
|
|
328
|
-
}
|
|
329
|
-
}
|
|
330
|
-
|
|
331
|
-
// ── AppBuilder nav prefetch ──────────────────────────────────
|
|
332
|
-
let abHeaderHtml = '';
|
|
333
|
-
let abFooterHtml = '';
|
|
334
|
-
let abFooterUtilsHtml = '';
|
|
335
|
-
let abFooterCopyrightHtml = '';
|
|
336
|
-
let abContactSalesHtml = '';
|
|
337
|
-
|
|
338
|
-
if (navType === 'appbuilder' && navUrl) {
|
|
339
|
-
try {
|
|
340
|
-
const abRes = await fetch(navUrl, {
|
|
341
|
-
credentials: 'omit',
|
|
342
|
-
signal: AbortSignal.timeout(15_000),
|
|
343
|
-
});
|
|
344
|
-
if (abRes.ok) {
|
|
345
|
-
const abRaw = await abRes.text();
|
|
346
|
-
// Endpoint may return JSON { header, footer } or a full HTML page.
|
|
347
|
-
let parsed = false;
|
|
348
|
-
try {
|
|
349
|
-
const data = JSON.parse(abRaw) as { header?: string; footer?: string };
|
|
350
|
-
if (data.header || data.footer) {
|
|
351
|
-
abHeaderHtml = data.header ?? '';
|
|
352
|
-
abFooterHtml = data.footer ?? '';
|
|
353
|
-
parsed = true;
|
|
354
|
-
}
|
|
355
|
-
} catch { /* not JSON — fall through to HTML extraction */ }
|
|
356
|
-
|
|
357
|
-
if (!parsed) {
|
|
358
|
-
abHeaderHtml = extractOuterHtml(abRaw, '<header');
|
|
359
|
-
abFooterHtml = extractOuterHtml(abRaw, '<footer');
|
|
360
|
-
abFooterUtilsHtml = extractOuterHtml(abRaw, '<[a-z][a-z0-9]*[^>]+class="[^"]*\\bfooter-utils\\b');
|
|
361
|
-
abFooterCopyrightHtml = extractOuterHtml(abRaw, '<[a-z][a-z0-9]*[^>]+class="[^"]*\\bfooter-copyright\\b');
|
|
362
|
-
abContactSalesHtml = extractOuterHtml(abRaw, '<[a-z][a-z0-9]*[^>]+id="contactSales"');
|
|
363
|
-
}
|
|
364
|
-
} else {
|
|
365
|
-
console.warn(`[docs-template] AppBuilder nav fetch returned ${abRes.status} — falling back to runtime loading.`);
|
|
366
|
-
}
|
|
367
|
-
} catch (err: unknown) {
|
|
368
|
-
console.warn(`[docs-template] Could not prefetch AppBuilder navigation: ${(err as Error).message} — falling back to runtime loading.`);
|
|
369
|
-
}
|
|
370
|
-
}
|
|
371
|
-
|
|
372
|
-
_navHtmlCache = [
|
|
373
|
-
`export const platform = ${JSON.stringify(effectivePlatform ?? null)};`,
|
|
374
|
-
`export const navLang = ${JSON.stringify(navLang)};`,
|
|
265
|
+
return [
|
|
266
|
+
`export const platform = ${JSON.stringify(platform ?? null)};`,
|
|
375
267
|
`export const themeApiUrl = ${JSON.stringify(themeApiUrl)};`,
|
|
376
268
|
`export const widgetScriptSrc = ${JSON.stringify(widgetScriptSrc)};`,
|
|
377
|
-
`export const prefetched = ${JSON.stringify(!!headerHtml)};`,
|
|
378
|
-
`export const headerHtml = ${JSON.stringify(headerHtml)};`,
|
|
379
|
-
`export const uiFooterHtml = ${JSON.stringify(uiFooterHtml)};`,
|
|
380
|
-
`export const footerHtml = ${JSON.stringify(footerHtml)};`,
|
|
381
|
-
`export const abPrefetched = ${JSON.stringify(!!abHeaderHtml)};`,
|
|
382
|
-
`export const abHeaderHtml = ${JSON.stringify(abHeaderHtml)};`,
|
|
383
|
-
`export const abFooterHtml = ${JSON.stringify(abFooterHtml)};`,
|
|
384
|
-
`export const abFooterUtilsHtml = ${JSON.stringify(abFooterUtilsHtml)};`,
|
|
385
|
-
`export const abFooterCopyrightHtml = ${JSON.stringify(abFooterCopyrightHtml)};`,
|
|
386
|
-
`export const abContactSalesHtml = ${JSON.stringify(abContactSalesHtml)};`,
|
|
387
269
|
].join('\n');
|
|
388
|
-
return _navHtmlCache;
|
|
389
270
|
},
|
|
390
271
|
}],
|
|
391
272
|
},
|
|
@@ -700,17 +581,12 @@ export interface CreateDocsSiteOptions {
|
|
|
700
581
|
productLinks?: ProductLink[];
|
|
701
582
|
/** Extra Astro integrations appended after the built-in ones. */
|
|
702
583
|
integrations?: AstroIntegration[];
|
|
703
|
-
/**
|
|
704
|
-
* @deprecated Starlight has been removed. This option is ignored.
|
|
705
|
-
* Use `head` for extra head entries and `integrations` for extra integrations.
|
|
706
|
-
*/
|
|
707
|
-
starlight?: Record<string, unknown>;
|
|
708
584
|
/** Any remaining keys are spread into `defineConfig` (markdown, image, build, …). */
|
|
709
585
|
[key: string]: unknown;
|
|
710
586
|
}
|
|
711
587
|
|
|
712
588
|
/**
|
|
713
|
-
* Creates a complete Astro config for a
|
|
589
|
+
* Creates a complete Astro config for a docs site.
|
|
714
590
|
*
|
|
715
591
|
* All individual helpers (`buildSidebarFromToc`, `staticImagesIntegration`,
|
|
716
592
|
* `siteMetaIntegration`) remain independently importable for cases that
|
|
@@ -759,7 +635,7 @@ export function createDocsSite(options: CreateDocsSiteOptions = {} as CreateDocs
|
|
|
759
635
|
if (!process.env.DOCS_ENV) {
|
|
760
636
|
process.env.DOCS_ENV = mode;
|
|
761
637
|
}
|
|
762
|
-
// Expose the platform so
|
|
638
|
+
// Expose the platform so plugins can set data-platform on widgets they generate.
|
|
763
639
|
if (platform) {
|
|
764
640
|
process.env.DOCS_PLATFORM = platform;
|
|
765
641
|
}
|
|
@@ -823,11 +699,12 @@ export function createDocsSite(options: CreateDocsSiteOptions = {} as CreateDocs
|
|
|
823
699
|
markdown: {
|
|
824
700
|
...(astroExtra as any).markdown,
|
|
825
701
|
remarkPlugins: [
|
|
826
|
-
|
|
702
|
+
remarkEnvVars,
|
|
703
|
+
remarkMdLinks,
|
|
704
|
+
remarkHtmlTransforms,
|
|
827
705
|
...((astroExtra as any).markdown?.remarkPlugins ?? []),
|
|
828
706
|
],
|
|
829
707
|
rehypePlugins: [
|
|
830
|
-
rehypeCodeView,
|
|
831
708
|
...((astroExtra as any).markdown?.rehypePlugins ?? []),
|
|
832
709
|
],
|
|
833
710
|
},
|
|
@@ -10,7 +10,7 @@ import DocsSubHeader from '../../components/DocsSubHeader/DocsSubHeader.astro';
|
|
|
10
10
|
import DocsBreadcrumb from '../../components/DocsBreadcrumb/DocsBreadcrumb.astro';
|
|
11
11
|
import MobileSidebarToggle from '../../components/MobileSidebarToggle/MobileSidebarToggle.astro';
|
|
12
12
|
import { widgetScriptSrc, platform as virtualPlatform } from 'virtual:docs-template/nav-html';
|
|
13
|
-
import { title as siteTitle, headEntries } from 'virtual:docs-template/site-meta';
|
|
13
|
+
import { title as siteTitle, headEntries, navLang } from 'virtual:docs-template/site-meta';
|
|
14
14
|
import '../../styles/theme.scss';
|
|
15
15
|
import '../../styles/custom.scss';
|
|
16
16
|
import './DocsLayout.scss';
|
|
@@ -64,7 +64,6 @@ type HeadEntry = { tag: string; attrs?: Record<string, string | boolean | undefi
|
|
|
64
64
|
<ClientRouter />
|
|
65
65
|
<script is:inline>
|
|
66
66
|
// Force light theme on load and after every View Transitions swap
|
|
67
|
-
try { localStorage.setItem('starlight-theme', 'light'); } catch (_) {}
|
|
68
67
|
document.documentElement.setAttribute('data-theme', 'light');
|
|
69
68
|
document.addEventListener('astro:after-swap', function () {
|
|
70
69
|
document.documentElement.setAttribute('data-theme', 'light');
|
|
@@ -152,7 +151,7 @@ type HeadEntry = { tag: string; attrs?: Record<string, string | boolean | undefi
|
|
|
152
151
|
</head>
|
|
153
152
|
<body>
|
|
154
153
|
<!-- INFRAGISTICS HEADER/NAVIGATION -->
|
|
155
|
-
{ showGlobalNav && <GlobalNavBar/> }
|
|
154
|
+
{ showGlobalNav && <GlobalNavBar lang={navLang}/> }
|
|
156
155
|
|
|
157
156
|
<!-- MAIN PAGE GRID LAYOUT -->
|
|
158
157
|
<!-- We don't set the CSS grid directly to the body -->
|
|
@@ -195,7 +194,7 @@ type HeadEntry = { tag: string; attrs?: Record<string, string | boolean | undefi
|
|
|
195
194
|
|
|
196
195
|
<!-- Footer is inside the grid so the sidebar's sticky containing block extends through it.
|
|
197
196
|
The JS initSidebarHeights() clamps sidebar max-height to prevent visual overlap. -->
|
|
198
|
-
<GlobalFooter/>
|
|
197
|
+
<GlobalFooter lang={navLang}/>
|
|
199
198
|
</div>
|
|
200
199
|
</body>
|
|
201
200
|
</html>
|
package/src/lib/nav-helpers.ts
CHANGED
|
@@ -10,20 +10,27 @@
|
|
|
10
10
|
* - components/GlobalFooter/GlobalFooter.astro
|
|
11
11
|
*/
|
|
12
12
|
|
|
13
|
-
import {
|
|
13
|
+
import { createRequire } from 'node:module';
|
|
14
14
|
import type { NavLang } from '../platform.ts';
|
|
15
15
|
|
|
16
|
+
// createRequire anchored to this file so it always resolves jsdom from
|
|
17
|
+
// igniteui-astro-components/node_modules, regardless of where the consumer
|
|
18
|
+
// project has its node_modules.
|
|
19
|
+
const _require = createRequire(import.meta.url);
|
|
20
|
+
|
|
16
21
|
// ---------------------------------------------------------------------------
|
|
17
22
|
// Low-level HTML helpers
|
|
18
23
|
// ---------------------------------------------------------------------------
|
|
19
24
|
|
|
20
25
|
/**
|
|
21
26
|
* Strip all <script> tags from an HTML string using a DOM parser.
|
|
22
|
-
*
|
|
23
|
-
*
|
|
24
|
-
*
|
|
27
|
+
*
|
|
28
|
+
* Uses createRequire so Vite/Rollup cannot statically trace the jsdom import —
|
|
29
|
+
* jsdom is resolved at Node runtime and never bundled into the prerender chunk.
|
|
25
30
|
*/
|
|
26
31
|
export function stripScripts(html: string): string {
|
|
32
|
+
// eslint-disable-next-line @typescript-eslint/no-require-imports
|
|
33
|
+
const { JSDOM } = _require('jsdom') as typeof import('jsdom');
|
|
27
34
|
const dom = new JSDOM(html);
|
|
28
35
|
const { document } = dom.window;
|
|
29
36
|
document.querySelectorAll('script').forEach((el: Element) => el.remove());
|
package/src/platform.ts
CHANGED
|
@@ -2,30 +2,23 @@
|
|
|
2
2
|
* platform.ts
|
|
3
3
|
*
|
|
4
4
|
* Central registry of per-platform CDN assets (styles / scripts) and nav
|
|
5
|
-
* endpoint configuration
|
|
6
|
-
* - template/partials/head.tmpl.partial (styles + AppBuilder init script)
|
|
7
|
-
* - template/partials/scripts.tmpl.partial (scripts per platform)
|
|
8
|
-
* - template/conceptual.html.primary.js (platform flag derivation)
|
|
5
|
+
* endpoint configuration.
|
|
9
6
|
*
|
|
10
7
|
* Usage from astro.config.ts:
|
|
11
8
|
* import { getPlatformHead } from './src/platform.ts';
|
|
12
|
-
* // inside
|
|
13
|
-
*
|
|
14
|
-
* Usage from integration.ts:
|
|
15
|
-
* import { getNavConfig } from './platform.ts';
|
|
16
|
-
* const { navType, navUrl } = getNavConfig(platform, navLang);
|
|
9
|
+
* // inside createDocsSite({ head: getPlatformHead('angular', 'en') })
|
|
17
10
|
*/
|
|
18
11
|
|
|
19
12
|
// ---------------------------------------------------------------------------
|
|
20
13
|
// Types
|
|
21
14
|
// ---------------------------------------------------------------------------
|
|
22
15
|
|
|
23
|
-
/** HTML tag names accepted by
|
|
16
|
+
/** HTML tag names accepted by the `head` array. */
|
|
24
17
|
export type HeadTag =
|
|
25
18
|
| 'title' | 'link' | 'style' | 'base'
|
|
26
19
|
| 'meta' | 'script' | 'noscript' | 'template';
|
|
27
20
|
|
|
28
|
-
/** Single entry in
|
|
21
|
+
/** Single entry in the `head` array — tag, attrs, optional content. */
|
|
29
22
|
export type HeadEntry = {
|
|
30
23
|
tag: HeadTag;
|
|
31
24
|
attrs?: Record<string, string | boolean | undefined>;
|
|
@@ -75,8 +68,8 @@ export interface NavConfig {
|
|
|
75
68
|
// ---------------------------------------------------------------------------
|
|
76
69
|
const IG_STYLES: HeadEntry[] = [
|
|
77
70
|
// Bootstrap is wrapped in a CSS cascade layer so its global resets do not
|
|
78
|
-
// bleed into the
|
|
79
|
-
// the top of custom.
|
|
71
|
+
// bleed into the docs theme. The layer priority order is declared at
|
|
72
|
+
// the top of custom.scss: @layer bootstrap
|
|
80
73
|
// Note: @import layer() does not support the `integrity` SRI attribute.
|
|
81
74
|
{
|
|
82
75
|
tag: 'style',
|
|
@@ -116,7 +109,7 @@ const APPBUILDER_STYLES: HeadEntry[] = [
|
|
|
116
109
|
{ tag: 'link', attrs: { rel: 'stylesheet', href: 'https://staging.appbuilder.dev/wp-content/plugins/megamenu-pro/icons/genericons/genericons/genericons.css', media: 'all' } },
|
|
117
110
|
{ tag: 'link', attrs: { rel: 'stylesheet', href: 'https://staging.appbuilder.dev/wp-content/plugins/megamenu-pro/icons/fontawesome6/css/all.min.css', media: 'all' } },
|
|
118
111
|
// Bootstrap v4.4 partials — wrapped in a CSS cascade layer so they don't
|
|
119
|
-
// override the
|
|
112
|
+
// override the docs theme. See custom.scss @layer declaration.
|
|
120
113
|
{
|
|
121
114
|
tag: 'style',
|
|
122
115
|
content: [
|
|
@@ -238,8 +231,8 @@ export const IGDOCS_PLATFORMS: Record<string, PlatformMeta> = {
|
|
|
238
231
|
};
|
|
239
232
|
|
|
240
233
|
/**
|
|
241
|
-
* Returns an array of
|
|
242
|
-
* Pass the result
|
|
234
|
+
* Returns an array of head entries for the given platform.
|
|
235
|
+
* Pass the result to `createDocsSite({ head: getPlatformHead(...) })`.
|
|
243
236
|
*
|
|
244
237
|
* @param platform - Platform identifier.
|
|
245
238
|
* @param lang - Locale — not currently used but kept for API completeness.
|
|
@@ -0,0 +1,110 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Remark plugin: environment variable substitution.
|
|
3
|
+
*
|
|
4
|
+
* Replaces `{environment:key}` tokens in markdown text, link URLs, image URLs,
|
|
5
|
+
* and inline HTML with values from the project's environment.json.
|
|
6
|
+
*
|
|
7
|
+
* Resolution order for environment.json:
|
|
8
|
+
* 1. {DOCS_SOURCE_PATH}/en/environment.json
|
|
9
|
+
* 2. {DOCS_SOURCE_PATH}/environment.json
|
|
10
|
+
* 3. {DOCS_SOURCE_PATH}/../environment.json
|
|
11
|
+
* 4. {DOCS_SOURCE_PATH}/../en/environment.json
|
|
12
|
+
* 5. Fallback: read demosBaseUrl from docConfig.json
|
|
13
|
+
*
|
|
14
|
+
* DOCS_ENV (or NODE_ENV) selects the env block: development | staging | production.
|
|
15
|
+
*/
|
|
16
|
+
|
|
17
|
+
import { visit } from 'unist-util-visit';
|
|
18
|
+
import fs from 'node:fs';
|
|
19
|
+
import path from 'node:path';
|
|
20
|
+
|
|
21
|
+
const ENV_PATTERN = /\{environment:(\w+)\}/g;
|
|
22
|
+
|
|
23
|
+
const DOCCONFIG_PLATFORM_MAP: Record<string, string> = {
|
|
24
|
+
angular: 'Angular',
|
|
25
|
+
react: 'React',
|
|
26
|
+
'web-components': 'WebComponents',
|
|
27
|
+
blazor: 'Blazor',
|
|
28
|
+
};
|
|
29
|
+
|
|
30
|
+
// Lazy-loaded, cached per DOCS_SOURCE_PATH value.
|
|
31
|
+
let _env: Record<string, string> | null = null;
|
|
32
|
+
let _envSourcePath: string | null = null;
|
|
33
|
+
|
|
34
|
+
function loadEnv(): Record<string, string> {
|
|
35
|
+
const currentPath = process.env.DOCS_SOURCE_PATH ?? null;
|
|
36
|
+
if (_env !== null && currentPath === _envSourcePath) return _env;
|
|
37
|
+
_envSourcePath = currentPath;
|
|
38
|
+
_env = null;
|
|
39
|
+
|
|
40
|
+
if (!currentPath) { _env = {}; return _env; }
|
|
41
|
+
const sourceRoot = path.resolve(currentPath);
|
|
42
|
+
const parent = path.dirname(sourceRoot);
|
|
43
|
+
|
|
44
|
+
const candidates = [
|
|
45
|
+
path.join(sourceRoot, 'en', 'environment.json'),
|
|
46
|
+
path.join(sourceRoot, 'environment.json'),
|
|
47
|
+
path.join(parent, 'environment.json'),
|
|
48
|
+
path.join(parent, 'en', 'environment.json'),
|
|
49
|
+
];
|
|
50
|
+
|
|
51
|
+
const envPath = candidates.find(c => fs.existsSync(c));
|
|
52
|
+
|
|
53
|
+
if (!envPath) {
|
|
54
|
+
try {
|
|
55
|
+
const envKey = process.env.DOCS_ENV ?? process.env.NODE_ENV ?? 'production';
|
|
56
|
+
const platform = DOCCONFIG_PLATFORM_MAP[process.env.DOCS_PLATFORM ?? ''] ?? '';
|
|
57
|
+
if (platform) {
|
|
58
|
+
const configPath = path.resolve(process.cwd(), 'docConfig.json');
|
|
59
|
+
const docConfig = JSON.parse(fs.readFileSync(configPath, 'utf-8'));
|
|
60
|
+
const demosUrl: string =
|
|
61
|
+
docConfig[platform]?.samplesBrowsers?.[envKey] ??
|
|
62
|
+
docConfig[platform]?.samplesBrowsers?.['development'] ?? '';
|
|
63
|
+
_env = { dvDemosBaseUrl: demosUrl, demosBaseUrl: demosUrl, infragisticsBaseUrl: 'https://www.infragistics.com' };
|
|
64
|
+
} else {
|
|
65
|
+
_env = {};
|
|
66
|
+
}
|
|
67
|
+
} catch {
|
|
68
|
+
_env = {};
|
|
69
|
+
}
|
|
70
|
+
return _env;
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
try {
|
|
74
|
+
const data = JSON.parse(fs.readFileSync(envPath, 'utf-8'));
|
|
75
|
+
const envKey = process.env.DOCS_ENV ?? process.env.NODE_ENV ?? 'production';
|
|
76
|
+
_env = data[envKey] ?? data.production ?? {};
|
|
77
|
+
} catch {
|
|
78
|
+
_env = {};
|
|
79
|
+
}
|
|
80
|
+
return _env!;
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
/** Replace all `{environment:key}` tokens in a string. Exported for use by other modules. */
|
|
84
|
+
export function replaceEnvVars(str: string): string {
|
|
85
|
+
if (!str || typeof str !== 'string') return str;
|
|
86
|
+
const env = loadEnv();
|
|
87
|
+
return str.replace(ENV_PATTERN, (_match, key) => env[key] ?? `{environment:${key}}`);
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
/** Remark plugin that substitutes `{environment:key}` tokens in the markdown AST. */
|
|
91
|
+
export function remarkEnvVars() {
|
|
92
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
93
|
+
return (tree: any) => {
|
|
94
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
95
|
+
visit(tree, (node: any) => {
|
|
96
|
+
if (node.type === 'text' && node.value) {
|
|
97
|
+
node.value = replaceEnvVars(node.value);
|
|
98
|
+
}
|
|
99
|
+
if (node.type === 'link' && node.url) {
|
|
100
|
+
node.url = replaceEnvVars(node.url);
|
|
101
|
+
}
|
|
102
|
+
if (node.type === 'image' && node.url) {
|
|
103
|
+
node.url = replaceEnvVars(node.url);
|
|
104
|
+
}
|
|
105
|
+
if (node.type === 'html' && node.value) {
|
|
106
|
+
node.value = replaceEnvVars(node.value);
|
|
107
|
+
}
|
|
108
|
+
});
|
|
109
|
+
};
|
|
110
|
+
}
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Remark plugin: inline HTML transforms.
|
|
3
|
+
*
|
|
4
|
+
* Handles legacy HTML patterns in markdown content:
|
|
5
|
+
* - `<div class="divider--half"></div>` → `<hr/>`
|
|
6
|
+
* - Normalizes code block language identifiers to lowercase
|
|
7
|
+
*/
|
|
8
|
+
|
|
9
|
+
import { visit } from 'unist-util-visit';
|
|
10
|
+
|
|
11
|
+
const DIVIDER_PATTERN = /<div\s+class="divider--half"\s*>\s*<\/div>/g;
|
|
12
|
+
const IMG_SRC_PATTERN = /src="(\.\.\/)+images\//g;
|
|
13
|
+
|
|
14
|
+
/** Remark plugin that transforms legacy HTML patterns in the AST. */
|
|
15
|
+
export function remarkHtmlTransforms() {
|
|
16
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
17
|
+
return (tree: any) => {
|
|
18
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
19
|
+
visit(tree, (node: any) => {
|
|
20
|
+
// Inline HTML: divider → hr, relative img src → root-relative
|
|
21
|
+
if (node.type === 'html' && node.value) {
|
|
22
|
+
node.value = (node.value as string).replace(DIVIDER_PATTERN, '<hr/>');
|
|
23
|
+
node.value = (node.value as string).replace(IMG_SRC_PATTERN, 'src="/images/');
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
// Code blocks: normalize language to lowercase
|
|
27
|
+
if (node.type === 'code' && node.lang) {
|
|
28
|
+
node.lang = (node.lang as string).toLowerCase();
|
|
29
|
+
}
|
|
30
|
+
});
|
|
31
|
+
};
|
|
32
|
+
}
|
|
@@ -0,0 +1,75 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Remark plugin: rewrite relative .md links to Astro-compatible URLs.
|
|
3
|
+
*
|
|
4
|
+
* Transforms `[label](./some-page.md)` or `[label](../folder/page.md#section)`
|
|
5
|
+
* into root-relative URLs like `/products/.../some-page/` (with DOCS_BASE prepended).
|
|
6
|
+
*
|
|
7
|
+
* Also prepends DOCS_BASE to bare root-relative internal links (e.g. `/grids/grid/...`)
|
|
8
|
+
* that are already absolute but missing the site base path.
|
|
9
|
+
*/
|
|
10
|
+
|
|
11
|
+
import { visit } from 'unist-util-visit';
|
|
12
|
+
import path from 'node:path';
|
|
13
|
+
|
|
14
|
+
/**
|
|
15
|
+
* Resolve a relative .md link to an absolute Astro URL.
|
|
16
|
+
* Non-relative, non-.md, and external links are returned unchanged.
|
|
17
|
+
*/
|
|
18
|
+
function rewriteMdLink(url: string, filePath: string, docsDir: string): string {
|
|
19
|
+
if (!url) return url;
|
|
20
|
+
if (
|
|
21
|
+
url.startsWith('http://') || url.startsWith('https://') ||
|
|
22
|
+
url.startsWith('/') || url.startsWith('#') || url.startsWith('mailto:')
|
|
23
|
+
) return url;
|
|
24
|
+
|
|
25
|
+
const hashIdx = url.indexOf('#');
|
|
26
|
+
const qIdx = url.indexOf('?');
|
|
27
|
+
const splitAt = hashIdx !== -1 ? hashIdx : qIdx !== -1 ? qIdx : -1;
|
|
28
|
+
let mdPath = splitAt !== -1 ? url.slice(0, splitAt) : url;
|
|
29
|
+
const suffix = splitAt !== -1 ? url.slice(splitAt) : '';
|
|
30
|
+
|
|
31
|
+
if (!mdPath.endsWith('.md')) return url;
|
|
32
|
+
|
|
33
|
+
const fileDir = path.dirname(filePath);
|
|
34
|
+
const resolved = path.resolve(fileDir, mdPath);
|
|
35
|
+
const rel = path.relative(docsDir, resolved).replace(/\\/g, '/');
|
|
36
|
+
const slug = rel.endsWith('.md') ? rel.slice(0, -3) : rel;
|
|
37
|
+
|
|
38
|
+
const docsBase = (process.env.DOCS_BASE ?? '').replace(/\/$/, '');
|
|
39
|
+
return docsBase + '/' + slug.toLowerCase() + '/' + suffix;
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
/** Remark plugin that rewrites relative .md links, prepends DOCS_BASE, and fixes relative image paths. */
|
|
43
|
+
export function remarkMdLinks() {
|
|
44
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
45
|
+
return (tree: any, file: any) => {
|
|
46
|
+
const filePath = (file.path as string) ?? '';
|
|
47
|
+
const docsDir = process.env.DOCS_SOURCE_PATH
|
|
48
|
+
? path.resolve(process.env.DOCS_SOURCE_PATH)
|
|
49
|
+
: (filePath ? path.dirname(filePath) : '');
|
|
50
|
+
|
|
51
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
52
|
+
visit(tree, (node: any) => {
|
|
53
|
+
if (node.type === 'link' && node.url) {
|
|
54
|
+
node.url = rewriteMdLink(node.url as string, filePath, docsDir);
|
|
55
|
+
|
|
56
|
+
// Prepend DOCS_BASE to root-relative internal links not already prefixed.
|
|
57
|
+
const docsBase = (process.env.DOCS_BASE ?? '').replace(/\/$/, '');
|
|
58
|
+
if (
|
|
59
|
+
docsBase &&
|
|
60
|
+
(node.url as string).startsWith('/') &&
|
|
61
|
+
!(node.url as string).startsWith('//') &&
|
|
62
|
+
!(node.url as string).startsWith(docsBase + '/')
|
|
63
|
+
) {
|
|
64
|
+
node.url = docsBase + (node.url as string);
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
// Rewrite relative `../images/` paths in markdown image nodes to root-relative `/images/`.
|
|
69
|
+
// Generated MDX files may contain relative image references that Vite cannot resolve.
|
|
70
|
+
if (node.type === 'image' && node.url) {
|
|
71
|
+
node.url = (node.url as string).replace(/^(\.\.\/)+images\//, '/images/');
|
|
72
|
+
}
|
|
73
|
+
});
|
|
74
|
+
};
|
|
75
|
+
}
|
|
@@ -11,8 +11,6 @@
|
|
|
11
11
|
* – Live-editing footer (StackBlitz / CodeSandbox)
|
|
12
12
|
*
|
|
13
13
|
* Selector: `.code-view[data-platform]`
|
|
14
|
-
* This distinguishes pre-rendered Sample.astro widgets from `.ig-code-view`
|
|
15
|
-
* elements that come from the docfx pipeline (handled by code-view.js).
|
|
16
14
|
*/
|
|
17
15
|
|
|
18
16
|
// ─── Constants ────────────────────────────────────────────────────────────────
|