igniteui-astro-components 0.0.30 → 1.0.1

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,10 +1,10 @@
1
1
  {
2
2
  "name": "igniteui-astro-components",
3
- "version": "0.0.30",
3
+ "version": "1.0.1",
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": {
7
- "node": "^20.19.0 || ^22.13.0 || >=24.0.0"
7
+ "node": ">=22.12.0"
8
8
  },
9
9
  "license": "MIT",
10
10
  "author": "Infragistics",
@@ -83,41 +83,44 @@
83
83
  "./package.json": "./package.json"
84
84
  },
85
85
  "peerDependencies": {
86
- "astro": "^5.0.0 || ^6.0.0",
86
+ "astro": "^7.0.0",
87
+ "igniteui-theming": "^26.0.1",
87
88
  "igniteui-webcomponents": "^7.2.4"
88
89
  },
89
90
  "dependencies": {
91
+ "@astrojs/mdx": "^7.0.7",
92
+ "@astrojs/markdown-satteri": "^0.3.5",
90
93
  "@fontsource-variable/instrument-sans": "^5.2.8",
91
94
  "@fontsource-variable/inter": "^5.2.8",
92
95
  "@fontsource-variable/jetbrains-mono": "^5.2.8",
96
+ "github-slugger": "^2.0.0",
93
97
  "jsdom": "^29.0.1",
94
- "shiki": "^3.23.0"
98
+ "satteri": "^0.9.5",
99
+ "shiki": "^4.3.0"
95
100
  },
96
101
  "devDependencies": {
102
+ "@astrojs/check": "^0.9.9",
97
103
  "@types/jsdom": "^21.1.7",
98
- "astro": "^6.1.6",
104
+ "astro": "^7.2.2",
99
105
  "husky": "^9.1.7",
100
106
  "igniteui-theming": "^26.0.1",
107
+ "igniteui-webcomponents": "^7.3.0-beta.1",
101
108
  "lint-staged": "^17.0.8",
102
109
  "oxlint": "^1.72.0",
103
110
  "prettier": "^3.9.4",
104
111
  "prettier-plugin-astro": "^0.14.1",
105
112
  "sass": "^1.83.0",
106
- "typescript": "^5.6.0"
113
+ "typescript": "^5.9.3"
107
114
  },
108
- "workspaces": [
109
- "playground"
110
- ],
111
115
  "publishConfig": {
112
116
  "access": "public"
113
117
  },
114
118
  "scripts": {
115
- "playground": "npm --prefix playground run dev",
116
- "playground:dev": "npm --prefix playground run dev",
117
- "playground:build": "npm --prefix playground run build",
118
- "playground:preview": "npm --prefix playground run preview",
119
- "playground:clean": "npm --prefix playground run clean",
120
- "playground:check": "npm --prefix playground run check",
119
+ "playground": "npm run playground:dev",
120
+ "playground:dev": "astro sync --root playground && astro dev --root playground --port 4567",
121
+ "playground:build": "astro sync --root playground && astro build --root playground",
122
+ "playground:preview": "astro preview --root playground --port 4567",
123
+ "playground:check": "astro check --root playground",
121
124
  "lint": "oxlint .",
122
125
  "lint:fix": "oxlint . --fix",
123
126
  "format": "prettier --write .",
@@ -25,7 +25,7 @@
25
25
  * { tag: 'link', attrs: { rel: 'stylesheet', href: '...' } },
26
26
  * ],
27
27
  * // Extra Astro options (markdown, image, build, …)
28
- * markdown: { remarkPlugins: [] },
28
+ * markdown: { mdastPlugins: [], hastPlugins: [] },
29
29
  * });
30
30
  *
31
31
  * --- Option B: manual composition (for full control) ---
