@writedocs/generator 0.13.3 → 0.13.5

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 (87) hide show
  1. package/README.md +28 -28
  2. package/astro.config.mjs +645 -645
  3. package/bin/writedocs.js +43 -12
  4. package/package.json +99 -99
  5. package/src/cli/base-path-layout.js +44 -44
  6. package/src/cli/build-auth.js +135 -135
  7. package/src/cli/build.js +203 -203
  8. package/src/cli/check-built-styles.js +41 -41
  9. package/src/cli/convert.js +1 -1
  10. package/src/cli/dev.js +268 -268
  11. package/src/cli/exit-when-flushed.js +4 -0
  12. package/src/cli/generate-api-pages.js +507 -507
  13. package/src/cli/og-image-worker.js +20 -20
  14. package/src/cli/og-images.js +70 -70
  15. package/src/cli/page-list-watch.js +69 -69
  16. package/src/cli/run-astro.js +97 -97
  17. package/src/cli/run-pagefind.js +154 -154
  18. package/src/cli/write-mcp-files.js +103 -103
  19. package/src/cli/write-redirects-file.js +158 -158
  20. package/src/components/ApiReferencePanel.astro +1792 -1792
  21. package/src/components/AppIcon.astro +51 -51
  22. package/src/components/Card.astro +193 -193
  23. package/src/components/CodeGroup.astro +63 -39
  24. package/src/components/CopyPageMenu.astro +374 -374
  25. package/src/components/Hint.astro +188 -188
  26. package/src/components/Icon.astro +72 -72
  27. package/src/components/Image.astro +165 -165
  28. package/src/components/Tile.astro +67 -67
  29. package/src/components/Video.astro +137 -137
  30. package/src/content.config.ts +203 -203
  31. package/src/layout/BaseLayout.astro +908 -908
  32. package/src/layout/components/AnalyticsScripts.astro +49 -49
  33. package/src/layout/components/Breadcrumbs.astro +98 -98
  34. package/src/layout/components/ConsentBanner.astro +119 -119
  35. package/src/layout/components/MobileMenu.astro +225 -225
  36. package/src/layout/components/NavTree.astro +408 -408
  37. package/src/layout/components/Sidebar.astro +232 -232
  38. package/src/layout/components/SiteFooter.astro +87 -87
  39. package/src/layout/components/TopBar.astro +386 -386
  40. package/src/layout/styles/base.css +332 -326
  41. package/src/layout/styles/mobile-menu.css +285 -285
  42. package/src/lib/agent-markdown.js +164 -164
  43. package/src/lib/asset-dimensions.js +89 -89
  44. package/src/lib/base-path.js +90 -90
  45. package/src/lib/cli-report.js +22 -22
  46. package/src/lib/code-line-numbers.js +13 -0
  47. package/src/lib/config-schema.js +414 -75
  48. package/src/lib/config-schema.ts +2509 -1905
  49. package/src/lib/config.ts +1316 -1314
  50. package/src/lib/consent.js +108 -108
  51. package/src/lib/content-store-reload-integration.js +101 -101
  52. package/src/lib/icon-data-dev.js +53 -53
  53. package/src/lib/image-size.js +152 -152
  54. package/src/lib/json-schema-descriptions.js +228 -228
  55. package/src/lib/link-check.js +544 -544
  56. package/src/lib/llms-index.ts +90 -90
  57. package/src/lib/mcp-dev-integration.js +65 -65
  58. package/src/lib/mcp-index.ts +102 -102
  59. package/src/lib/mintlify-convert.js +605 -605
  60. package/src/lib/moved-api-pages.js +49 -49
  61. package/src/lib/og-cards.js +33 -33
  62. package/src/lib/og-image.js +235 -235
  63. package/src/lib/openapi-dev-status.js +80 -80
  64. package/src/lib/openapi-reload-integration.js +193 -193
  65. package/src/lib/pages.js +312 -312
  66. package/src/lib/project-files-integration.js +116 -116
  67. package/src/lib/project-files.js +137 -137
  68. package/src/lib/rehype-base-path.js +62 -62
  69. package/src/lib/rehype-image-loading.js +71 -71
  70. package/src/lib/robots-txt.js +21 -21
  71. package/src/lib/search-scope.js +44 -44
  72. package/src/lib/selector-placement.js +50 -50
  73. package/src/lib/seo-tags.js +155 -155
  74. package/src/lib/shiki-code-block.js +7 -1
  75. package/src/lib/site-base.ts +27 -27
  76. package/src/lib/styles-asset-integration.js +291 -291
  77. package/src/lib/wdignore-cases.json +195 -195
  78. package/src/lib/wdignore.js +177 -177
  79. package/src/pages/404.astro +63 -63
  80. package/src/pages/[...slug].astro +1762 -1608
  81. package/src/pages/[...slug].md.ts +93 -93
  82. package/src/pages/llms-full.txt.ts +88 -88
  83. package/src/pages/og/[...slug].png.ts +63 -63
  84. package/src/scripts/mobile-menu.ts +80 -80
  85. package/src/scripts/search.ts +245 -245
  86. package/src/scripts/sidebar-scroll.ts +61 -61
  87. package/src/styles/global.css +40 -40
