@writedocs/generator 0.10.20 → 0.11.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/astro.config.mjs +32 -8
- package/package.json +3 -1
- package/src/cli/astro-output.js +44 -11
- package/src/cli/base-path-layout.js +44 -0
- package/src/cli/build.js +18 -9
- package/src/cli/check-built-styles.js +41 -33
- package/src/cli/dev.js +21 -4
- 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 +3 -2
- 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 -89
- 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/json-schema-descriptions.js +1 -0
- package/src/lib/link-check.js +7 -2
- 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/project-files-integration.js +2 -2
- package/src/lib/rehype-base-path.js +62 -0
- 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 +23 -10
- package/src/lib/wdignore-cases.json +195 -195
- package/src/lib/wdignore.js +177 -177
- 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 +245 -237
- package/writedocs.schema.json +6 -0
package/src/lib/mcp-index.ts
CHANGED
|
@@ -1,101 +1,102 @@
|
|
|
1
|
-
// mcp-index.json - everything the site's MCP server (src/mcp/server.js)
|
|
2
|
-
// answers from: every page an agent may read, as it should read it. Built
|
|
3
|
-
// from the same pipeline as llms-full.txt (markdownForAgents(): snippets
|
|
4
|
-
// inlined, `variables` filled in, <Visibility> for agents), in navigation
|
|
5
|
-
// order, with each page's real URL and the version/language it sits under in
|
|
6
|
-
// the navigation - what search_docs filters on.
|
|
7
|
-
import { getCollection, type CollectionEntry } from 'astro:content';
|
|
8
|
-
import fs from 'node:fs';
|
|
9
|
-
import path from 'node:path';
|
|
10
|
-
import {
|
|
11
|
-
loadDocsConfig,
|
|
12
|
-
normalizeEntryId,
|
|
13
|
-
findAllPages,
|
|
14
|
-
|
|
15
|
-
fileIdForEntry,
|
|
16
|
-
resolveSections,
|
|
17
|
-
resolveLandings,
|
|
18
|
-
flattenNav,
|
|
19
|
-
} from './config';
|
|
20
|
-
import { pageMarkdown } from './openapi-markdown';
|
|
21
|
-
import { orderByNavigation } from './llms.js';
|
|
22
|
-
import { writedocsTempDir } from './writedocs-temp-dir.js';
|
|
23
|
-
|
|
24
|
-
type DocsEntry = CollectionEntry<'pages'> | CollectionEntry<'generatedDocs'>;
|
|
25
|
-
|
|
26
|
-
export interface McpDoc {
|
|
27
|
-
path: string;
|
|
28
|
-
url: string;
|
|
29
|
-
title: string;
|
|
30
|
-
description: string;
|
|
31
|
-
content: string;
|
|
32
|
-
version: string;
|
|
33
|
-
language: string;
|
|
34
|
-
}
|
|
35
|
-
|
|
36
|
-
export interface McpIndex {
|
|
37
|
-
meta: { name: string; description: string; siteUrl: string; generator: 'writedocs' };
|
|
38
|
-
docs: McpDoc[];
|
|
39
|
-
}
|
|
40
|
-
|
|
41
|
-
export async function mcpIndex(): Promise<McpIndex> {
|
|
42
|
-
const contentDir = process.env.WRITEDOCS_CONTENT_DIR || process.cwd();
|
|
43
|
-
const packageRoot = process.env.WRITEDOCS_PACKAGE_ROOT || process.cwd();
|
|
44
|
-
const config = loadDocsConfig(contentDir);
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
const
|
|
49
|
-
const
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
//
|
|
57
|
-
//
|
|
58
|
-
|
|
59
|
-
const
|
|
60
|
-
const
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
if (segment.kind === '
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
//
|
|
76
|
-
|
|
77
|
-
.
|
|
78
|
-
|
|
79
|
-
const
|
|
80
|
-
|
|
81
|
-
//
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
}
|
|
1
|
+
// mcp-index.json - everything the site's MCP server (src/mcp/server.js)
|
|
2
|
+
// answers from: every page an agent may read, as it should read it. Built
|
|
3
|
+
// from the same pipeline as llms-full.txt (markdownForAgents(): snippets
|
|
4
|
+
// inlined, `variables` filled in, <Visibility> for agents), in navigation
|
|
5
|
+
// order, with each page's real URL and the version/language it sits under in
|
|
6
|
+
// the navigation - what search_docs filters on.
|
|
7
|
+
import { getCollection, type CollectionEntry } from 'astro:content';
|
|
8
|
+
import fs from 'node:fs';
|
|
9
|
+
import path from 'node:path';
|
|
10
|
+
import {
|
|
11
|
+
loadDocsConfig,
|
|
12
|
+
normalizeEntryId,
|
|
13
|
+
findAllPages,
|
|
14
|
+
resolveSiteRoot,
|
|
15
|
+
fileIdForEntry,
|
|
16
|
+
resolveSections,
|
|
17
|
+
resolveLandings,
|
|
18
|
+
flattenNav,
|
|
19
|
+
} from './config';
|
|
20
|
+
import { pageMarkdown } from './openapi-markdown';
|
|
21
|
+
import { orderByNavigation } from './llms.js';
|
|
22
|
+
import { writedocsTempDir } from './writedocs-temp-dir.js';
|
|
23
|
+
|
|
24
|
+
type DocsEntry = CollectionEntry<'pages'> | CollectionEntry<'generatedDocs'>;
|
|
25
|
+
|
|
26
|
+
export interface McpDoc {
|
|
27
|
+
path: string;
|
|
28
|
+
url: string;
|
|
29
|
+
title: string;
|
|
30
|
+
description: string;
|
|
31
|
+
content: string;
|
|
32
|
+
version: string;
|
|
33
|
+
language: string;
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
export interface McpIndex {
|
|
37
|
+
meta: { name: string; description: string; siteUrl: string; generator: 'writedocs' };
|
|
38
|
+
docs: McpDoc[];
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
export async function mcpIndex(): Promise<McpIndex> {
|
|
42
|
+
const contentDir = process.env.WRITEDOCS_CONTENT_DIR || process.cwd();
|
|
43
|
+
const packageRoot = process.env.WRITEDOCS_PACKAGE_ROOT || process.cwd();
|
|
44
|
+
const config = loadDocsConfig(contentDir);
|
|
45
|
+
// {domain}{basePath} - or the base alone ("/docs", or "") with no `domain`.
|
|
46
|
+
const siteUrl = resolveSiteRoot(config);
|
|
47
|
+
|
|
48
|
+
const hasGeneratedDocs = fs.existsSync(path.join(writedocsTempDir(contentDir), 'generated-docs'));
|
|
49
|
+
const hasPages = findAllPages(contentDir).length > 0;
|
|
50
|
+
const [pagesEntries, generatedDocsEntries] = await Promise.all([
|
|
51
|
+
hasPages ? getCollection('pages') : Promise.resolve([]),
|
|
52
|
+
hasGeneratedDocs ? getCollection('generatedDocs') : Promise.resolve([]),
|
|
53
|
+
]);
|
|
54
|
+
const entries: DocsEntry[] = [...pagesEntries, ...generatedDocsEntries];
|
|
55
|
+
|
|
56
|
+
// The version and language each page sits under, from its section's path
|
|
57
|
+
// through the navigation (tabs > versions > languages > ...).
|
|
58
|
+
// An item's own page that no sidebar lists sits under that item.
|
|
59
|
+
const sections = resolveSections(config.navigation);
|
|
60
|
+
const landings = resolveLandings(config.navigation);
|
|
61
|
+
const placeOf = (fileId: string) => {
|
|
62
|
+
const section =
|
|
63
|
+
sections.find((s) => flattenNav(s.pages).some((e) => e.slug === fileId)) ??
|
|
64
|
+
landings.find((landing) => landing.slug === fileId);
|
|
65
|
+
const place = { version: '', language: '' };
|
|
66
|
+
for (const segment of section?.path ?? []) {
|
|
67
|
+
const item = segment.items[segment.index] as { version?: string; language?: string };
|
|
68
|
+
if (segment.kind === 'version' && item.version) place.version = item.version;
|
|
69
|
+
if (segment.kind === 'language' && item.language) place.language = item.language;
|
|
70
|
+
}
|
|
71
|
+
return place;
|
|
72
|
+
};
|
|
73
|
+
|
|
74
|
+
const docs = entries
|
|
75
|
+
// Same pages llms.txt lists: not `noindex`, not a frontmatter `url`
|
|
76
|
+
// (an external link, with no content of its own).
|
|
77
|
+
.filter((entry) => !entry.data.seo?.noindex && !entry.data.url)
|
|
78
|
+
.map((entry) => {
|
|
79
|
+
const slug = normalizeEntryId(entry.id);
|
|
80
|
+
const fileId = fileIdForEntry(contentDir, packageRoot, entry);
|
|
81
|
+
// An API page's source is a near-empty stub - its operation, written
|
|
82
|
+
// out from the spec, follows its own text (lib/openapi-markdown.ts).
|
|
83
|
+
const content = pageMarkdown(entry, { contentDir, packageRoot, variables: config.variables, siteUrl: siteUrl || null });
|
|
84
|
+
return {
|
|
85
|
+
slug,
|
|
86
|
+
fileId,
|
|
87
|
+
doc: {
|
|
88
|
+
path: fileId,
|
|
89
|
+
url: `${siteUrl}${slug === 'index' ? '/' : `/${slug}/`}`,
|
|
90
|
+
title: entry.data.title,
|
|
91
|
+
description: entry.data.description ?? '',
|
|
92
|
+
content,
|
|
93
|
+
...placeOf(fileId),
|
|
94
|
+
},
|
|
95
|
+
};
|
|
96
|
+
});
|
|
97
|
+
|
|
98
|
+
return {
|
|
99
|
+
meta: { name: config.name, description: config.description ?? '', siteUrl, generator: 'writedocs' },
|
|
100
|
+
docs: orderByNavigation(docs, config.navigation).map((d) => d.doc),
|
|
101
|
+
};
|
|
102
|
+
}
|
|
@@ -97,7 +97,7 @@ export function publishProjectFiles(contentDir) {
|
|
|
97
97
|
};
|
|
98
98
|
}
|
|
99
99
|
|
|
100
|
-
export function generatedRobotsTxt({ siteUrl, seo }) {
|
|
100
|
+
export function generatedRobotsTxt({ siteUrl, seo, basePath = '' }) {
|
|
101
101
|
return {
|
|
102
102
|
name: 'writedocs-robots-txt',
|
|
103
103
|
hooks: {
|
|
@@ -109,7 +109,7 @@ export function generatedRobotsTxt({ siteUrl, seo }) {
|
|
|
109
109
|
return;
|
|
110
110
|
}
|
|
111
111
|
const sitemap = ['sitemap.xml', 'sitemap-index.xml'].find((name) => fs.existsSync(path.join(outDir, name))) ?? null;
|
|
112
|
-
fs.writeFileSync(target, robotsTxt({ siteUrl, sitemap, noindex: isNoindex(seo) }));
|
|
112
|
+
fs.writeFileSync(target, robotsTxt({ siteUrl, sitemap, noindex: isNoindex(seo), basePath }));
|
|
113
113
|
},
|
|
114
114
|
},
|
|
115
115
|
};
|
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
// writedocs.json's `basePath` in a page's own content: a link or a picture
|
|
2
|
+
// written from the site's root - `[a](/guides/a)`, ``,
|
|
3
|
+
// `<a href="/guides/a">`, `<img src="/images/x.png">` - gets the base in
|
|
4
|
+
// front (`/docs/guides/a`), so the author keeps writing site addresses
|
|
5
|
+
// whether or not the site is served under a path. A relative address, a full
|
|
6
|
+
// URL, `#anchor` and `mailto:` stay as written (lib/base-path.js).
|
|
7
|
+
//
|
|
8
|
+
// What it changes: Markdown's own elements (hast `element`), raw HTML in a
|
|
9
|
+
// .md page (`raw`), and HTML tags written in MDX (`mdxJsx*` with a lowercase
|
|
10
|
+
// name) - their href, src, srcset, poster and action. Not a component's
|
|
11
|
+
// props (`<Card href="/a">`): a component writes its own addresses, with
|
|
12
|
+
// siteHref() (lib/site-base.ts), so prefixing here too would give them the
|
|
13
|
+
// base twice. Not a value written as an expression (`href={link}`), which
|
|
14
|
+
// isn't known until the page runs.
|
|
15
|
+
//
|
|
16
|
+
// Runs last among the rehype plugins (astro.config.mjs): rehypeImageLoading
|
|
17
|
+
// reads an image's file by its site address before this changes it.
|
|
18
|
+
import { withBase, srcsetWithBase } from './base-path.js';
|
|
19
|
+
|
|
20
|
+
/** hast property names (camelCase) of the attributes that hold an address. */
|
|
21
|
+
const HAST_URL_PROPERTIES = ['href', 'src', 'poster', 'action', 'formAction'];
|
|
22
|
+
/** The same attributes as written in HTML/JSX. */
|
|
23
|
+
const JSX_URL_ATTRIBUTES = new Set(['href', 'src', 'poster', 'action', 'formAction', 'formaction']);
|
|
24
|
+
const JSX_SRCSET_ATTRIBUTES = new Set(['srcSet', 'srcset']);
|
|
25
|
+
|
|
26
|
+
const isJsx = (node) => node.type === 'mdxJsxFlowElement' || node.type === 'mdxJsxTextElement';
|
|
27
|
+
/** An HTML tag (`a`, `img`), not a component (`Card`, `Tree.Folder`). */
|
|
28
|
+
const isHtmlTag = (name) => typeof name === 'string' && /^[a-z][a-z0-9-]*$/.test(name);
|
|
29
|
+
|
|
30
|
+
/** A raw HTML string with the base in front of each site address in an
|
|
31
|
+
* href, src, poster or action attribute. */
|
|
32
|
+
export function rawHtmlWithBase(base, html) {
|
|
33
|
+
if (!base) return html;
|
|
34
|
+
return html.replace(/(\s(?:href|src|poster|action)\s*=\s*["'])(\/(?!\/))/gi, `$1${base}$2`);
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
export function rehypeBasePath({ base = '' } = {}) {
|
|
38
|
+
return (tree) => {
|
|
39
|
+
if (!base) return;
|
|
40
|
+
const visit = (node) => {
|
|
41
|
+
if (node.type === 'element' && node.properties) {
|
|
42
|
+
const p = node.properties;
|
|
43
|
+
for (const name of HAST_URL_PROPERTIES) {
|
|
44
|
+
if (typeof p[name] === 'string') p[name] = withBase(base, p[name]);
|
|
45
|
+
}
|
|
46
|
+
if (typeof p.srcSet === 'string') p.srcSet = srcsetWithBase(base, p.srcSet);
|
|
47
|
+
// hast keeps srcset as a list of its comma-separated candidates.
|
|
48
|
+
else if (Array.isArray(p.srcSet)) p.srcSet = p.srcSet.map((candidate) => srcsetWithBase(base, candidate));
|
|
49
|
+
} else if (node.type === 'raw' && typeof node.value === 'string') {
|
|
50
|
+
node.value = rawHtmlWithBase(base, node.value);
|
|
51
|
+
} else if (isJsx(node) && isHtmlTag(node.name)) {
|
|
52
|
+
for (const attribute of node.attributes ?? []) {
|
|
53
|
+
if (attribute.type !== 'mdxJsxAttribute' || typeof attribute.value !== 'string') continue;
|
|
54
|
+
if (JSX_URL_ATTRIBUTES.has(attribute.name)) attribute.value = withBase(base, attribute.value);
|
|
55
|
+
else if (JSX_SRCSET_ATTRIBUTES.has(attribute.name)) attribute.value = srcsetWithBase(base, attribute.value);
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
if (Array.isArray(node.children)) node.children.forEach(visit);
|
|
59
|
+
};
|
|
60
|
+
visit(tree);
|
|
61
|
+
};
|
|
62
|
+
}
|
package/src/lib/robots-txt.js
CHANGED
|
@@ -1,16 +1,21 @@
|
|
|
1
|
-
// The robots.txt a build writes when the project has none of its own
|
|
2
|
-
// (lib/project-files-integration.js). Plain JavaScript, for
|
|
3
|
-
// scripts/robots-txt.test.js.
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
*
|
|
8
|
-
*
|
|
9
|
-
* `
|
|
10
|
-
*
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
1
|
+
// The robots.txt a build writes when the project has none of its own
|
|
2
|
+
// (lib/project-files-integration.js). Plain JavaScript, for
|
|
3
|
+
// scripts/robots-txt.test.js.
|
|
4
|
+
import { withBase } from './base-path.js';
|
|
5
|
+
|
|
6
|
+
/** `siteUrl`: the site's URL ({domain}{basePath}), or null without a `domain`.
|
|
7
|
+
* `sitemap`: the sitemap's file name in the build ("sitemap.xml",
|
|
8
|
+
* "sitemap-index.xml"), or null when there's none.
|
|
9
|
+
* `noindex`: the whole site is kept out of search engines (writedocs.json's
|
|
10
|
+
* `seo.noindex`, or a `seo.robots` with "noindex") - crawlers are then
|
|
11
|
+
* asked to stay out, and no sitemap is advertised.
|
|
12
|
+
* `basePath`: the site's base ("/docs", lib/base-path.js) - the rules then
|
|
13
|
+
* cover the site's own path, ready to copy into the robots.txt at the root
|
|
14
|
+
* of the domain (crawlers only read that one, not /docs/robots.txt). */
|
|
15
|
+
export function robotsTxt({ siteUrl = null, sitemap = null, noindex = false, basePath = '' } = {}) {
|
|
16
|
+
const root = withBase(basePath, '/');
|
|
17
|
+
if (noindex) return ['User-agent: *', `Disallow: ${root}`, ''].join('\n');
|
|
18
|
+
const lines = ['User-agent: *', `Allow: ${root}`];
|
|
19
|
+
if (siteUrl && sitemap) lines.push('', `Sitemap: ${siteUrl}/${sitemap}`);
|
|
20
|
+
return `${lines.join('\n')}\n`;
|
|
21
|
+
}
|