@dogsbay/docs-layout 0.2.0-beta.152 → 0.2.0-beta.154
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/package.json +6 -6
- package/src/DocsLayout.astro +55 -64
- package/src/switcher.ts +54 -0
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@dogsbay/docs-layout",
|
|
3
|
-
"version": "0.2.0-beta.
|
|
3
|
+
"version": "0.2.0-beta.154",
|
|
4
4
|
"description": "Standard documentation layout components for Dogsbay",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"exports": {
|
|
@@ -35,11 +35,11 @@
|
|
|
35
35
|
"./site-chrome": "./src/site-chrome.ts"
|
|
36
36
|
},
|
|
37
37
|
"dependencies": {
|
|
38
|
-
"@dogsbay/elements": "0.2.0-beta.
|
|
39
|
-
"@dogsbay/primitives": "0.2.0-beta.
|
|
40
|
-
"@dogsbay/
|
|
41
|
-
"@dogsbay/
|
|
42
|
-
"@dogsbay/ui": "0.2.0-beta.
|
|
38
|
+
"@dogsbay/elements": "0.2.0-beta.154",
|
|
39
|
+
"@dogsbay/primitives": "0.2.0-beta.154",
|
|
40
|
+
"@dogsbay/site-files": "0.2.0-beta.154",
|
|
41
|
+
"@dogsbay/search": "0.2.0-beta.154",
|
|
42
|
+
"@dogsbay/ui": "0.2.0-beta.154"
|
|
43
43
|
},
|
|
44
44
|
"devDependencies": {
|
|
45
45
|
"happy-dom": "^20.10.6",
|
package/src/DocsLayout.astro
CHANGED
|
@@ -53,9 +53,10 @@ import { COLOR_MODE_HEAD_SCRIPTS } from "@dogsbay/elements/color-mode-head";
|
|
|
53
53
|
import { ANNOUNCEMENT_CSS, ANNOUNCEMENT_HEAD_SCRIPT } from "@dogsbay/elements/announcement-head";
|
|
54
54
|
import LocaleSwitcher from "./LocaleSwitcher.astro";
|
|
55
55
|
import { filterNavByAxis, rootVersionFilter } from "./nav-filter.js";
|
|
56
|
-
import { versionBadge } from "./switcher.js";
|
|
56
|
+
import { versionBadge, versionBanner, type VersionBannerWording } from "./switcher.js";
|
|
57
57
|
import type { LlmProviderName } from "./llm-actions.js";
|
|
58
58
|
import { jsonLdTypeFor, normalizeCustomJsonLd, buildArticleJsonLd, buildWebSiteJsonLd } from "./json-ld.js";
|
|
59
|
+
import { pageFacets, type PageFacets } from "@dogsbay/site-files";
|
|
59
60
|
import { resolveTagKeywords } from "./tag-list-data.js";
|
|
60
61
|
|
|
61
62
|
interface NavItem {
|
|
@@ -317,6 +318,16 @@ interface Props {
|
|
|
317
318
|
* chip rendering elsewhere). When unset, raw slugs are shown.
|
|
318
319
|
*/
|
|
319
320
|
taxonomies?: Record<string, string[]>;
|
|
321
|
+
/**
|
|
322
|
+
* The page's search facets (facet name → values), as `pageFacets` from
|
|
323
|
+
* `@dogsbay/site-files` maps them — the ONE mapping dogsbay-ssg uses for its
|
|
324
|
+
* search index too. format-astro computes it with the config's
|
|
325
|
+
* `hierarchical` taxonomies. When absent, the layout runs `pageFacets` over
|
|
326
|
+
* `tags`, `audience`, `category`, `status`, `pageType`, `taxonomies` and
|
|
327
|
+
* `multiSource` itself. Each pair becomes a hidden
|
|
328
|
+
* `data-pagefind-filter="name:value"` element.
|
|
329
|
+
*/
|
|
330
|
+
facets?: PageFacets;
|
|
320
331
|
/**
|
|
321
332
|
* Map of taxonomy name → index path for declared taxonomies.
|
|
322
333
|
* Used to wire links from built-in field badges (TypeBadge,
|
|
@@ -352,6 +363,11 @@ interface Props {
|
|
|
352
363
|
* dogsbay-ssg's English `versionBadge` string.
|
|
353
364
|
*/
|
|
354
365
|
versionBadgeWording?: string;
|
|
366
|
+
/**
|
|
367
|
+
* The version banner's words (an older, unmaintained or unreleased version, and the link to the
|
|
368
|
+
* latest), as dogsbay-ssg's English strings by default. A version's own `banner:` text is used as written.
|
|
369
|
+
*/
|
|
370
|
+
versionBannerWording?: Partial<VersionBannerWording>;
|
|
355
371
|
/**
|
|
356
372
|
* When `true`, render `<p>{description}</p>` below the auto H1
|
|
357
373
|
* (or above the meta strip when there's no H1) — used when the
|
|
@@ -560,10 +576,12 @@ const {
|
|
|
560
576
|
audience,
|
|
561
577
|
category,
|
|
562
578
|
taxonomies,
|
|
579
|
+
facets,
|
|
563
580
|
taxonomyIndexPaths,
|
|
564
581
|
taxonomyDisplay,
|
|
565
582
|
autoH1,
|
|
566
583
|
versionBadgeWording,
|
|
584
|
+
versionBannerWording,
|
|
567
585
|
autoLede,
|
|
568
586
|
llmActions,
|
|
569
587
|
customJsonLd,
|
|
@@ -582,6 +600,15 @@ const {
|
|
|
582
600
|
class: className,
|
|
583
601
|
} = Astro.props;
|
|
584
602
|
|
|
603
|
+
// The page's search facets: given (format-astro, with the config's hierarchical
|
|
604
|
+
// taxonomies) or mapped here from the props, by the same function either way.
|
|
605
|
+
const pageFacetValues: PageFacets =
|
|
606
|
+
facets ??
|
|
607
|
+
pageFacets(
|
|
608
|
+
{ tags, audience, category, status, type: pageType, taxonomies },
|
|
609
|
+
{ tagPrefixes, unit: { product: multiSource?.namespace, version: multiSource?.version } },
|
|
610
|
+
);
|
|
611
|
+
|
|
585
612
|
// The version served at the site root (`path: ""`), if any: the sidebar
|
|
586
613
|
// keeps its pages by leaving out the other versions' folders.
|
|
587
614
|
// With a products: block the page carries its version's URL segment, which may
|
|
@@ -594,6 +621,8 @@ const navRootVersion = multiSource?.versionPath !== undefined
|
|
|
594
621
|
: rootVersionFilter(switcherMap?.versions);
|
|
595
622
|
// "Version: 3.33" above the title, on a version with `badge: true` (Docusaurus's version badge)
|
|
596
623
|
const badgeText = versionBadge(switcherMap as never, multiSource as never, versionBadgeWording);
|
|
624
|
+
// "You are viewing documentation for an older version. Go to the latest version" (dogsbay-ssg's banner)
|
|
625
|
+
const bannerData = versionBanner(switcherMap as never, multiSource as never, versionBannerWording);
|
|
597
626
|
const navVersion = multiSource?.versionPath ? multiSource.versionPath : multiSource?.version;
|
|
598
627
|
|
|
599
628
|
// Link icons — classified in CSS by href shape. `data-link-icons`
|
|
@@ -908,11 +937,11 @@ const siteIcon = '<svg xmlns="http://www.w3.org/2000/svg" width="16" height="16"
|
|
|
908
937
|
classified purely by href shape, so it covers both structured
|
|
909
938
|
links and raw-HTML anchors from imported content. Scoped to
|
|
910
939
|
`.docs-prose` so nav/header/footer links are untouched; buttons
|
|
911
|
-
(`<a data-variant>`, from Button.astro) carry no icon.
|
|
940
|
+
(`<a data-variant>`, from Button.astro) and anything inside `.not-prose` carry no icon.
|
|
912
941
|
*/
|
|
913
|
-
body[data-link-icons~="external"] .docs-prose a[href^="http://" i]:not([data-variant])::after,
|
|
914
|
-
body[data-link-icons~="external"] .docs-prose a[href^="https://" i]:not([data-variant])::after,
|
|
915
|
-
body[data-link-icons~="external"] .docs-prose a[href^="//"]:not([data-variant])::after {
|
|
942
|
+
body[data-link-icons~="external"] .docs-prose a[href^="http://" i]:not([data-variant], .not-prose, .not-prose *)::after,
|
|
943
|
+
body[data-link-icons~="external"] .docs-prose a[href^="https://" i]:not([data-variant], .not-prose, .not-prose *)::after,
|
|
944
|
+
body[data-link-icons~="external"] .docs-prose a[href^="//"]:not([data-variant], .not-prose, .not-prose *)::after {
|
|
916
945
|
content: var(--db-link-icon-external, "");
|
|
917
946
|
display: inline-block;
|
|
918
947
|
margin-inline-start: 0.15em;
|
|
@@ -923,9 +952,9 @@ const siteIcon = '<svg xmlns="http://www.w3.org/2000/svg" width="16" height="16"
|
|
|
923
952
|
}
|
|
924
953
|
body[data-link-icons~="internal"]
|
|
925
954
|
.docs-prose
|
|
926
|
-
a[href^="/"]:not([href^="//"]):not([data-variant])::after,
|
|
927
|
-
body[data-link-icons~="internal"] .docs-prose a[href^="./"]:not([data-variant])::after,
|
|
928
|
-
body[data-link-icons~="internal"] .docs-prose a[href^="../"]:not([data-variant])::after {
|
|
955
|
+
a[href^="/"]:not([href^="//"]):not([data-variant], .not-prose, .not-prose *)::after,
|
|
956
|
+
body[data-link-icons~="internal"] .docs-prose a[href^="./"]:not([data-variant], .not-prose, .not-prose *)::after,
|
|
957
|
+
body[data-link-icons~="internal"] .docs-prose a[href^="../"]:not([data-variant], .not-prose, .not-prose *)::after {
|
|
929
958
|
content: var(--db-link-icon-internal, "");
|
|
930
959
|
display: inline-block;
|
|
931
960
|
margin-inline-start: 0.15em;
|
|
@@ -1099,7 +1128,7 @@ const siteIcon = '<svg xmlns="http://www.w3.org/2000/svg" width="16" height="16"
|
|
|
1099
1128
|
not match and it fills the width.
|
|
1100
1129
|
*/}
|
|
1101
1130
|
{chrome === "docs" && (
|
|
1102
|
-
<Sidebar collapsible="icon">
|
|
1131
|
+
<Sidebar collapsible="icon" label="Docs">
|
|
1103
1132
|
<SidebarHeader>
|
|
1104
1133
|
<SidebarMenu>
|
|
1105
1134
|
<SidebarMenuItem>
|
|
@@ -1303,62 +1332,17 @@ const siteIcon = '<svg xmlns="http://www.w3.org/2000/svg" width="16" height="16"
|
|
|
1303
1332
|
now to stay inside that scope.
|
|
1304
1333
|
*/}
|
|
1305
1334
|
{/*
|
|
1306
|
-
|
|
1307
|
-
`
|
|
1308
|
-
|
|
1309
|
-
|
|
1310
|
-
|
|
1311
|
-
|
|
1312
|
-
|
|
1313
|
-
|
|
1314
|
-
for sites that haven't declared prefixes.
|
|
1315
|
-
|
|
1316
|
-
See plans/per-prefix-search-facets.md.
|
|
1317
|
-
*/}
|
|
1318
|
-
{Array.isArray(tags) && tags.map((tag) => {
|
|
1319
|
-
const slash = tag.indexOf("/");
|
|
1320
|
-
if (slash > 0) {
|
|
1321
|
-
const prefix = tag.slice(0, slash);
|
|
1322
|
-
const leaf = tag.slice(slash + 1);
|
|
1323
|
-
if (tagPrefixes && tagPrefixes[prefix]) {
|
|
1324
|
-
return <div hidden data-pagefind-filter={`${prefix}:${leaf}`}></div>;
|
|
1325
|
-
}
|
|
1326
|
-
}
|
|
1327
|
-
return <div hidden data-pagefind-filter={`tag:${tag}`}></div>;
|
|
1328
|
-
})}
|
|
1329
|
-
{Array.isArray(audience) && audience.map((value) => (
|
|
1330
|
-
<div hidden data-pagefind-filter={`audience:${value}`}></div>
|
|
1331
|
-
))}
|
|
1332
|
-
{Array.isArray(category) && category.map((value) => (
|
|
1333
|
-
<div hidden data-pagefind-filter={`category:${value}`}></div>
|
|
1334
|
-
))}
|
|
1335
|
-
{status && <div hidden data-pagefind-filter={`status:${status}`}></div>}
|
|
1336
|
-
{pageType && <div hidden data-pagefind-filter={`type:${pageType}`}></div>}
|
|
1337
|
-
{/*
|
|
1338
|
-
Multi-source axis filters — so search on a versioned/multi-
|
|
1339
|
-
product site can be scoped to (or faceted by) the current
|
|
1340
|
-
product and version. `product` = namespace, `version` = the
|
|
1341
|
-
version segment. Only emitted when the axis is active.
|
|
1342
|
-
*/}
|
|
1343
|
-
{multiSource?.namespace && (
|
|
1344
|
-
<div hidden data-pagefind-filter={`product:${multiSource.namespace}`}></div>
|
|
1345
|
-
)}
|
|
1346
|
-
{multiSource?.version && (
|
|
1347
|
-
<div hidden data-pagefind-filter={`version:${multiSource.version}`}></div>
|
|
1348
|
-
)}
|
|
1349
|
-
{/*
|
|
1350
|
-
Custom-taxonomy filters. Any taxonomy declared in
|
|
1351
|
-
`dogsbay.config.yml` that isn't one of the five built-ins
|
|
1352
|
-
flows through here, so `difficulty: intermediate` (etc.)
|
|
1353
|
-
becomes a real Pagefind facet checkbox automatically.
|
|
1354
|
-
See plans/beta-launch-followups.md for context.
|
|
1335
|
+
Search facets: one hidden Pagefind filter per facet value, from
|
|
1336
|
+
`pageFacets` (@dogsbay/site-files), the mapping dogsbay-ssg's
|
|
1337
|
+
search index uses too. A tag whose prefix is declared in
|
|
1338
|
+
`taxonomies.tags.prefixes` is a facet of its own (Difficulty,
|
|
1339
|
+
Topic, …); other tags pool under `tag`; audience, category,
|
|
1340
|
+
status and type always; product and version on a multi-product
|
|
1341
|
+
or versioned site; then every declared custom taxonomy. See
|
|
1342
|
+
plans/per-prefix-search-facets.md and plans/page-facets.md.
|
|
1355
1343
|
*/}
|
|
1356
|
-
{
|
|
1357
|
-
|
|
1358
|
-
? values.map((value) => (
|
|
1359
|
-
<div hidden data-pagefind-filter={`${name}:${value}`}></div>
|
|
1360
|
-
))
|
|
1361
|
-
: []
|
|
1344
|
+
{Object.entries(pageFacetValues).flatMap(([name, values]) =>
|
|
1345
|
+
values.map((value) => <div hidden data-pagefind-filter={`${name}:${value}`}></div>)
|
|
1362
1346
|
)}
|
|
1363
1347
|
|
|
1364
1348
|
<div class:list={["mx-auto", wideLayout ? "max-w-7xl" : "max-w-3xl"]}>
|
|
@@ -1394,6 +1378,13 @@ const siteIcon = '<svg xmlns="http://www.w3.org/2000/svg" width="16" height="16"
|
|
|
1394
1378
|
gets context (title, summary) before classification
|
|
1395
1379
|
(chips), then content.
|
|
1396
1380
|
*/}
|
|
1381
|
+
{bannerData && (
|
|
1382
|
+
<div class="not-prose mb-6 rounded-md border border-warning/50 bg-warning/5 px-4 py-2 text-sm text-foreground" role="status" data-version-banner>
|
|
1383
|
+
{bannerData.text}{bannerData.link && (
|
|
1384
|
+
<>{" "}<a href={bannerData.link.href} class="font-medium underline underline-offset-2" data-db-version-link>{bannerData.link.label}</a></>
|
|
1385
|
+
)}
|
|
1386
|
+
</div>
|
|
1387
|
+
)}
|
|
1397
1388
|
{badgeText && (
|
|
1398
1389
|
<div class="not-prose mb-3" data-version-badge>
|
|
1399
1390
|
<span class="inline-flex items-center rounded-md border border-border bg-muted px-2 py-0.5 text-xs font-medium text-muted-foreground">{badgeText}</span>
|
package/src/switcher.ts
CHANGED
|
@@ -62,8 +62,28 @@ export interface SwitcherMap {
|
|
|
62
62
|
products?: Record<string, ProductMenuEntry[]>;
|
|
63
63
|
/** Per product name (`_`: the site-wide versions), the version menu's links and limit. */
|
|
64
64
|
versionMenu?: Record<string, VersionMenuData>;
|
|
65
|
+
/** Each unit's version banner, keyed `<product|_>/<locale|_>/<version>` (format-astro `versionBanners`). */
|
|
66
|
+
banners?: Record<string, VersionBannerData>;
|
|
65
67
|
}
|
|
66
68
|
|
|
69
|
+
/** A unit's version banner: its own text or a kind worded here, and the default version it points to. */
|
|
70
|
+
export type VersionBannerData = ({ kind: "custom"; text: string } | { kind: "eol" | "prerelease" | "old" }) & { latest?: { id: string; label: string; home: string } };
|
|
71
|
+
|
|
72
|
+
/** The banner's words, as dogsbay-ssg's English strings. */
|
|
73
|
+
export interface VersionBannerWording {
|
|
74
|
+
old: string;
|
|
75
|
+
eol: string;
|
|
76
|
+
prerelease: string;
|
|
77
|
+
goLatest: string;
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
export const VERSION_BANNER_WORDING: VersionBannerWording = {
|
|
81
|
+
old: "You are viewing documentation for an older version.",
|
|
82
|
+
eol: "This version is no longer maintained.",
|
|
83
|
+
prerelease: "This version is not released yet.",
|
|
84
|
+
goLatest: "Go to the latest version",
|
|
85
|
+
};
|
|
86
|
+
|
|
67
87
|
export interface ProductMenuEntry {
|
|
68
88
|
name: string;
|
|
69
89
|
label: string;
|
|
@@ -324,3 +344,37 @@ export function versionBadge(switcherMap: SwitcherMap | undefined, ms: MultiSour
|
|
|
324
344
|
const shown = target ?? entry;
|
|
325
345
|
return wording.split("{label}").join(shown.label ?? shown.id);
|
|
326
346
|
}
|
|
347
|
+
|
|
348
|
+
/**
|
|
349
|
+
* The version banner over a page (dogsbay-ssg's `versionBanner`): the text, and a link to the same
|
|
350
|
+
* page in the default version, or to that version's home when the page is not there. Undefined on
|
|
351
|
+
* the default version, a hidden one, and a page outside every version.
|
|
352
|
+
*/
|
|
353
|
+
export function versionBanner(
|
|
354
|
+
switcherMap: SwitcherMap | undefined,
|
|
355
|
+
ms: MultiSourceMeta | undefined,
|
|
356
|
+
wording: Partial<VersionBannerWording> = {},
|
|
357
|
+
): { text: string; link?: { href: string; label: string } } | undefined {
|
|
358
|
+
if (!switcherMap?.banners || !ms?.version) return undefined;
|
|
359
|
+
const w = { ...VERSION_BANNER_WORDING, ...wording };
|
|
360
|
+
// The page's own unit, exactly: a fallback would hand it another product's or language's banner
|
|
361
|
+
const b = switcherMap.banners[`${ms.namespace ?? "_"}/${ms.locale ?? "_"}/${ms.version}`];
|
|
362
|
+
if (!b) return undefined;
|
|
363
|
+
const text = b.kind === "custom" ? b.text : b.kind === "eol" ? w.eol : b.kind === "prerelease" ? w.prerelease : w.old;
|
|
364
|
+
if (!b.latest) return { text };
|
|
365
|
+
const variants = switcherMap.byLogicalKey[`${ms.namespace ?? "docs"}/${ms.originalSlug}`] ?? [];
|
|
366
|
+
const same = variants.find((v) => v.version === b.latest!.id && (v.locale ?? undefined) === (ms.locale ?? undefined));
|
|
367
|
+
return { text, link: { href: same ? servedHref(same.url) : b.latest.home, label: w.goLatest } };
|
|
368
|
+
}
|
|
369
|
+
|
|
370
|
+
/**
|
|
371
|
+
* A variant's URL as the site serves the page (format-astro `pageHref`): a page is a folder, so
|
|
372
|
+
* `…/index` is its folder and the slash is kept; otherwise each link costs a redirect.
|
|
373
|
+
*/
|
|
374
|
+
export function servedHref(url: string): string {
|
|
375
|
+
const at = url.search(/[?#]/);
|
|
376
|
+
const [path, rest] = at < 0 ? [url, ""] : [url.slice(0, at), url.slice(at)];
|
|
377
|
+
let p = path.replace(/\/+$/, "");
|
|
378
|
+
if (p === "index" || p.endsWith("/index")) p = p.slice(0, -"index".length).replace(/\/+$/, "");
|
|
379
|
+
return `${p}/${rest}`;
|
|
380
|
+
}
|