@@ -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, 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
+ 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,88 +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, 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
- };
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
+ };
@@ -1,63 +1,63 @@
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, mergeSeo } from '../../lib/config';
6
- import { writedocsTempDir } from '../../lib/writedocs-temp-dir.js';
7
- import { ogImagePng } from '../../lib/og-image.js';
8
- import { ogCardSet, ogCardOptions } from '../../lib/og-cards.js';
9
-
10
- // /og/<page>.png - the picture a link to a page shows when it's shared, for
11
- // every page with no `seo.ogImage` of its own: the site's logo, the page's
12
- // title and description, the site's primary color (lib/og-image.js).
13
- // Which pages, and what's on each card, is lib/og-cards.js's - the build's
14
- // own step draws from the same list. [...slug].astro points the page's
15
- // og:image here under the same condition (wantsGeneratedCard()), so a card is
16
- // only built for a page that uses it - a site with `seo.ogImage` in
17
- // writedocs.json builds none at all, and neither does one with
18
- // `"seo": { "generatedOgImage": false }`.
19
- //
20
- // In `writedocs dev`, a static route like [...slug].md.ts next to it, built
21
- // on request. In `writedocs build` it renders nothing: build.js names a file
22
- // in WRITEDOCS_OG_CARDS_FILE, the list goes there, and the build draws every
23
- // card after Astro, in parallel (src/cli/og-images.js) - inside Astro they
24
- // were drawn one at a time, on one core.
25
-
26
- type DocsEntry = CollectionEntry<'pages'> | CollectionEntry<'generatedDocs'>;
27
-
28
- export async function getStaticPaths() {
29
- const contentDir = process.env.WRITEDOCS_CONTENT_DIR || process.cwd();
30
- const config = loadDocsConfig(contentDir);
31
- const hasGeneratedDocs = fs.existsSync(path.join(writedocsTempDir(contentDir), 'generated-docs'));
32
- const hasPages = findAllPages(contentDir).length > 0;
33
- const [pagesEntries, generatedDocsEntries] = await Promise.all([
34
- hasPages ? getCollection('pages') : Promise.resolve([]),
35
- hasGeneratedDocs ? getCollection('generatedDocs') : Promise.resolve([]),
36
- ]);
37
- const entries: DocsEntry[] = [...pagesEntries, ...generatedDocsEntries];
38
-
39
- const set = ogCardSet(
40
- config,
41
- entries.map((entry) => ({ id: normalizeEntryId(entry.id), data: entry.data, seo: mergeSeo(config.seo, entry.data.seo) })),
42
- contentDir
43
- );
44
- const listFile = process.env.WRITEDOCS_OG_CARDS_FILE;
45
- if (listFile) {
46
- fs.writeFileSync(listFile, JSON.stringify(set));
47
- return [];
48
- }
49
- return set.cards.map((card) => ({ params: { slug: card.slug }, props: ogCardOptions(set, card) }));
50
- }
51
-
52
- interface Props {
53
- title: string;
54
- description?: string;
55
- siteName: string;
56
- primary: string;
57
- logo: { src: string; width: number; height: number } | null;
58
- }
59
-
60
- export const GET: APIRoute = async ({ props }) => {
61
- const png = await ogImagePng(props as Props);
62
- return new Response(png, { headers: { 'Content-Type': 'image/png' } });
63
- };
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, mergeSeo } from '../../lib/config';
6
+ import { writedocsTempDir } from '../../lib/writedocs-temp-dir.js';
7
+ import { ogImagePng } from '../../lib/og-image.js';
8
+ import { ogCardSet, ogCardOptions } from '../../lib/og-cards.js';
9
+
10
+ // /og/<page>.png - the picture a link to a page shows when it's shared, for
11
+ // every page with no `seo.ogImage` of its own: the site's logo, the page's
12
+ // title and description, the site's primary color (lib/og-image.js).
13
+ // Which pages, and what's on each card, is lib/og-cards.js's - the build's
14
+ // own step draws from the same list. [...slug].astro points the page's
15
+ // og:image here under the same condition (wantsGeneratedCard()), so a card is
16
+ // only built for a page that uses it - a site with `seo.ogImage` in
17
+ // writedocs.json builds none at all, and neither does one with
18
+ // `"seo": { "generatedOgImage": false }`.
19
+ //
20
+ // In `writedocs dev`, a static route like [...slug].md.ts next to it, built
21
+ // on request. In `writedocs build` it renders nothing: build.js names a file
22
+ // in WRITEDOCS_OG_CARDS_FILE, the list goes there, and the build draws every
23
+ // card after Astro, in parallel (src/cli/og-images.js) - inside Astro they
24
+ // were drawn one at a time, on one core.
25
+
26
+ type DocsEntry = CollectionEntry<'pages'> | CollectionEntry<'generatedDocs'>;
27
+
28
+ export async function getStaticPaths() {
29
+ const contentDir = process.env.WRITEDOCS_CONTENT_DIR || process.cwd();
30
+ const config = loadDocsConfig(contentDir);
31
+ const hasGeneratedDocs = fs.existsSync(path.join(writedocsTempDir(contentDir), 'generated-docs'));
32
+ const hasPages = findAllPages(contentDir).length > 0;
33
+ const [pagesEntries, generatedDocsEntries] = await Promise.all([
34
+ hasPages ? getCollection('pages') : Promise.resolve([]),
35
+ hasGeneratedDocs ? getCollection('generatedDocs') : Promise.resolve([]),
36
+ ]);
37
+ const entries: DocsEntry[] = [...pagesEntries, ...generatedDocsEntries];
38
+
39
+ const set = ogCardSet(
40
+ config,
41
+ entries.map((entry) => ({ id: normalizeEntryId(entry.id), data: entry.data, seo: mergeSeo(config.seo, entry.data.seo) })),
42
+ contentDir
43
+ );
44
+ const listFile = process.env.WRITEDOCS_OG_CARDS_FILE;
45
+ if (listFile) {
46
+ fs.writeFileSync(listFile, JSON.stringify(set));
47
+ return [];
48
+ }
49
+ return set.cards.map((card) => ({ params: { slug: card.slug }, props: ogCardOptions(set, card) }));
50
+ }
51
+
52
+ interface Props {
53
+ title: string;
54
+ description?: string;
55
+ siteName: string;
56
+ primary: string;
57
+ logo: { src: string; width: number; height: number } | null;
58
+ }
59
+
60
+ export const GET: APIRoute = async ({ props }) => {
61
+ const png = await ogImagePng(props as Props);
62
+ return new Response(png, { headers: { 'Content-Type': 'image/png' } });
63
+ };