@writedocs/generator 0.10.20 → 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.
Files changed (52) hide show
  1. package/astro.config.mjs +32 -8
  2. package/package.json +1 -1
  3. package/src/cli/base-path-layout.js +44 -0
  4. package/src/cli/build.js +177 -168
  5. package/src/cli/check-built-styles.js +41 -33
  6. package/src/cli/dev.js +261 -244
  7. package/src/cli/run-pagefind.js +154 -148
  8. package/src/cli/write-mcp-files.js +103 -96
  9. package/src/cli/write-redirects-file.js +25 -8
  10. package/src/components/AppIcon.astro +51 -50
  11. package/src/components/Card.astro +193 -192
  12. package/src/components/CopyPageMenu.astro +374 -370
  13. package/src/components/Hint.astro +188 -187
  14. package/src/components/Icon.astro +72 -71
  15. package/src/components/Image.astro +3 -2
  16. package/src/components/Tile.astro +67 -66
  17. package/src/components/Video.astro +137 -136
  18. package/src/layout/BaseLayout.astro +21 -12
  19. package/src/layout/components/AnalyticsScripts.astro +6 -2
  20. package/src/layout/components/Breadcrumbs.astro +98 -97
  21. package/src/layout/components/ConsentBanner.astro +119 -118
  22. package/src/layout/components/MobileMenu.astro +229 -228
  23. package/src/layout/components/NavTree.astro +393 -392
  24. package/src/layout/components/Sidebar.astro +232 -231
  25. package/src/layout/components/SiteFooter.astro +87 -86
  26. package/src/layout/components/TopBar.astro +386 -385
  27. package/src/lib/agent-markdown.js +164 -162
  28. package/src/lib/asset-dimensions.js +89 -89
  29. package/src/lib/base-path.js +90 -0
  30. package/src/lib/config-schema.js +10 -0
  31. package/src/lib/config-schema.ts +17 -0
  32. package/src/lib/config.ts +1314 -1289
  33. package/src/lib/consent.js +108 -102
  34. package/src/lib/json-schema-descriptions.js +1 -0
  35. package/src/lib/link-check.js +7 -2
  36. package/src/lib/llms-index.ts +90 -88
  37. package/src/lib/mcp-dev-integration.js +65 -60
  38. package/src/lib/mcp-index.ts +102 -101
  39. package/src/lib/project-files-integration.js +2 -2
  40. package/src/lib/rehype-base-path.js +62 -0
  41. package/src/lib/robots-txt.js +21 -16
  42. package/src/lib/seo-tags.js +155 -140
  43. package/src/lib/site-base.ts +27 -0
  44. package/src/lib/styles-asset-integration.js +23 -10
  45. package/src/lib/wdignore-cases.json +195 -195
  46. package/src/lib/wdignore.js +177 -177
  47. package/src/pages/404.astro +63 -62
  48. package/src/pages/[...slug].astro +1604 -1597
  49. package/src/pages/[...slug].md.ts +93 -93
  50. package/src/pages/llms-full.txt.ts +88 -86
  51. package/src/scripts/search.ts +241 -237
  52. package/writedocs.schema.json +6 -0
