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/sidebar.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* sidebar.ts
|
|
3
3
|
*
|
|
4
|
-
* Builds
|
|
4
|
+
* Builds the docs sidebar from a JSON TOC file.
|
|
5
5
|
* Source-agnostic: consuming repos pass their own paths.
|
|
6
6
|
*
|
|
7
7
|
* Usage in a consuming repo's astro.config.ts:
|
|
@@ -9,7 +9,7 @@
|
|
|
9
9
|
* import { buildSidebarFromToc } from 'docs-template/sidebar';
|
|
10
10
|
*
|
|
11
11
|
* const sidebar = buildSidebarFromToc({
|
|
12
|
-
* tocPath: './node_modules/my-docs-source/toc.
|
|
12
|
+
* tocPath: './node_modules/my-docs-source/toc.json',
|
|
13
13
|
* docsDir: './node_modules/my-docs-source/en/components',
|
|
14
14
|
* // exclude: [/^internal\//], // optional extra exclude patterns
|
|
15
15
|
* });
|
|
@@ -17,7 +17,6 @@
|
|
|
17
17
|
|
|
18
18
|
import fs from 'node:fs';
|
|
19
19
|
import path from 'node:path';
|
|
20
|
-
import * as yaml from 'js-yaml';
|
|
21
20
|
import type { SidebarEntry, SidebarGroup, SidebarLink } from './lib/sidebar/types';
|
|
22
21
|
|
|
23
22
|
// Re-export so consumers (astro.config.ts in child sites) can import the
|
|
@@ -102,7 +101,7 @@ function convertTocItem(
|
|
|
102
101
|
if (item.href) {
|
|
103
102
|
if (!docExists(docsDir, item.href, exclude)) return null;
|
|
104
103
|
const entry: SidebarLink = { label: item.name, slug: hrefToSlug(item.href) };
|
|
105
|
-
// Status badge — only one slot available
|
|
104
|
+
// Status badge — only one slot available, priority order:
|
|
106
105
|
if (item.new) entry.badge = { text: 'New', variant: 'success' };
|
|
107
106
|
else if (item.preview) entry.badge = { text: 'Preview', variant: 'caution' };
|
|
108
107
|
else if (item.updated) entry.badge = { text: 'Updated', variant: 'note' };
|
|
@@ -124,7 +123,7 @@ function convertTocItem(
|
|
|
124
123
|
// ---------------------------------------------------------------------------
|
|
125
124
|
|
|
126
125
|
export interface BuildSidebarFromTocOptions {
|
|
127
|
-
/** Absolute path to the TOC file (.
|
|
126
|
+
/** Absolute path to the TOC file (.json). */
|
|
128
127
|
tocPath: string;
|
|
129
128
|
/** Absolute path to the Markdown docs directory. */
|
|
130
129
|
docsDir: string;
|
|
@@ -133,12 +132,12 @@ export interface BuildSidebarFromTocOptions {
|
|
|
133
132
|
}
|
|
134
133
|
|
|
135
134
|
/**
|
|
136
|
-
* Reads a
|
|
135
|
+
* Reads a JSON TOC file and converts it to a sidebar array.
|
|
137
136
|
*/
|
|
138
137
|
export function buildSidebarFromToc({ tocPath, docsDir, exclude = [] }: BuildSidebarFromTocOptions): SidebarEntry[] {
|
|
139
138
|
if (!tocPath || !fs.existsSync(tocPath)) return [];
|
|
140
139
|
const tocRaw = fs.readFileSync(tocPath, 'utf-8');
|
|
141
|
-
const tocItems =
|
|
140
|
+
const tocItems: TocItem[] = JSON.parse(tocRaw);
|
|
142
141
|
|
|
143
142
|
const sidebar: SidebarEntry[] = [];
|
|
144
143
|
let currentGroup: SidebarGroup | null = null;
|
package/src/virtual-modules.d.ts
CHANGED
|
@@ -12,6 +12,7 @@ declare global {
|
|
|
12
12
|
declare module 'virtual:docs-template/site-meta' {
|
|
13
13
|
export const sidebar: { label: string; slug?: string; items?: unknown[] }[];
|
|
14
14
|
export const title: string;
|
|
15
|
+
export const navLang: import('./platform.ts').NavLang;
|
|
15
16
|
/** Cross-product navigation links for the DocsSubHeader. */
|
|
16
17
|
export const productLinks: Array<{
|
|
17
18
|
label: string;
|
|
@@ -28,21 +29,8 @@ declare module 'virtual:docs-template/site-meta' {
|
|
|
28
29
|
export const trailingSlash: 'always' | 'never' | 'ignore';
|
|
29
30
|
}
|
|
30
31
|
|
|
31
|
-
import type { NavLang, NavTheme } from './platform.ts';
|
|
32
|
-
|
|
33
32
|
declare module 'virtual:docs-template/nav-html' {
|
|
34
33
|
export const platform: 'igniteui' | 'angular' | 'react' | 'blazor' | 'web-components' | 'slingshot' | 'appbuilder' | null;
|
|
35
|
-
export const navLang: NavLang;
|
|
36
34
|
export const themeApiUrl: string;
|
|
37
35
|
export const widgetScriptSrc: string;
|
|
38
|
-
export const prefetched: boolean;
|
|
39
|
-
export const headerHtml: string;
|
|
40
|
-
export const uiFooterHtml: string;
|
|
41
|
-
export const footerHtml: string;
|
|
42
|
-
export const abPrefetched: boolean;
|
|
43
|
-
export const abHeaderHtml: string;
|
|
44
|
-
export const abFooterHtml: string;
|
|
45
|
-
export const abFooterUtilsHtml: string;
|
|
46
|
-
export const abFooterCopyrightHtml: string;
|
|
47
|
-
export const abContactSalesHtml: string;
|
|
48
36
|
}
|
|
@@ -1,368 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Remark plugin that transforms docfx-specific markdown syntax into
|
|
3
|
-
* standard HTML / markdown that Starlight can render.
|
|
4
|
-
*
|
|
5
|
-
* Handles:
|
|
6
|
-
* 1. {environment:...} variable substitution in text, links, and raw HTML
|
|
7
|
-
* 2. <code-view> elements -> .ig-code-view placeholder divs (enhanced by code-view.js)
|
|
8
|
-
* 3. <div class="divider--half"></div> -> <hr>
|
|
9
|
-
* 4. Relative .md link rewriting for Astro trailing-slash URLs
|
|
10
|
-
*/
|
|
11
|
-
|
|
12
|
-
import { visit } from 'unist-util-visit';
|
|
13
|
-
import fs from 'node:fs';
|
|
14
|
-
import path from 'node:path';
|
|
15
|
-
|
|
16
|
-
// ENV is loaded lazily the first time replaceEnvVars() is called — NOT at
|
|
17
|
-
// module load time. Module-level code runs while the Astro config is being
|
|
18
|
-
// evaluated, before createDocsSite() has had a chance to set DOCS_SOURCE_PATH.
|
|
19
|
-
// Deferring the load ensures we read the correct environment.json for the
|
|
20
|
-
// active project (Angular, Blazor, React, WC, …).
|
|
21
|
-
let _ENV: Record<string, string> | null = null;
|
|
22
|
-
let _envSourcePath: string | null = null; // tracks which DOCS_SOURCE_PATH was used
|
|
23
|
-
|
|
24
|
-
function loadEnv(): Record<string, string> {
|
|
25
|
-
const currentPath = process.env.DOCS_SOURCE_PATH ?? null;
|
|
26
|
-
// Re-load if the source path changed (e.g. two projects built in the same process)
|
|
27
|
-
if (_ENV !== null && currentPath === _envSourcePath) return _ENV as Record<string, string>;
|
|
28
|
-
_envSourcePath = currentPath;
|
|
29
|
-
_ENV = null;
|
|
30
|
-
|
|
31
|
-
if (!process.env.DOCS_SOURCE_PATH) { _ENV = {}; return _ENV as Record<string, string>; }
|
|
32
|
-
const sourceRoot = path.resolve(process.env.DOCS_SOURCE_PATH);
|
|
33
|
-
|
|
34
|
-
// Search order:
|
|
35
|
-
// 1. {docsDir}/en/environment.json — docfx repo layout
|
|
36
|
-
// 2. {docsDir}/environment.json — flat layout
|
|
37
|
-
// 3. {docsDir}/../environment.json — xplat layout: docsDir = dist/{P}/{lang}/components,
|
|
38
|
-
// environment.json lives one level up
|
|
39
|
-
// 4. {docsDir}/../en/environment.json
|
|
40
|
-
const parent = path.dirname(sourceRoot);
|
|
41
|
-
const candidates = [
|
|
42
|
-
path.join(sourceRoot, 'en', 'environment.json'),
|
|
43
|
-
path.join(sourceRoot, 'environment.json'),
|
|
44
|
-
path.join(parent, 'environment.json'),
|
|
45
|
-
path.join(parent, 'en', 'environment.json'),
|
|
46
|
-
];
|
|
47
|
-
|
|
48
|
-
const envPath = candidates.find(c => fs.existsSync(c));
|
|
49
|
-
if (!envPath) { _ENV = {}; return _ENV; }
|
|
50
|
-
|
|
51
|
-
try {
|
|
52
|
-
const envData = JSON.parse(fs.readFileSync(envPath, 'utf-8'));
|
|
53
|
-
// DOCS_ENV overrides explicitly (useful for staging builds).
|
|
54
|
-
// Otherwise fall back to NODE_ENV ('development' | 'production').
|
|
55
|
-
// Matches environment.json keys: development / staging / production.
|
|
56
|
-
const envKey = process.env.DOCS_ENV ?? process.env.NODE_ENV ?? 'production';
|
|
57
|
-
_ENV = envData[envKey] ?? envData.production ?? {};
|
|
58
|
-
} catch {
|
|
59
|
-
_ENV = {};
|
|
60
|
-
}
|
|
61
|
-
|
|
62
|
-
return _ENV as Record<string, string>;
|
|
63
|
-
}
|
|
64
|
-
|
|
65
|
-
const ENV_PATTERN = /\{environment:(\w+)\}/g;
|
|
66
|
-
|
|
67
|
-
/**
|
|
68
|
-
* Rewrite a relative .md link to a root-relative Astro URL.
|
|
69
|
-
* Absolute, root-relative, fragment-only, and protocol links are left untouched.
|
|
70
|
-
* @param url - Raw link URL from the markdown AST.
|
|
71
|
-
* @param filePath - Absolute path of the current .md file.
|
|
72
|
-
* @param docsDir - Absolute path to the docs root (DOCS_SOURCE_PATH).
|
|
73
|
-
*/
|
|
74
|
-
function rewriteMdLink(url: string, filePath: string, docsDir: string): string {
|
|
75
|
-
if (!url) return url;
|
|
76
|
-
if (
|
|
77
|
-
url.startsWith('http://') || url.startsWith('https://') ||
|
|
78
|
-
url.startsWith('/') || url.startsWith('#') || url.startsWith('mailto:')
|
|
79
|
-
) return url;
|
|
80
|
-
|
|
81
|
-
// Separate path from fragment / query-string suffix.
|
|
82
|
-
const hashIdx = url.indexOf('#');
|
|
83
|
-
const qIdx = url.indexOf('?');
|
|
84
|
-
const splitAt = hashIdx !== -1 ? hashIdx : qIdx !== -1 ? qIdx : -1;
|
|
85
|
-
let mdPath = splitAt !== -1 ? url.slice(0, splitAt) : url;
|
|
86
|
-
const suffix = splitAt !== -1 ? url.slice(splitAt) : '';
|
|
87
|
-
|
|
88
|
-
if (!mdPath.endsWith('.md')) return url;
|
|
89
|
-
|
|
90
|
-
// Resolve the link relative to the current file's directory.
|
|
91
|
-
const fileDir = path.dirname(filePath);
|
|
92
|
-
const resolved = path.resolve(fileDir, mdPath);
|
|
93
|
-
|
|
94
|
-
// Compute the slug: path relative to docsDir, forward slashes, no .md extension.
|
|
95
|
-
const rel = path.relative(docsDir, resolved).replace(/\\/g, '/');
|
|
96
|
-
const slug = rel.endsWith('.md') ? rel.slice(0, -3) : rel;
|
|
97
|
-
|
|
98
|
-
// Return a URL with the site base prepended so links remain correct when
|
|
99
|
-
// the site is mounted at a sub-path (e.g. /docs-react-new/).
|
|
100
|
-
// DOCS_BASE is set by createDocsSite() in integration.ts; it is empty in dev mode.
|
|
101
|
-
const docsBase = (process.env.DOCS_BASE ?? '').replace(/\/$/, '');
|
|
102
|
-
return docsBase + '/' + slug.toLowerCase() + '/' + suffix;
|
|
103
|
-
}
|
|
104
|
-
|
|
105
|
-
export function replaceEnvVars(str: string): string {
|
|
106
|
-
if (!str || typeof str !== 'string') return str;
|
|
107
|
-
const env = loadEnv();
|
|
108
|
-
return str.replace(ENV_PATTERN, (_match, key) => env[key] ?? `{environment:${key}}`);
|
|
109
|
-
}
|
|
110
|
-
|
|
111
|
-
/**
|
|
112
|
-
* Build the pre-rendered widget HTML shell (matches the Sample.astro structure).
|
|
113
|
-
* Picked up at runtime by sample-widget.ts via `.code-view[data-platform]`.
|
|
114
|
-
*/
|
|
115
|
-
function buildWidgetHtml(
|
|
116
|
-
src: string,
|
|
117
|
-
demosBase: string,
|
|
118
|
-
githubSrc: string,
|
|
119
|
-
height: string,
|
|
120
|
-
alt: string,
|
|
121
|
-
platform: string,
|
|
122
|
-
): string {
|
|
123
|
-
const widgetId = 'cw' + src.replace(/[^a-z0-9]/gi, '-');
|
|
124
|
-
const tabId = `${widgetId}-example`;
|
|
125
|
-
const safeAlt = alt.replace(/"/g, '"');
|
|
126
|
-
return (
|
|
127
|
-
`<div class="code-view" id="${widgetId}"` +
|
|
128
|
-
` data-iframe-src="${src}"` +
|
|
129
|
-
(demosBase ? ` data-demos-base-url="${demosBase}"` : '') +
|
|
130
|
-
(githubSrc ? ` data-github-src="${githubSrc}"` : '') +
|
|
131
|
-
` data-platform="${platform}">` +
|
|
132
|
-
`<div class="code-view-navbar">` +
|
|
133
|
-
`<div class="code-view-tab code-view-tab--active" data-tab-id="${tabId}">EXAMPLE</div>` +
|
|
134
|
-
`<span class="fs-button-container" title="Expand to fullscreen"></span>` +
|
|
135
|
-
`</div>` +
|
|
136
|
-
`<div class="code-views-container">` +
|
|
137
|
-
`<div id="${tabId}" class="sample-container code-view-tab-content loading" style="height: ${height}">` +
|
|
138
|
-
`<iframe data-src="${src}" title="${safeAlt}" style="width: 100%; height: 100%;" frameborder="0" seamless=""></iframe>` +
|
|
139
|
-
`</div>` +
|
|
140
|
-
`</div>` +
|
|
141
|
-
`</div>`
|
|
142
|
-
);
|
|
143
|
-
}
|
|
144
|
-
|
|
145
|
-
/**
|
|
146
|
-
* Transform <code-view ...> ... </code-view> raw HTML blocks into the
|
|
147
|
-
* pre-rendered widget shell consumed by sample-widget.ts at runtime.
|
|
148
|
-
*/
|
|
149
|
-
function transformCodeView(html: string): string {
|
|
150
|
-
return html.replace(
|
|
151
|
-
/<code-view\s+([\s\S]*?)>\s*(?:<\/code-view>)?/g,
|
|
152
|
-
(_match, attrs: string) => {
|
|
153
|
-
const stackblitzMatch = attrs.match(/stackblitz="([^"]*)"/);
|
|
154
|
-
const codesandboxMatch = attrs.match(/codesandbox="([^"]*)"/);
|
|
155
|
-
const srcMatch = attrs.match(/iframe-src="([^"]*)"/);
|
|
156
|
-
const demosBaseMatch = attrs.match(/data-demos-base-url="([^"]*)"/);
|
|
157
|
-
const githubSrcMatch = attrs.match(/github-src="([^"]*)"/);
|
|
158
|
-
const heightMatch = attrs.match(/style="height:\s*(\d+px)"/);
|
|
159
|
-
const altMatch = attrs.match(/alt="([^"]*)"/);
|
|
160
|
-
const height = heightMatch ? heightMatch[1] : '400px';
|
|
161
|
-
const alt = altMatch ? altMatch[1] : 'Demo';
|
|
162
|
-
|
|
163
|
-
// Explicit StackBlitz embed (stackblitz="<project-or-url>")
|
|
164
|
-
if (stackblitzMatch) {
|
|
165
|
-
const project = replaceEnvVars(stackblitzMatch[1]);
|
|
166
|
-
const embedUrl = project.startsWith('http')
|
|
167
|
-
? project
|
|
168
|
-
: `https://stackblitz.com/edit/${project}?embed=1&file=src/app/app.component.ts`;
|
|
169
|
-
return `<iframe src="${embedUrl}" style="width:100%;height:${height};border:1px solid #e5e7eb;border-radius:8px;" title="${alt} (StackBlitz)" loading="lazy" allow="accelerometer; ambient-light-sensor; camera; encrypted-media; geolocation; gyroscope; hid; microphone; midi; payment; usb; vr; xr-spatial-tracking" sandbox="allow-forms allow-modals allow-popups allow-presentation allow-same-origin allow-scripts"></iframe>`;
|
|
170
|
-
}
|
|
171
|
-
|
|
172
|
-
// Explicit CodeSandbox embed (codesandbox="<project-or-url>")
|
|
173
|
-
if (codesandboxMatch) {
|
|
174
|
-
const project = replaceEnvVars(codesandboxMatch[1]);
|
|
175
|
-
const embedUrl = project.startsWith('http')
|
|
176
|
-
? project
|
|
177
|
-
: `https://codesandbox.io/embed/${project}?fontsize=14&hidenavigation=1&theme=light`;
|
|
178
|
-
return `<iframe src="${embedUrl}" style="width:100%;height:${height};border:1px solid #e5e7eb;border-radius:8px;" title="${alt} (CodeSandbox)" loading="lazy" allow="accelerometer; ambient-light-sensor; camera; encrypted-media; geolocation; gyroscope; hid; microphone; midi; payment; usb; vr; xr-spatial-tracking" sandbox="allow-forms allow-modals allow-popups allow-presentation allow-same-origin allow-scripts"></iframe>`;
|
|
179
|
-
}
|
|
180
|
-
|
|
181
|
-
// Standard docfx code-view with iframe-src + data-demos-base-url.
|
|
182
|
-
// Output the pre-rendered widget shell; sample-widget.ts activates it at runtime.
|
|
183
|
-
if (srcMatch) {
|
|
184
|
-
const src = replaceEnvVars(srcMatch[1]);
|
|
185
|
-
if (!src || src.includes('{environment:')) return ''; // env var not resolved
|
|
186
|
-
const demosBaseUrl = demosBaseMatch ? replaceEnvVars(demosBaseMatch[1]) : '';
|
|
187
|
-
const githubSrc = githubSrcMatch ? githubSrcMatch[1] : '';
|
|
188
|
-
const platform = process.env.DOCS_PLATFORM || 'angular';
|
|
189
|
-
return buildWidgetHtml(src, demosBaseUrl, githubSrc, height, alt, platform);
|
|
190
|
-
}
|
|
191
|
-
|
|
192
|
-
return '';
|
|
193
|
-
}
|
|
194
|
-
);
|
|
195
|
-
}
|
|
196
|
-
|
|
197
|
-
/**
|
|
198
|
-
* Transform <div class="divider--half"></div> into <hr>
|
|
199
|
-
*/
|
|
200
|
-
function transformDividers(html: string): string {
|
|
201
|
-
return html.replace(/<div\s+class="divider--half"\s*>\s*<\/div>/g, '<hr/>');
|
|
202
|
-
}
|
|
203
|
-
|
|
204
|
-
function strVal(v: unknown): string {
|
|
205
|
-
return typeof v === 'string' ? v : Array.isArray(v) ? v.join(' ') : String(v ?? '');
|
|
206
|
-
}
|
|
207
|
-
|
|
208
|
-
/**
|
|
209
|
-
* Rehype plugin — transforms <code-view> elements into the pre-rendered widget shell.
|
|
210
|
-
*
|
|
211
|
-
* Handles two HAST representations depending on what's in the pipeline:
|
|
212
|
-
*
|
|
213
|
-
* 1. `element` nodes (tagName === 'code-view') — produced when rehype-raw is
|
|
214
|
-
* present and re-parses raw HTML fragments into proper HAST elements.
|
|
215
|
-
*
|
|
216
|
-
* 2. `raw` string nodes — produced when rehype-raw is NOT in the pipeline
|
|
217
|
-
* (e.g. Astro content-collection .md files). In that case multiline
|
|
218
|
-
* <code-view> blocks are opaque raw strings; we run the same regex
|
|
219
|
-
* transformer used in the remark stage.
|
|
220
|
-
*/
|
|
221
|
-
export function rehypeCodeView() {
|
|
222
|
-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
223
|
-
return (tree: any) => {
|
|
224
|
-
// ── 1. element nodes (after rehype-raw) ──────────────────────────────────
|
|
225
|
-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
226
|
-
visit(tree, 'element', (node: any) => {
|
|
227
|
-
if (node.tagName !== 'code-view') return;
|
|
228
|
-
|
|
229
|
-
const p = node.properties || {};
|
|
230
|
-
|
|
231
|
-
// HAST converts hyphenated attributes to camelCase via property-information.
|
|
232
|
-
const iframeSrc = strVal(p.iframeSrc ?? p['iframe-src'] ?? '');
|
|
233
|
-
const demosBase = strVal(p.dataDemosBaseUrl ?? p['data-demos-base-url'] ?? '');
|
|
234
|
-
const githubSrc = strVal(p.githubSrc ?? p['github-src'] ?? '');
|
|
235
|
-
const styleStr = strVal(p.style ?? '');
|
|
236
|
-
const alt = strVal(p.alt ?? 'Demo');
|
|
237
|
-
|
|
238
|
-
const src = replaceEnvVars(iframeSrc);
|
|
239
|
-
const baseUrl = replaceEnvVars(demosBase);
|
|
240
|
-
|
|
241
|
-
if (!src || src.includes('{environment:')) return;
|
|
242
|
-
|
|
243
|
-
const heightMatch = styleStr.match(/height:\s*(\d+\s*px)/i);
|
|
244
|
-
const height = heightMatch ? heightMatch[1].replace(/\s+/, '') : '400px';
|
|
245
|
-
const platform = process.env.DOCS_PLATFORM || 'angular';
|
|
246
|
-
const widgetId = 'cw' + src.replace(/[^a-z0-9]/gi, '-');
|
|
247
|
-
const tabId = `${widgetId}-example`;
|
|
248
|
-
|
|
249
|
-
node.tagName = 'div';
|
|
250
|
-
node.properties = {
|
|
251
|
-
className: ['code-view'],
|
|
252
|
-
id: widgetId,
|
|
253
|
-
'data-iframe-src': src,
|
|
254
|
-
'data-platform': platform,
|
|
255
|
-
...(baseUrl ? { 'data-demos-base-url': baseUrl } : {}),
|
|
256
|
-
...(githubSrc ? { 'data-github-src': githubSrc } : {}),
|
|
257
|
-
};
|
|
258
|
-
node.children = [
|
|
259
|
-
{
|
|
260
|
-
type: 'element', tagName: 'div',
|
|
261
|
-
properties: { className: ['code-view-navbar'] },
|
|
262
|
-
children: [
|
|
263
|
-
{
|
|
264
|
-
type: 'element', tagName: 'div',
|
|
265
|
-
properties: { className: ['code-view-tab', 'code-view-tab--active'], 'data-tab-id': tabId },
|
|
266
|
-
children: [{ type: 'text', value: 'EXAMPLE' }],
|
|
267
|
-
},
|
|
268
|
-
{
|
|
269
|
-
type: 'element', tagName: 'span',
|
|
270
|
-
properties: { className: ['fs-button-container'], title: 'Expand to fullscreen' },
|
|
271
|
-
children: [],
|
|
272
|
-
},
|
|
273
|
-
],
|
|
274
|
-
},
|
|
275
|
-
{
|
|
276
|
-
type: 'element', tagName: 'div',
|
|
277
|
-
properties: { className: ['code-views-container'] },
|
|
278
|
-
children: [
|
|
279
|
-
{
|
|
280
|
-
type: 'element', tagName: 'div',
|
|
281
|
-
properties: {
|
|
282
|
-
id: tabId,
|
|
283
|
-
className: ['sample-container', 'code-view-tab-content', 'loading'],
|
|
284
|
-
style: `height: ${height}`,
|
|
285
|
-
},
|
|
286
|
-
children: [
|
|
287
|
-
{
|
|
288
|
-
type: 'element', tagName: 'iframe',
|
|
289
|
-
properties: {
|
|
290
|
-
'data-src': src,
|
|
291
|
-
title: alt,
|
|
292
|
-
style: 'width: 100%; height: 100%;',
|
|
293
|
-
frameBorder: '0',
|
|
294
|
-
seamless: '',
|
|
295
|
-
},
|
|
296
|
-
children: [],
|
|
297
|
-
},
|
|
298
|
-
],
|
|
299
|
-
},
|
|
300
|
-
],
|
|
301
|
-
},
|
|
302
|
-
];
|
|
303
|
-
});
|
|
304
|
-
|
|
305
|
-
// ── 2. raw string nodes (no rehype-raw in pipeline) ──────────────────────
|
|
306
|
-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
307
|
-
visit(tree, 'raw', (node: any) => {
|
|
308
|
-
if (!node.value || !node.value.includes('<code-view')) return;
|
|
309
|
-
const updated = transformCodeView(replaceEnvVars(node.value as string));
|
|
310
|
-
if (updated !== node.value) node.value = updated;
|
|
311
|
-
});
|
|
312
|
-
};
|
|
313
|
-
}
|
|
314
|
-
|
|
315
|
-
export function remarkDocfx() {
|
|
316
|
-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
317
|
-
return (tree: any, file: any) => {
|
|
318
|
-
const filePath = (file.path as string) ?? '';
|
|
319
|
-
const docsDir = process.env.DOCS_SOURCE_PATH
|
|
320
|
-
? path.resolve(process.env.DOCS_SOURCE_PATH)
|
|
321
|
-
: (filePath ? path.dirname(filePath) : '');
|
|
322
|
-
// 1. Walk the AST and replace environment variables in text/links/html
|
|
323
|
-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
324
|
-
visit(tree, (node: any) => {
|
|
325
|
-
// Text nodes
|
|
326
|
-
if (node.type === 'text' && node.value) {
|
|
327
|
-
node.value = replaceEnvVars(node.value as string);
|
|
328
|
-
}
|
|
329
|
-
|
|
330
|
-
// Links
|
|
331
|
-
if (node.type === 'link' && node.url) {
|
|
332
|
-
node.url = replaceEnvVars(node.url as string);
|
|
333
|
-
node.url = rewriteMdLink(node.url as string, filePath, docsDir);
|
|
334
|
-
// Prepend DOCS_BASE to root-relative internal links that were not already
|
|
335
|
-
// rewritten by rewriteMdLink (e.g. bare /grids/grid/… links that skip
|
|
336
|
-
// the .md-only rewriter above).
|
|
337
|
-
const docsBase = (process.env.DOCS_BASE ?? '').replace(/\/$/, '');
|
|
338
|
-
if (
|
|
339
|
-
docsBase &&
|
|
340
|
-
(node.url as string).startsWith('/') &&
|
|
341
|
-
!(node.url as string).startsWith('//') &&
|
|
342
|
-
!(node.url as string).startsWith(docsBase + '/')
|
|
343
|
-
) {
|
|
344
|
-
node.url = docsBase + (node.url as string);
|
|
345
|
-
}
|
|
346
|
-
}
|
|
347
|
-
|
|
348
|
-
// Images
|
|
349
|
-
if (node.type === 'image' && node.url) {
|
|
350
|
-
node.url = replaceEnvVars(node.url as string);
|
|
351
|
-
node.url = (node.url as string).replace(/^(\.\.\/)+images\//, '/images/');
|
|
352
|
-
}
|
|
353
|
-
|
|
354
|
-
// Code blocks — normalize language identifiers to lowercase
|
|
355
|
-
if (node.type === 'code' && node.lang) {
|
|
356
|
-
node.lang = (node.lang as string).toLowerCase();
|
|
357
|
-
}
|
|
358
|
-
|
|
359
|
-
// Inline HTML
|
|
360
|
-
if (node.type === 'html' && node.value) {
|
|
361
|
-
node.value = replaceEnvVars(node.value as string);
|
|
362
|
-
node.value = transformCodeView(node.value as string);
|
|
363
|
-
node.value = transformDividers(node.value as string);
|
|
364
|
-
node.value = (node.value as string).replace(/src="(\.\.\/)+images\//g, 'src="/images/');
|
|
365
|
-
}
|
|
366
|
-
});
|
|
367
|
-
};
|
|
368
|
-
}
|