@writedocs/generator 0.10.14 → 0.10.16

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 (48) hide show
  1. package/astro.config.mjs +610 -572
  2. package/package.json +1 -1
  3. package/src/cli/generate-api-pages.js +418 -384
  4. package/src/cli/write-redirects-file.js +141 -116
  5. package/src/components/Accordion.astro +2 -1
  6. package/src/components/Callout.astro +1 -1
  7. package/src/components/CopyPageMenu.astro +1 -1
  8. package/src/components/Image.astro +19 -3
  9. package/src/components/Parameter.astro +11 -6
  10. package/src/components/Visibility.astro +11 -1
  11. package/src/layout/BaseLayout.astro +896 -831
  12. package/src/layout/components/AnalyticsScripts.astro +45 -77
  13. package/src/layout/components/Breadcrumbs.astro +1 -1
  14. package/src/layout/components/ConsentBanner.astro +118 -0
  15. package/src/layout/components/MobileMenu.astro +3 -2
  16. package/src/layout/components/Sidebar.astro +2 -2
  17. package/src/layout/components/SiteFooter.astro +3 -2
  18. package/src/layout/components/TopBar.astro +3 -2
  19. package/src/layout/styles/base.css +30 -0
  20. package/src/lib/agent-directive.js +47 -0
  21. package/src/lib/agent-markdown.js +22 -2
  22. package/src/lib/components-to-markdown.js +297 -0
  23. package/src/lib/config-schema.js +97 -10
  24. package/src/lib/config-schema.ts +1882 -1768
  25. package/src/lib/consent.js +102 -0
  26. package/src/lib/font-fallback.js +79 -0
  27. package/src/lib/image-size.js +140 -0
  28. package/src/lib/item-pages.js +63 -0
  29. package/src/lib/json-ld.js +127 -0
  30. package/src/lib/json-schema-descriptions.js +226 -212
  31. package/src/lib/last-modified.js +52 -0
  32. package/src/lib/link-check.js +506 -500
  33. package/src/lib/mcp-index.ts +1 -1
  34. package/src/lib/meta-description.js +41 -0
  35. package/src/lib/mintlify-convert.js +605 -603
  36. package/src/lib/moved-api-pages.js +54 -0
  37. package/src/lib/openapi-markdown.ts +16 -6
  38. package/src/lib/project-files-integration.js +61 -0
  39. package/src/lib/project-files.js +126 -0
  40. package/src/lib/rehype-image-loading.js +71 -0
  41. package/src/lib/robots-txt.js +16 -0
  42. package/src/lib/seo-tags.js +137 -0
  43. package/src/lib/styles-asset-integration.js +21 -3
  44. package/src/pages/[...slug].astro +22 -3
  45. package/src/pages/[...slug].md.ts +15 -5
  46. package/src/pages/llms-full.txt.ts +1 -1
  47. package/src/scripts/consent.ts +62 -0
  48. package/writedocs.schema.json +100 -0
@@ -2,7 +2,8 @@ import { getCollection, type CollectionEntry } from 'astro:content';
2
2
  import fs from 'node:fs';
3
3
  import path from 'node:path';
4
4
  import type { APIRoute } from 'astro';
5
- import { loadDocsConfig, normalizeEntryId, findAllPages, contextMenuOptions } from '../lib/config';
5
+ import { loadDocsConfig, normalizeEntryId, findAllPages, contextMenuOptions, resolveSiteUrl } from '../lib/config';
6
+ import { pageMarkdownDocument } from '../lib/agent-directive.js';
6
7
  import { writedocsTempDir } from '../lib/writedocs-temp-dir.js';
7
8
  import { pageMarkdown } from '../lib/openapi-markdown';
8
9
 
@@ -52,17 +53,18 @@ export async function getStaticPaths() {
52
53
  .map((entry) => ({
53
54
  params: { slug: normalizeEntryId(entry.id) },
54
55
  // Passed along rather than re-read per page - GET only renders one entry.
55
- props: { entry, variables: config.variables },
56
+ props: { entry, variables: config.variables, siteUrl: resolveSiteUrl(config) },
56
57
  }));
57
58
  }
58
59
 
59
60
  interface Props {
60
61
  entry: DocsEntry;
61
62
  variables: Record<string, string>;
63
+ siteUrl: string | null;
62
64
  }
63
65
 