@@ -1,93 +1,93 @@
1
- import { getCollection, type CollectionEntry } from 'astro:content';
2
- import fs from 'node:fs';
3
- import path from 'node:path';
4
- import type { APIRoute } from 'astro';
5
- import { loadDocsConfig, normalizeEntryId, findAllPages, contextMenuOptions, resolveSiteUrl } from '../lib/config';
6
- import { pageMarkdownDocument } from '../lib/agent-directive.js';
7
- import { writedocsTempDir } from '../lib/writedocs-temp-dir.js';
8
- import { pageMarkdown } from '../lib/openapi-markdown';
9
-
10
- // The raw-Markdown twin of [...slug].astro: every content page is also
11
- // reachable at the exact same slug with a literal ".md" suffix (e.g.
12
- // /guides/foo/ -> /guides/foo.md), serving its untouched MDX/Markdown
13
- // source instead of rendered HTML - what the "Copy page"/"View as
14
- // Markdown" menu (CopyPageMenu.astro, wired in from [...slug].astro)
15
- // links to, and what an LLM fetching that URL directly gets. On by
16
- // default, like the menu; writedocs.json `"contextMenu": false` (see
17
- // contextMenuOptions() in lib/config-schema.ts) leaves out the .md routes
18
- // too, not just the menu.
19
- //
20
- // A literal ".md" filename suffix rather than a `[...slug]` capture
21
- // covering it: naming the file `[...slug].md.ts` makes Astro treat ".md"
22
- // as a static part of the route, not part of the `...slug` rest
23
- // parameter - requesting /guides/foo.md resolves with `slug ===
24
- // "guides/foo"`, exactly like the HTML router's own `entry.id`-derived
25
- // slug, just without the trailing-slash convention HTML pages use.
26
- //
27
- // getStaticPaths here is intentionally self-contained rather than
28
- // sharing a module-level helper with [...slug].astro's own
29
- // getStaticPaths - see that file's own extensive comment on Astro's
30
- // getStaticPaths bundling extraction silently dropping top-level
31
- // helper functions that are only referenced from inside it.
32
- type DocsEntry = CollectionEntry<'pages'> | CollectionEntry<'generatedDocs'>;
33
-
34
- export async function getStaticPaths() {
35
- const contentDir = process.env.WRITEDOCS_CONTENT_DIR || process.cwd();
36
- const config = loadDocsConfig(contentDir);
37
- // `"contextMenu": false` - the feature is off entirely, these routes
38
- // included (not just the menu UI - see the file-level comment above).
39
- if (contextMenuOptions(config.contextMenu).length === 0) return [];
40
-
41
- const hasGeneratedDocs = fs.existsSync(path.join(writedocsTempDir(contentDir), 'generated-docs'));
42
- const hasPages = findAllPages(contentDir).length > 0;
43
- const [pagesEntries, generatedDocsEntries] = await Promise.all([
44
- hasPages ? getCollection('pages') : Promise.resolve([]),
45
- hasGeneratedDocs ? getCollection('generatedDocs') : Promise.resolve([]),
46
- ]);
47
- const entries: DocsEntry[] = [...pagesEntries, ...generatedDocsEntries];
48
-
49
- return entries
50
- // A frontmatter `url` page's HTML route is a redirect to that link -
51
- // there's no page content to serve as Markdown.
52
- .filter((entry) => !entry.data.url)
53
- .map((entry) => ({
54
- params: { slug: normalizeEntryId(entry.id) },
55
- // Passed along rather than re-read per page - GET only renders one entry.
56
- props: { entry, variables: config.variables, siteUrl: resolveSiteUrl(config) },
57
- }));
58
- }
59
-
60
- interface Props {
61
- entry: DocsEntry;
62
- variables: Record<string, string>;
63
- siteUrl: string | null;
64
- }
65
-
66
- export const GET: APIRoute = ({ props }) => {
67
- const { entry, variables, siteUrl } = props as Props;
68
- const contentDir = process.env.WRITEDOCS_CONTENT_DIR || process.cwd();
69
- const packageRoot = process.env.WRITEDOCS_PACKAGE_ROOT || process.cwd();
70
- // entry.body is the raw, frontmatter-stripped MDX/Markdown source text
71
- // Astro's glob() loader already read off disk and stashed on every
72
- // entry by default (see astro/dist/content/loaders/glob.js) - reusing
73
- // it here means this route needs no separate file read/parse of its
74
- // own, and always matches exactly what [...slug].astro rendered from
75
- // (same entry, same collection query).
76
- // What the page shows rather than its raw source: Mintlify's <Visibility>
77
- // for agents, imported snippets inlined, `variables` filled in - see
78
- // lib/agent-markdown.js (llms-full.txt uses the same).
79
- // An API page's operation is written out after its own text (lib/openapi-markdown.ts).
80
- const body = pageMarkdown(entry, { contentDir, packageRoot, variables, siteUrl });
81
- // The title, a line pointing an agent at llms.txt, the page's description, then the page
82
- // (lib/agent-directive.js).
83
- const markdown = pageMarkdownDocument(
84
- entry.data.title,
85
- body,
86
- siteUrl,
87
- // An API page's description is the operation's, which the body already has.
88
- entry.data.openapi ? undefined : entry.data.description
89
- );
90
- return new Response(markdown, {
91
- headers: { 'Content-Type': 'text/markdown; charset=utf-8' },
92
- });
93
- };
1
+ import { getCollection, type CollectionEntry } from 'astro:content';
2
+ import fs from 'node:fs';
3
+ import path from 'node:path';
4
+ import type { APIRoute } from 'astro';
5
+ import { loadDocsConfig, normalizeEntryId, findAllPages, contextMenuOptions, resolveSiteRoot } from '../lib/config';
6
+ import { pageMarkdownDocument } from '../lib/agent-directive.js';
7
+ import { writedocsTempDir } from '../lib/writedocs-temp-dir.js';
8
+ import { pageMarkdown } from '../lib/openapi-markdown';
9
+
10
+ // The raw-Markdown twin of [...slug].astro: every content page is also
11
+ // reachable at the exact same slug with a literal ".md" suffix (e.g.
12
+ // /guides/foo/ -> /guides/foo.md), serving its untouched MDX/Markdown
13
+ // source instead of rendered HTML - what the "Copy page"/"View as
14
+ // Markdown" menu (CopyPageMenu.astro, wired in from [...slug].astro)
15
+ // links to, and what an LLM fetching that URL directly gets. On by
16
+ // default, like the menu; writedocs.json `"contextMenu": false` (see
17
+ // contextMenuOptions() in lib/config-schema.ts) leaves out the .md routes
18
+ // too, not just the menu.
19
+ //
20
+ // A literal ".md" filename suffix rather than a `[...slug]` capture
21
+ // covering it: naming the file `[...slug].md.ts` makes Astro treat ".md"
22
+ // as a static part of the route, not part of the `...slug` rest
23
+ // parameter - requesting /guides/foo.md resolves with `slug ===
24
+ // "guides/foo"`, exactly like the HTML router's own `entry.id`-derived
25
+ // slug, just without the trailing-slash convention HTML pages use.
26
+ //
27
+ // getStaticPaths here is intentionally self-contained rather than
28
+ // sharing a module-level helper with [...slug].astro's own
29
+ // getStaticPaths - see that file's own extensive comment on Astro's
30
+ // getStaticPaths bundling extraction silently dropping top-level
31
+ // helper functions that are only referenced from inside it.
32
+ type DocsEntry = CollectionEntry<'pages'> | CollectionEntry<'generatedDocs'>;
33
+
34
+ export async function getStaticPaths() {
35
+ const contentDir = process.env.WRITEDOCS_CONTENT_DIR || process.cwd();
36
+ const config = loadDocsConfig(contentDir);
37
+ // `"contextMenu": false` - the feature is off entirely, these routes
38
+ // included (not just the menu UI - see the file-level comment above).
39
+ if (contextMenuOptions(config.contextMenu).length === 0) return [];
40
+
41
+ const hasGeneratedDocs = fs.existsSync(path.join(writedocsTempDir(contentDir), 'generated-docs'));
42
+ const hasPages = findAllPages(contentDir).length > 0;
43
+ const [pagesEntries, generatedDocsEntries] = await Promise.all([
44
+ hasPages ? getCollection('pages') : Promise.resolve([]),
45
+ hasGeneratedDocs ? getCollection('generatedDocs') : Promise.resolve([]),
46
+ ]);
47
+ const entries: DocsEntry[] = [...pagesEntries, ...generatedDocsEntries];
48
+
49
+ return entries
50
+ // A frontmatter `url` page's HTML route is a redirect to that link -
51
+ // there's no page content to serve as Markdown.
52
+ .filter((entry) => !entry.data.url)
53
+ .map((entry) => ({
54
+ params: { slug: normalizeEntryId(entry.id) },
55
+ // Passed along rather than re-read per page - GET only renders one entry.
56
+ props: { entry, variables: config.variables, siteUrl: resolveSiteRoot(config) || null },
57
+ }));
58
+ }
59
+
60
+ interface Props {
61
+ entry: DocsEntry;
62
+ variables: Record<string, string>;
63
+ siteUrl: string | null;
64
+ }
65
+
66
+ export const GET: APIRoute = ({ props }) => {
67
+ const { entry, variables, siteUrl } = props as Props;
68
+ const contentDir = process.env.WRITEDOCS_CONTENT_DIR || process.cwd();
69
+ const packageRoot = process.env.WRITEDOCS_PACKAGE_ROOT || process.cwd();
70
+ // entry.body is the raw, frontmatter-stripped MDX/Markdown source text
71
+ // Astro's glob() loader already read off disk and stashed on every
72
+ // entry by default (see astro/dist/content/loaders/glob.js) - reusing
73
+ // it here means this route needs no separate file read/parse of its
74
+ // own, and always matches exactly what [...slug].astro rendered from
75
+ // (same entry, same collection query).
76
+ // What the page shows rather than its raw source: Mintlify's <Visibility>
77
+ // for agents, imported snippets inlined, `variables` filled in - see
78
+ // lib/agent-markdown.js (llms-full.txt uses the same).
79
+ // An API page's operation is written out after its own text (lib/openapi-markdown.ts).
80
+ const body = pageMarkdown(entry, { contentDir, packageRoot, variables, siteUrl });
81
+ // The title, a line pointing an agent at llms.txt, the page's description, then the page
82
+ // (lib/agent-directive.js).
83
+ const markdown = pageMarkdownDocument(
84
+ entry.data.title,
85
+ body,
86
+ siteUrl,
87
+ // An API page's description is the operation's, which the body already has.
88
+ entry.data.openapi ? undefined : entry.data.description
89
+ );
90
+ return new Response(markdown, {
91
+ headers: { 'Content-Type': 'text/markdown; charset=utf-8' },
92
+ });
93
+ };
@@ -1,86 +1,88 @@
1
- import { getCollection, type CollectionEntry } from 'astro:content';
2
- import fs from 'node:fs';
3
- import path from 'node:path';
4
- import type { APIRoute } from 'astro';
5
- import { loadDocsConfig, normalizeEntryId, findAllPages, resolveSiteUrl, fileIdForEntry } from '../lib/config';
6
- import { writedocsTempDir } from '../lib/writedocs-temp-dir.js';
7
- import { pageMarkdown } from '../lib/openapi-markdown';
8
- import { orderByNavigation } from '../lib/llms.js';
9
-
10
- // The "everything, concatenated" half of the llms.txt pair - see
11
- // llms.txt.ts (right next to this file) for the lightweight index half,
12
- // and that file's own top-of-file comment for the shared design notes
13
- // (fixed non-dynamic route, unconditional/always generated, custom
14
- // project-root override file support).
15
- //
16
- // Unlike llms.txt.ts, there's no `contextMenu`-dependent branch here:
17
- // this route doesn't link to anything, it *is* the raw content, sourced
18
- // the same way [...slug].md.ts sources a single page's raw content
19
- // (`entry.body`, already read off disk by the glob() loader - no
20
- // separate file read needed).
21
- type DocsEntry = CollectionEntry<'pages'> | CollectionEntry<'generatedDocs'>;
22
-
23
- export const GET: APIRoute = async () => {
24
- const contentDir = process.env.WRITEDOCS_CONTENT_DIR || process.cwd();
25
-
26
- const customPath = path.join(contentDir, 'llms-full.txt');
27
- if (fs.existsSync(customPath)) {
28
- return new Response(fs.readFileSync(customPath, 'utf-8'), {
29
- headers: { 'Content-Type': 'text/plain; charset=utf-8' },
30
- });
31
- }
32
-
33
- const packageRoot = process.env.WRITEDOCS_PACKAGE_ROOT || process.cwd();
34
- const config = loadDocsConfig(contentDir);
35
- const siteUrl = resolveSiteUrl(config);
36
-
37
- const hasGeneratedDocs = fs.existsSync(path.join(writedocsTempDir(contentDir), 'generated-docs'));
38
- const hasPages = findAllPages(contentDir).length > 0;
39
- const [pagesEntries, generatedDocsEntries] = await Promise.all([
40
- hasPages ? getCollection('pages') : Promise.resolve([]),
41
- hasGeneratedDocs ? getCollection('generatedDocs') : Promise.resolve([]),
42
- ]);
43
- const entries: DocsEntry[] = [...pagesEntries, ...generatedDocsEntries];
44
-
45
- const unordered = entries
46
- // Same noindex exclusion llms.txt.ts applies to its own listing -
47
- // see that file's comment.
48
- .filter((entry) => !entry.data.seo?.noindex)
49
- // Same `url` exclusion as llms.txt.ts - a redirect, not a page.
50
- .filter((entry) => !entry.data.url)
51
- .map((entry: DocsEntry) => {
52
- const slug = normalizeEntryId(entry.id);
53
- // What the page shows, not its raw source: <Visibility> for agents,
54
- // imported snippets inlined, `variables` filled in - same as the .md
55
- // route (lib/agent-markdown.js).
56
- // An API page's operation is written out after its own text (lib/openapi-markdown.ts).
57
- const body = pageMarkdown(entry, { contentDir, packageRoot, variables: config.variables, siteUrl });
58
- // The page's own URL, so an agent can cite it.
59
- const url = `${siteUrl ?? ''}${slug === 'index' ? '/' : `/${slug}/`}`;
60
- return {
61
- slug,
62
- fileId: fileIdForEntry(contentDir, packageRoot, entry),
63
- title: entry.data.title,
64
- description: entry.data.description,
65
- url,
66
- body,
67
- };
68
- });
69
- // Navigation order, same as llms.txt.
70
- const sections = orderByNavigation(unordered, config.navigation);
71
-
72
- const lines: string[] = [`# ${config.name}`, ''];
73
- if (config.description) lines.push(`> ${config.description}`, '');
74
-
75
- for (const section of sections) {
76
- lines.push('---', '', `# ${section.title}`, '', `URL: ${section.url}`, '');
77
- if (section.description) lines.push(`> ${section.description}`, '');
78
- lines.push(section.body.trim(), '');
79
- }
80
-
81
- const content = lines.join('\n') + '\n';
82
-
83
- return new Response(content, {
84
- headers: { 'Content-Type': 'text/plain; charset=utf-8' },
85
- });
86
- };
1
+ import { getCollection, type CollectionEntry } from 'astro:content';
2
+ import fs from 'node:fs';
3
+ import path from 'node:path';
4
+ import type { APIRoute } from 'astro';
5
+ import { loadDocsConfig, normalizeEntryId, findAllPages, resolveSiteRoot, fileIdForEntry } from '../lib/config';
6
+ import { writedocsTempDir } from '../lib/writedocs-temp-dir.js';
7
+ import { pageMarkdown } from '../lib/openapi-markdown';
8
+ import { orderByNavigation } from '../lib/llms.js';
9
+
10
+ // The "everything, concatenated" half of the llms.txt pair - see
11
+ // llms.txt.ts (right next to this file) for the lightweight index half,
12
+ // and that file's own top-of-file comment for the shared design notes
13
+ // (fixed non-dynamic route, unconditional/always generated, custom
14
+ // project-root override file support).
15
+ //
16
+ // Unlike llms.txt.ts, there's no `contextMenu`-dependent branch here:
17
+ // this route doesn't link to anything, it *is* the raw content, sourced
18
+ // the same way [...slug].md.ts sources a single page's raw content
19
+ // (`entry.body`, already read off disk by the glob() loader - no
20
+ // separate file read needed).
21
+ type DocsEntry = CollectionEntry<'pages'> | CollectionEntry<'generatedDocs'>;
22
+
23
+ export const GET: APIRoute = async () => {
24
+ const contentDir = process.env.WRITEDOCS_CONTENT_DIR || process.cwd();
25
+
26
+ const customPath = path.join(contentDir, 'llms-full.txt');
27
+ if (fs.existsSync(customPath)) {
28
+ return new Response(fs.readFileSync(customPath, 'utf-8'), {
29
+ headers: { 'Content-Type': 'text/plain; charset=utf-8' },
30
+ });
31
+ }
32
+
33
+ const packageRoot = process.env.WRITEDOCS_PACKAGE_ROOT || process.cwd();
34
+ const config = loadDocsConfig(contentDir);
35
+ // The site's URL, or its base alone without a `domain` (lib/config.ts) -
36
+ // null when that's "", a site at the root with no domain.
37
+ const siteUrl = resolveSiteRoot(config) || null;
38
+
39
+ const hasGeneratedDocs = fs.existsSync(path.join(writedocsTempDir(contentDir), 'generated-docs'));
40
+ const hasPages = findAllPages(contentDir).length > 0;
41
+ const [pagesEntries, generatedDocsEntries] = await Promise.all([
42
+ hasPages ? getCollection('pages') : Promise.resolve([]),
43
+ hasGeneratedDocs ? getCollection('generatedDocs') : Promise.resolve([]),
44
+ ]);
45
+ const entries: DocsEntry[] = [...pagesEntries, ...generatedDocsEntries];
46
+
47
+ const unordered = entries
48
+ // Same noindex exclusion llms.txt.ts applies to its own listing -
49
+ // see that file's comment.
50
+ .filter((entry) => !entry.data.seo?.noindex)
51
+ // Same `url` exclusion as llms.txt.ts - a redirect, not a page.
52
+ .filter((entry) => !entry.data.url)
53
+ .map((entry: DocsEntry) => {
54
+ const slug = normalizeEntryId(entry.id);
55
+ // What the page shows, not its raw source: <Visibility> for agents,
56
+ // imported snippets inlined, `variables` filled in - same as the .md
57
+ // route (lib/agent-markdown.js).
58
+ // An API page's operation is written out after its own text (lib/openapi-markdown.ts).
59
+ const body = pageMarkdown(entry, { contentDir, packageRoot, variables: config.variables, siteUrl });
60
+ // The page's own URL, so an agent can cite it.
61
+ const url = `${siteUrl ?? ''}${slug === 'index' ? '/' : `/${slug}/`}`;
62
+ return {
63
+ slug,
64
+ fileId: fileIdForEntry(contentDir, packageRoot, entry),
65
+ title: entry.data.title,
66
+ description: entry.data.description,
67
+ url,
68
+ body,
69
+ };
70
+ });
71
+ // Navigation order, same as llms.txt.
72
+ const sections = orderByNavigation(unordered, config.navigation);
73
+
74
+ const lines: string[] = [`# ${config.name}`, ''];
75
+ if (config.description) lines.push(`> ${config.description}`, '');
76
+
77
+ for (const section of sections) {
78
+ lines.push('---', '', `# ${section.title}`, '', `URL: ${section.url}`, '');
79
+ if (section.description) lines.push(`> ${section.description}`, '');
80
+ lines.push(section.body.trim(), '');
81
+ }
82
+
83
+ const content = lines.join('\n') + '\n';
84
+
85
+ return new Response(content, {
86
+ headers: { 'Content-Type': 'text/plain; charset=utf-8' },
87
+ });
88
+ };