@terra-symposium/docs 0.1.72 → 0.1.73
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": "@terra-symposium/docs",
|
|
3
|
-
|
|
3
|
+
"version": "0.1.73",
|
|
4
4
|
"description": "Terra Docs workspace and Markdown site generator.",
|
|
5
5
|
"repository": {
|
|
6
6
|
"type": "git",
|
|
@@ -64,13 +64,13 @@
|
|
|
64
64
|
"@changesets/cli": "^3.0.3",
|
|
65
65
|
"@eslint/js": "10.0.1",
|
|
66
66
|
"@playwright/test": "^1.64.1",
|
|
67
|
+
"@terra-symposium/standards-quality": "2.1.0",
|
|
67
68
|
"@terra-symposium/standards-reporting": "0.6.2",
|
|
68
69
|
"@types/katex": "^0.16.8",
|
|
69
70
|
"@types/node": "^24.19.2",
|
|
70
71
|
"@types/react": "19.3.0",
|
|
71
72
|
"@types/react-dom": "19.3.0",
|
|
72
73
|
"@types/sanitize-html": "^2.16.2",
|
|
73
|
-
"@terra-symposium/standards-quality": "2.1.0",
|
|
74
74
|
"@vitejs/plugin-react": "6.1.2",
|
|
75
75
|
"eslint": "10.13.0",
|
|
76
76
|
"husky": "^9.1.7",
|
|
@@ -83,6 +83,7 @@
|
|
|
83
83
|
"vite": "8.3.4"
|
|
84
84
|
},
|
|
85
85
|
"dependencies": {
|
|
86
|
+
"@astrojs/markdown-remark": "7.3.5",
|
|
86
87
|
"@astrojs/mdx": "8.1.2",
|
|
87
88
|
"@astrojs/react": "^7.1.0",
|
|
88
89
|
"@carbon/icons-react": "11.90.0",
|
|
@@ -98,9 +99,9 @@
|
|
|
98
99
|
"@portabletext/editor": "7.9.0",
|
|
99
100
|
"@radix-ui/react-popover": "^1.1.15",
|
|
100
101
|
"@radix-ui/react-select": "2.4.1",
|
|
102
|
+
"@terra-symposium/styling": "0.1.34",
|
|
101
103
|
"@uiw/codemirror-theme-github": "^4.25.9",
|
|
102
104
|
"@xyflow/react": "^12.3.6",
|
|
103
|
-
"@terra-symposium/styling": "0.1.34",
|
|
104
105
|
"astro": "^7.4.2",
|
|
105
106
|
"jszip": "^3.10.1",
|
|
106
107
|
"katex": "^0.19.1",
|
package/site/astro.config.mjs
CHANGED
|
@@ -5,6 +5,8 @@ import { createRequire } from 'node:module';
|
|
|
5
5
|
import { defineConfig } from 'astro/config';
|
|
6
6
|
import mdx from '@astrojs/mdx';
|
|
7
7
|
import react from '@astrojs/react';
|
|
8
|
+
import { unified } from '@astrojs/markdown-remark';
|
|
9
|
+
import { basePathRemarkPlugin } from './base-path-remark-plugin.mjs';
|
|
8
10
|
import { docsContentPlugin } from './docs-content-plugin.mjs';
|
|
9
11
|
|
|
10
12
|
const packageRoot = fileURLToPath(new URL('../', import.meta.url));
|
|
@@ -13,6 +15,7 @@ const projectRoot = process.env.TERRA_DOCS_ROOT ?? process.cwd();
|
|
|
13
15
|
const publicDir = resolve(projectRoot, '.terra-docs/public');
|
|
14
16
|
const outDir = resolve(projectRoot, process.env.TERRA_DOCS_OUT ?? 'docs-dist');
|
|
15
17
|
const site = process.env.TERRA_DOCS_SITE;
|
|
18
|
+
const base = process.env.TERRA_DOCS_BASE ?? '/';
|
|
16
19
|
const projectManifest = (() => {
|
|
17
20
|
try {
|
|
18
21
|
return JSON.parse(readFileSync(resolve(projectRoot, 'package.json'), 'utf8'));
|
|
@@ -40,7 +43,7 @@ const packageDependencyResolver = {
|
|
|
40
43
|
name: 'terra-docs-package-dependencies',
|
|
41
44
|
enforce: 'pre',
|
|
42
45
|
resolveId(source) {
|
|
43
|
-
if (!/^(?:astro|@astrojs\/(?:mdx|react))(?:\/|$)/.test(source)) return null;
|
|
46
|
+
if (!/^(?:astro|@astrojs\/(?:markdown-remark|mdx|react))(?:\/|$)/.test(source)) return null;
|
|
44
47
|
try {
|
|
45
48
|
return requireFromPackage.resolve(source);
|
|
46
49
|
} catch {
|
|
@@ -55,12 +58,13 @@ export default defineConfig({
|
|
|
55
58
|
publicDir,
|
|
56
59
|
outDir,
|
|
57
60
|
...(site ? { site } : {}),
|
|
58
|
-
base
|
|
61
|
+
base,
|
|
59
62
|
devToolbar: { enabled: false },
|
|
60
63
|
build: { format: 'directory' },
|
|
61
64
|
integrations: [react(), mdx()],
|
|
65
|
+
markdown: { processor: unified({ remarkPlugins: [[basePathRemarkPlugin, { base }]] }) },
|
|
62
66
|
vite: {
|
|
63
|
-
plugins: [packageDependencyResolver, docsContentPlugin({ root: projectRoot, base
|
|
67
|
+
plugins: [packageDependencyResolver, docsContentPlugin({ root: projectRoot, base })],
|
|
64
68
|
resolve: { alias: packageExportAliases() },
|
|
65
69
|
server: { fs: { allow: [projectRoot, packageRoot] } },
|
|
66
70
|
},
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
function addBasePath(value, base) {
|
|
2
|
+
if (typeof value !== 'string' || !value.startsWith('/') || value.startsWith('//') || base === '/') return value;
|
|
3
|
+
const basePath = `/${base.replace(/^\/+|\/+$/g, '')}`;
|
|
4
|
+
if (value === basePath) return `${basePath}/`;
|
|
5
|
+
if (value.startsWith(`${basePath}/`)) return value;
|
|
6
|
+
return `${basePath}${value}`;
|
|
7
|
+
}
|
|
8
|
+
|
|
9
|
+
function addBaseToHtml(source, base) {
|
|
10
|
+
return source.replace(/\b(href|src)=(['"])(\/[^'"#?]*)([^'"]*)\2/gi, (_match, attribute, quote, pathname, suffix) =>
|
|
11
|
+
`${attribute}=${quote}${addBasePath(`${pathname}${suffix}`, base)}${quote}`,
|
|
12
|
+
);
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
export function basePathRemarkPlugin({ base }) {
|
|
16
|
+
return (tree) => {
|
|
17
|
+
const visit = (node) => {
|
|
18
|
+
if (['link', 'image', 'definition'].includes(node.type) && typeof node.url === 'string') {
|
|
19
|
+
node.url = addBasePath(node.url, base);
|
|
20
|
+
}
|
|
21
|
+
if (node.type === 'html' && typeof node.value === 'string') {
|
|
22
|
+
node.value = addBaseToHtml(node.value, base);
|
|
23
|
+
}
|
|
24
|
+
if (node.type === 'mdxJsxAttribute' && ['href', 'src'].includes(node.name) && typeof node.value === 'string') {
|
|
25
|
+
node.value = addBasePath(node.value, base);
|
|
26
|
+
}
|
|
27
|
+
for (const child of node.children ?? []) visit(child);
|
|
28
|
+
};
|
|
29
|
+
visit(tree);
|
|
30
|
+
};
|
|
31
|
+
}
|
|
@@ -11,7 +11,7 @@ function publicRoute(file, docsRoot, base) {
|
|
|
11
11
|
|
|
12
12
|
function rewriteTarget(rawTarget, sourceFile, docsRoot, base) {
|
|
13
13
|
const target = rawTarget.trim();
|
|
14
|
-
if (!target || /^(?:[a-z][a-z\d+.-]
|
|
14
|
+
if (!target || /^(?:[a-z][a-z\d+.-]*:|\/\/|#)/i.test(target)) return rawTarget;
|
|
15
15
|
const match = /^(<[^>]+>|[^\s]+)([\s\S]*)$/.exec(target);
|
|
16
16
|
if (!match) return rawTarget;
|
|
17
17
|
const bracketed = match[1].startsWith('<') && match[1].endsWith('>');
|
|
@@ -19,6 +19,19 @@ function rewriteTarget(rawTarget, sourceFile, docsRoot, base) {
|
|
|
19
19
|
const suffix = match[2];
|
|
20
20
|
const [filePath, ...hashParts] = pathname.split('#');
|
|
21
21
|
const [cleanPath, ...queryParts] = filePath.split('?');
|
|
22
|
+
const fragment = hashParts.length ? `#${hashParts.join('#')}` : '';
|
|
23
|
+
const query = queryParts.length ? `?${queryParts.join('?')}` : '';
|
|
24
|
+
if (cleanPath.startsWith('/')) {
|
|
25
|
+
const basePath = base === '/' ? '' : `/${base.replace(/^\/+|\/+$/g, '')}`;
|
|
26
|
+
const rootBase = `${basePath}/`;
|
|
27
|
+
const routedPath = base === '/' || cleanPath.startsWith(rootBase)
|
|
28
|
+
? cleanPath
|
|
29
|
+
: cleanPath === basePath
|
|
30
|
+
? rootBase
|
|
31
|
+
: `${basePath}${cleanPath}`;
|
|
32
|
+
const rewritten = `${routedPath}${query}${fragment}`;
|
|
33
|
+
return `${bracketed ? `<${rewritten}>` : rewritten}${suffix}`;
|
|
34
|
+
}
|
|
22
35
|
let resolvedPath;
|
|
23
36
|
try {
|
|
24
37
|
resolvedPath = resolve(sourceFile, '..', decodeURIComponent(cleanPath));
|
|
@@ -28,8 +41,6 @@ function rewriteTarget(rawTarget, sourceFile, docsRoot, base) {
|
|
|
28
41
|
const relativePath = relative(docsRoot, resolvedPath);
|
|
29
42
|
if (relativePath.startsWith(`..${sep}`) || relativePath === '..' || !existsSync(resolvedPath)) return rawTarget;
|
|
30
43
|
const extension = extname(resolvedPath).toLowerCase();
|
|
31
|
-
const fragment = hashParts.length ? `#${hashParts.join('#')}` : '';
|
|
32
|
-
const query = queryParts.length ? `?${queryParts.join('?')}` : '';
|
|
33
44
|
const rewritten = markdownExtensions.has(extension)
|
|
34
45
|
? publicRoute(resolvedPath, docsRoot, base)
|
|
35
46
|
: `${base}_terra-docs/assets/${relativePath.split(sep).join('/')}`;
|