64
66
  export const GET: APIRoute = ({ props }) => {
65
- const { entry, variables } = props as Props;
67
+ const { entry, variables, siteUrl } = props as Props;
66
68
  const contentDir = process.env.WRITEDOCS_CONTENT_DIR || process.cwd();
67
69
  const packageRoot = process.env.WRITEDOCS_PACKAGE_ROOT || process.cwd();
68
70
  // entry.body is the raw, frontmatter-stripped MDX/Markdown source text
@@ -75,8 +77,16 @@ export const GET: APIRoute = ({ props }) => {
75
77
  // for agents, imported snippets inlined, `variables` filled in - see
76
78
  // lib/agent-markdown.js (llms-full.txt uses the same).
77
79
  // An API page's operation is written out after its own text (lib/openapi-markdown.ts).
78
- const body = pageMarkdown(entry, { contentDir, packageRoot, variables });
79
- const markdown = `# ${entry.data.title}\n\n${body}`;
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
+ );
80
90
  return new Response(markdown, {
81
91
  headers: { 'Content-Type': 'text/markdown; charset=utf-8' },
82
92
  });
@@ -54,7 +54,7 @@ export const GET: APIRoute = async () => {
54
54
  // imported snippets inlined, `variables` filled in - same as the .md
55
55
  // route (lib/agent-markdown.js).
56
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 });
57
+ const body = pageMarkdown(entry, { contentDir, packageRoot, variables: config.variables, siteUrl });
58
58
  // The page's own URL, so an agent can cite it.
59
59
  const url = `${siteUrl ?? ''}${slug === 'index' ? '/' : `/${slug}/`}`;
60
60
  return {
@@ -0,0 +1,62 @@
1
+ // The consent banner's behavior (ConsentBanner.astro) - shows it until the
2
+ // reader answers, stores the answer through window.wdConsent (defined in
3
+ // <head> by consentLoaderScript() in lib/consent.js, which also loads the
4
+ // analytics once the answer is "granted"), and opens it again from any link
5
+ // to #cookie-settings, so a reader can change their mind.
6
+ //
7
+ // Runs on every page load, client-side navigations included: the banner is
8
+ // part of <body>, which Astro's router replaces with the new page's - a new,
9
+ // hidden banner each time.
10
+
11
+ type Consent = { get(): 'granted' | 'denied' | null; set(value: 'granted' | 'denied'): void };
12
+
13
+ const SETTINGS_HASH = '#cookie-settings';
14
+
15
+ function show(banner: HTMLElement) {
16
+ banner.hidden = false;
17
+ // The strip covers the end of the page; this lets the footer scroll clear of it.
18
+ document.body.style.paddingBottom = `${banner.offsetHeight}px`;
19
+ }
20
+
21
+ function hide(banner: HTMLElement) {
22
+ banner.hidden = true;
23
+ document.body.style.paddingBottom = '';
24
+ }
25
+
26
+ let listening = false;
27
+
28
+ export function initConsent(root: Document) {
29
+ const banner = root.getElementById('wd-consent');
30
+ const consent = (window as unknown as { wdConsent?: Consent }).wdConsent;
31
+ if (!banner || !consent) return;
32
+
33
+ if (!banner.dataset.wdInit) {
34
+ banner.dataset.wdInit = 'true';
35
+ banner.querySelectorAll<HTMLButtonElement>('[data-consent]').forEach((button) => {
36
+ button.addEventListener('click', () => {
37
+ hide(banner);
38
+ // Answered: the address stops asking for the banner, so a reload
39
+ // (declining after accepting causes one) doesn't open it again.
40
+ if (location.hash === SETTINGS_HASH) history.replaceState(history.state, '', location.pathname + location.search);
41
+ consent.set(button.dataset.consent === 'granted' ? 'granted' : 'denied');
42
+ });
43
+ });
44
+ }
45
+
46
+ if (consent.get() === null || location.hash === SETTINGS_HASH) show(banner);
47
+ else hide(banner);
48
+
49
+ // One listener for the whole visit - it looks the banner up when clicked,
50
+ // since each navigation brings a new one.
51
+ if (listening) return;
52
+ listening = true;
53
+ document.addEventListener('click', (event) => {
54
+ const link = (event.target as Element | null)?.closest?.(`a[href$="${SETTINGS_HASH}"]`);
55
+ if (!link) return;
56
+ const current = document.getElementById('wd-consent');
57
+ if (!current) return;
58
+ event.preventDefault();
59
+ show(current);
60
+ current.querySelector<HTMLButtonElement>('[data-consent]')?.focus();
61
+ });
62
+ }
@@ -740,6 +740,56 @@
740
740
  "type": "boolean",
741
741
  "description": "Ask search engines not to index pages, and leave them out of sitemap.xml.",
742
742
  "markdownDescription": "Ask search engines not to index pages, and leave them out of sitemap.xml."
743
+ },
744
+ "robots": {
745
+ "type": "string",
746
+ "description": "The whole <meta name=\"robots\"> value, like \"noindex, follow\". Replaces `noindex`; a value with \"noindex\" leaves pages out of sitemap.xml too.",
747
+ "markdownDescription": "The whole <meta name=\"robots\"> value, like \"noindex, follow\". Replaces `noindex`; a value with \"noindex\" leaves pages out of sitemap.xml too."
748
+ },
749
+ "metatags": {
750
+ "type": "object",
751
+ "propertyNames": {
752
+ "type": "string"
753
+ },
754
+ "additionalProperties": {
755
+ "type": "string"
756
+ },
757
+ "description": "Other <meta> tags, name to content - like { \"google-site-verification\": \"...\" }. One with the name of a tag writedocs writes (\"og:image\", \"twitter:image\") replaces it.",
758
+ "markdownDescription": "Other <meta> tags, name to content - like { \"google-site-verification\": \"...\" }. One with the name of a tag writedocs writes (\"og:image\", \"twitter:image\") replaces it."
759
+ },
760
+ "organization": {
761
+ "type": "object",
762
+ "properties": {
763
+ "name": {
764
+ "type": "string",
765
+ "description": "The organization's name, like \"Acme\".",
766
+ "markdownDescription": "The organization's name, like \"Acme\"."
767
+ },
768
+ "url": {
769
+ "type": "string",
770
+ "description": "The organization's own site. Default: this site's address.",
771
+ "markdownDescription": "The organization's own site. Default: this site's address."
772
+ },
773
+ "logo": {
774
+ "type": "string",
775
+ "description": "Its logo - a path or a full URL. Default: the site's logo.",
776
+ "markdownDescription": "Its logo - a path or a full URL. Default: the site's logo."
777
+ },
778
+ "sameAs": {
779
+ "type": "array",
780
+ "items": {
781
+ "type": "string"
782
+ },
783
+ "description": "Its profiles on other sites. Default: the URLs in `socials`.",
784
+ "markdownDescription": "Its profiles on other sites. Default: the URLs in `socials`."
785
+ }
786
+ },
787
+ "required": [
788
+ "name"
789
+ ],
790
+ "additionalProperties": false,
791
+ "description": "Who publishes the site, for search engines: an Organization in the home page's structured data, and the publisher of every page.",
792
+ "markdownDescription": "Who publishes the site, for search engines: an Organization in the home page's structured data, and the publisher of every page."
743
793
  }
