@writedocs/generator 0.13.4 → 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.
- package/README.md +28 -28
- package/astro.config.mjs +645 -645
- package/bin/writedocs.js +356 -356
- package/package.json +99 -99
- package/src/cli/base-path-layout.js +44 -44
- package/src/cli/build-auth.js +135 -135
- package/src/cli/build.js +203 -203
- package/src/cli/check-built-styles.js +41 -41
- package/src/cli/convert.js +124 -124
- package/src/cli/dev.js +268 -268
- package/src/cli/exit-when-flushed.js +42 -42
- package/src/cli/generate-api-pages.js +507 -507
- package/src/cli/og-image-worker.js +20 -20
- package/src/cli/og-images.js +70 -70
- package/src/cli/page-list-watch.js +69 -69
- package/src/cli/run-astro.js +97 -97
- package/src/cli/run-pagefind.js +154 -154
- package/src/cli/write-mcp-files.js +103 -103
- package/src/cli/write-redirects-file.js +158 -158
- package/src/components/ApiReferencePanel.astro +1792 -1792
- package/src/components/AppIcon.astro +51 -51
- package/src/components/Card.astro +193 -193
- package/src/components/CodeGroup.astro +63 -39
- package/src/components/CopyPageMenu.astro +374 -374
- package/src/components/Hint.astro +188 -188
- package/src/components/Icon.astro +72 -72
- package/src/components/Image.astro +165 -165
- package/src/components/Tile.astro +67 -67
- package/src/components/Video.astro +137 -137
- package/src/content.config.ts +203 -203
- package/src/layout/BaseLayout.astro +908 -908
- package/src/layout/components/AnalyticsScripts.astro +49 -49
- package/src/layout/components/Breadcrumbs.astro +98 -98
- package/src/layout/components/ConsentBanner.astro +119 -119
- package/src/layout/components/MobileMenu.astro +225 -225
- package/src/layout/components/NavTree.astro +408 -408
- package/src/layout/components/Sidebar.astro +232 -232
- package/src/layout/components/SiteFooter.astro +87 -87
- package/src/layout/components/TopBar.astro +386 -386
- package/src/layout/styles/base.css +332 -326
- package/src/layout/styles/mobile-menu.css +285 -285
- package/src/lib/agent-markdown.js +164 -164
- package/src/lib/asset-dimensions.js +89 -89
- package/src/lib/base-path.js +90 -90
- package/src/lib/cli-report.js +22 -22
- package/src/lib/code-line-numbers.js +13 -0
- package/src/lib/config-schema.ts +2509 -2509
- package/src/lib/config.ts +1316 -1316
- package/src/lib/consent.js +108 -108
- package/src/lib/content-store-reload-integration.js +101 -101
- package/src/lib/icon-data-dev.js +53 -53
- package/src/lib/image-size.js +152 -152
- package/src/lib/json-schema-descriptions.js +228 -228
- package/src/lib/link-check.js +544 -544
- package/src/lib/llms-index.ts +90 -90
- package/src/lib/mcp-dev-integration.js +65 -65
- package/src/lib/mcp-index.ts +102 -102
- package/src/lib/mintlify-convert.js +605 -605
- package/src/lib/moved-api-pages.js +49 -49
- package/src/lib/og-cards.js +33 -33
- package/src/lib/og-image.js +235 -235
- package/src/lib/openapi-dev-status.js +80 -80
- package/src/lib/openapi-reload-integration.js +193 -193
- package/src/lib/pages.js +312 -312
- package/src/lib/project-files-integration.js +116 -116
- package/src/lib/project-files.js +137 -137
- package/src/lib/rehype-base-path.js +62 -62
- package/src/lib/rehype-image-loading.js +71 -71
- package/src/lib/robots-txt.js +21 -21
- package/src/lib/search-scope.js +44 -44
- package/src/lib/selector-placement.js +50 -50
- package/src/lib/seo-tags.js +155 -155
- package/src/lib/shiki-code-block.js +7 -1
- package/src/lib/site-base.ts +27 -27
- package/src/lib/styles-asset-integration.js +291 -291
- package/src/lib/wdignore-cases.json +195 -195
- package/src/lib/wdignore.js +177 -177
- package/src/pages/404.astro +63 -63
- package/src/pages/[...slug].astro +1762 -1608
- package/src/pages/[...slug].md.ts +93 -93
- package/src/pages/llms-full.txt.ts +88 -88
- package/src/pages/og/[...slug].png.ts +63 -63
- package/src/scripts/mobile-menu.ts +80 -80
- package/src/scripts/search.ts +245 -245
- package/src/scripts/sidebar-scroll.ts +61 -61
- package/src/styles/global.css +40 -40
package/src/lib/seo-tags.js
CHANGED
|
@@ -1,155 +1,155 @@
|
|
|
1
|
-
// What a page's <head> says to search engines and link previews: the
|
|
2
|
-
// <title>, the canonical link, and every <meta> tag - built here from the
|
|
3
|
-
// page's title and description, the site's and the page's `seo`
|
|
4
|
-
// (seoFieldsSchema, lib/config-schema.ts), and the site's address.
|
|
5
|
-
// BaseLayout.astro renders the result as it is.
|
|
6
|
-
//
|
|
7
|
-
// Plain JavaScript with no Astro or config.ts import, so scripts/
|
|
8
|
-
// seo-tags.test.js can run it directly, and astro.config.mjs can use the
|
|
9
|
-
// same rules for the sitemap before any page is rendered.
|
|
10
|
-
//
|
|
11
|
-
// `siteUrl` is the site's URL - {domain}{basePath}, see resolveSiteUrl() in
|
|
12
|
-
// lib/config.ts - and a page's `path` is its address in the site, without
|
|
13
|
-
// the base ("/guides/a/").
|
|
14
|
-
import { withBase } from './base-path.js';
|
|
15
|
-
|
|
16
|
-
/** Meta tags written as `<meta property>` (Open Graph and its relatives);
|
|
17
|
-
* every other one is `<meta name>`. */
|
|
18
|
-
const PROPERTY_PREFIXES = ['og:', 'article:', 'book:', 'profile:', 'music:', 'video:', 'fb:'];
|
|
19
|
-
|
|
20
|
-
/** Whether a `robots` value, or the older `noindex` flag, keeps a page out
|
|
21
|
-
* of search engines. `robots` wins when both are set. */
|
|
22
|
-
export function isNoindex(seo) {
|
|
23
|
-
if (!seo) return false;
|
|
24
|
-
if (typeof seo.robots === 'string') return /\bnoindex\b|\bnone\b/i.test(seo.robots);
|
|
25
|
-
return seo.noindex === true;
|
|
26
|
-
}
|
|
27
|
-
|
|
28
|
-
/** A page's frontmatter as gray-matter read it - before the schema folds
|
|
29
|
-
* Mintlify's top-level `noindex`/`robots` into `seo`, and marks a `hidden`
|
|
30
|
-
* page noindex. Used where pages aren't loaded yet (astro.config.mjs). */
|
|
31
|
-
export function frontmatterNoindex(data) {
|
|
32
|
-
const robots = data?.seo?.robots ?? data?.robots;
|
|
33
|
-
if (typeof robots === 'string') return isNoindex({ robots });
|
|
34
|
-
return (data?.seo?.noindex ?? data?.noindex ?? data?.hidden === true) === true;
|
|
35
|
-
}
|
|
36
|
-
|
|
37
|
-
/** `value` - a full URL or a site address - as a full URL; without a
|
|
38
|
-
* siteUrl, a site address with the site's `base` in front. */
|
|
39
|
-
function absoluteUrl(siteUrl, value, base = '') {
|
|
40
|
-
if (/^https?:\/\//i.test(value)) return value;
|
|
41
|
-
if (!siteUrl) return withBase(base, value);
|
|
42
|
-
return `${siteUrl}${value.startsWith('/') ? '' : '/'}${value}`;
|
|
43
|
-
}
|
|
44
|
-
|
|
45
|
-
/** A page's canonical URL: its own address on the site's domain, or
|
|
46
|
-
* `canonical` - a full URL, or a path on the same domain. Null when there's
|
|
47
|
-
* no full URL to give (no `domain`, and `canonical` is a path). */
|
|
48
|
-
export function canonicalUrl(siteUrl, pagePath, canonical) {
|
|
49
|
-
if (canonical) {
|
|
50
|
-
if (/^https?:\/\//i.test(canonical)) return canonical;
|
|
51
|
-
return siteUrl ? absoluteUrl(siteUrl, canonical) : null;
|
|
52
|
-
}
|
|
53
|
-
return siteUrl ? `${siteUrl}${pagePath}` : null;
|
|
54
|
-
}
|
|
55
|
-
|
|
56
|
-
const samePath = (a, b) => a.replace(/^\/+|\/+$/g, '').toLowerCase() === b.replace(/^\/+|\/+$/g, '').toLowerCase();
|
|
57
|
-
|
|
58
|
-
/** Whether `canonical` names another address than the page's own - such a
|
|
59
|
-
* page is left out of sitemap.xml, which lists canonical addresses only. */
|
|
60
|
-
export function canonicalIsElsewhere(siteUrl, pagePath, canonical) {
|
|
61
|
-
if (!canonical) return false;
|
|
62
|
-
if (/^https?:\/\//i.test(canonical)) {
|
|
63
|
-
if (!siteUrl) return true;
|
|
64
|
-
let url;
|
|
65
|
-
try {
|
|
66
|
-
url = new URL(canonical);
|
|
67
|
-
} catch {
|
|
68
|
-
return false;
|
|
69
|
-
}
|
|
70
|
-
const site = new URL(siteUrl);
|
|
71
|
-
if (url.origin.toLowerCase() !== site.origin.toLowerCase()) return true;
|
|
72
|
-
// The canonical's path, from the site's root - outside the basePath, it's
|
|
73
|
-
// another site's address.
|
|
74
|
-
const root = site.pathname.replace(/\/+$/, '').toLowerCase();
|
|
75
|
-
const pathname = url.pathname.toLowerCase();
|
|
76
|
-
if (root && pathname !== root && !pathname.startsWith(`${root}/`)) return true;
|
|
77
|
-
return !samePath(pathname.slice(root.length), pagePath);
|
|
78
|
-
}
|
|
79
|
-
return !samePath(canonical, pagePath);
|
|
80
|
-
}
|
|
81
|
-
|
|
82
|
-
/** The `<link rel="alternate" hreflang>` set for a page: one per language
|
|
83
|
-
* it exists in (its own included - each page of the set has to list all
|
|
84
|
-
* of them, itself too), then `x-default`, the first language, for a
|
|
85
|
-
* reader whose language is none of them. `alternates` is
|
|
86
|
-
* `[{ lang, href }]` with site paths. Empty without a `domain` (the
|
|
87
|
-
* links must be full URLs) or with fewer than two languages. */
|
|
88
|
-
export function hreflangLinks(siteUrl, alternates = []) {
|
|
89
|
-
if (!siteUrl || alternates.length < 2) return [];
|
|
90
|
-
const links = alternates.map(({ lang, href }) => ({ hreflang: lang, href: absoluteUrl(siteUrl, href) }));
|
|
91
|
-
return [...links, { hreflang: 'x-default', href: links[0].href }];
|
|
92
|
-
}
|
|
93
|
-
|
|
94
|
-
/** The <title>: `seo.title` exactly as written, or "Page title · Site name"
|
|
95
|
-
* - the site name once when the page's title is the site's name. */
|
|
96
|
-
export function documentTitle(title, siteName, seoTitle) {
|
|
97
|
-
if (seoTitle && seoTitle.trim()) return seoTitle.trim();
|
|
98
|
-
if (!siteName || title.trim().toLowerCase() === siteName.trim().toLowerCase()) return title;
|
|
99
|
-
return `${title} · ${siteName}`;
|
|
100
|
-
}
|
|
101
|
-
|
|
102
|
-
/** Everything BaseLayout.astro writes for search engines and link previews.
|
|
103
|
-
* `seo` is the site's `seo` with the page's own merged over it (mergeSeo()).
|
|
104
|
-
* Returns `{ title, canonical, metas }`, each meta as
|
|
105
|
-
* `{ attr: 'name' | 'property', key, content }`, in the order they're
|
|
106
|
-
* written. An entry of `seo.metatags` replaces the tag of the same name,
|
|
107
|
-
* or is added after the others. `base` is the site's basePath ("/docs"),
|
|
108
|
-
* for a picture's address when there's no siteUrl to make it full. */
|
|
109
|
-
export function seoHead({ title, siteName, description, siteDescription, seo = {}, siteUrl = null, path = '/', base = '' }) {
|
|
110
|
-
const shareTitle = seo.title?.trim() || title;
|
|
111
|
-
const metaDescription = seo.description?.trim() || description || siteDescription;
|
|
112
|
-
const canonical = canonicalUrl(siteUrl, path, seo.canonical);
|
|
113
|
-
const custom = seo.metatags ?? {};
|
|
114
|
-
// The picture in a link preview: the page's or the site's `ogImage` -
|
|
115
|
-
// or, set by [...slug].astro when there is neither, the card generated
|
|
116
|
-
// for the page (lib/og-image.js).
|
|
117
|
-
const image = seo.ogImage ? absoluteUrl(siteUrl, seo.ogImage, base) : undefined;
|
|
118
|
-
// The large card needs a picture - that one, or a tag set by hand.
|
|
119
|
-
const hasImage = Boolean(image || custom['og:image'] || custom['twitter:image']);
|
|
120
|
-
const robots = typeof seo.robots === 'string' && seo.robots.trim() ? seo.robots.trim() : seo.noindex ? 'noindex, nofollow' : undefined;
|
|
121
|
-
|
|
122
|
-
const tags = new Map();
|
|
123
|
-
const set = (key, content) => {
|
|
124
|
-
if (content === undefined || content === null || content === '') return;
|
|
125
|
-
tags.set(key, String(content));
|
|
126
|
-
};
|
|
127
|
-
set('description', metaDescription);
|
|
128
|
-
if (seo.keywords?.length) set('keywords', seo.keywords.join(', '));
|
|
129
|
-
set('robots', robots);
|
|
130
|
-
set('og:title', shareTitle);
|
|
131
|
-
set('og:description', metaDescription);
|
|
132
|
-
set('og:type', seo.ogType ?? 'website');
|
|
133
|
-
set('og:site_name', siteName);
|
|
134
|
-
set('og:url', canonical);
|
|
135
|
-
set('og:image', image);
|
|
136
|
-
set('twitter:card', seo.twitterCard ?? (hasImage ? 'summary_large_image' : 'summary'));
|
|
137
|
-
set('twitter:title', shareTitle);
|
|
138
|
-
set('twitter:description', metaDescription);
|
|
139
|
-
set('twitter:image', image);
|
|
140
|
-
for (const [key, value] of Object.entries(custom)) {
|
|
141
|
-
if (typeof value !== 'string' || !value.trim()) continue;
|
|
142
|
-
// A picture's address has to be a full URL for the sites that read it.
|
|
143
|
-
set(key, /(^|:)image$/.test(key) ? absoluteUrl(siteUrl, value, base) : value);
|
|
144
|
-
}
|
|
145
|
-
|
|
146
|
-
return {
|
|
147
|
-
title: documentTitle(title, siteName, seo.title),
|
|
148
|
-
canonical,
|
|
149
|
-
metas: [...tags].map(([key, content]) => ({
|
|
150
|
-
attr: PROPERTY_PREFIXES.some((prefix) => key.startsWith(prefix)) ? 'property' : 'name',
|
|
151
|
-
key,
|
|
152
|
-
content,
|
|
153
|
-
})),
|
|
154
|
-
};
|
|
155
|
-
}
|
|
1
|
+
// What a page's <head> says to search engines and link previews: the
|
|
2
|
+
// <title>, the canonical link, and every <meta> tag - built here from the
|
|
3
|
+
// page's title and description, the site's and the page's `seo`
|
|
4
|
+
// (seoFieldsSchema, lib/config-schema.ts), and the site's address.
|
|
5
|
+
// BaseLayout.astro renders the result as it is.
|
|
6
|
+
//
|
|
7
|
+
// Plain JavaScript with no Astro or config.ts import, so scripts/
|
|
8
|
+
// seo-tags.test.js can run it directly, and astro.config.mjs can use the
|
|
9
|
+
// same rules for the sitemap before any page is rendered.
|
|
10
|
+
//
|
|
11
|
+
// `siteUrl` is the site's URL - {domain}{basePath}, see resolveSiteUrl() in
|
|
12
|
+
// lib/config.ts - and a page's `path` is its address in the site, without
|
|
13
|
+
// the base ("/guides/a/").
|
|
14
|
+
import { withBase } from './base-path.js';
|
|
15
|
+
|
|
16
|
+
/** Meta tags written as `<meta property>` (Open Graph and its relatives);
|
|
17
|
+
* every other one is `<meta name>`. */
|
|
18
|
+
const PROPERTY_PREFIXES = ['og:', 'article:', 'book:', 'profile:', 'music:', 'video:', 'fb:'];
|
|
19
|
+
|
|
20
|
+
/** Whether a `robots` value, or the older `noindex` flag, keeps a page out
|
|
21
|
+
* of search engines. `robots` wins when both are set. */
|
|
22
|
+
export function isNoindex(seo) {
|
|
23
|
+
if (!seo) return false;
|
|
24
|
+
if (typeof seo.robots === 'string') return /\bnoindex\b|\bnone\b/i.test(seo.robots);
|
|
25
|
+
return seo.noindex === true;
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
/** A page's frontmatter as gray-matter read it - before the schema folds
|
|
29
|
+
* Mintlify's top-level `noindex`/`robots` into `seo`, and marks a `hidden`
|
|
30
|
+
* page noindex. Used where pages aren't loaded yet (astro.config.mjs). */
|
|
31
|
+
export function frontmatterNoindex(data) {
|
|
32
|
+
const robots = data?.seo?.robots ?? data?.robots;
|
|
33
|
+
if (typeof robots === 'string') return isNoindex({ robots });
|
|
34
|
+
return (data?.seo?.noindex ?? data?.noindex ?? data?.hidden === true) === true;
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
/** `value` - a full URL or a site address - as a full URL; without a
|
|
38
|
+
* siteUrl, a site address with the site's `base` in front. */
|
|
39
|
+
function absoluteUrl(siteUrl, value, base = '') {
|
|
40
|
+
if (/^https?:\/\//i.test(value)) return value;
|
|
41
|
+
if (!siteUrl) return withBase(base, value);
|
|
42
|
+
return `${siteUrl}${value.startsWith('/') ? '' : '/'}${value}`;
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
/** A page's canonical URL: its own address on the site's domain, or
|
|
46
|
+
* `canonical` - a full URL, or a path on the same domain. Null when there's
|
|
47
|
+
* no full URL to give (no `domain`, and `canonical` is a path). */
|
|
48
|
+
export function canonicalUrl(siteUrl, pagePath, canonical) {
|
|
49
|
+
if (canonical) {
|
|
50
|
+
if (/^https?:\/\//i.test(canonical)) return canonical;
|
|
51
|
+
return siteUrl ? absoluteUrl(siteUrl, canonical) : null;
|
|
52
|
+
}
|
|
53
|
+
return siteUrl ? `${siteUrl}${pagePath}` : null;
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
const samePath = (a, b) => a.replace(/^\/+|\/+$/g, '').toLowerCase() === b.replace(/^\/+|\/+$/g, '').toLowerCase();
|
|
57
|
+
|
|
58
|
+
/** Whether `canonical` names another address than the page's own - such a
|
|
59
|
+
* page is left out of sitemap.xml, which lists canonical addresses only. */
|
|
60
|
+
export function canonicalIsElsewhere(siteUrl, pagePath, canonical) {
|
|
61
|
+
if (!canonical) return false;
|
|
62
|
+
if (/^https?:\/\//i.test(canonical)) {
|
|
63
|
+
if (!siteUrl) return true;
|
|
64
|
+
let url;
|
|
65
|
+
try {
|
|
66
|
+
url = new URL(canonical);
|
|
67
|
+
} catch {
|
|
68
|
+
return false;
|
|
69
|
+
}
|
|
70
|
+
const site = new URL(siteUrl);
|
|
71
|
+
if (url.origin.toLowerCase() !== site.origin.toLowerCase()) return true;
|
|
72
|
+
// The canonical's path, from the site's root - outside the basePath, it's
|
|
73
|
+
// another site's address.
|
|
74
|
+
const root = site.pathname.replace(/\/+$/, '').toLowerCase();
|
|
75
|
+
const pathname = url.pathname.toLowerCase();
|
|
76
|
+
if (root && pathname !== root && !pathname.startsWith(`${root}/`)) return true;
|
|
77
|
+
return !samePath(pathname.slice(root.length), pagePath);
|
|
78
|
+
}
|
|
79
|
+
return !samePath(canonical, pagePath);
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
/** The `<link rel="alternate" hreflang>` set for a page: one per language
|
|
83
|
+
* it exists in (its own included - each page of the set has to list all
|
|
84
|
+
* of them, itself too), then `x-default`, the first language, for a
|
|
85
|
+
* reader whose language is none of them. `alternates` is
|
|
86
|
+
* `[{ lang, href }]` with site paths. Empty without a `domain` (the
|
|
87
|
+
* links must be full URLs) or with fewer than two languages. */
|
|
88
|
+
export function hreflangLinks(siteUrl, alternates = []) {
|
|
89
|
+
if (!siteUrl || alternates.length < 2) return [];
|
|
90
|
+
const links = alternates.map(({ lang, href }) => ({ hreflang: lang, href: absoluteUrl(siteUrl, href) }));
|
|
91
|
+
return [...links, { hreflang: 'x-default', href: links[0].href }];
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
/** The <title>: `seo.title` exactly as written, or "Page title · Site name"
|
|
95
|
+
* - the site name once when the page's title is the site's name. */
|
|
96
|
+
export function documentTitle(title, siteName, seoTitle) {
|
|
97
|
+
if (seoTitle && seoTitle.trim()) return seoTitle.trim();
|
|
98
|
+
if (!siteName || title.trim().toLowerCase() === siteName.trim().toLowerCase()) return title;
|
|
99
|
+
return `${title} · ${siteName}`;
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
/** Everything BaseLayout.astro writes for search engines and link previews.
|
|
103
|
+
* `seo` is the site's `seo` with the page's own merged over it (mergeSeo()).
|
|
104
|
+
* Returns `{ title, canonical, metas }`, each meta as
|
|
105
|
+
* `{ attr: 'name' | 'property', key, content }`, in the order they're
|
|
106
|
+
* written. An entry of `seo.metatags` replaces the tag of the same name,
|
|
107
|
+
* or is added after the others. `base` is the site's basePath ("/docs"),
|
|
108
|
+
* for a picture's address when there's no siteUrl to make it full. */
|
|
109
|
+
export function seoHead({ title, siteName, description, siteDescription, seo = {}, siteUrl = null, path = '/', base = '' }) {
|
|
110
|
+
const shareTitle = seo.title?.trim() || title;
|
|
111
|
+
const metaDescription = seo.description?.trim() || description || siteDescription;
|
|
112
|
+
const canonical = canonicalUrl(siteUrl, path, seo.canonical);
|
|
113
|
+
const custom = seo.metatags ?? {};
|
|
114
|
+
// The picture in a link preview: the page's or the site's `ogImage` -
|
|
115
|
+
// or, set by [...slug].astro when there is neither, the card generated
|
|
116
|
+
// for the page (lib/og-image.js).
|
|
117
|
+
const image = seo.ogImage ? absoluteUrl(siteUrl, seo.ogImage, base) : undefined;
|
|
118
|
+
// The large card needs a picture - that one, or a tag set by hand.
|
|
119
|
+
const hasImage = Boolean(image || custom['og:image'] || custom['twitter:image']);
|
|
120
|
+
const robots = typeof seo.robots === 'string' && seo.robots.trim() ? seo.robots.trim() : seo.noindex ? 'noindex, nofollow' : undefined;
|
|
121
|
+
|
|
122
|
+
const tags = new Map();
|
|
123
|
+
const set = (key, content) => {
|
|
124
|
+
if (content === undefined || content === null || content === '') return;
|
|
125
|
+
tags.set(key, String(content));
|
|
126
|
+
};
|
|
127
|
+
set('description', metaDescription);
|
|
128
|
+
if (seo.keywords?.length) set('keywords', seo.keywords.join(', '));
|
|
129
|
+
set('robots', robots);
|
|
130
|
+
set('og:title', shareTitle);
|
|
131
|
+
set('og:description', metaDescription);
|
|
132
|
+
set('og:type', seo.ogType ?? 'website');
|
|
133
|
+
set('og:site_name', siteName);
|
|
134
|
+
set('og:url', canonical);
|
|
135
|
+
set('og:image', image);
|
|
136
|
+
set('twitter:card', seo.twitterCard ?? (hasImage ? 'summary_large_image' : 'summary'));
|
|
137
|
+
set('twitter:title', shareTitle);
|
|
138
|
+
set('twitter:description', metaDescription);
|
|
139
|
+
set('twitter:image', image);
|
|
140
|
+
for (const [key, value] of Object.entries(custom)) {
|
|
141
|
+
if (typeof value !== 'string' || !value.trim()) continue;
|
|
142
|
+
// A picture's address has to be a full URL for the sites that read it.
|
|
143
|
+
set(key, /(^|:)image$/.test(key) ? absoluteUrl(siteUrl, value, base) : value);
|
|
144
|
+
}
|
|
145
|
+
|
|
146
|
+
return {
|
|
147
|
+
title: documentTitle(title, siteName, seo.title),
|
|
148
|
+
canonical,
|
|
149
|
+
metas: [...tags].map(([key, content]) => ({
|
|
150
|
+
attr: PROPERTY_PREFIXES.some((prefix) => key.startsWith(prefix)) ? 'property' : 'name',
|
|
151
|
+
key,
|
|
152
|
+
content,
|
|
153
|
+
})),
|
|
154
|
+
};
|
|
155
|
+
}
|
|
@@ -22,6 +22,7 @@
|
|
|
22
22
|
// never collides with the API playground's own bespoke copy buttons.
|
|
23
23
|
|
|
24
24
|
import { iconSvg } from './config.ts';
|
|
25
|
+
import { lineNumberDigits } from './code-line-numbers.js';
|
|
25
26
|
|
|
26
27
|
// The fence's info string after the language, split into tokens: a
|
|
27
28
|
// `key=value` option (value quoted, in braces, or bare), a bare `{1,3-5}`
|
|
@@ -197,16 +198,21 @@ export function codeBlockTransformer() {
|
|
|
197
198
|
type: 'button',
|
|
198
199
|
class: 'wd-code-expand-btn',
|
|
199
200
|
'data-role': 'toggle-expand',
|
|
201
|
+
'aria-expanded': 'false',
|
|
200
202
|
},
|
|
201
203
|
children: [{ type: 'text', value: 'Show more' }],
|
|
202
204
|
});
|
|
203
205
|
}
|
|
204
206
|
|
|
207
|
+
const properties = { class: wrapperClass.join(' ') };
|
|
208
|
+
// The number column is as wide as the last line number - see
|
|
209
|
+
// code-line-numbers.js.
|
|
210
|
+
if (meta.lines) properties.style = `--wd-code-digits: ${lineNumberDigits(pre)}`;
|
|
205
211
|
hast.children = [
|
|
206
212
|
{
|
|
207
213
|
type: 'element',
|
|
208
214
|
tagName: 'div',
|
|
209
|
-
properties
|
|
215
|
+
properties,
|
|
210
216
|
children,
|
|
211
217
|
},
|
|
212
218
|
];
|
package/src/lib/site-base.ts
CHANGED
|
@@ -1,27 +1,27 @@
|
|
|
1
|
-
// The site's base (writedocs.json `basePath`) for components and page
|
|
2
|
-
// scripts - lib/base-path.js explains the base and which addresses take it.
|
|
3
|
-
// __WD_BASE__ is "" or "/docs", set by astro.config.mjs (vite.define), so
|
|
4
|
-
// the same import works in a component's frontmatter and in a <script>; with
|
|
5
|
-
// no base, siteHref() returns its argument and the built pages don't change.
|
|
6
|
-
//
|
|
7
|
-
// The rule: logic keeps site addresses as they are ("/guides/a/"); the base
|
|
8
|
-
// goes in where the address is written - an href, a src, a url() - with
|
|
9
|
-
// siteHref(). Doing it once there is what keeps an address from getting it
|
|
10
|
-
// twice.
|
|
11
|
-
import { withBase, srcsetWithBase } from './base-path.js';
|
|
12
|
-
|
|
13
|
-
declare const __WD_BASE__: string;
|
|
14
|
-
|
|
15
|
-
/** "" or "/docs". */
|
|
16
|
-
export const BASE: string = __WD_BASE__;
|
|
17
|
-
|
|
18
|
-
/** A site address with the base in front ("/a/" -> "/docs/a/"); anything
|
|
19
|
-
* else - a full URL, "#x", a relative path - as it is. */
|
|
20
|
-
export function siteHref<T extends string | undefined | null>(url: T): T {
|
|
21
|
-
return withBase(BASE, url) as T;
|
|
22
|
-
}
|
|
23
|
-
|
|
24
|
-
/** A `srcset` with the base in front of each site address. */
|
|
25
|
-
export function siteSrcset<T extends string | undefined | null>(srcset: T): T {
|
|
26
|
-
return srcsetWithBase(BASE, srcset) as T;
|
|
27
|
-
}
|
|
1
|
+
// The site's base (writedocs.json `basePath`) for components and page
|
|
2
|
+
// scripts - lib/base-path.js explains the base and which addresses take it.
|
|
3
|
+
// __WD_BASE__ is "" or "/docs", set by astro.config.mjs (vite.define), so
|
|
4
|
+
// the same import works in a component's frontmatter and in a <script>; with
|
|
5
|
+
// no base, siteHref() returns its argument and the built pages don't change.
|
|
6
|
+
//
|
|
7
|
+
// The rule: logic keeps site addresses as they are ("/guides/a/"); the base
|
|
8
|
+
// goes in where the address is written - an href, a src, a url() - with
|
|
9
|
+
// siteHref(). Doing it once there is what keeps an address from getting it
|
|
10
|
+
// twice.
|
|
11
|
+
import { withBase, srcsetWithBase } from './base-path.js';
|
|
12
|
+
|
|
13
|
+
declare const __WD_BASE__: string;
|
|
14
|
+
|
|
15
|
+
/** "" or "/docs". */
|
|
16
|
+
export const BASE: string = __WD_BASE__;
|
|
17
|
+
|
|
18
|
+
/** A site address with the base in front ("/a/" -> "/docs/a/"); anything
|
|
19
|
+
* else - a full URL, "#x", a relative path - as it is. */
|
|
20
|
+
export function siteHref<T extends string | undefined | null>(url: T): T {
|
|
21
|
+
return withBase(BASE, url) as T;
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
/** A `srcset` with the base in front of each site address. */
|
|
25
|
+
export function siteSrcset<T extends string | undefined | null>(srcset: T): T {
|
|
26
|
+
return srcsetWithBase(BASE, srcset) as T;
|
|
27
|
+
}
|