@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.
- package/astro.config.mjs +610 -572
- package/package.json +1 -1
- package/src/cli/generate-api-pages.js +418 -384
- package/src/cli/write-redirects-file.js +141 -116
- package/src/components/Accordion.astro +2 -1
- package/src/components/Callout.astro +1 -1
- package/src/components/CopyPageMenu.astro +1 -1
- package/src/components/Image.astro +19 -3
- package/src/components/Parameter.astro +11 -6
- package/src/components/Visibility.astro +11 -1
- package/src/layout/BaseLayout.astro +896 -831
- package/src/layout/components/AnalyticsScripts.astro +45 -77
- package/src/layout/components/Breadcrumbs.astro +1 -1
- package/src/layout/components/ConsentBanner.astro +118 -0
- package/src/layout/components/MobileMenu.astro +3 -2
- package/src/layout/components/Sidebar.astro +2 -2
- package/src/layout/components/SiteFooter.astro +3 -2
- package/src/layout/components/TopBar.astro +3 -2
- package/src/layout/styles/base.css +30 -0
- package/src/lib/agent-directive.js +47 -0
- package/src/lib/agent-markdown.js +22 -2
- package/src/lib/components-to-markdown.js +297 -0
- package/src/lib/config-schema.js +97 -10
- package/src/lib/config-schema.ts +1882 -1768
- package/src/lib/consent.js +102 -0
- package/src/lib/font-fallback.js +79 -0
- package/src/lib/image-size.js +140 -0
- package/src/lib/item-pages.js +63 -0
- package/src/lib/json-ld.js +127 -0
- package/src/lib/json-schema-descriptions.js +226 -212
- package/src/lib/last-modified.js +52 -0
- package/src/lib/link-check.js +506 -500
- package/src/lib/mcp-index.ts +1 -1
- package/src/lib/meta-description.js +41 -0
- package/src/lib/mintlify-convert.js +605 -603
- package/src/lib/moved-api-pages.js +54 -0
- package/src/lib/openapi-markdown.ts +16 -6
- package/src/lib/project-files-integration.js +61 -0
- package/src/lib/project-files.js +126 -0
- package/src/lib/rehype-image-loading.js +71 -0
- package/src/lib/robots-txt.js +16 -0
- package/src/lib/seo-tags.js +137 -0
- package/src/lib/styles-asset-integration.js +21 -3
- package/src/pages/[...slug].astro +22 -3
- package/src/pages/[...slug].md.ts +15 -5
- package/src/pages/llms-full.txt.ts +1 -1
- package/src/scripts/consent.ts +62 -0
- package/writedocs.schema.json +100 -0
|
@@ -0,0 +1,297 @@
|
|
|
1
|
+
// A page's components, written as Markdown - for the text an AI agent reads
|
|
2
|
+
// (a page's .md copy, llms-full.txt, the MCP server).
|
|
3
|
+
//
|
|
4
|
+
// A page's source keeps its components as tags, and what a component shows
|
|
5
|
+
// from its attributes is then not text at all:
|
|
6
|
+
//
|
|
7
|
+
// <Parameter name="amount" type="integer" required> -> **`amount`** `integer` required
|
|
8
|
+
// The amount to charge.
|
|
9
|
+
// </Parameter> The amount to charge.
|
|
10
|
+
//
|
|
11
|
+
// An agent reading the tags has to guess what the page looks like; one
|
|
12
|
+
// comparing the copy with the page finds a third of a reference page
|
|
13
|
+
// missing. So each component writedocs knows is replaced by the Markdown
|
|
14
|
+
// that says what it shows: its title, labels and caption as text, its
|
|
15
|
+
// content where it was - no longer indented under a tag, which Markdown
|
|
16
|
+
// would read as a code block.
|
|
17
|
+
//
|
|
18
|
+
// Comments in the source - {/* ... */} - are dropped on the way: the page
|
|
19
|
+
// doesn't show them, and they are often notes not meant for readers. Before
|
|
20
|
+
// this, a page's copy, llms-full.txt and the MCP server all published them.
|
|
21
|
+
//
|
|
22
|
+
// How: the page is parsed as MDX only to find the components; the output is
|
|
23
|
+
// stitched from the page's own source text, so everything that isn't one of
|
|
24
|
+
// these components - prose, code, tables, a site's own snippet components -
|
|
25
|
+
// comes back exactly as written. A page that doesn't parse is returned
|
|
26
|
+
// untouched.
|
|
27
|
+
//
|
|
28
|
+
// Plain JavaScript, for scripts/components-to-markdown.test.js.
|
|
29
|
+
import { createProcessor } from '@mdx-js/mdx';
|
|
30
|
+
|
|
31
|
+
let processor = null;
|
|
32
|
+
function parseMdx(text) {
|
|
33
|
+
processor ??= createProcessor({ format: 'mdx' });
|
|
34
|
+
return processor.parse(text);
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
const isJsx = (node) => node.type === 'mdxJsxFlowElement' || node.type === 'mdxJsxTextElement';
|
|
38
|
+
/** An expression holding nothing but comments: `{/* draft - check with legal *\/}`. */
|
|
39
|
+
const isComment = (node) =>
|
|
40
|
+
(node.type === 'mdxFlowExpression' || node.type === 'mdxTextExpression') && /^\s*(\/\*[\s\S]*?\*\/\s*)+$/.test(node.value ?? '');
|
|
41
|
+
|
|
42
|
+
/** Markup in a title written as JSX (`{<><code>X</code> details</>}`) as text. */
|
|
43
|
+
const stripTags = (text) => text.replace(/<\/?[A-Za-z][^>]*>|<\/?>/g, '');
|
|
44
|
+
|
|
45
|
+
/** An attribute's value as text: a string as it is, `{4}`/`{"x"}`/`{true}` as
|
|
46
|
+
* their value, a bare attribute as true; undefined when absent. */
|
|
47
|
+
function attr(node, name) {
|
|
48
|
+
const attribute = node.attributes?.find((a) => a.type === 'mdxJsxAttribute' && a.name === name);
|
|
49
|
+
if (!attribute) return undefined;
|
|
50
|
+
if (attribute.value === null || attribute.value === undefined) return true;
|
|
51
|
+
if (typeof attribute.value === 'string') return attribute.value;
|
|
52
|
+
const raw = String(attribute.value.value ?? '').trim();
|
|
53
|
+
if (raw === 'true') return true;
|
|
54
|
+
if (raw === 'false') return false;
|
|
55
|
+
const quoted = raw.match(/^(["'`])([\s\S]*)\1$/);
|
|
56
|
+
if (quoted) return quoted[2];
|
|
57
|
+
return stripTags(raw).trim();
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
/** A list attribute - `pre={["read-only"]}` - as its items. */
|
|
61
|
+
function listAttr(node, name) {
|
|
62
|
+
const value = attr(node, name);
|
|
63
|
+
if (typeof value !== 'string') return [];
|
|
64
|
+
return [...value.matchAll(/(["'`])((?:(?!\1).)*)\1/g)].map((m) => m[2]);
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
const text = (value) => (typeof value === 'string' && value.trim() ? value.trim() : '');
|
|
68
|
+
const on = (value) => value === true || value === 'true' || value === '';
|
|
69
|
+
const code = (value) => `\`${String(value).replace(/`/g, "'")}\``;
|
|
70
|
+
const blocks = (...parts) => parts.filter((part) => part && part.trim()).join('\n\n');
|
|
71
|
+
const quote = (body) =>
|
|
72
|
+
body
|
|
73
|
+
.split('\n')
|
|
74
|
+
.map((line) => (line ? `> ${line}` : '>'))
|
|
75
|
+
.join('\n');
|
|
76
|
+
|
|
77
|
+
/** A field of a reference: its name, type and labels on one line, in the
|
|
78
|
+
* order the page shows them, then what it says. */
|
|
79
|
+
function parameter(node, body) {
|
|
80
|
+
// ParamField names the field by where it goes: path="id", query="limit"...
|
|
81
|
+
const place = ['path', 'query', 'body', 'header'].find((key) => text(attr(node, key)));
|
|
82
|
+
const name = text(attr(node, 'name')) || (place ? text(attr(node, place)) : '');
|
|
83
|
+
const head = [
|
|
84
|
+
...listAttr(node, 'pre'),
|
|
85
|
+
name && `**${code(name)}**`,
|
|
86
|
+
text(attr(node, 'type')) && code(attr(node, 'type')),
|
|
87
|
+
on(attr(node, 'required')) && 'required',
|
|
88
|
+
on(attr(node, 'deprecated')) && 'deprecated',
|
|
89
|
+
...listAttr(node, 'post'),
|
|
90
|
+
attr(node, 'default') !== undefined && attr(node, 'default') !== '' && `default: ${code(attr(node, 'default'))}`,
|
|
91
|
+
].filter(Boolean);
|
|
92
|
+
return blocks(head.join(' '), body);
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
const titled = (node, body, extra) => blocks(text(attr(node, 'title')) && `**${text(attr(node, 'title'))}**`, extra, body);
|
|
96
|
+
const unwrap = (node, body) => body;
|
|
97
|
+
|
|
98
|
+
function callout(label) {
|
|
99
|
+
return (node, body) => {
|
|
100
|
+
const title = text(attr(node, 'title')) || label;
|
|
101
|
+
return quote(blocks(title && `**${title}**`, body));
|
|
102
|
+
};
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
function card(node, body) {
|
|
106
|
+
const title = text(attr(node, 'title'));
|
|
107
|
+
const href = text(attr(node, 'href'));
|
|
108
|
+
const heading = title ? (href ? `**[${title}](${href})**` : `**${title}**`) : href ? `[${href}](${href})` : '';
|
|
109
|
+
return blocks(heading, text(attr(node, 'description')), body);
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
/** Component name -> (node, its content as Markdown, context) -> Markdown.
|
|
113
|
+
* A component that isn't here keeps its tags. */
|
|
114
|
+
const RENDERERS = {
|
|
115
|
+
Parameter: parameter,
|
|
116
|
+
ParamField: parameter,
|
|
117
|
+
ResponseField: parameter,
|
|
118
|
+
Expandable: (node, body) => titled(node, body),
|
|
119
|
+
Accordion: (node, body) => titled(node, body, text(attr(node, 'description'))),
|
|
120
|
+
AccordionGroup: unwrap,
|
|
121
|
+
Steps: unwrap,
|
|
122
|
+
Step: (node, body, context) => {
|
|
123
|
+
const title = text(attr(node, 'title'));
|
|
124
|
+
// `stepNumber` restarts the count, as on the page.
|
|
125
|
+
const number = Number(attr(node, 'stepNumber'));
|
|
126
|
+
if (Number.isFinite(number) && number > 0) context.offset.value = number - 1 - context.index;
|
|
127
|
+
return blocks(`**${context.index + 1 + context.offset.value}.${title ? ` ${title}` : ''}**`, body);
|
|
128
|
+
},
|
|
129
|
+
Tabs: unwrap,
|
|
130
|
+
Tab: (node, body) => titled(node, body),
|
|
131
|
+
View: (node, body) => titled(node, body),
|
|
132
|
+
CodeGroup: unwrap,
|
|
133
|
+
CardGroup: unwrap,
|
|
134
|
+
Columns: unwrap,
|
|
135
|
+
Column: unwrap,
|
|
136
|
+
Panel: unwrap,
|
|
137
|
+
Searchbar: unwrap,
|
|
138
|
+
RequestExample: unwrap,
|
|
139
|
+
ResponseExample: unwrap,
|
|
140
|
+
Callout: callout(''),
|
|
141
|
+
Note: callout('Note'),
|
|
142
|
+
Info: callout('Info'),
|
|
143
|
+
Tip: callout('Tip'),
|
|
144
|
+
Warning: callout('Warning'),
|
|
145
|
+
Danger: callout('Danger'),
|
|
146
|
+
Check: callout(''),
|
|
147
|
+
Card: card,
|
|
148
|
+
Tile: card,
|
|
149
|
+
Update: (node, body) => blocks(text(attr(node, 'label')) && `**${text(attr(node, 'label'))}**`, text(attr(node, 'description')), body),
|
|
150
|
+
Frame: (node, body) => blocks(body, text(attr(node, 'caption')) && `*${text(attr(node, 'caption'))}*`),
|
|
151
|
+
Image: (node) => {
|
|
152
|
+
const src = text(attr(node, 'src'));
|
|
153
|
+
if (!src) return null;
|
|
154
|
+
return blocks(``, text(attr(node, 'caption')) && `*${text(attr(node, 'caption'))}*`);
|
|
155
|
+
},
|
|
156
|
+
// Inline ones: what they wrap, as text.
|
|
157
|
+
Badge: unwrap,
|
|
158
|
+
Tooltip: (node, body) => (text(attr(node, 'tip')) ? `${body} (${text(attr(node, 'tip'))})` : body),
|
|
159
|
+
Hint: (node, body) => {
|
|
160
|
+
const note = [text(attr(node, 'headline')), text(attr(node, 'tip'))].filter(Boolean).join(': ');
|
|
161
|
+
const link = text(attr(node, 'cta')) && text(attr(node, 'href')) ? `[${text(attr(node, 'cta'))}](${text(attr(node, 'href'))})` : '';
|
|
162
|
+
const aside = [note, link].filter(Boolean).join(' ');
|
|
163
|
+
return aside ? `${body} (${aside})` : body;
|
|
164
|
+
},
|
|
165
|
+
Icon: () => '',
|
|
166
|
+
};
|
|
167
|
+
|
|
168
|
+
/** Written inside a sentence; every other one is a block of its own, even
|
|
169
|
+
* when its tags sit on one line (`<Step title="Go">Run it.</Step>`, which
|
|
170
|
+
* MDX reads as part of a paragraph). */
|
|
171
|
+
const INLINE = new Set(['Badge', 'Tooltip', 'Hint', 'Icon']);
|
|
172
|
+
|
|
173
|
+
/** The components that become Markdown. */
|
|
174
|
+
export const CONVERTED_COMPONENTS = Object.keys(RENDERERS);
|
|
175
|
+
|
|
176
|
+
function dedent(value) {
|
|
177
|
+
const lines = value.replace(/^[ \t]*\n+/, '').replace(/\s+$/, '').split('\n');
|
|
178
|
+
const indents = lines.filter((line) => line.trim()).map((line) => line.match(/^[ \t]*/)[0].length);
|
|
179
|
+
const min = indents.length ? Math.min(...indents) : 0;
|
|
180
|
+
return lines.map((line) => line.slice(min)).join('\n');
|
|
181
|
+
}
|
|
182
|
+
|
|
183
|
+
/** Where an element's opening tag ends: its first `>` outside quotes and
|
|
184
|
+
* `{...}` - an attribute can hold either. */
|
|
185
|
+
function openingTagEnd(source, start) {
|
|
186
|
+
let depth = 0;
|
|
187
|
+
let quoteChar = null;
|
|
188
|
+
for (let i = start; i < source.length; i++) {
|
|
189
|
+
const c = source[i];
|
|
190
|
+
if (quoteChar) {
|
|
191
|
+
if (c === quoteChar) quoteChar = null;
|
|
192
|
+
} else if (depth === 0 && (c === '"' || c === "'")) quoteChar = c;
|
|
193
|
+
else if (c === '{') depth++;
|
|
194
|
+
else if (c === '}') depth--;
|
|
195
|
+
else if (c === '>' && depth === 0) return i + 1;
|
|
196
|
+
}
|
|
197
|
+
return -1;
|
|
198
|
+
}
|
|
199
|
+
|
|
200
|
+
/** Runs of blank lines as one - unwrapped groups leave them behind. Code
|
|
201
|
+
* blocks keep theirs: blank lines there are part of the example. */
|
|
202
|
+
function collapseBlankLines(value) {
|
|
203
|
+
const out = [];
|
|
204
|
+
let fence = null;
|
|
205
|
+
for (const line of value.split('\n')) {
|
|
206
|
+
const marker = /^\s*(`{3,}|~{3,})/.exec(line)?.[1];
|
|
207
|
+
if (fence) {
|
|
208
|
+
if (marker && marker[0] === fence[0] && marker.length >= fence.length && line.trim() === marker) fence = null;
|
|
209
|
+
} else if (marker) fence = marker;
|
|
210
|
+
else if (!line.trim() && out.length && !out[out.length - 1].trim()) continue;
|
|
211
|
+
out.push(line);
|
|
212
|
+
}
|
|
213
|
+
return out.join('\n');
|
|
214
|
+
}
|
|
215
|
+
|
|
216
|
+
/** `source` with every known component replaced by its Markdown. */
|
|
217
|
+
export function componentsToMarkdown(source) {
|
|
218
|
+
if (typeof source !== 'string' || !/<[A-Z]|\{\s*\/\*/.test(source)) return source;
|
|
219
|
+
let tree;
|
|
220
|
+
try {
|
|
221
|
+
tree = parseMdx(source);
|
|
222
|
+
} catch {
|
|
223
|
+
return source; // not valid MDX - the build reports it; the copy stays as written
|
|
224
|
+
}
|
|
225
|
+
|
|
226
|
+
/** The source between two offsets, each known component in it replaced. */
|
|
227
|
+
const stitch = (nodes, from, to) => {
|
|
228
|
+
let out = '';
|
|
229
|
+
let at = from;
|
|
230
|
+
const visit = (list) => {
|
|
231
|
+
const counts = {};
|
|
232
|
+
const offset = { value: 0 };
|
|
233
|
+
for (const node of list) {
|
|
234
|
+
const start = node.position?.start?.offset;
|
|
235
|
+
const end = node.position?.end?.offset;
|
|
236
|
+
// A comment - {/* ... */} - is a note to whoever edits the page. The
|
|
237
|
+
// page doesn't show it, and neither does the copy.
|
|
238
|
+
if (isComment(node) && start !== undefined && start >= at && end <= to) {
|
|
239
|
+
out += source.slice(at, start);
|
|
240
|
+
at = end;
|
|
241
|
+
continue;
|
|
242
|
+
}
|
|
243
|
+
if (isJsx(node) && node.name && RENDERERS[node.name] && start !== undefined && start >= at && end <= to) {
|
|
244
|
+
const index = (counts[node.name] = (counts[node.name] ?? -1) + 1);
|
|
245
|
+
const rendered = render(node, { index, offset });
|
|
246
|
+
if (rendered !== null) {
|
|
247
|
+
// A flow element starts after its line's indentation; every line
|
|
248
|
+
// of what replaces it gets the same, so the whole block still
|
|
249
|
+
// dedents together with its siblings.
|
|
250
|
+
const lineStart = source.lastIndexOf('\n', start - 1) + 1;
|
|
251
|
+
const indent = /^[ \t]*$/.test(source.slice(lineStart, start)) ? source.slice(lineStart, start) : '';
|
|
252
|
+
let before = out + source.slice(at, start);
|
|
253
|
+
// Blank lines stay empty - no trailing indentation.
|
|
254
|
+
let block = rendered
|
|
255
|
+
.split('\n')
|
|
256
|
+
.map((line, i) => (i && line ? indent + line : line))
|
|
257
|
+
.join('\n');
|
|
258
|
+
if (!INLINE.has(node.name) && rendered) {
|
|
259
|
+
// Two components in a row, written with no blank line between
|
|
260
|
+
// their tags, are still two blocks of Markdown.
|
|
261
|
+
if (before.trim() && !/\n[ \t]*\n[ \t]*$/.test(before)) {
|
|
262
|
+
before = before.replace(/[ \t]+$/, '');
|
|
263
|
+
block = `\n${indent}${block}`;
|
|
264
|
+
}
|
|
265
|
+
const after = source.slice(end, to);
|
|
266
|
+
if (after.trim() && !/^[ \t]*\n[ \t]*\n/.test(after)) block += '\n';
|
|
267
|
+
}
|
|
268
|
+
out = before + block;
|
|
269
|
+
at = end;
|
|
270
|
+
continue;
|
|
271
|
+
}
|
|
272
|
+
}
|
|
273
|
+
if (Array.isArray(node.children)) visit(node.children);
|
|
274
|
+
}
|
|
275
|
+
};
|
|
276
|
+
visit(nodes);
|
|
277
|
+
return out + source.slice(at, to);
|
|
278
|
+
};
|
|
279
|
+
|
|
280
|
+
const render = (node, context) => {
|
|
281
|
+
const start = node.position.start.offset;
|
|
282
|
+
const end = node.position.end.offset;
|
|
283
|
+
const openEnd = openingTagEnd(source, start);
|
|
284
|
+
if (openEnd === -1) return null;
|
|
285
|
+
const selfClosing = source[openEnd - 2] === '/' || openEnd >= end;
|
|
286
|
+
let body = '';
|
|
287
|
+
if (!selfClosing) {
|
|
288
|
+
const closeStart = source.lastIndexOf('</', end);
|
|
289
|
+
if (closeStart < openEnd) return null;
|
|
290
|
+
const inner = stitch(node.children ?? [], openEnd, closeStart);
|
|
291
|
+
body = INLINE.has(node.name) ? inner.trim() : dedent(inner);
|
|
292
|
+
}
|
|
293
|
+
return RENDERERS[node.name](node, body, context);
|
|
294
|
+
};
|
|
295
|
+
|
|
296
|
+
return collapseBlankLines(stitch(tree.children, 0, source.length));
|
|
297
|
+
}
|
package/src/lib/config-schema.js
CHANGED
|
@@ -306,16 +306,68 @@ const seoFieldsSchema = z.object({
|
|
|
306
306
|
// sitemap.xml entirely - both driven off this one flag, since listing
|
|
307
307
|
// a page in the sitemap while also telling crawlers not to index it
|
|
308
308
|
// would be self-contradictory.
|
|
309
|
-
noindex: z.boolean().optional()
|
|
309
|
+
noindex: z.boolean().optional(),
|
|
310
|
+
// The whole <meta name="robots"> value, for anything `noindex` (always
|
|
311
|
+
// "noindex, nofollow") doesn't say - "noindex, follow", "max-snippet:50".
|
|
312
|
+
// Wins over `noindex`; a value with "noindex" keeps the page out of
|
|
313
|
+
// sitemap.xml and llms.txt the same way (isNoindex(), lib/seo-tags.js).
|
|
314
|
+
robots: z.string().optional(),
|
|
315
|
+
// Any other <meta> tag, name -> content: "google-site-verification",
|
|
316
|
+
// "twitter:site", "og:locale"... One with the name of a tag writedocs
|
|
317
|
+
// writes itself ("og:image", "twitter:image", "description") replaces
|
|
318
|
+
// it. Open Graph names become <meta property>, the rest <meta name> -
|
|
319
|
+
// see seoHead() in lib/seo-tags.js. A page's own are merged over the
|
|
320
|
+
// site's, name by name.
|
|
321
|
+
metatags: z.record(z.string(), z.string()).optional()
|
|
322
|
+
}).strict();
|
|
323
|
+
const pageSeoFieldsSchema = seoFieldsSchema.extend({
|
|
324
|
+
// The <title> and og:title/twitter:title, exactly as written - no site
|
|
325
|
+
// name is added. The page's <h1> and sidebar entry keep `title`.
|
|
326
|
+
title: z.string().optional(),
|
|
327
|
+
// The <meta name="description"> and og/twitter descriptions, when they
|
|
328
|
+
// should differ from the `description` shown under the page's title.
|
|
329
|
+
description: z.string().optional(),
|
|
330
|
+
// The page's canonical URL, when it isn't its own address: a full URL,
|
|
331
|
+
// or a path on the site's domain. A page whose canonical is another
|
|
332
|
+
// address is left out of sitemap.xml.
|
|
333
|
+
canonical: z.string().optional(),
|
|
334
|
+
// The page's own structured data (schema.org JSON-LD): one block, or a
|
|
335
|
+
// list of them, written into the page after the ones writedocs
|
|
336
|
+
// generates (lib/json-ld.js). Any shape - it is the author's to get right.
|
|
337
|
+
jsonLd: z.union([z.record(z.string(), z.unknown()), z.array(z.record(z.string(), z.unknown()))]).optional()
|
|
310
338
|
}).strict();
|
|
311
|
-
|
|
312
|
-
|
|
339
|
+
const siteSeoFieldsSchema = seoFieldsSchema.extend({
|
|
340
|
+
// Who publishes the site - an Organization block in the home page's
|
|
341
|
+
// structured data, and the `publisher` of every page (lib/json-ld.js).
|
|
342
|
+
// Not derived from `name`: a site is called "Acme Docs", the
|
|
343
|
+
// organization "Acme".
|
|
344
|
+
organization: z.object({
|
|
345
|
+
name: z.string(),
|
|
346
|
+
// The organization's own site. Default: this site's address.
|
|
347
|
+
url: z.string().optional(),
|
|
348
|
+
// A path in the project or a full URL. Default: the site's logo.
|
|
349
|
+
logo: z.string().optional(),
|
|
350
|
+
// Its profiles elsewhere. Default: the URLs in `socials`.
|
|
351
|
+
sameAs: z.array(z.string()).optional()
|
|
352
|
+
}).strict().optional()
|
|
353
|
+
}).strict();
|
|
354
|
+
function mergeSeo(site, page = {}) {
|
|
355
|
+
const pageDecides = page.robots !== void 0 || page.noindex !== void 0;
|
|
356
|
+
const robots = pageDecides ? page.robots : site.robots;
|
|
357
|
+
const noindex = robots !== void 0 ? /\bnoindex\b|\bnone\b/i.test(robots) : pageDecides ? page.noindex : site.noindex;
|
|
358
|
+
const metatags = site.metatags || page.metatags ? { ...site.metatags, ...page.metatags } : void 0;
|
|
313
359
|
return {
|
|
314
360
|
ogImage: page.ogImage ?? site.ogImage,
|
|
315
361
|
ogType: page.ogType ?? site.ogType,
|
|
316
362
|
twitterCard: page.twitterCard ?? site.twitterCard,
|
|
317
363
|
keywords: page.keywords ?? site.keywords,
|
|
318
|
-
noindex
|
|
364
|
+
noindex,
|
|
365
|
+
robots,
|
|
366
|
+
metatags,
|
|
367
|
+
title: page.title,
|
|
368
|
+
description: page.description,
|
|
369
|
+
canonical: page.canonical,
|
|
370
|
+
jsonLd: page.jsonLd
|
|
319
371
|
};
|
|
320
372
|
}
|
|
321
373
|
const MINTLIFY_MODE_ALIASES = { center: "frame", assistant: "default" };
|
|
@@ -386,12 +438,16 @@ const pageFrontmatterSchema = z.object({
|
|
|
386
438
|
// it wants to override; mergeSeo() falls back to the site-wide default
|
|
387
439
|
// for anything left unset. See BaseLayout.astro for where this and the
|
|
388
440
|
// site-wide seo actually get merged and rendered.
|
|
389
|
-
seo:
|
|
441
|
+
seo: pageSeoFieldsSchema.optional(),
|
|
390
442
|
// Mintlify's spelling of `seo.noindex` - a top-level `noindex: true`.
|
|
391
443
|
// Folded into `seo` by the transform below, so everything downstream
|
|
392
444
|
// (the robots meta tag, sitemap.xml, llms.txt) keeps reading
|
|
393
445
|
// `seo.noindex` only.
|
|
394
446
|
noindex: z.boolean().optional(),
|
|
447
|
+
// Mintlify's spellings of `seo.robots` and `seo.canonical`, folded into
|
|
448
|
+
// `seo` the same way.
|
|
449
|
+
robots: z.string().optional(),
|
|
450
|
+
canonical: z.string().optional(),
|
|
395
451
|
// Mintlify's short navigation label - used for the sidebar and the
|
|
396
452
|
// topbar dropdown menus in place of `title` ([...slug].astro's
|
|
397
453
|
// navTitleForSlug). The page's own <h1> and prev/next links keep `title`.
|
|
@@ -425,15 +481,28 @@ const pageFrontmatterSchema = z.object({
|
|
|
425
481
|
hideFooterPagination: z.boolean().optional(),
|
|
426
482
|
hideApiMarker: z.boolean().optional()
|
|
427
483
|
}).transform(
|
|
428
|
-
({ noindex, keywords, "og:image": ogImage, "og:type": ogType, "twitter:card": twitterCard, ...data }) => {
|
|
429
|
-
const fromMintlify = { noindex: noindex ?? (data.hidden ? true : void 0), keywords, ogImage, ogType, twitterCard };
|
|
484
|
+
({ noindex, robots, canonical, keywords, "og:image": ogImage, "og:type": ogType, "twitter:card": twitterCard, ...data }) => {
|
|
430
485
|
const seo = { ...data.seo };
|
|
486
|
+
const pageRobots = seo.robots ?? robots;
|
|
487
|
+
const fromMintlify = {
|
|
488
|
+
robots,
|
|
489
|
+
canonical,
|
|
490
|
+
noindex: pageRobots !== void 0 ? void 0 : noindex ?? (data.hidden ? true : void 0),
|
|
491
|
+
keywords,
|
|
492
|
+
ogImage,
|
|
493
|
+
ogType,
|
|
494
|
+
twitterCard
|
|
495
|
+
};
|
|
431
496
|
let changed = false;
|
|
432
497
|
for (const [key, value] of Object.entries(fromMintlify)) {
|
|
433
498
|
if (value === void 0 || seo[key] !== void 0) continue;
|
|
434
499
|
seo[key] = value;
|
|
435
500
|
changed = true;
|
|
436
501
|
}
|
|
502
|
+
if (pageRobots !== void 0) {
|
|
503
|
+
seo.noindex = /\bnoindex\b|\bnone\b/i.test(pageRobots);
|
|
504
|
+
changed = true;
|
|
505
|
+
}
|
|
437
506
|
return changed ? { ...data, seo } : data;
|
|
438
507
|
}
|
|
439
508
|
);
|
|
@@ -493,7 +562,11 @@ const notFoundSchema = z.object({
|
|
|
493
562
|
}).strict().default({});
|
|
494
563
|
const scriptEntrySchema = z.object({
|
|
495
564
|
src: z.string().optional(),
|
|
496
|
-
content: z.string().optional()
|
|
565
|
+
content: z.string().optional(),
|
|
566
|
+
// With `integrations.consent` on, a script marked `true` loads only
|
|
567
|
+
// once the reader accepts, like the analytics integrations. Without the
|
|
568
|
+
// banner it loads as any other script.
|
|
569
|
+
consent: z.boolean().optional()
|
|
497
570
|
}).strict().refine((v) => v.src ? !v.content : !!v.content, {
|
|
498
571
|
message: 'Each scripts.head/scripts.body entry needs exactly one of "src" or "content", not both or neither.'
|
|
499
572
|
});
|
|
@@ -551,6 +624,17 @@ const umamiIntegrationSchema = z.object({
|
|
|
551
624
|
const askAiIntegrationSchema = z.object({
|
|
552
625
|
id: z.string()
|
|
553
626
|
}).strict();
|
|
627
|
+
const consentSchema = z.union([
|
|
628
|
+
z.boolean(),
|
|
629
|
+
z.object({
|
|
630
|
+
message: z.string().optional(),
|
|
631
|
+
acceptLabel: z.string().optional(),
|
|
632
|
+
declineLabel: z.string().optional(),
|
|
633
|
+
// A link after the message - a privacy or cookie policy.
|
|
634
|
+
policyUrl: z.string().optional(),
|
|
635
|
+
policyLabel: z.string().optional()
|
|
636
|
+
}).strict()
|
|
637
|
+
]);
|
|
554
638
|
const integrationsSchema = z.object({
|
|
555
639
|
ga4: ga4IntegrationSchema.optional(),
|
|
556
640
|
googleTagManager: googleTagManagerIntegrationSchema.optional(),
|
|
@@ -558,7 +642,8 @@ const integrationsSchema = z.object({
|
|
|
558
642
|
fathom: fathomIntegrationSchema.optional(),
|
|
559
643
|
posthog: posthogIntegrationSchema.optional(),
|
|
560
644
|
umami: umamiIntegrationSchema.optional(),
|
|
561
|
-
askAi: askAiIntegrationSchema.optional()
|
|
645
|
+
askAi: askAiIntegrationSchema.optional(),
|
|
646
|
+
consent: consentSchema.optional()
|
|
562
647
|
}).strict().default({});
|
|
563
648
|
const docsConfigSchema = z.object({
|
|
564
649
|
name: z.string(),
|
|
@@ -596,7 +681,7 @@ const docsConfigSchema = z.object({
|
|
|
596
681
|
// frontmatter `seo` (content.config.ts's docsSchema) overrides these
|
|
597
682
|
// field by field via mergeSeo(), rather than needing to repeat every
|
|
598
683
|
// field on every page.
|
|
599
|
-
seo:
|
|
684
|
+
seo: siteSeoFieldsSchema.default({}),
|
|
600
685
|
// The "Copy page" menu - see contextMenuSchema above. Absent means on,
|
|
601
686
|
// with every option; read it through contextMenuOptions().
|
|
602
687
|
contextMenu: contextMenuSchema.optional(),
|
|
@@ -975,7 +1060,9 @@ export {
|
|
|
975
1060
|
formatValidationIssuesDetailed,
|
|
976
1061
|
mergeSeo,
|
|
977
1062
|
pageFrontmatterSchema,
|
|
1063
|
+
pageSeoFieldsSchema,
|
|
978
1064
|
seoFieldsSchema,
|
|
1065
|
+
siteSeoFieldsSchema,
|
|
979
1066
|
unknownRootKeyIssues,
|
|
980
1067
|
validateDocsConfig
|
|
981
1068
|
};
|