@writedocs/generator 0.10.14 → 0.10.15
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 +125 -116
- package/src/components/Image.astro +19 -3
- package/src/layout/BaseLayout.astro +877 -831
- package/src/layout/components/AnalyticsScripts.astro +45 -77
- package/src/layout/components/ConsentBanner.astro +118 -0
- package/src/layout/styles/base.css +8 -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/image-size.js +130 -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/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/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 +19 -0
- package/src/scripts/consent.ts +62 -0
- package/writedocs.schema.json +100 -0
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
// A short, plain-text description for a generated API page's
|
|
2
|
+
// <meta name="description">, from the operation in the spec. OpenAPI
|
|
3
|
+
// descriptions are Markdown and often several paragraphs - a search result
|
|
4
|
+
// shows about 160 characters of plain text.
|
|
5
|
+
// Plain JavaScript: src/cli/generate-api-pages.js runs under plain Node.
|
|
6
|
+
|
|
7
|
+
export const META_DESCRIPTION_LENGTH = 160;
|
|
8
|
+
|
|
9
|
+
/** Markdown (or HTML) as one line of plain text. */
|
|
10
|
+
export function plainLine(markdown) {
|
|
11
|
+
return String(markdown ?? '')
|
|
12
|
+
.replace(/```[\s\S]*?```/g, ' ') // code blocks
|
|
13
|
+
.replace(/<[^>]+>/g, ' ') // HTML tags
|
|
14
|
+
.replace(/!\[([^\]]*)\]\([^)]*\)/g, '$1') // images -> alt text
|
|
15
|
+
.replace(/\[([^\]]+)\]\([^)]*\)/g, '$1') // links -> their text
|
|
16
|
+
.replace(/^\s{0,3}(#{1,6}|>|[-*+]|\d+\.)\s+/gm, '') // headings, quotes, list markers
|
|
17
|
+
.replace(/(\*\*|\*|~~|`)/g, '') // emphasis and inline code marks (not _: customer_id)
|
|
18
|
+
.replace(/\|/g, ' ') // table cells
|
|
19
|
+
.replace(/\s+/g, ' ')
|
|
20
|
+
.trim();
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
/** `text` cut to `max` characters at a word, with an ellipsis. */
|
|
24
|
+
export function truncateAtWord(text, max = META_DESCRIPTION_LENGTH) {
|
|
25
|
+
if (text.length <= max) return text;
|
|
26
|
+
const cut = text.slice(0, max - 1);
|
|
27
|
+
const lastSpace = cut.lastIndexOf(' ');
|
|
28
|
+
return `${(lastSpace > max * 0.6 ? cut.slice(0, lastSpace) : cut).replace(/[\s.,;:!?-]+$/, '')}…`;
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
/** The description for an operation's page: its own `description`, as plain
|
|
32
|
+
* text and cut to length - or, without one, its summary with the method
|
|
33
|
+
* and path ("List all customers - GET /customers"), so the page still has
|
|
34
|
+
* a description that says more than its title. */
|
|
35
|
+
export function operationMetaDescription({ description, summary, method, path }) {
|
|
36
|
+
const text = plainLine(description);
|
|
37
|
+
if (text) return truncateAtWord(text);
|
|
38
|
+
const request = `${method} ${path}`;
|
|
39
|
+
const fallback = summary && summary.trim() ? `${plainLine(summary)} - ${request}` : request;
|
|
40
|
+
return truncateAtWord(fallback);
|
|
41
|
+
}
|