@writedocs/generator 0.13.4 → 0.14.0
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 +359 -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 +223 -203
- package/src/cli/check-built-styles.js +41 -41
- package/src/cli/convert.js +124 -124
- package/src/cli/dev.js +269 -268
- package/src/cli/exit-when-flushed.js +42 -42
- package/src/cli/generate-api-pages.js +509 -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 +71 -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 +219 -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 +422 -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 +12 -1
- package/src/lib/config-schema.ts +2523 -2509
- package/src/lib/config.ts +1331 -1316
- package/src/lib/consent.js +108 -108
- package/src/lib/content-check.js +4 -1
- package/src/lib/content-store-reload-integration.js +101 -101
- package/src/lib/drafts.js +186 -0
- 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 +553 -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 +346 -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 +157 -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 +1773 -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
|
@@ -1,71 +1,71 @@
|
|
|
1
|
-
// How content images load. For every image a page's Markdown or MDX writes -
|
|
2
|
-
// ``, `<img src="/a.png">`, `<Image src="/a.png">`:
|
|
3
|
-
//
|
|
4
|
-
// - `loading="lazy"`: the browser fetches it when the reader gets near
|
|
5
|
-
// it, not with the page. The first image of a page is left alone - it's
|
|
6
|
-
// usually at the top, where waiting would make the page look slower.
|
|
7
|
-
// - `decoding="async"`: decoding it doesn't hold up the text.
|
|
8
|
-
// - `width` and `height`, read from the file: the browser keeps the
|
|
9
|
-
// image's place before it arrives, so the text below doesn't jump
|
|
10
|
-
// (layout shift). With them goes `data-wd-sized`, which base.css uses
|
|
11
|
-
// to keep the height following the width (`height: auto`) - without
|
|
12
|
-
// that, an image narrower than its file would be stretched.
|
|
13
|
-
//
|
|
14
|
-
// What the author wrote always wins: an image with its own `loading`,
|
|
15
|
-
// `width` or `height` keeps them, and gets no size from here.
|
|
16
|
-
//
|
|
17
|
-
// `<Image>` reads its own files' sizes (it may have two, light and dark -
|
|
18
|
-
// Image.astro); all it gets from here is `loading="eager"` when it's the
|
|
19
|
-
// page's first image. Sizes are only known for files in the project
|
|
20
|
-
// (addresses starting with "/"); a relative Markdown image is Astro's own
|
|
21
|
-
// to process, and an image on another site only gets the two loading hints.
|
|
22
|
-
import { imageFileFor, imageSize } from './image-size.js';
|
|
23
|
-
|
|
24
|
-
const isJsx = (node) => node.type === 'mdxJsxFlowElement' || node.type === 'mdxJsxTextElement';
|
|
25
|
-
|
|
26
|
-
/** A JSX attribute's value when it's a plain string; undefined when the
|
|
27
|
-
* attribute is absent, null when it's an expression (`src={logo}`). */
|
|
28
|
-
function jsxAttribute(node, name) {
|
|
29
|
-
const attribute = node.attributes?.find((a) => a.type === 'mdxJsxAttribute' && a.name === name);
|
|
30
|
-
if (!attribute) return undefined;
|
|
31
|
-
return typeof attribute.value === 'string' ? attribute.value : null;
|
|
32
|
-
}
|
|
33
|
-
|
|
34
|
-
const setJsx = (node, name, value) => node.attributes.push({ type: 'mdxJsxAttribute', name, value: String(value) });
|
|
35
|
-
|
|
36
|
-
export function rehypeImageLoading({ contentDir } = {}) {
|
|
37
|
-
return (tree) => {
|
|
38
|
-
let seen = 0;
|
|
39
|
-
const visit = (node) => {
|
|
40
|
-
if (node.type === 'element' && node.tagName === 'img') {
|
|
41
|
-
const first = seen++ === 0;
|
|
42
|
-
const p = (node.properties ??= {});
|
|
43
|
-
if (p.loading === undefined && !first) p.loading = 'lazy';
|
|
44
|
-
if (p.decoding === undefined) p.decoding = 'async';
|
|
45
|
-
if (p.width === undefined && p.height === undefined && contentDir) {
|
|
46
|
-
const file = imageFileFor(p.src, contentDir);
|
|
47
|
-
const size = file && imageSize(file, contentDir);
|
|
48
|
-
if (size) Object.assign(p, { width: size.width, height: size.height, 'data-wd-sized': '' });
|
|
49
|
-
}
|
|
50
|
-
} else if (isJsx(node) && node.name === 'img') {
|
|
51
|
-
const first = seen++ === 0;
|
|
52
|
-
if (jsxAttribute(node, 'loading') === undefined && !first) setJsx(node, 'loading', 'lazy');
|
|
53
|
-
if (jsxAttribute(node, 'decoding') === undefined) setJsx(node, 'decoding', 'async');
|
|
54
|
-
if (jsxAttribute(node, 'width') === undefined && jsxAttribute(node, 'height') === undefined && contentDir) {
|
|
55
|
-
const file = imageFileFor(jsxAttribute(node, 'src'), contentDir);
|
|
56
|
-
const size = file && imageSize(file, contentDir);
|
|
57
|
-
if (size) {
|
|
58
|
-
setJsx(node, 'width', size.width);
|
|
59
|
-
setJsx(node, 'height', size.height);
|
|
60
|
-
setJsx(node, 'data-wd-sized', '');
|
|
61
|
-
}
|
|
62
|
-
}
|
|
63
|
-
} else if (isJsx(node) && node.name === 'Image') {
|
|
64
|
-
const first = seen++ === 0;
|
|
65
|
-
if (first && jsxAttribute(node, 'loading') === undefined) setJsx(node, 'loading', 'eager');
|
|
66
|
-
}
|
|
67
|
-
if (Array.isArray(node.children)) node.children.forEach(visit);
|
|
68
|
-
};
|
|
69
|
-
visit(tree);
|
|
70
|
-
};
|
|
71
|
-
}
|
|
1
|
+
// How content images load. For every image a page's Markdown or MDX writes -
|
|
2
|
+
// ``, `<img src="/a.png">`, `<Image src="/a.png">`:
|
|
3
|
+
//
|
|
4
|
+
// - `loading="lazy"`: the browser fetches it when the reader gets near
|
|
5
|
+
// it, not with the page. The first image of a page is left alone - it's
|
|
6
|
+
// usually at the top, where waiting would make the page look slower.
|
|
7
|
+
// - `decoding="async"`: decoding it doesn't hold up the text.
|
|
8
|
+
// - `width` and `height`, read from the file: the browser keeps the
|
|
9
|
+
// image's place before it arrives, so the text below doesn't jump
|
|
10
|
+
// (layout shift). With them goes `data-wd-sized`, which base.css uses
|
|
11
|
+
// to keep the height following the width (`height: auto`) - without
|
|
12
|
+
// that, an image narrower than its file would be stretched.
|
|
13
|
+
//
|
|
14
|
+
// What the author wrote always wins: an image with its own `loading`,
|
|
15
|
+
// `width` or `height` keeps them, and gets no size from here.
|
|
16
|
+
//
|
|
17
|
+
// `<Image>` reads its own files' sizes (it may have two, light and dark -
|
|
18
|
+
// Image.astro); all it gets from here is `loading="eager"` when it's the
|
|
19
|
+
// page's first image. Sizes are only known for files in the project
|
|
20
|
+
// (addresses starting with "/"); a relative Markdown image is Astro's own
|
|
21
|
+
// to process, and an image on another site only gets the two loading hints.
|
|
22
|
+
import { imageFileFor, imageSize } from './image-size.js';
|
|
23
|
+
|
|
24
|
+
const isJsx = (node) => node.type === 'mdxJsxFlowElement' || node.type === 'mdxJsxTextElement';
|
|
25
|
+
|
|
26
|
+
/** A JSX attribute's value when it's a plain string; undefined when the
|
|
27
|
+
* attribute is absent, null when it's an expression (`src={logo}`). */
|
|
28
|
+
function jsxAttribute(node, name) {
|
|
29
|
+
const attribute = node.attributes?.find((a) => a.type === 'mdxJsxAttribute' && a.name === name);
|
|
30
|
+
if (!attribute) return undefined;
|
|
31
|
+
return typeof attribute.value === 'string' ? attribute.value : null;
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
const setJsx = (node, name, value) => node.attributes.push({ type: 'mdxJsxAttribute', name, value: String(value) });
|
|
35
|
+
|
|
36
|
+
export function rehypeImageLoading({ contentDir } = {}) {
|
|
37
|
+
return (tree) => {
|
|
38
|
+
let seen = 0;
|
|
39
|
+
const visit = (node) => {
|
|
40
|
+
if (node.type === 'element' && node.tagName === 'img') {
|
|
41
|
+
const first = seen++ === 0;
|
|
42
|
+
const p = (node.properties ??= {});
|
|
43
|
+
if (p.loading === undefined && !first) p.loading = 'lazy';
|
|
44
|
+
if (p.decoding === undefined) p.decoding = 'async';
|
|
45
|
+
if (p.width === undefined && p.height === undefined && contentDir) {
|
|
46
|
+
const file = imageFileFor(p.src, contentDir);
|
|
47
|
+
const size = file && imageSize(file, contentDir);
|
|
48
|
+
if (size) Object.assign(p, { width: size.width, height: size.height, 'data-wd-sized': '' });
|
|
49
|
+
}
|
|
50
|
+
} else if (isJsx(node) && node.name === 'img') {
|
|
51
|
+
const first = seen++ === 0;
|
|
52
|
+
if (jsxAttribute(node, 'loading') === undefined && !first) setJsx(node, 'loading', 'lazy');
|
|
53
|
+
if (jsxAttribute(node, 'decoding') === undefined) setJsx(node, 'decoding', 'async');
|
|
54
|
+
if (jsxAttribute(node, 'width') === undefined && jsxAttribute(node, 'height') === undefined && contentDir) {
|
|
55
|
+
const file = imageFileFor(jsxAttribute(node, 'src'), contentDir);
|
|
56
|
+
const size = file && imageSize(file, contentDir);
|
|
57
|
+
if (size) {
|
|
58
|
+
setJsx(node, 'width', size.width);
|
|
59
|
+
setJsx(node, 'height', size.height);
|
|
60
|
+
setJsx(node, 'data-wd-sized', '');
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
} else if (isJsx(node) && node.name === 'Image') {
|
|
64
|
+
const first = seen++ === 0;
|
|
65
|
+
if (first && jsxAttribute(node, 'loading') === undefined) setJsx(node, 'loading', 'eager');
|
|
66
|
+
}
|
|
67
|
+
if (Array.isArray(node.children)) node.children.forEach(visit);
|
|
68
|
+
};
|
|
69
|
+
visit(tree);
|
|
70
|
+
};
|
|
71
|
+
}
|
package/src/lib/robots-txt.js
CHANGED
|
@@ -1,21 +1,21 @@
|
|
|
1
|
-
// The robots.txt a build writes when the project has none of its own
|
|
2
|
-
// (lib/project-files-integration.js). Plain JavaScript, for
|
|
3
|
-
// scripts/robots-txt.test.js.
|
|
4
|
-
import { withBase } from './base-path.js';
|
|
5
|
-
|
|
6
|
-
/** `siteUrl`: the site's URL ({domain}{basePath}), or null without a `domain`.
|
|
7
|
-
* `sitemap`: the sitemap's file name in the build ("sitemap.xml",
|
|
8
|
-
* "sitemap-index.xml"), or null when there's none.
|
|
9
|
-
* `noindex`: the whole site is kept out of search engines (writedocs.json's
|
|
10
|
-
* `seo.noindex`, or a `seo.robots` with "noindex") - crawlers are then
|
|
11
|
-
* asked to stay out, and no sitemap is advertised.
|
|
12
|
-
* `basePath`: the site's base ("/docs", lib/base-path.js) - the rules then
|
|
13
|
-
* cover the site's own path, ready to copy into the robots.txt at the root
|
|
14
|
-
* of the domain (crawlers only read that one, not /docs/robots.txt). */
|
|
15
|
-
export function robotsTxt({ siteUrl = null, sitemap = null, noindex = false, basePath = '' } = {}) {
|
|
16
|
-
const root = withBase(basePath, '/');
|
|
17
|
-
if (noindex) return ['User-agent: *', `Disallow: ${root}`, ''].join('\n');
|
|
18
|
-
const lines = ['User-agent: *', `Allow: ${root}`];
|
|
19
|
-
if (siteUrl && sitemap) lines.push('', `Sitemap: ${siteUrl}/${sitemap}`);
|
|
20
|
-
return `${lines.join('\n')}\n`;
|
|
21
|
-
}
|
|
1
|
+
// The robots.txt a build writes when the project has none of its own
|
|
2
|
+
// (lib/project-files-integration.js). Plain JavaScript, for
|
|
3
|
+
// scripts/robots-txt.test.js.
|
|
4
|
+
import { withBase } from './base-path.js';
|
|
5
|
+
|
|
6
|
+
/** `siteUrl`: the site's URL ({domain}{basePath}), or null without a `domain`.
|
|
7
|
+
* `sitemap`: the sitemap's file name in the build ("sitemap.xml",
|
|
8
|
+
* "sitemap-index.xml"), or null when there's none.
|
|
9
|
+
* `noindex`: the whole site is kept out of search engines (writedocs.json's
|
|
10
|
+
* `seo.noindex`, or a `seo.robots` with "noindex") - crawlers are then
|
|
11
|
+
* asked to stay out, and no sitemap is advertised.
|
|
12
|
+
* `basePath`: the site's base ("/docs", lib/base-path.js) - the rules then
|
|
13
|
+
* cover the site's own path, ready to copy into the robots.txt at the root
|
|
14
|
+
* of the domain (crawlers only read that one, not /docs/robots.txt). */
|
|
15
|
+
export function robotsTxt({ siteUrl = null, sitemap = null, noindex = false, basePath = '' } = {}) {
|
|
16
|
+
const root = withBase(basePath, '/');
|
|
17
|
+
if (noindex) return ['User-agent: *', `Disallow: ${root}`, ''].join('\n');
|
|
18
|
+
const lines = ['User-agent: *', `Allow: ${root}`];
|
|
19
|
+
if (siteUrl && sitemap) lines.push('', `Sitemap: ${siteUrl}/${sitemap}`);
|
|
20
|
+
return `${lines.join('\n')}\n`;
|
|
21
|
+
}
|
package/src/lib/search-scope.js
CHANGED
|
@@ -1,44 +1,44 @@
|
|
|
1
|
-
// What search knows about a page beyond its text: where it sits (the
|
|
2
|
-
// section line under a result's title, and words a search can match - a
|
|
3
|
-
// page under the "Webhooks" tab is found by "webhooks"), and which version,
|
|
4
|
-
// language and product it belongs to (search shows those of the page the
|
|
5
|
-
// reader is on, with a way to search everything). Built from a Section's
|
|
6
|
-
// `path` (resolveSections() in lib/config.ts) and the page's breadcrumb
|
|
7
|
-
// groups. src/scripts/search.ts reads both back.
|
|
8
|
-
|
|
9
|
-
/** Every page outside any version, language and product - shown whatever
|
|
10
|
-
* the reader is on. */
|
|
11
|
-
export const ALL_SCOPES = 'all';
|
|
12
|
-
|
|
13
|
-
const SCOPE_KINDS = { version: 'version', language: 'language', product: 'product' };
|
|
14
|
-
|
|
15
|
-
function segmentValue(segment) {
|
|
16
|
-
const item = segment.items[segment.index] ?? {};
|
|
17
|
-
switch (segment.kind) {
|
|
18
|
-
case 'tab': return { id: item.tab, label: item.tab };
|
|
19
|
-
case 'dropdown': return { id: item.dropdown, label: item.dropdown };
|
|
20
|
-
case 'product': return { id: item.product, label: item.product };
|
|
21
|
-
case 'version': return { id: item.version, label: item.label ?? item.version };
|
|
22
|
-
case 'language': return { id: item.language, label: item.label ?? item.language };
|
|
23
|
-
default: return { id: '', label: '' };
|
|
24
|
-
}
|
|
25
|
-
}
|
|
26
|
-
|
|
27
|
-
/** `key` - the same for every page of one version/language/product
|
|
28
|
-
* combination; `label` - how the search box names it ("v2 · English"). */
|
|
29
|
-
export function searchScope(path = []) {
|
|
30
|
-
const parts = path.filter((s) => s.kind in SCOPE_KINDS).map((s) => ({ kind: s.kind, ...segmentValue(s) }));
|
|
31
|
-
if (parts.length === 0) return { key: ALL_SCOPES, label: '' };
|
|
32
|
-
return {
|
|
33
|
-
// Pagefind's `data-pagefind-filter="scope:..."` reads a comma as the next
|
|
34
|
-
// filter and the first colon as the end of the name.
|
|
35
|
-
key: parts.map((p) => `${p.kind}=${String(p.id).replace(/[,:]/g, '_')}`).join('/'),
|
|
36
|
-
label: parts.map((p) => p.label).join(' · '),
|
|
37
|
-
};
|
|
38
|
-
}
|
|
39
|
-
|
|
40
|
-
/** "API Reference › Webhooks › Events group": every level above the page,
|
|
41
|
-
* navigation containers first, then its groups. */
|
|
42
|
-
export function sectionTrail(path = [], groups = []) {
|
|
43
|
-
return [...path.map((s) => segmentValue(s).label), ...groups.map((g) => g.label)].filter(Boolean).join(' › ');
|
|
44
|
-
}
|
|
1
|
+
// What search knows about a page beyond its text: where it sits (the
|
|
2
|
+
// section line under a result's title, and words a search can match - a
|
|
3
|
+
// page under the "Webhooks" tab is found by "webhooks"), and which version,
|
|
4
|
+
// language and product it belongs to (search shows those of the page the
|
|
5
|
+
// reader is on, with a way to search everything). Built from a Section's
|
|
6
|
+
// `path` (resolveSections() in lib/config.ts) and the page's breadcrumb
|
|
7
|
+
// groups. src/scripts/search.ts reads both back.
|
|
8
|
+
|
|
9
|
+
/** Every page outside any version, language and product - shown whatever
|
|
10
|
+
* the reader is on. */
|
|
11
|
+
export const ALL_SCOPES = 'all';
|
|
12
|
+
|
|
13
|
+
const SCOPE_KINDS = { version: 'version', language: 'language', product: 'product' };
|
|
14
|
+
|
|
15
|
+
function segmentValue(segment) {
|
|
16
|
+
const item = segment.items[segment.index] ?? {};
|
|
17
|
+
switch (segment.kind) {
|
|
18
|
+
case 'tab': return { id: item.tab, label: item.tab };
|
|
19
|
+
case 'dropdown': return { id: item.dropdown, label: item.dropdown };
|
|
20
|
+
case 'product': return { id: item.product, label: item.product };
|
|
21
|
+
case 'version': return { id: item.version, label: item.label ?? item.version };
|
|
22
|
+
case 'language': return { id: item.language, label: item.label ?? item.language };
|
|
23
|
+
default: return { id: '', label: '' };
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
/** `key` - the same for every page of one version/language/product
|
|
28
|
+
* combination; `label` - how the search box names it ("v2 · English"). */
|
|
29
|
+
export function searchScope(path = []) {
|
|
30
|
+
const parts = path.filter((s) => s.kind in SCOPE_KINDS).map((s) => ({ kind: s.kind, ...segmentValue(s) }));
|
|
31
|
+
if (parts.length === 0) return { key: ALL_SCOPES, label: '' };
|
|
32
|
+
return {
|
|
33
|
+
// Pagefind's `data-pagefind-filter="scope:..."` reads a comma as the next
|
|
34
|
+
// filter and the first colon as the end of the name.
|
|
35
|
+
key: parts.map((p) => `${p.kind}=${String(p.id).replace(/[,:]/g, '_')}`).join('/'),
|
|
36
|
+
label: parts.map((p) => p.label).join(' · '),
|
|
37
|
+
};
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
/** "API Reference › Webhooks › Events group": every level above the page,
|
|
41
|
+
* navigation containers first, then its groups. */
|
|
42
|
+
export function sectionTrail(path = [], groups = []) {
|
|
43
|
+
return [...path.map((s) => segmentValue(s).label), ...groups.map((g) => g.label)].filter(Boolean).join(' › ');
|
|
44
|
+
}
|
|
@@ -1,50 +1,50 @@
|
|
|
1
|
-
// Where each level of a page's navigation path shows its switcher - one
|
|
2
|
-
// entry per Selector (buildSelectors() in lib/config.ts), root first:
|
|
3
|
-
//
|
|
4
|
-
// 'tabs' a row of tabs in the top bar (a second row for tabs inside tabs)
|
|
5
|
-
// 'tab-menu' the menu of the tab it sits in (dropdowns directly inside a tab)
|
|
6
|
-
// 'tab-submenu' a flyout beside its entry in that menu (dropdowns inside a
|
|
7
|
-
// 'tab-menu' dropdown - SelectorOption.submenu in lib/config.ts)
|
|
8
|
-
// 'sidebar' the top of the sidebar: products inside a tab or a dropdown,
|
|
9
|
-
// like Mintlify's - they pick what the sidebar shows
|
|
10
|
-
// 'topbar' a switcher next to the site name (everything else)
|
|
11
|
-
// 'none' not shown: the page is inside a hidden item on this level
|
|
12
|
-
// (lib/hidden-sections.js), or it's a 'sidebar' level on a
|
|
13
|
-
// page without a sidebar (below)
|
|
14
|
-
//
|
|
15
|
-
// Without a sidebar on the page (`mode: frame` / `custom` / `blank`), a
|
|
16
|
-
// 'sidebar' switcher isn't shown - a hand-built page keeps its top bar to
|
|
17
|
-
// the site's own levels. The mobile menu lists every level either way.
|
|
18
|
-
|
|
19
|
-
export function selectorPlacements(selectors, { sidebar = true } = {}) {
|
|
20
|
-
const placements = [];
|
|
21
|
-
selectors.forEach((sel, i) => {
|
|
22
|
-
const parent = selectors[i - 1]?.kind;
|
|
23
|
-
const placement = (() => {
|
|
24
|
-
if (sel.hidden) return 'none';
|
|
25
|
-
if (sel.kind === 'tab') return 'tabs';
|
|
26
|
-
if (sel.kind === 'dropdown' && parent === 'tab') return 'tab-menu';
|
|
27
|
-
if (sel.kind === 'dropdown' && placements[i - 1] === 'tab-menu') return 'tab-submenu';
|
|
28
|
-
if (sel.kind === 'product' && (parent === 'tab' || parent === 'dropdown')) return sidebar ? 'sidebar' : 'none';
|
|
29
|
-
return 'topbar';
|
|
30
|
-
})();
|
|
31
|
-
placements.push(placement);
|
|
32
|
-
});
|
|
33
|
-
return placements;
|
|
34
|
-
}
|
|
35
|
-
|
|
36
|
-
/** Whether a page gets the mobile menu (its button in the top bar, and the
|
|
37
|
-
* panel - TopBar.astro and MobileMenu.astro both ask this). On a phone the
|
|
38
|
-
* top bar hides the tabs and switchers, so any page with navigation to
|
|
39
|
-
* reach needs it - with a sidebar or without (`mode: custom`). */
|
|
40
|
-
export function hasMobileMenu({ sidebar, selectors = [], globalDropdowns = [] }) {
|
|
41
|
-
return sidebar || selectors.some((sel) => !sel.hidden) || globalDropdowns.length > 0;
|
|
42
|
-
}
|
|
43
|
-
|
|
44
|
-
/** What a switcher's button shows: the chosen option - or, on the level
|
|
45
|
-
* under an item whose own page the reader is on, where none is chosen, the
|
|
46
|
-
* selector's `placeholder` (the item's name - landingSelectors() in
|
|
47
|
-
* lib/config.ts). Falls back to the first option. */
|
|
48
|
-
export function currentOption(selector) {
|
|
49
|
-
return selector.options.find((option) => option.active) ?? selector.placeholder ?? selector.options[0];
|
|
50
|
-
}
|
|
1
|
+
// Where each level of a page's navigation path shows its switcher - one
|
|
2
|
+
// entry per Selector (buildSelectors() in lib/config.ts), root first:
|
|
3
|
+
//
|
|
4
|
+
// 'tabs' a row of tabs in the top bar (a second row for tabs inside tabs)
|
|
5
|
+
// 'tab-menu' the menu of the tab it sits in (dropdowns directly inside a tab)
|
|
6
|
+
// 'tab-submenu' a flyout beside its entry in that menu (dropdowns inside a
|
|
7
|
+
// 'tab-menu' dropdown - SelectorOption.submenu in lib/config.ts)
|
|
8
|
+
// 'sidebar' the top of the sidebar: products inside a tab or a dropdown,
|
|
9
|
+
// like Mintlify's - they pick what the sidebar shows
|
|
10
|
+
// 'topbar' a switcher next to the site name (everything else)
|
|
11
|
+
// 'none' not shown: the page is inside a hidden item on this level
|
|
12
|
+
// (lib/hidden-sections.js), or it's a 'sidebar' level on a
|
|
13
|
+
// page without a sidebar (below)
|
|
14
|
+
//
|
|
15
|
+
// Without a sidebar on the page (`mode: frame` / `custom` / `blank`), a
|
|
16
|
+
// 'sidebar' switcher isn't shown - a hand-built page keeps its top bar to
|
|
17
|
+
// the site's own levels. The mobile menu lists every level either way.
|
|
18
|
+
|
|
19
|
+
export function selectorPlacements(selectors, { sidebar = true } = {}) {
|
|
20
|
+
const placements = [];
|
|
21
|
+
selectors.forEach((sel, i) => {
|
|
22
|
+
const parent = selectors[i - 1]?.kind;
|
|
23
|
+
const placement = (() => {
|
|
24
|
+
if (sel.hidden) return 'none';
|
|
25
|
+
if (sel.kind === 'tab') return 'tabs';
|
|
26
|
+
if (sel.kind === 'dropdown' && parent === 'tab') return 'tab-menu';
|
|
27
|
+
if (sel.kind === 'dropdown' && placements[i - 1] === 'tab-menu') return 'tab-submenu';
|
|
28
|
+
if (sel.kind === 'product' && (parent === 'tab' || parent === 'dropdown')) return sidebar ? 'sidebar' : 'none';
|
|
29
|
+
return 'topbar';
|
|
30
|
+
})();
|
|
31
|
+
placements.push(placement);
|
|
32
|
+
});
|
|
33
|
+
return placements;
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
/** Whether a page gets the mobile menu (its button in the top bar, and the
|
|
37
|
+
* panel - TopBar.astro and MobileMenu.astro both ask this). On a phone the
|
|
38
|
+
* top bar hides the tabs and switchers, so any page with navigation to
|
|
39
|
+
* reach needs it - with a sidebar or without (`mode: custom`). */
|
|
40
|
+
export function hasMobileMenu({ sidebar, selectors = [], globalDropdowns = [] }) {
|
|
41
|
+
return sidebar || selectors.some((sel) => !sel.hidden) || globalDropdowns.length > 0;
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
/** What a switcher's button shows: the chosen option - or, on the level
|
|
45
|
+
* under an item whose own page the reader is on, where none is chosen, the
|
|
46
|
+
* selector's `placeholder` (the item's name - landingSelectors() in
|
|
47
|
+
* lib/config.ts). Falls back to the first option. */
|
|
48
|
+
export function currentOption(selector) {
|
|
49
|
+
return selector.options.find((option) => option.active) ?? selector.placeholder ?? selector.options[0];
|
|
50
|
+
}
|