744
794
  },
745
795
  "additionalProperties": false,
@@ -908,6 +958,11 @@
908
958
  "type": "string",
909
959
  "description": "The script's code, inline. Use either `src` or `content`, not both.",
910
960
  "markdownDescription": "The script's code, inline. Use either `src` or `content`, not both."
961
+ },
962
+ "consent": {
963
+ "type": "boolean",
964
+ "description": "With `integrations.consent` on, load this script only once the reader accepts.",
965
+ "markdownDescription": "With `integrations.consent` on, load this script only once the reader accepts."
911
966
  }
912
967
  },
913
968
  "additionalProperties": false
@@ -930,6 +985,11 @@
930
985
  "type": "string",
931
986
  "description": "The script's code, inline. Use either `src` or `content`, not both.",
932
987
  "markdownDescription": "The script's code, inline. Use either `src` or `content`, not both."
988
+ },
989
+ "consent": {
990
+ "type": "boolean",
991
+ "description": "With `integrations.consent` on, load this script only once the reader accepts.",
992
+ "markdownDescription": "With `integrations.consent` on, load this script only once the reader accepts."
933
993
  }
934
994
  },
935
995
  "additionalProperties": false
@@ -1075,6 +1135,46 @@
1075
1135
  "additionalProperties": false,
1076
1136
  "description": "AI chat over the docs, with DocsBot.",
1077
1137
  "markdownDescription": "AI chat over the docs, with DocsBot."
1138
+ },
1139
+ "consent": {
1140
+ "anyOf": [
1141
+ {
1142
+ "type": "boolean"
1143
+ },
1144
+ {
1145
+ "type": "object",
1146
+ "properties": {
1147
+ "message": {
1148
+ "type": "string",
1149
+ "description": "The banner's text.",
1150
+ "markdownDescription": "The banner's text."
1151
+ },
1152
+ "acceptLabel": {
1153
+ "type": "string",
1154
+ "description": "The accept button's text. Default \"Accept\".",
1155
+ "markdownDescription": "The accept button's text. Default \"Accept\"."
1156
+ },
1157
+ "declineLabel": {
1158
+ "type": "string",
1159
+ "description": "The decline button's text. Default \"Decline\".",
1160
+ "markdownDescription": "The decline button's text. Default \"Decline\"."
1161
+ },
1162
+ "policyUrl": {
1163
+ "type": "string",
1164
+ "description": "A link after the text, to your privacy or cookie policy.",
1165
+ "markdownDescription": "A link after the text, to your privacy or cookie policy."
1166
+ },
1167
+ "policyLabel": {
1168
+ "type": "string",
1169
+ "description": "That link's text. Default \"Privacy policy\".",
1170
+ "markdownDescription": "That link's text. Default \"Privacy policy\"."
1171
+ }
1172
+ },
1173
+ "additionalProperties": false
1174
+ }
1175
+ ],
1176
+ "description": "A consent banner: the analytics integrations load only once the reader accepts. true uses the default texts; an object changes them.",
1177
+ "markdownDescription": "A consent banner: the analytics integrations load only once the reader accepts. true uses the default texts; an object changes them."
1078
1178
  }
1079
1179
  },
1080
1180
  "additionalProperties": false,