@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.
- package/README.md +28 -28
- package/astro.config.mjs +645 -645
- package/bin/writedocs.js +43 -12
- 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 +1 -1
- package/src/cli/dev.js +268 -268
- package/src/cli/exit-when-flushed.js +4 -0
- 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.js +414 -75
- package/src/lib/config-schema.ts +2509 -1905
- package/src/lib/config.ts +1316 -1314
- 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/base-path.js
CHANGED
|
@@ -1,90 +1,90 @@
|
|
|
1
|
-
// writedocs.json's `basePath` - the site served under a path of a domain,
|
|
2
|
-
// `empresa.com/docs`, usually behind a proxy that passes `/docs/*` on to the
|
|
3
|
-
// site as it is. Every address the site makes starts with it, and the build
|
|
4
|
-
// writes the site into dist/<basePath>/ (src/cli/base-path-layout.js), so a
|
|
5
|
-
// static server or a proxy that keeps the path finds every file where its
|
|
6
|
-
// address says.
|
|
7
|
-
//
|
|
8
|
-
// The base is either "" (no basePath: the site at the root, as before) or
|
|
9
|
-
// "/docs" - a leading slash and none at the end. Addresses come in two
|
|
10
|
-
// kinds, and only one of them takes the base:
|
|
11
|
-
// - site addresses: "/guides/a/", "/images/x.png" - a path in the site,
|
|
12
|
-
// written by the project (writedocs.json, page content) or by writedocs
|
|
13
|
-
// itself (navigation, assets). withBase() prefixes them, once, where the
|
|
14
|
-
// final address is written - never twice: a page can live at "/docs/..."
|
|
15
|
-
// inside a site whose base is "/docs", so "already starts with the base"
|
|
16
|
-
// can't tell whether an address has been prefixed.
|
|
17
|
-
// - everything else - "https://...", "#a", "mailto:", "//cdn...", a relative
|
|
18
|
-
// "../a" - is left as it is.
|
|
19
|
-
//
|
|
20
|
-
// Plain JS so the tests can import it; lib/config.ts reads the field
|
|
21
|
-
// (resolveBasePath()), and astro.config.mjs hands it to Astro (`base`) and to
|
|
22
|
-
// the page scripts (__WD_BASE__).
|
|
23
|
-
|
|
24
|
-
/** The accepted form: "/docs", "/help/docs" - lowercase letters, digits, `-`
|
|
25
|
-
* and `_` in each segment. "" and "/" are accepted too and mean no base
|
|
26
|
-
* (BASE_PATH_FIELD_PATTERN). */
|
|
27
|
-
export const BASE_PATH_PATTERN = /^(\/[a-z0-9_-]+)+$/;
|
|
28
|
-
|
|
29
|
-
/** What writedocs.json may hold in `basePath` - the form above, "" or "/". */
|
|
30
|
-
export const BASE_PATH_FIELD_PATTERN = /^(\/|(\/[a-z0-9_-]+)+)?$/;
|
|
31
|
-
|
|
32
|
-
/** The base from writedocs.json's value: "" when unset, "" or "/", else the
|
|
33
|
-
* value itself. Assumes a value the schema accepted. */
|
|
34
|
-
export function normalizeBasePath(value) {
|
|
35
|
-
if (typeof value !== 'string' || value === '' || value === '/') return '';
|
|
36
|
-
return value;
|
|
37
|
-
}
|
|
38
|
-
|
|
39
|
-
/** Whether `url` is a site address: a path from the site's root ("/a/b"),
|
|
40
|
-
* not a protocol-relative "//host/a". */
|
|
41
|
-
export function isSiteAddress(url) {
|
|
42
|
-
return typeof url === 'string' && url.startsWith('/') && !url.startsWith('//');
|
|
43
|
-
}
|
|
44
|
-
|
|
45
|
-
/** `url` with the base in front, if it's a site address - "/a/" -> "/docs/a/",
|
|
46
|
-
* "/" -> "/docs/". Anything else, and everything when there's no base,
|
|
47
|
-
* comes back as it is. */
|
|
48
|
-
export function withBase(base, url) {
|
|
49
|
-
if (!base || !isSiteAddress(url)) return url;
|
|
50
|
-
return base + url;
|
|
51
|
-
}
|
|
52
|
-
|
|
53
|
-
/** A `srcset` with the base in front of each site address in it. */
|
|
54
|
-
export function srcsetWithBase(base, srcset) {
|
|
55
|
-
if (!base || typeof srcset !== 'string') return srcset;
|
|
56
|
-
return srcset
|
|
57
|
-
.split(',')
|
|
58
|
-
.map((candidate) => {
|
|
59
|
-
const [url, ...descriptor] = candidate.trim().split(/\s+/);
|
|
60
|
-
return [withBase(base, url), ...descriptor].join(' ');
|
|
61
|
-
})
|
|
62
|
-
.join(', ');
|
|
63
|
-
}
|
|
64
|
-
|
|
65
|
-
/** The address inside the site for a request path - "/docs/a/" -> "/a/",
|
|
66
|
-
* "/docs" -> "/" - or null when the path isn't under the base. With no base,
|
|
67
|
-
* the path itself. For `writedocs dev`'s own middleware, which sees the full
|
|
68
|
-
* request path. */
|
|
69
|
-
export function withoutBase(base, pathname) {
|
|
70
|
-
if (!base) return pathname;
|
|
71
|
-
if (pathname === base) return '/';
|
|
72
|
-
if (pathname.startsWith(`${base}/`)) return pathname.slice(base.length);
|
|
73
|
-
return null;
|
|
74
|
-
}
|
|
75
|
-
|
|
76
|
-
/** The site's URL - "https://empresa.com/docs" - from writedocs.json's
|
|
77
|
-
* `domain` (scheme optional, trailing slash dropped) and the base; null
|
|
78
|
-
* without a `domain`. resolveSiteUrl() in lib/config.ts is this, for a
|
|
79
|
-
* loaded config. */
|
|
80
|
-
export function siteUrlFor(domain, base = '') {
|
|
81
|
-
const origin = siteOriginFor(domain);
|
|
82
|
-
return origin === null ? null : origin + base;
|
|
83
|
-
}
|
|
84
|
-
|
|
85
|
-
/** The `domain` alone as a full origin ("https://docs.example.com"), or null. */
|
|
86
|
-
export function siteOriginFor(domain) {
|
|
87
|
-
if (!domain) return null;
|
|
88
|
-
const withScheme = /^https?:\/\//i.test(domain) ? domain : `https://${domain}`;
|
|
89
|
-
return withScheme.replace(/\/+$/, '');
|
|
90
|
-
}
|
|
1
|
+
// writedocs.json's `basePath` - the site served under a path of a domain,
|
|
2
|
+
// `empresa.com/docs`, usually behind a proxy that passes `/docs/*` on to the
|
|
3
|
+
// site as it is. Every address the site makes starts with it, and the build
|
|
4
|
+
// writes the site into dist/<basePath>/ (src/cli/base-path-layout.js), so a
|
|
5
|
+
// static server or a proxy that keeps the path finds every file where its
|
|
6
|
+
// address says.
|
|
7
|
+
//
|
|
8
|
+
// The base is either "" (no basePath: the site at the root, as before) or
|
|
9
|
+
// "/docs" - a leading slash and none at the end. Addresses come in two
|
|
10
|
+
// kinds, and only one of them takes the base:
|
|
11
|
+
// - site addresses: "/guides/a/", "/images/x.png" - a path in the site,
|
|
12
|
+
// written by the project (writedocs.json, page content) or by writedocs
|
|
13
|
+
// itself (navigation, assets). withBase() prefixes them, once, where the
|
|
14
|
+
// final address is written - never twice: a page can live at "/docs/..."
|
|
15
|
+
// inside a site whose base is "/docs", so "already starts with the base"
|
|
16
|
+
// can't tell whether an address has been prefixed.
|
|
17
|
+
// - everything else - "https://...", "#a", "mailto:", "//cdn...", a relative
|
|
18
|
+
// "../a" - is left as it is.
|
|
19
|
+
//
|
|
20
|
+
// Plain JS so the tests can import it; lib/config.ts reads the field
|
|
21
|
+
// (resolveBasePath()), and astro.config.mjs hands it to Astro (`base`) and to
|
|
22
|
+
// the page scripts (__WD_BASE__).
|
|
23
|
+
|
|
24
|
+
/** The accepted form: "/docs", "/help/docs" - lowercase letters, digits, `-`
|
|
25
|
+
* and `_` in each segment. "" and "/" are accepted too and mean no base
|
|
26
|
+
* (BASE_PATH_FIELD_PATTERN). */
|
|
27
|
+
export const BASE_PATH_PATTERN = /^(\/[a-z0-9_-]+)+$/;
|
|
28
|
+
|
|
29
|
+
/** What writedocs.json may hold in `basePath` - the form above, "" or "/". */
|
|
30
|
+
export const BASE_PATH_FIELD_PATTERN = /^(\/|(\/[a-z0-9_-]+)+)?$/;
|
|
31
|
+
|
|
32
|
+
/** The base from writedocs.json's value: "" when unset, "" or "/", else the
|
|
33
|
+
* value itself. Assumes a value the schema accepted. */
|
|
34
|
+
export function normalizeBasePath(value) {
|
|
35
|
+
if (typeof value !== 'string' || value === '' || value === '/') return '';
|
|
36
|
+
return value;
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
/** Whether `url` is a site address: a path from the site's root ("/a/b"),
|
|
40
|
+
* not a protocol-relative "//host/a". */
|
|
41
|
+
export function isSiteAddress(url) {
|
|
42
|
+
return typeof url === 'string' && url.startsWith('/') && !url.startsWith('//');
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
/** `url` with the base in front, if it's a site address - "/a/" -> "/docs/a/",
|
|
46
|
+
* "/" -> "/docs/". Anything else, and everything when there's no base,
|
|
47
|
+
* comes back as it is. */
|
|
48
|
+
export function withBase(base, url) {
|
|
49
|
+
if (!base || !isSiteAddress(url)) return url;
|
|
50
|
+
return base + url;
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
/** A `srcset` with the base in front of each site address in it. */
|
|
54
|
+
export function srcsetWithBase(base, srcset) {
|
|
55
|
+
if (!base || typeof srcset !== 'string') return srcset;
|
|
56
|
+
return srcset
|
|
57
|
+
.split(',')
|
|
58
|
+
.map((candidate) => {
|
|
59
|
+
const [url, ...descriptor] = candidate.trim().split(/\s+/);
|
|
60
|
+
return [withBase(base, url), ...descriptor].join(' ');
|
|
61
|
+
})
|
|
62
|
+
.join(', ');
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
/** The address inside the site for a request path - "/docs/a/" -> "/a/",
|
|
66
|
+
* "/docs" -> "/" - or null when the path isn't under the base. With no base,
|
|
67
|
+
* the path itself. For `writedocs dev`'s own middleware, which sees the full
|
|
68
|
+
* request path. */
|
|
69
|
+
export function withoutBase(base, pathname) {
|
|
70
|
+
if (!base) return pathname;
|
|
71
|
+
if (pathname === base) return '/';
|
|
72
|
+
if (pathname.startsWith(`${base}/`)) return pathname.slice(base.length);
|
|
73
|
+
return null;
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
/** The site's URL - "https://empresa.com/docs" - from writedocs.json's
|
|
77
|
+
* `domain` (scheme optional, trailing slash dropped) and the base; null
|
|
78
|
+
* without a `domain`. resolveSiteUrl() in lib/config.ts is this, for a
|
|
79
|
+
* loaded config. */
|
|
80
|
+
export function siteUrlFor(domain, base = '') {
|
|
81
|
+
const origin = siteOriginFor(domain);
|
|
82
|
+
return origin === null ? null : origin + base;
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
/** The `domain` alone as a full origin ("https://docs.example.com"), or null. */
|
|
86
|
+
export function siteOriginFor(domain) {
|
|
87
|
+
if (!domain) return null;
|
|
88
|
+
const withScheme = /^https?:\/\//i.test(domain) ? domain : `https://${domain}`;
|
|
89
|
+
return withScheme.replace(/\/+$/, '');
|
|
90
|
+
}
|
package/src/lib/cli-report.js
CHANGED
|
@@ -1,22 +1,22 @@
|
|
|
1
|
-
// How writedocs code that runs inside Astro - astro.config.mjs, remark
|
|
2
|
-
// plugins, components - tells the author something. Under the writedocs CLI
|
|
3
|
-
// the message goes over IPC to the CLI process (src/cli/run-astro.js), which
|
|
4
|
-
// prints it in its own format: warnings are listed at the end of a build,
|
|
5
|
-
// or as they happen in `writedocs dev`. Anywhere else (Astro run directly,
|
|
6
|
-
// a test) it's printed with a [writedocs] prefix.
|
|
7
|
-
//
|
|
8
|
-
// level: 'error' - something broken right now, in `writedocs dev` (an
|
|
9
|
-
// OpenAPI spec that stopped parsing);
|
|
10
|
-
// 'warn' - something the author should fix or know about;
|
|
11
|
-
// 'info' - a note about how the site was built (shown after a build);
|
|
12
|
-
// 'debug' - only with --verbose.
|
|
13
|
-
// where: optional "file:line" the message is about, relative to the project.
|
|
14
|
-
export function report(level, message, where) {
|
|
15
|
-
if (typeof process !== 'undefined' && typeof process.send === 'function' && process.connected) {
|
|
16
|
-
process.send({ type: 'report', level, message, where: where ?? null });
|
|
17
|
-
return;
|
|
18
|
-
}
|
|
19
|
-
const text = `[writedocs] ${where ? `${where} - ` : ''}${message}`;
|
|
20
|
-
if (level === 'warn') console.warn(text);
|
|
21
|
-
else console.log(text);
|
|
22
|
-
}
|
|
1
|
+
// How writedocs code that runs inside Astro - astro.config.mjs, remark
|
|
2
|
+
// plugins, components - tells the author something. Under the writedocs CLI
|
|
3
|
+
// the message goes over IPC to the CLI process (src/cli/run-astro.js), which
|
|
4
|
+
// prints it in its own format: warnings are listed at the end of a build,
|
|
5
|
+
// or as they happen in `writedocs dev`. Anywhere else (Astro run directly,
|
|
6
|
+
// a test) it's printed with a [writedocs] prefix.
|
|
7
|
+
//
|
|
8
|
+
// level: 'error' - something broken right now, in `writedocs dev` (an
|
|
9
|
+
// OpenAPI spec that stopped parsing);
|
|
10
|
+
// 'warn' - something the author should fix or know about;
|
|
11
|
+
// 'info' - a note about how the site was built (shown after a build);
|
|
12
|
+
// 'debug' - only with --verbose.
|
|
13
|
+
// where: optional "file:line" the message is about, relative to the project.
|
|
14
|
+
export function report(level, message, where) {
|
|
15
|
+
if (typeof process !== 'undefined' && typeof process.send === 'function' && process.connected) {
|
|
16
|
+
process.send({ type: 'report', level, message, where: where ?? null });
|
|
17
|
+
return;
|
|
18
|
+
}
|
|
19
|
+
const text = `[writedocs] ${where ? `${where} - ` : ''}${message}`;
|
|
20
|
+
if (level === 'warn') console.warn(text);
|
|
21
|
+
else console.log(text);
|
|
22
|
+
}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
// The width of a ```js lines block's number column, in digits: as many as
|
|
2
|
+
// its last line number has. The column is that many `ch` wide (see
|
|
3
|
+
// .wd-code-lines in [...slug].astro), so a block of under ten lines starts
|
|
4
|
+
// its numbers at the panel's padding, like Mintlify's, instead of inside a
|
|
5
|
+
// fixed-width box sized for two or three digits.
|
|
6
|
+
//
|
|
7
|
+
// `pre` is the HAST <pre> Shiki builds: one <code> holding one element per
|
|
8
|
+
// line (the newlines between them are text nodes).
|
|
9
|
+
export function lineNumberDigits(pre) {
|
|
10
|
+
const code = pre.children.find((child) => child.type === 'element' && child.tagName === 'code');
|
|
11
|
+
const lines = code ? code.children.filter((child) => child.type === 'element').length : 0;
|
|
12
|
+
return String(Math.max(lines, 1)).length;
|
|
13
|
+
}
|