@@ -66,6 +66,7 @@ import {
66
66
  import { buildSidebarFromToc } from './sidebar';
67
67
  import { getPlatformHead } from './platform';
68
68
  import type { HeadEntry, PlatformKey, NavLang } from './platform.ts';
69
+ import { satteri } from '@astrojs/markdown-satteri';
69
70
  import { remarkEnvVars } from './plugins/remark-env-vars';
70
71
  export { rehypeTableWrapper } from './plugins/rehype-table-wrapper';
71
72
  import { rehypeTableWrapper } from './plugins/rehype-table-wrapper';
@@ -699,6 +700,13 @@ export function createDocsSite(
699
700
  return defineConfig({
700
701
  site,
701
702
  ...(base !== undefined ? { base } : {}),
703
+ // Astro 7 defaults to `compressHTML: 'jsx'`, which drops whitespace between
704
+ // inline elements entirely instead of collapsing it to a single space. That
705
+ // silently joins adjacent text — breadcrumb segments, badge labels and callout
706
+ // titles render as "Open SourceIgnite UI" / "InfoThe -y flag". Keeping the
707
+ // Astro 6 behaviour preserves the rendered copy; switch to 'jsx' only after
708
+ // auditing templates for the inline pairs that need an explicit {" "}.
709
+ compressHTML: true,
702
710
  // Docs sites serve images statically — disable Astro's image optimization
703
711
  // so relative image paths in markdown don't cause build errors.
704
712
  image: { service: { entrypoint: 'astro/assets/services/noop' }, ...(astroExtra as any).image },
@@ -715,19 +723,23 @@ export function createDocsSite(
715
723
  },
716
724
  markdown: {
717
725
  ...(astroExtra as any).markdown,
718
- remarkPlugins: [
719
- remarkEnvVars,
720
- remarkMdLinks,
721
- remarkHtmlTransforms,
722
- ...((astroExtra as any).markdown?.remarkPlugins ?? []),
723
- ],
724
- rehypePlugins: [
725
- rehypeCodeView,
726
- rehypeTableWrapper,
727
- rehypeHeadingAnchors,
728
- rehypePagefindIgnore,
729
- ...((astroExtra as any).markdown?.rehypePlugins ?? []),
730
- ],
726
+ // Astro 7 renders Markdown/MDX with Sätteri instead of remark/rehype.
727
+ // MDAST plugins run before HAST plugins, matching the old
728
+ // remarkPlugins-then-rehypePlugins ordering.
729
+ processor: satteri({
730
+ mdastPlugins: [
731
+ remarkEnvVars,
732
+ remarkMdLinks,
733
+ remarkHtmlTransforms,
734
+ ...((astroExtra as any).markdown?.mdastPlugins ?? []),
735
+ ],
736
+ hastPlugins: [
737
+ rehypeTableWrapper,
738
+ rehypeHeadingAnchors,
739
+ rehypePagefindIgnore,
740
+ ...((astroExtra as any).markdown?.hastPlugins ?? []),
741
+ ],
742
+ }),
731
743
  },
732
744
  integrations: [
733
745
  siteMetaIntegration({
@@ -1,74 +1,66 @@
1
- import { visit } from 'unist-util-visit';
1
+ import { defineHastPlugin } from 'satteri';
2
2
  import Slugger from 'github-slugger';
3
3
 
4
- const HEADING_TAGS = new Set(['h2', 'h3', 'h4', 'h5', 'h6']);
5
-
6
- // Extract the text content of a hast node (ignores child elements, reads text/raw nodes).
7
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
8
- function textContent(node: any): string {
9
- let text = '';
10
- visit(node, (child) => {
11
- if (child.type === 'text' || child.type === 'raw') text += child.value ?? '';
12
- });
13
- return text;
14
- }
4
+ const HEADING_TAGS = ['h2', 'h3', 'h4', 'h5', 'h6'];
15
5
 
16
6
  /**
17
- * Rehype plugin that appends a copy-link icon button to every heading
7
+ * Sätteri HAST plugin that appends a copy-link icon button to every heading
18
8
  * (h2–h6).
19
9
  *
20
- * Runs before Astro's internal `rehypeHeadingIds` pass so it must
21
- * generate its own slug using the same `github-slugger` algorithm.
22
- * If the heading already has an `id` (e.g. set in raw HTML), it is reused.
23
- * Headings without an existing id get one assigned here — `rehypeHeadingIds`
24
- * will then see the id already present and skip re-assigning it, ensuring
25
- * the button href and the heading's id always match.
10
+ * Runs before Astro's internal heading-id pass so it must generate its own slug
11
+ * using the same `github-slugger` algorithm. If the heading already has an `id`
12
+ * (e.g. set in raw HTML), it is reused. Headings without an existing id get one
13
+ * assigned here — the built-in pass will then see the id already present and
14
+ * skip re-assigning it, ensuring the button href and the heading's id always
15
+ * match.
16
+ *
17
+ * Exported as a factory so Sätteri calls it once per document, giving each page
18
+ * a fresh slugger and therefore a fresh duplicate-suffix counter.
26
19
  */
27
20
  export function rehypeHeadingAnchors() {
28
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
29
- return (tree: any) => {
30
- const slugger = new Slugger();
31
-
32
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
33
- visit(tree, 'element', (node: any) => {
34
- if (!HEADING_TAGS.has(node.tagName)) return;
21
+ const slugger = new Slugger();
35
22
 
36
- node.properties ??= {};
23
+ return defineHastPlugin({
24
+ name: 'heading-anchors',
25
+ element: {
26
+ filter: HEADING_TAGS,
27
+ visit(node, ctx) {
28
+ // Reuse an existing id or generate one from heading text.
29
+ const existing = node.properties?.id;
30
+ let id: string;
37
31
 
38
- // Reuse an existing id or generate one from heading text.
39
- if (typeof node.properties.id !== 'string') {
40
- node.properties.id = slugger.slug(textContent(node));
41
- } else {
42
- // Keep slugger in sync so it doesn't generate duplicate ids.
43
- slugger.slug(node.properties.id);
44
- }
32
+ if (typeof existing === 'string' && existing) {
33
+ // Keep slugger in sync so it doesn't generate duplicate ids.
34
+ slugger.slug(existing);
35
+ id = existing;
36
+ } else {
37
+ id = slugger.slug(ctx.textContent(node));
38
+ ctx.setProperty(node, 'id', id);
39
+ }
45
40
 
46
- const id = node.properties.id as string;
47
-
48
- const iconButton = {
49
- type: 'element',
50
- tagName: 'igc-icon-button',
51
- properties: {
52
- class: 'igd-anchor-link',
53
- href: `#${id}`,
54
- variant: 'flat',
55
- 'aria-label': 'Link to this section',
56
- tabIndex: 0,
57
- },
58
- children: [
59
- {
60
- type: 'element',
61
- tagName: 'igc-icon',
62
- properties: {
63
- name: 'link',
64
- collection: 'docs',
65
- },
66
- children: [],
41
+ ctx.appendChild(node, {
42
+ type: 'element',
43
+ tagName: 'igc-icon-button',
44
+ properties: {
45
+ class: 'igd-anchor-link',
46
+ href: `#${id}`,
47
+ variant: 'flat',
48
+ 'aria-label': 'Link to this section',
49
+ tabIndex: 0,
67
50
  },
68
- ],
69
- };
70
-
71
- node.children.push(iconButton);
72
- });
73
- };
51
+ children: [
52
+ {
53
+ type: 'element',
54
+ tagName: 'igc-icon',
55
+ properties: {
56
+ name: 'link',
57
+ collection: 'docs',
58
+ },
59
+ children: [],
60
+ },
61
+ ],
62
+ });
63
+ },
64
+ },
65
+ });
74
66
  }
@@ -1,4 +1,4 @@
1
- import { visit } from 'unist-util-visit';
1
+ import { defineHastPlugin } from 'satteri';
2
2
 
3
3
  /**
4
4
  * Marks code with `data-pagefind-ignore` so Pagefind doesn't index it.
@@ -8,33 +8,24 @@ import { visit } from 'unist-util-visit';
8
8
  * `keyof T` across unrelated pages. Excluding `<pre>` (and single-char inline
9
9
  * `<code>`) removes that noise; real inline `<code>` like `dataSource` stays.
10
10
  */
11
-
12
- // Concatenate all descendant text of a HAST node.
13
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
14
- function textContent(node: any): string {
15
- if (node.type === 'text') return node.value ?? '';
16
- if (!node.children) return '';
17
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
18
- return node.children.map((c: any) => textContent(c)).join('');
19
- }
20
-
21
11
  export function rehypePagefindIgnore() {
22
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
23
- return (tree: any) => {
24
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
25
- visit(tree, 'element', (node: any) => {
26
- const ignore = () => {
27
- node.properties = { ...node.properties, 'data-pagefind-ignore': 'all' };
28
- };
29
-
30
- // Fenced code blocks (covers their inner <code> via subtree ignore).
31
- if (node.tagName === 'pre') return ignore();
12
+ return defineHastPlugin({
13
+ name: 'pagefind-ignore',
14
+ element: {
15
+ filter: ['pre', 'code'],
16
+ visit(node, ctx) {
17
+ // Fenced code blocks (covers their inner <code> via subtree ignore).
18
+ if (node.tagName === 'pre') {
19
+ ctx.setProperty(node, 'data-pagefind-ignore', 'all');
20
+ return;
21
+ }
32
22
 
33
- // Inline code that reduces to a single alphanumeric token.
34
- if (node.tagName === 'code') {
35
- const token = textContent(node).replace(/[^a-z0-9]/gi, '');
36
- if (token.length <= 1) ignore();
37
- }
38
- });
39
- };
23
+ // Inline code that reduces to a single alphanumeric token.
24
+ const token = ctx.textContent(node).replace(/[^a-z0-9]/gi, '');
25
+ if (token.length <= 1) {
26
+ ctx.setProperty(node, 'data-pagefind-ignore', 'all');
27
+ }
28
+ },
29
+ },
30
+ });
40
31
  }
@@ -1,49 +1,51 @@
1
- import { visit } from 'unist-util-visit';
2
-
3
- let _counter = 0;
1
+ import { defineHastPlugin } from 'satteri';
4
2
 
5
3
  /**
6
- * Rehype plugin that wraps every <table> in a scroll container div.
4
+ * Sätteri HAST plugin that wraps every <table> in a scroll container div.
7
5
  * The wrapper is fully accessible per the recommendations in:
8
6
  * https://piccalil.li/blog/styling-tables-the-modern-css-way/
9
7
  *
10
8
  * - role="region" + aria-labelledby pointing to the <caption> (or a generated id)
11
9
  * - tabindex="0" makes the scroll region keyboard-focusable
10
+ *
11
+ * Exported as a factory so Sätteri calls it once per document, resetting the id
12
+ * counter — these ids only have to be unique within a single page.
12
13
  */
13
14
  export function rehypeTableWrapper() {
14
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
15
- return (tree: any) => {
16
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
17
- visit(tree, 'element', (node: any, index: number | undefined, parent: any) => {
18
- if (node.tagName !== 'table' || !parent || index == null) return;
19
-
20
- // Find an existing <caption> to use as the accessible label.
21
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
22
- const caption = node.children?.find((c: any) => c.tagName === 'caption');
23
- let labelId: string;
15
+ let counter = 0;
24
16
 
25
- if (caption) {
26
- // Reuse or assign an id on the caption element.
27
- labelId = caption.properties?.id || `igd-table-caption-${++_counter}`;
28
- caption.properties = { ...caption.properties, id: labelId };
29
- } else {
30
- // No caption — generate a unique id for the wrapper itself.
31
- labelId = `igd-table-${++_counter}`;
32
- }
17
+ return defineHastPlugin({
18
+ name: 'table-wrapper',
19
+ element: {
20
+ filter: ['table'],
21
+ visit(node, ctx) {
22
+ // Find an existing <caption> to use as the accessible label.
23
+ const caption = node.children?.find((c) => c.type === 'element' && c.tagName === 'caption');
24
+ let labelId: string;
33
25
 
34
- const wrapper = {
35
- type: 'element',
36
- tagName: 'div',
37
- properties: {
38
- className: ['igd-table-wrapper'],
39
- role: 'region',
40
- 'aria-labelledby': labelId,
41
- tabIndex: 0,
42
- },
43
- children: [node],
44
- };
26
+ if (caption && caption.type === 'element') {
27
+ // Reuse or assign an id on the caption element.
28
+ const existing = caption.properties?.id;
29
+ labelId =
30
+ typeof existing === 'string' && existing ? existing : `igd-table-caption-${++counter}`;
31
+ ctx.setProperty(caption, 'id', labelId);
32
+ } else {
33
+ // No caption — generate a unique id for the wrapper itself.
34
+ labelId = `igd-table-${++counter}`;
35
+ }
45
36
 
46
- parent.children[index] = wrapper;
47
- });
48
- };
37
+ ctx.wrapNode(node, {
38
+ type: 'element',
39
+ tagName: 'div',
40
+ properties: {
41
+ className: ['igd-table-wrapper'],
42
+ role: 'region',
43
+ 'aria-labelledby': labelId,
44
+ tabIndex: 0,
45
+ },
46
+ children: [],
47
+ });
48
+ },
49
+ },
50
+ });
49
51
  }
@@ -14,7 +14,7 @@
14
14
  * DOCS_ENV (or NODE_ENV) selects the env block: development | staging | production.
15
15
  */
16
16
 
17
- import { visit } from 'unist-util-visit';
17
+ import { defineMdastPlugin } from 'satteri';
18
18
  import fs from 'node:fs';
19
19
  import path from 'node:path';
20
20
 
@@ -95,24 +95,30 @@ export function replaceEnvVars(str: string): string {
95
95
  return str.replace(ENV_PATTERN, (_match, key) => env[key] ?? `{environment:${key}}`);
96
96
  }
97
97
 
98
- /** Remark plugin that substitutes `{environment:key}` tokens in the markdown AST. */
98
+ /**
99
+ * Sätteri MDAST plugin that substitutes `{environment:key}` tokens.
100
+ *
101
+ * Exported as a factory so Sätteri calls it once per compile; the `loadEnv()`
102
+ * cache is module-level and intentionally shared across documents.
103
+ */
99
104
  export function remarkEnvVars() {
100
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
101
- return (tree: any) => {
102
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
103
- visit(tree, (node: any) => {
104
- if (node.type === 'text' && node.value) {
105
- node.value = replaceEnvVars(node.value);
106
- }
107
- if (node.type === 'link' && node.url) {
108
- node.url = replaceEnvVars(node.url);
109
- }
110
- if (node.type === 'image' && node.url) {
111
- node.url = replaceEnvVars(node.url);
112
- }
113
- if (node.type === 'html' && node.value) {
114
- node.value = replaceEnvVars(node.value);
115
- }
116
- });
117
- };
105
+ return defineMdastPlugin({
106
+ name: 'env-vars',
107
+ text(node, ctx) {
108
+ const value = replaceEnvVars(node.value);
109
+ if (value !== node.value) ctx.setProperty(node, 'value', value);
110
+ },
111
+ html(node, ctx) {
112
+ const value = replaceEnvVars(node.value);
113
+ if (value !== node.value) ctx.setProperty(node, 'value', value);
114
+ },
115
+ link(node, ctx) {
116
+ const url = replaceEnvVars(node.url);
117
+ if (url !== node.url) ctx.setProperty(node, 'url', url);
118
+ },
119
+ image(node, ctx) {
120
+ const url = replaceEnvVars(node.url);
121
+ if (url !== node.url) ctx.setProperty(node, 'url', url);
122
+ },
123
+ });
118
124
  }
@@ -1,32 +1,35 @@
1
1
  /**
2
- * Remark plugin: inline HTML transforms.
2
+ * Sätteri MDAST plugin: inline HTML transforms.
3
3
  *
4
4
  * Handles legacy HTML patterns in markdown content:
5
5
  * - `<div class="divider--half"></div>` → `<hr/>`
6
6
  * - Normalizes code block language identifiers to lowercase
7
7
  */
8
8
 
9
- import { visit } from 'unist-util-visit';
9
+ import { defineMdastPlugin } from 'satteri';
10
10
 
11
11
  const DIVIDER_PATTERN = /<div\s+class="divider--half"\s*>\s*<\/div>/g;
12
12
  const IMG_SRC_PATTERN = /src="(\.\.\/)+images\//g;
13
13
 
14
- /** Remark plugin that transforms legacy HTML patterns in the AST. */
14
+ /** Sätteri MDAST plugin that transforms legacy HTML patterns in the AST. */
15
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
- }
16
+ return defineMdastPlugin({
17
+ name: 'html-transforms',
25
18
 
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
- };
19
+ // Inline HTML: divider → hr, relative img src → root-relative
20
+ html(node, ctx) {
21
+ if (!node.value) return;
22
+ const value = node.value
23
+ .replace(DIVIDER_PATTERN, '<hr/>')
24
+ .replace(IMG_SRC_PATTERN, 'src="/images/');
25
+ if (value !== node.value) ctx.setProperty(node, 'value', value);
26
+ },
27
+
28
+ // Code blocks: normalize language to lowercase
29
+ code(node, ctx) {
30
+ if (!node.lang) return;
31
+ const lang = node.lang.toLowerCase();
32
+ if (lang !== node.lang) ctx.setProperty(node, 'lang', lang);
33
+ },
34
+ });
32
35
  }
@@ -8,8 +8,9 @@
8
8
  * that are already absolute but missing the site base path.
9
9
  */
10
10
 
11
- import { visit } from 'unist-util-visit';
11
+ import { defineMdastPlugin } from 'satteri';
12
12
  import path from 'node:path';
13
+ import { fileURLToPath } from 'node:url';
13
14
 
14
15
  /**
15
16
  * Resolve a relative .md link to an absolute Astro URL.
@@ -43,39 +44,50 @@ function rewriteMdLink(url: string, filePath: string, docsDir: string): string {
43
44
  return docsBase + '/' + slug.toLowerCase() + '/' + suffix;
44
45
  }
45
46
 
46
- /** Remark plugin that rewrites relative .md links, prepends DOCS_BASE, and fixes relative image paths. */
47
+ /** Resolve the source file path and docs root for the document being compiled. */
48
+ function resolvePaths(fileURL: URL | undefined): { filePath: string; docsDir: string } {
49
+ const filePath = fileURL ? fileURLToPath(fileURL) : '';
50
+ const docsDir = process.env.DOCS_SOURCE_PATH
51
+ ? path.resolve(process.env.DOCS_SOURCE_PATH)
52
+ : filePath
53
+ ? path.dirname(filePath)
54
+ : '';
55
+ return { filePath, docsDir };
56
+ }
57
+
58
+ /**
59
+ * Satteri MDAST plugin that rewrites relative .md links, prepends DOCS_BASE,
60
+ * and fixes relative image paths.
61
+ */
47
62
  export function remarkMdLinks() {
48
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
49
- return (tree: any, file: any) => {
50
- const filePath = (file.path as string) ?? '';
51
- const docsDir = process.env.DOCS_SOURCE_PATH
52
- ? path.resolve(process.env.DOCS_SOURCE_PATH)
53
- : filePath
54
- ? path.dirname(filePath)
55
- : '';
63
+ return defineMdastPlugin({
64
+ name: 'md-links',
56
65
 
57
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
58
- visit(tree, (node: any) => {
59
- if (node.type === 'link' && node.url) {
60
- node.url = rewriteMdLink(node.url as string, filePath, docsDir);
66
+ link(node, ctx) {
67
+ if (!node.url) return;
68
+ const { filePath, docsDir } = resolvePaths(ctx.fileURL);
69
+ let url = rewriteMdLink(node.url, filePath, docsDir);
61
70
 
62
- // Prepend DOCS_BASE to root-relative internal links not already prefixed.
63
- const docsBase = (process.env.DOCS_BASE ?? '').replace(/\/$/, '');
64
- if (
65
- docsBase &&
66
- (node.url as string).startsWith('/') &&
67
- !(node.url as string).startsWith('//') &&
68
- !(node.url as string).startsWith(docsBase + '/')
69
- ) {
70
- node.url = docsBase + (node.url as string);
71
- }
71
+ // Prepend DOCS_BASE to root-relative internal links not already prefixed.
72
+ const docsBase = (process.env.DOCS_BASE ?? '').replace(/[/]$/, '');
73
+ if (
74
+ docsBase &&
75
+ url.startsWith('/') &&
76
+ !url.startsWith('//') &&
77
+ !url.startsWith(docsBase + '/')
78
+ ) {
79
+ url = docsBase + url;
72
80
  }
73
81
 
74
- // Rewrite relative `../images/` paths in markdown image nodes to root-relative `/images/`.
75
- // Generated MDX files may contain relative image references that Vite cannot resolve.
76
- if (node.type === 'image' && node.url) {
77
- node.url = (node.url as string).replace(/^(\.\.\/)+images\//, '/images/');
78
- }
79
- });
80
- };
82
+ if (url !== node.url) ctx.setProperty(node, 'url', url);
83
+ },
84
+
85
+ // Rewrite relative `../images/` paths in markdown image nodes to root-relative `/images/`.
86
+ // Generated MDX files may contain relative image references that Vite cannot resolve.
87
+ image(node, ctx) {
88
+ if (!node.url) return;
89
+ const url = node.url.replace(/^([.][.][/])+images[/]/, '/images/');
90
+ if (url !== node.url) ctx.setProperty(node, 'url', url);
91
+ },
92
+ });
81
93
  }