@writedocs/generator 0.10.19 → 0.11.0
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/astro.config.mjs +32 -8
- package/package.json +96 -93
- package/src/cli/base-path-layout.js +44 -0
- package/src/cli/build.js +177 -168
- package/src/cli/check-built-styles.js +41 -33
- package/src/cli/dev.js +261 -244
- package/src/cli/generate-api-pages.js +9 -5
- package/src/cli/page-list-watch.js +69 -66
- package/src/cli/run-pagefind.js +154 -148
- package/src/cli/write-mcp-files.js +103 -96
- package/src/cli/write-redirects-file.js +25 -8
- package/src/components/AppIcon.astro +51 -50
- package/src/components/Card.astro +193 -192
- package/src/components/CopyPageMenu.astro +374 -370
- package/src/components/Hint.astro +188 -187
- package/src/components/Icon.astro +72 -71
- package/src/components/Image.astro +165 -164
- package/src/components/Tile.astro +67 -66
- package/src/components/Video.astro +137 -136
- package/src/layout/BaseLayout.astro +21 -12
- package/src/layout/components/AnalyticsScripts.astro +6 -2
- package/src/layout/components/Breadcrumbs.astro +98 -97
- package/src/layout/components/ConsentBanner.astro +119 -118
- package/src/layout/components/MobileMenu.astro +229 -228
- package/src/layout/components/NavTree.astro +393 -392
- package/src/layout/components/Sidebar.astro +232 -231
- package/src/layout/components/SiteFooter.astro +87 -86
- package/src/layout/components/TopBar.astro +386 -385
- package/src/lib/agent-markdown.js +164 -162
- package/src/lib/asset-dimensions.js +89 -0
- package/src/lib/base-path.js +90 -0
- package/src/lib/config-schema.js +10 -0
- package/src/lib/config-schema.ts +17 -0
- package/src/lib/config.ts +1314 -1289
- package/src/lib/consent.js +108 -102
- package/src/lib/image-size.js +152 -140
- package/src/lib/json-schema-descriptions.js +1 -0
- package/src/lib/link-check.js +42 -4
- package/src/lib/llms-index.ts +90 -88
- package/src/lib/mcp-dev-integration.js +65 -60
- package/src/lib/mcp-index.ts +102 -101
- package/src/lib/pages.js +312 -304
- package/src/lib/project-files-integration.js +116 -61
- package/src/lib/project-files.js +137 -126
- package/src/lib/project-ignore.js +46 -0
- package/src/lib/rehype-base-path.js +62 -0
- package/src/lib/rehype-image-loading.js +71 -71
- package/src/lib/robots-txt.js +21 -16
- package/src/lib/seo-tags.js +155 -140
- package/src/lib/site-base.ts +27 -0
- package/src/lib/styles-asset-integration.js +58 -12
- package/src/lib/wdignore-cases.json +195 -0
- package/src/lib/wdignore.js +177 -0
- package/src/pages/404.astro +63 -62
- package/src/pages/[...slug].astro +1604 -1597
- package/src/pages/[...slug].md.ts +93 -93
- package/src/pages/llms-full.txt.ts +88 -86
- package/src/scripts/search.ts +241 -237
- package/writedocs.schema.json +6 -0
|
@@ -1,96 +1,103 @@
|
|
|
1
|
-
// After `writedocs build`: the files that make dist/ serve the site's MCP
|
|
2
|
-
// server at /mcp on Cloudflare, with no setup of the host's own - next to
|
|
3
|
-
// mcp-index.json, which the build itself writes (src/pages/[mcpIndex].json.ts).
|
|
4
|
-
//
|
|
5
|
-
// _worker.js the MCP server (src/mcp/server.js, inlined - no imports)
|
|
6
|
-
// plus a small fetch handler: /mcp goes to the server,
|
|
7
|
-
// everything else to the static files (env.ASSETS).
|
|
8
|
-
// - Cloudflare Pages runs it on its own ("advanced mode").
|
|
9
|
-
// - Cloudflare Workers with static assets: point `main` at
|
|
10
|
-
// dist/_worker.js, assets at dist/ with an ASSETS binding.
|
|
11
|
-
// _routes.json Pages: only /mcp runs the worker; every other path stays a
|
|
12
|
-
// plain static file (and `_redirects` keeps applying).
|
|
13
|
-
// .assetsignore Workers: don't publish _worker.js / _routes.json as files.
|
|
14
|
-
//
|
|
15
|
-
// Anywhere else - Netlify, Vercel, the WriteDocs platform's serving Worker -
|
|
16
|
-
// import handleMcpHttp from `@writedocs/generator/mcp` and give it
|
|
17
|
-
// mcp-index.json; a purely static host (GitHub Pages, S3) can't run /mcp.
|
|
18
|
-
//
|
|
19
|
-
// A project that brings its own _worker.js or _routes.json (in public/), or a
|
|
20
|
-
// Pages `functions/` folder (which Pages ignores once a _worker.js exists),
|
|
21
|
-
// keeps them: the worker isn't written, and the build says so.
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
//
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
};
|
|
67
|
-
|
|
68
|
-
}
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
1
|
+
// After `writedocs build`: the files that make dist/ serve the site's MCP
|
|
2
|
+
// server at /mcp on Cloudflare, with no setup of the host's own - next to
|
|
3
|
+
// mcp-index.json, which the build itself writes (src/pages/[mcpIndex].json.ts).
|
|
4
|
+
//
|
|
5
|
+
// _worker.js the MCP server (src/mcp/server.js, inlined - no imports)
|
|
6
|
+
// plus a small fetch handler: /mcp goes to the server,
|
|
7
|
+
// everything else to the static files (env.ASSETS).
|
|
8
|
+
// - Cloudflare Pages runs it on its own ("advanced mode").
|
|
9
|
+
// - Cloudflare Workers with static assets: point `main` at
|
|
10
|
+
// dist/_worker.js, assets at dist/ with an ASSETS binding.
|
|
11
|
+
// _routes.json Pages: only /mcp runs the worker; every other path stays a
|
|
12
|
+
// plain static file (and `_redirects` keeps applying).
|
|
13
|
+
// .assetsignore Workers: don't publish _worker.js / _routes.json as files.
|
|
14
|
+
//
|
|
15
|
+
// Anywhere else - Netlify, Vercel, the WriteDocs platform's serving Worker -
|
|
16
|
+
// import handleMcpHttp from `@writedocs/generator/mcp` and give it
|
|
17
|
+
// mcp-index.json; a purely static host (GitHub Pages, S3) can't run /mcp.
|
|
18
|
+
//
|
|
19
|
+
// A project that brings its own _worker.js or _routes.json (in public/), or a
|
|
20
|
+
// Pages `functions/` folder (which Pages ignores once a _worker.js exists),
|
|
21
|
+
// keeps them: the worker isn't written, and the build says so.
|
|
22
|
+
//
|
|
23
|
+
// With a `basePath` ("/docs"), the site is in dist/docs/ (base-path-layout.js)
|
|
24
|
+
// and so is mcp-index.json; these three files stay at the root of dist/, where
|
|
25
|
+
// Cloudflare reads them, and the server answers at /docs/mcp.
|
|
26
|
+
import fs from 'node:fs';
|
|
27
|
+
import path from 'node:path';
|
|
28
|
+
import { fileURLToPath } from 'node:url';
|
|
29
|
+
|
|
30
|
+
const SERVER_SOURCE = path.join(path.dirname(fileURLToPath(import.meta.url)), '..', 'mcp', 'server.js');
|
|
31
|
+
const IGNORED_BY_WORKERS = ['_worker.js', '_routes.json'];
|
|
32
|
+
|
|
33
|
+
/** The `_worker.js` source: server.js without its `export`s, and the fetch
|
|
34
|
+
* handler. `version` is the writedocs version, reported by the server;
|
|
35
|
+
* `basePath` the site's base ("" or "/docs" - only `[a-z0-9_/-]`, safe in a
|
|
36
|
+
* string literal), in front of /mcp and /mcp-index.json. */
|
|
37
|
+
export function mcpWorkerSource(version, basePath = '') {
|
|
38
|
+
const server = fs.readFileSync(SERVER_SOURCE, 'utf-8').replace(/^export (?=(?:const|let|async function|function) )/gm, '');
|
|
39
|
+
return `// Generated by writedocs ${version} - the site's MCP server at ${basePath}/mcp.
|
|
40
|
+
// Cloudflare Pages runs this file on its own; on Cloudflare Workers, use it as
|
|
41
|
+
// \`main\` with dist/ as the static assets (binding ASSETS). See
|
|
42
|
+
// https://github.com/writedocs/writedocs (src/cli/write-mcp-files.js).
|
|
43
|
+
|
|
44
|
+
${server}
|
|
45
|
+
const WRITEDOCS_VERSION = ${JSON.stringify(version)};
|
|
46
|
+
|
|
47
|
+
// The page index, read once per isolate from the site's own static files.
|
|
48
|
+
let indexPromise = null;
|
|
49
|
+
function loadIndex(request, env) {
|
|
50
|
+
if (!indexPromise) {
|
|
51
|
+
indexPromise = env.ASSETS.fetch(new URL('${basePath}/mcp-index.json', request.url))
|
|
52
|
+
.then((res) => {
|
|
53
|
+
if (!res.ok) throw new Error('mcp-index.json: HTTP ' + res.status);
|
|
54
|
+
return res.json();
|
|
55
|
+
})
|
|
56
|
+
.catch((err) => {
|
|
57
|
+
indexPromise = null;
|
|
58
|
+
throw err;
|
|
59
|
+
});
|
|
60
|
+
}
|
|
61
|
+
return indexPromise;
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
export default {
|
|
65
|
+
async fetch(request, env) {
|
|
66
|
+
const { pathname } = new URL(request.url);
|
|
67
|
+
if (pathname === '${basePath}/mcp' || pathname === '${basePath}/mcp/') {
|
|
68
|
+
return handleMcpHttp(request, { loadIndex: () => loadIndex(request, env), version: WRITEDOCS_VERSION });
|
|
69
|
+
}
|
|
70
|
+
return env.ASSETS.fetch(request);
|
|
71
|
+
},
|
|
72
|
+
};
|
|
73
|
+
`;
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
/** Writes the files into `distDir`. Returns { written: [names], skipped:
|
|
77
|
+
* reason or null } - nothing at all when there's no mcp-index.json
|
|
78
|
+
* (writedocs.json `"mcp": false`). `siteDir` is where the site itself is
|
|
79
|
+
* (dist/docs/ with a `basePath`). */
|
|
80
|
+
export function writeMcpFiles(distDir, contentDir, version, { siteDir = distDir, basePath = '' } = {}) {
|
|
81
|
+
if (!fs.existsSync(path.join(siteDir, 'mcp-index.json'))) return { written: [], skipped: null };
|
|
82
|
+
|
|
83
|
+
const own = ['_worker.js', '_routes.json'].filter((name) => fs.existsSync(path.join(distDir, name)));
|
|
84
|
+
if (own.length) {
|
|
85
|
+
return { written: [], skipped: `the project has its own ${own.join(' and ')} - /mcp needs its handler added there (see @writedocs/generator/mcp)` };
|
|
86
|
+
}
|
|
87
|
+
if (fs.existsSync(path.join(contentDir, 'functions'))) {
|
|
88
|
+
return { written: [], skipped: 'the project has a Cloudflare Pages functions/ folder, which a _worker.js would switch off - add /mcp there with @writedocs/generator/mcp' };
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
fs.writeFileSync(path.join(distDir, '_worker.js'), mcpWorkerSource(version, basePath));
|
|
92
|
+
fs.writeFileSync(path.join(distDir, '_routes.json'), JSON.stringify({ version: 1, include: [`${basePath}/mcp`, `${basePath}/mcp/`], exclude: [] }, null, 2) + '\n');
|
|
93
|
+
|
|
94
|
+
const ignorePath = path.join(distDir, '.assetsignore');
|
|
95
|
+
const existing = fs.existsSync(ignorePath) ? fs.readFileSync(ignorePath, 'utf-8') : '';
|
|
96
|
+
const lines = existing.split(/\r?\n/).map((l) => l.trim());
|
|
97
|
+
const missing = IGNORED_BY_WORKERS.filter((name) => !lines.includes(name));
|
|
98
|
+
if (missing.length) {
|
|
99
|
+
const prefix = existing && !existing.endsWith('\n') ? `${existing}\n` : existing;
|
|
100
|
+
fs.writeFileSync(ignorePath, `${prefix}${missing.join('\n')}\n`);
|
|
101
|
+
}
|
|
102
|
+
return { written: ['_worker.js', '_routes.json', '.assetsignore'], skipped: null };
|
|
103
|
+
}
|
|
@@ -2,6 +2,7 @@ import fs from 'node:fs';
|
|
|
2
2
|
import path from 'node:path';
|
|
3
3
|
import { readConfigText } from '../lib/config-file.js';
|
|
4
4
|
import { readMovedApiPages } from '../lib/moved-api-pages.js';
|
|
5
|
+
import { withBase } from '../lib/base-path.js';
|
|
5
6
|
|
|
6
7
|
// Astro's own `output: 'static'` redirects (both writedocs.json's `redirects`
|
|
7
8
|
// feature and the automatic "/" -> first-nav-page redirect in
|
|
@@ -32,10 +33,19 @@ import { readMovedApiPages } from '../lib/moved-api-pages.js';
|
|
|
32
33
|
// second, un-validated JSON.parse() here is safe - this only ever reads
|
|
33
34
|
// the one `redirects` array back out, nothing that needs zod's defaults
|
|
34
35
|
// or transforms.
|
|
35
|
-
|
|
36
|
+
//
|
|
37
|
+
// `distDir` is the site's own folder - dist/, or dist/docs/ with a
|
|
38
|
+
// `basePath` (base-path-layout.js) - where the built pages are read from.
|
|
39
|
+
// `outDir` is where `_redirects` goes: the root of dist/, always, since the
|
|
40
|
+
// host reads it there. `basePath` ("/docs") goes in front of every address
|
|
41
|
+
// the rules name, source and destination - the host matches the full path
|
|
42
|
+
// it was asked for - and adds `/ -> /docs/` for whoever opens the root of
|
|
43
|
+
// the address directly.
|
|
44
|
+
export function writeRedirectsFile(distDir, contentDir, { outDir = distDir, basePath = '' } = {}) {
|
|
36
45
|
const writedocsJson = JSON.parse(readConfigText(contentDir));
|
|
37
46
|
const redirects = writedocsJson.redirects ?? [];
|
|
38
47
|
const lines = [];
|
|
48
|
+
const at = (address) => withBase(basePath, address);
|
|
39
49
|
|
|
40
50
|
// writedocs.json's own `redirects` array - one line per entry, always 301
|
|
41
51
|
// (there's nowhere else in this project to source a status code from;
|
|
@@ -48,9 +58,9 @@ export function writeRedirectsFile(distDir, contentDir) {
|
|
|
48
58
|
// An address the site lists itself keeps its own destination.
|
|
49
59
|
const listed = new Set(redirects.map((r) => r.source));
|
|
50
60
|
for (const { source, destination } of redirects) {
|
|
51
|
-
lines.push(`${source} ${destination} 301`);
|
|
61
|
+
lines.push(`${at(source)} ${at(destination)} 301`);
|
|
52
62
|
const other = otherSlashForm(source);
|
|
53
|
-
if (other && !listed.has(other)) lines.push(`${other} ${destination} 301`);
|
|
63
|
+
if (other && !listed.has(other)) lines.push(`${at(other)} ${at(destination)} 301`);
|
|
54
64
|
}
|
|
55
65
|
// Generated API pages that changed address (lib/moved-api-pages.js) -
|
|
56
66
|
// after the site's own, which win for the same address (first match).
|
|
@@ -58,7 +68,7 @@ export function writeRedirectsFile(distDir, contentDir) {
|
|
|
58
68
|
// as requested.
|
|
59
69
|
for (const { source, destination } of readMovedApiPages(contentDir)) {
|
|
60
70
|
if (redirects.some((r) => r.source.replace(/\/+$/, '') === source)) continue;
|
|
61
|
-
lines.push(`${source} ${destination} 301`, `${source}/ ${destination} 301`);
|
|
71
|
+
lines.push(`${at(source)} ${at(destination)} 301`, `${at(source)}/ ${at(destination)} 301`);
|
|
62
72
|
}
|
|
63
73
|
|
|
64
74
|
// The automatic root "/" redirect (see the `rootRedirect` block in
|
|
@@ -75,8 +85,11 @@ export function writeRedirectsFile(distDir, contentDir) {
|
|
|
75
85
|
const html = fs.readFileSync(indexHtmlPath, 'utf8');
|
|
76
86
|
const match = html.match(/<meta http-equiv="refresh" content="\d+;\s*url=([^"]+)"/i);
|
|
77
87
|
// 302, not 301: see [...slug].astro - a browser keeps a 301 for good,
|
|
78
|
-
// and "/" stops redirecting once the site gets a home page.
|
|
79
|
-
|
|
88
|
+
// and "/" stops redirecting once the site gets a home page. The page's
|
|
89
|
+
// target already carries the base ([...slug].astro writes it so); the
|
|
90
|
+
// site's root under a base answers with and without the slash.
|
|
91
|
+
if (match) lines.push(basePath ? `${basePath}/ ${match[1]} 302` : `/ ${match[1]} 302`);
|
|
92
|
+
if (match && basePath) lines.push(`${basePath} ${match[1]} 302`);
|
|
80
93
|
}
|
|
81
94
|
|
|
82
95
|
// Folder addresses redirecting to the first page under them
|
|
@@ -87,9 +100,13 @@ export function writeRedirectsFile(distDir, contentDir) {
|
|
|
87
100
|
// automatic folder redirects. (Read before rewrite-redirect-pages.js makes
|
|
88
101
|
// every redirect page go at once.)
|
|
89
102
|
for (const { url, target } of temporaryRedirectPages(distDir)) {
|
|
90
|
-
lines.push(`${url} ${target} 302`, `${url.replace(/\/$/, '')} ${target} 302`);
|
|
103
|
+
lines.push(`${at(url)} ${target} 302`, `${at(url).replace(/\/$/, '')} ${target} 302`);
|
|
91
104
|
}
|
|
92
105
|
|
|
106
|
+
// The root of the address, opened directly (empresa.com/ on a host that
|
|
107
|
+
// serves only this site): to the site, under its base. Temporary, like "/".
|
|
108
|
+
if (basePath) lines.push(`/ ${basePath}/ 302`);
|
|
109
|
+
|
|
93
110
|
if (lines.length === 0) return;
|
|
94
111
|
|
|
95
112
|
const generated = [
|
|
@@ -101,7 +118,7 @@ export function writeRedirectsFile(distDir, contentDir) {
|
|
|
101
118
|
'',
|
|
102
119
|
].join('\n');
|
|
103
120
|
|
|
104
|
-
const redirectsPath = path.join(
|
|
121
|
+
const redirectsPath = path.join(outDir, '_redirects');
|
|
105
122
|
// A hand-written public/_redirects is already copied into dist by Astro
|
|
106
123
|
// by this point - preserve it (and its priority: first match wins) by
|
|
107
124
|
// appending after it rather than overwriting.
|
|
@@ -1,50 +1,51 @@
|
|
|
1
|
-
---
|
|
2
|
-
// Renders any writedocs.json `icon` string, whichever of the two forms it
|
|
3
|
-
// takes (see resolveIcon() in lib/config.ts): an Iconify icon id (looked
|
|
4
|
-
// up against whatever @iconify-json/* collections are installed - see
|
|
5
|
-
// astro.config.mjs) rendered as a real <svg>, or literal text/emoji
|
|
6
|
-
// rendered as-is. Centralizes the icon/text branch so BaseLayout.astro
|
|
7
|
-
// and Card.astro (the two places writedocs.json icon strings get rendered)
|
|
8
|
-
// don't each need their own copy of the resolveIcon() call + branch.
|
|
9
|
-
import { Icon } from 'astro-icon/components';
|
|
10
|
-
import { resolveIcon, iconExists } from '../lib/config';
|
|
11
|
-
import { report } from '../lib/cli-report.js';
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
//
|
|
18
|
-
//
|
|
19
|
-
//
|
|
20
|
-
//
|
|
21
|
-
//
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
//
|
|
27
|
-
//
|
|
28
|
-
//
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
// span
|
|
45
|
-
//
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
)
|
|
1
|
+
---
|
|
2
|
+
// Renders any writedocs.json `icon` string, whichever of the two forms it
|
|
3
|
+
// takes (see resolveIcon() in lib/config.ts): an Iconify icon id (looked
|
|
4
|
+
// up against whatever @iconify-json/* collections are installed - see
|
|
5
|
+
// astro.config.mjs) rendered as a real <svg>, or literal text/emoji
|
|
6
|
+
// rendered as-is. Centralizes the icon/text branch so BaseLayout.astro
|
|
7
|
+
// and Card.astro (the two places writedocs.json icon strings get rendered)
|
|
8
|
+
// don't each need their own copy of the resolveIcon() call + branch.
|
|
9
|
+
import { Icon } from 'astro-icon/components';
|
|
10
|
+
import { resolveIcon, iconExists } from '../lib/config';
|
|
11
|
+
import { report } from '../lib/cli-report.js';
|
|
12
|
+
import { siteHref } from '../lib/site-base';
|
|
13
|
+
|
|
14
|
+
interface Props {
|
|
15
|
+
icon?: string;
|
|
16
|
+
class?: string;
|
|
17
|
+
// Optional inline style passthrough - Icon.astro is the one real
|
|
18
|
+
// consumer, needing this to apply its own per-instance `size`/`color`
|
|
19
|
+
// props (arbitrary values, not a fixed set of classes like every
|
|
20
|
+
// other AppIcon call site uses). Left off Props' required list and
|
|
21
|
+
// undefined by default so every existing caller (BaseLayout, Card,
|
|
22
|
+
// Badge) is unaffected.
|
|
23
|
+
style?: string;
|
|
24
|
+
}
|
|
25
|
+
const { icon, class: className = 'wd-icon', style } = Astro.props as Props;
|
|
26
|
+
// An icon name no installed collection has renders nothing, with a warning
|
|
27
|
+
// (once per name - a sidebar icon renders on every page), instead of
|
|
28
|
+
// failing the whole build the way astro-icon does on a missing name.
|
|
29
|
+
// `writedocs validate` lists the same names ahead of time.
|
|
30
|
+
let resolved = icon ? resolveIcon(icon) : null;
|
|
31
|
+
if (icon && resolved?.kind === 'iconify' && !iconExists(icon)) {
|
|
32
|
+
const warned: Set<string> = ((globalThis as any).__wdWarnedIcons ??= new Set());
|
|
33
|
+
if (!warned.has(icon)) {
|
|
34
|
+
warned.add(icon);
|
|
35
|
+
report('warn', `Unknown icon "${icon}" - no installed icon set has it, so it's left out.`);
|
|
36
|
+
}
|
|
37
|
+
resolved = null;
|
|
38
|
+
}
|
|
39
|
+
---
|
|
40
|
+
{resolved && (
|
|
41
|
+
resolved.kind === 'iconify' ? (
|
|
42
|
+
<Icon name={resolved.name} class={className} style={style} />
|
|
43
|
+
) : resolved.kind === 'image' ? (
|
|
44
|
+
// Wrapped in the same <span> text icons use, so each caller's own
|
|
45
|
+
// span.<class> rule (font-size, spacing) sizes it; the image fills
|
|
46
|
+
// 1em of that (img.wd-icon-img in layout/styles/base.css).
|
|
47
|
+
<span class={className} style={style}><img src={siteHref(resolved.src)} alt="" class="wd-icon-img" /></span>
|
|
48
|
+
) : (
|
|
49
|
+
<span class={className} style={style}>{resolved.value}</span>
|
|
50
|
+
)
|
|
51
|
+
)}
|