@opentf/afw-docs 0.0.0-stage → 0.30.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/build/blog-posts-plugin.js +141 -0
- package/build/docs-nav-plugin.js +196 -0
- package/build/feed.js +147 -0
- package/build/frontmatter.js +45 -0
- package/build/host.js +54 -0
- package/build/index.js +12 -0
- package/build/last-updated-plugin.js +99 -0
- package/build/last-updated.js +40 -0
- package/build/llms.js +176 -0
- package/build/reading-time.js +16 -0
- package/build/search.js +27 -0
- package/components/BlogLayout.jsx +90 -0
- package/components/Breadcrumbs.jsx +71 -0
- package/components/Callout.jsx +29 -0
- package/components/Card.jsx +21 -0
- package/components/Cards.jsx +11 -0
- package/components/CodeBlock.jsx +39 -0
- package/components/DocsLayout.jsx +106 -0
- package/components/Footer.jsx +25 -0
- package/components/LastUpdated.jsx +22 -0
- package/components/NavIcon.jsx +34 -0
- package/components/Navbar.jsx +64 -0
- package/components/NavbarLink.jsx +40 -0
- package/components/Pagination.jsx +49 -0
- package/components/PostBanner.jsx +25 -0
- package/components/PostCard.jsx +19 -0
- package/components/PostList.jsx +17 -0
- package/components/PostMeta.jsx +28 -0
- package/components/ReadingTime.jsx +6 -0
- package/components/Search.jsx +191 -0
- package/components/SearchTrigger.jsx +32 -0
- package/components/Sidebar.jsx +199 -0
- package/components/SidebarNode.jsx +143 -0
- package/components/SidebarToggle.jsx +47 -0
- package/components/Steps.jsx +14 -0
- package/components/Table.jsx +10 -0
- package/components/Tabs.jsx +77 -0
- package/components/ThemeToggle.jsx +164 -0
- package/components/Toc.jsx +79 -0
- package/components/Tooltip.jsx +19 -0
- package/components/format.js +21 -0
- package/components/post-dates.js +21 -0
- package/components/sidebar-collapse.js +38 -0
- package/config.js +77 -0
- package/index.js +67 -0
- package/nav-virtual.js +18 -0
- package/package.json +75 -4
- package/posts-virtual.js +17 -0
- package/search.js +285 -0
- package/theme/index.css +1749 -0
- package/types/config.d.ts +37 -0
- package/types/index.d.ts +66 -0
- package/types/nav.d.ts +9 -0
- package/types/posts.d.ts +17 -0
- package/types/search.d.ts +28 -0
- package/types/updated.d.ts +4 -0
- package/updated-virtual.js +10 -0
- package/README.md +0 -3
|
@@ -0,0 +1,106 @@
|
|
|
1
|
+
// Top-level documentation frame: navbar + (sidebar · content · TOC) + footer.
|
|
2
|
+
//
|
|
3
|
+
// import config from "../../afw.config.js";
|
|
4
|
+
// export default function (props) {
|
|
5
|
+
// return <DocsLayout config={config.docs}>{props.children}</DocsLayout>;
|
|
6
|
+
// }
|
|
7
|
+
//
|
|
8
|
+
// That's the whole thing — any folder becomes a documentation section just by giving it
|
|
9
|
+
// a layout that renders `DocsLayout`. The sidebar/breadcrumbs/prev-next come from the
|
|
10
|
+
// generated nav (`@opentf/afw-docs/nav`, imported here), and the layout scopes them to
|
|
11
|
+
// the current section by route. So every section shares the same traits, and the docs
|
|
12
|
+
// and api layout files are identical. (Pass a `nav` prop only to override.)
|
|
13
|
+
//
|
|
14
|
+
// `frame` (default true) renders the full chrome (navbar + footer). Pass
|
|
15
|
+
// `frame={false}` when nesting inside an existing site layout that already provides
|
|
16
|
+
// the navbar/footer — only the sidebar · content · TOC grid is rendered.
|
|
17
|
+
|
|
18
|
+
import { router } from "@opentf/afw";
|
|
19
|
+
import navMap from "@opentf/afw-docs/nav";
|
|
20
|
+
import updated, { editPaths } from "@opentf/afw-docs/updated";
|
|
21
|
+
|
|
22
|
+
import Navbar from "./Navbar.jsx";
|
|
23
|
+
import Sidebar from "./Sidebar.jsx";
|
|
24
|
+
import Toc from "./Toc.jsx";
|
|
25
|
+
import Footer from "./Footer.jsx";
|
|
26
|
+
import Breadcrumbs from "./Breadcrumbs.jsx";
|
|
27
|
+
import Pagination from "./Pagination.jsx";
|
|
28
|
+
import LastUpdated from "./LastUpdated.jsx";
|
|
29
|
+
|
|
30
|
+
// Code blocks own their copy behavior now: MDX fences compile to the
|
|
31
|
+
// `afw-internal-code-block` built-in and `<CodeBlock>` wires `onclick` directly, so a
|
|
32
|
+
// copy button works in any layout (docs, blog, …) with no delegated listener here.
|
|
33
|
+
|
|
34
|
+
export default function DocsLayout(props) {
|
|
35
|
+
const config = props.config || {};
|
|
36
|
+
const nav = props.nav || navMap;
|
|
37
|
+
const frame = props.frame !== false;
|
|
38
|
+
|
|
39
|
+
// The sidebar/breadcrumbs/prev-next operate on the *current section's* tree. `nav` is
|
|
40
|
+
// a section map keyed by base path; pick the branch whose base prefixes the route
|
|
41
|
+
// (longest match wins). A bare array means a single, unscoped section. Each section is
|
|
42
|
+
// its own layout instance, so resolving once at mount is correct.
|
|
43
|
+
const sectionNav = pickSection(nav, router.pathname);
|
|
44
|
+
|
|
45
|
+
// Last-updated time for the current page, looked up in the build-time map keyed by
|
|
46
|
+
// route (same exact-path match Pagination uses). `$derived` so it tracks navigation.
|
|
47
|
+
const lastUpdated = $derived(updated[router.pathname]);
|
|
48
|
+
// "Edit this page" URL: <repoUrl>/edit/main/<repo-relative file>, when both the repo
|
|
49
|
+
// is configured and the page's source path is known.
|
|
50
|
+
const editUrl = $derived(
|
|
51
|
+
config.repoUrl && editPaths[router.pathname]
|
|
52
|
+
? `${config.repoUrl.replace(/\/+$/, "")}/edit/main/${editPaths[router.pathname]}`
|
|
53
|
+
: null,
|
|
54
|
+
);
|
|
55
|
+
|
|
56
|
+
const body = (
|
|
57
|
+
<div class="afwd-docs">
|
|
58
|
+
<Sidebar nav={sectionNav} config={config} />
|
|
59
|
+
<main id="afw-content" class="afwd-content" data-afw-search-body>
|
|
60
|
+
<Breadcrumbs nav={sectionNav} siteUrl={props.siteUrl} />
|
|
61
|
+
<article class="afwd-prose">{props.children}</article>
|
|
62
|
+
{lastUpdated || editUrl ? (
|
|
63
|
+
<div class="afwd-page-meta">
|
|
64
|
+
{lastUpdated ? <LastUpdated date={lastUpdated} /> : null}
|
|
65
|
+
{editUrl ? (
|
|
66
|
+
<a class="afwd-edit-page" href={editUrl} target="_blank" rel="noreferrer">
|
|
67
|
+
Edit this page
|
|
68
|
+
<svg width="13" height="13" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2.2" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true">
|
|
69
|
+
<path d="M7 17 17 7M9 7h8v8" />
|
|
70
|
+
</svg>
|
|
71
|
+
</a>
|
|
72
|
+
) : null}
|
|
73
|
+
</div>
|
|
74
|
+
) : null}
|
|
75
|
+
<Pagination nav={sectionNav} />
|
|
76
|
+
</main>
|
|
77
|
+
<Toc />
|
|
78
|
+
</div>
|
|
79
|
+
);
|
|
80
|
+
|
|
81
|
+
return frame ? (
|
|
82
|
+
<div class="afwd-shell">
|
|
83
|
+
<Navbar config={config} />
|
|
84
|
+
<div class="afwd-shell-body">{body}</div>
|
|
85
|
+
<Footer config={config} />
|
|
86
|
+
</div>
|
|
87
|
+
) : (
|
|
88
|
+
body
|
|
89
|
+
);
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
// Resolve the section tree for `pathname` from a `{ [base]: tree }` map. Longest base
|
|
93
|
+
// prefix wins ("/" matches anything). Tolerates a bare array (single section).
|
|
94
|
+
function pickSection(nav, pathname) {
|
|
95
|
+
if (Array.isArray(nav)) return nav;
|
|
96
|
+
let best = null;
|
|
97
|
+
let bestLen = -1;
|
|
98
|
+
for (const base in nav) {
|
|
99
|
+
const match = base === "/" ? true : pathname === base || pathname.startsWith(base + "/");
|
|
100
|
+
if (match && base.length > bestLen) {
|
|
101
|
+
best = nav[base];
|
|
102
|
+
bestLen = base.length;
|
|
103
|
+
}
|
|
104
|
+
}
|
|
105
|
+
return best || nav[Object.keys(nav)[0]] || [];
|
|
106
|
+
}
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
// Site footer, driven by `config.footer` ({ text, links }).
|
|
2
|
+
|
|
3
|
+
export default function Footer(props) {
|
|
4
|
+
const config = props.config || {};
|
|
5
|
+
const footer = config.footer || {};
|
|
6
|
+
const text = footer.text || "Built with AFW";
|
|
7
|
+
const links = footer.links || [];
|
|
8
|
+
|
|
9
|
+
return (
|
|
10
|
+
<footer class="afwd-footer">
|
|
11
|
+
<div class="afwd-footer-inner">
|
|
12
|
+
<div class="afwd-footer-text">{text}</div>
|
|
13
|
+
{links.length > 0 ? (
|
|
14
|
+
<div class="afwd-footer-links">
|
|
15
|
+
{links.map((l) => (
|
|
16
|
+
<a href={l.href} class="afwd-footer-link">
|
|
17
|
+
{l.label}
|
|
18
|
+
</a>
|
|
19
|
+
))}
|
|
20
|
+
</div>
|
|
21
|
+
) : null}
|
|
22
|
+
</div>
|
|
23
|
+
</footer>
|
|
24
|
+
);
|
|
25
|
+
}
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
// "Last updated on <date>" line. Presentational — pass an ISO-8601 (or any
|
|
2
|
+
// Date-parseable) `date`; renders nothing when it's absent. The date itself comes from
|
|
3
|
+
// the build-time `@opentf/afw-docs/updated` map (git commit time or a frontmatter
|
|
4
|
+
// override); layouts look up the current route there and pass it in.
|
|
5
|
+
//
|
|
6
|
+
// import updated from "@opentf/afw-docs/updated";
|
|
7
|
+
// <LastUpdated date={updated[router.pathname]} />
|
|
8
|
+
import { formatDate } from "./format.js";
|
|
9
|
+
|
|
10
|
+
export default function LastUpdated(props) {
|
|
11
|
+
const date = props.date;
|
|
12
|
+
if (!date) return null;
|
|
13
|
+
const label = props.label || "Last updated on";
|
|
14
|
+
return (
|
|
15
|
+
<div class="afwd-last-updated">
|
|
16
|
+
{label}{" "}
|
|
17
|
+
<time class="afwd-last-updated-time" datetime={String(date)}>
|
|
18
|
+
{formatDate(date)}
|
|
19
|
+
</time>
|
|
20
|
+
</div>
|
|
21
|
+
);
|
|
22
|
+
}
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
// Named SVG icons for navbar links and actions. A nav item references an icon by
|
|
2
|
+
// name — `nav: [{ label, href, icon: "book" }]` — so the markup stays in the theme
|
|
3
|
+
// package rather than in the consumer's plain-JS config (which can't hold JSX). Add
|
|
4
|
+
// a case here to extend the set.
|
|
5
|
+
|
|
6
|
+
export default function NavIcon(props) {
|
|
7
|
+
const name = props.name;
|
|
8
|
+
|
|
9
|
+
return (
|
|
10
|
+
<span class="afwd-nav-icon" aria-hidden="true">
|
|
11
|
+
{name === "github" ? (
|
|
12
|
+
<svg width="18" height="18" viewBox="0 0 24 24" fill="currentColor">
|
|
13
|
+
<path d="M12 .5C5.7.5.5 5.7.5 12c0 5.1 3.3 9.4 7.9 10.9.6.1.8-.2.8-.5v-1.7c-3.2.7-3.9-1.5-3.9-1.5-.5-1.3-1.3-1.7-1.3-1.7-1.1-.7.1-.7.1-.7 1.2.1 1.8 1.2 1.8 1.2 1 1.8 2.7 1.3 3.4 1 .1-.8.4-1.3.7-1.6-2.6-.3-5.3-1.3-5.3-5.7 0-1.3.5-2.3 1.2-3.1-.1-.3-.5-1.5.1-3.1 0 0 1-.3 3.3 1.2a11.5 11.5 0 016 0C17 4.7 18 5 18 5c.6 1.6.2 2.8.1 3.1.8.8 1.2 1.8 1.2 3.1 0 4.4-2.7 5.4-5.3 5.7.4.4.8 1.1.8 2.2v3.3c0 .3.2.6.8.5a11.5 11.5 0 007.9-10.9C23.5 5.7 18.3.5 12 .5z" />
|
|
14
|
+
</svg>
|
|
15
|
+
) : null}
|
|
16
|
+
{name === "discord" ? (
|
|
17
|
+
<svg width="19" height="19" viewBox="0 0 24 24" fill="currentColor">
|
|
18
|
+
<path d="M20.3 4.4A19.8 19.8 0 0 0 15.4 3l-.2.4a18 18 0 0 1 4.3 1.4 16.6 16.6 0 0 0-14.9 0A18 18 0 0 1 8.8 3.4L8.6 3a19.8 19.8 0 0 0-4.9 1.4C.6 9 0 13.5.3 17.9a19.9 19.9 0 0 0 6 3l.7-1.2a13 13 0 0 1-2-1l.5-.4a14.2 14.2 0 0 0 12 0l.5.4a13 13 0 0 1-2 1l.7 1.2a19.9 19.9 0 0 0 6-3c.4-5.1-.6-9.6-2.6-13.5ZM8.3 15.3c-1.2 0-2.2-1.1-2.2-2.4s1-2.5 2.2-2.5 2.2 1.1 2.2 2.5-1 2.4-2.2 2.4Zm7.4 0c-1.2 0-2.2-1.1-2.2-2.4s1-2.5 2.2-2.5 2.2 1.1 2.2 2.5-1 2.4-2.2 2.4Z" />
|
|
19
|
+
</svg>
|
|
20
|
+
) : null}
|
|
21
|
+
{name === "book" ? (
|
|
22
|
+
<svg width="16" height="16" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round">
|
|
23
|
+
<path d="M4 4.5A2.5 2.5 0 0 1 6.5 2H20v18H6.5A2.5 2.5 0 0 0 4 22.5z" />
|
|
24
|
+
<path d="M4 19.5A2.5 2.5 0 0 1 6.5 17H20" />
|
|
25
|
+
</svg>
|
|
26
|
+
) : null}
|
|
27
|
+
{name === "external" ? (
|
|
28
|
+
<svg width="13" height="13" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2.2" stroke-linecap="round" stroke-linejoin="round">
|
|
29
|
+
<path d="M7 17 17 7M9 7h8v8" />
|
|
30
|
+
</svg>
|
|
31
|
+
) : null}
|
|
32
|
+
</span>
|
|
33
|
+
);
|
|
34
|
+
}
|
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
// Top navigation bar: brand, top-level links, search, GitHub, theme toggle. All
|
|
2
|
+
// content is driven by the `docs` config object passed down from DocsLayout.
|
|
3
|
+
// Top-level links support a per-item `icon` (NavIcon name) and `external` flag, and
|
|
4
|
+
// the active route is underlined (see NavbarLink). The search trigger only renders
|
|
5
|
+
// when a search provider is configured.
|
|
6
|
+
|
|
7
|
+
import ThemeToggle from "./ThemeToggle.jsx";
|
|
8
|
+
import SearchTrigger from "./SearchTrigger.jsx";
|
|
9
|
+
import Search from "./Search.jsx";
|
|
10
|
+
import SidebarToggle from "./SidebarToggle.jsx";
|
|
11
|
+
import NavbarLink from "./NavbarLink.jsx";
|
|
12
|
+
import NavIcon from "./NavIcon.jsx";
|
|
13
|
+
import { Link } from "@opentf/afw";
|
|
14
|
+
|
|
15
|
+
// `aria-label` / `aria-labelledby` name the banner landmark, `navLabel` names the
|
|
16
|
+
// primary navigation landmark, and `id` lets a caller reference the header.
|
|
17
|
+
export default function Navbar(props) {
|
|
18
|
+
const config = props.config || {};
|
|
19
|
+
const links = config.nav || [];
|
|
20
|
+
const navLabel = props.navLabel || "Main navigation";
|
|
21
|
+
const ariaLabel = props["aria-label"] || props.ariaLabel;
|
|
22
|
+
const ariaLabelledby = props["aria-labelledby"] || props.ariaLabelledby;
|
|
23
|
+
|
|
24
|
+
return (
|
|
25
|
+
<header
|
|
26
|
+
id={props.id}
|
|
27
|
+
aria-label={ariaLabel}
|
|
28
|
+
aria-labelledby={ariaLabelledby}
|
|
29
|
+
class="afwd-navbar"
|
|
30
|
+
>
|
|
31
|
+
<div class="afwd-navbar-inner">
|
|
32
|
+
<div class="afwd-navbar-lead">
|
|
33
|
+
<SidebarToggle />
|
|
34
|
+
<Link href={config.homeUrl || "/"} class="afwd-navbar-brand">
|
|
35
|
+
{config.logo ? <img src={config.logo} alt="" class="afwd-navbar-logo" /> : null}
|
|
36
|
+
<span class="afwd-navbar-title">{config.title || "Docs"}</span>
|
|
37
|
+
{config.version ? <span class="afwd-navbar-version">{config.version}</span> : null}
|
|
38
|
+
</Link>
|
|
39
|
+
</div>
|
|
40
|
+
|
|
41
|
+
<div class="afwd-navbar-search">
|
|
42
|
+
{config.search ? <SearchTrigger /> : null}
|
|
43
|
+
</div>
|
|
44
|
+
|
|
45
|
+
<div class="afwd-navbar-right">
|
|
46
|
+
<nav class="afwd-navbar-nav" aria-label={navLabel}>
|
|
47
|
+
{links.map((l) => (
|
|
48
|
+
<NavbarLink link={l} />
|
|
49
|
+
))}
|
|
50
|
+
</nav>
|
|
51
|
+
<div class="afwd-navbar-actions">
|
|
52
|
+
{config.github ? (
|
|
53
|
+
<a href={config.github} target="_blank" rel="noreferrer" class="afwd-navbar-icon" aria-label="GitHub">
|
|
54
|
+
<NavIcon name="github" />
|
|
55
|
+
</a>
|
|
56
|
+
) : null}
|
|
57
|
+
<ThemeToggle />
|
|
58
|
+
</div>
|
|
59
|
+
{config.search ? <Search /> : null}
|
|
60
|
+
</div>
|
|
61
|
+
</div>
|
|
62
|
+
</header>
|
|
63
|
+
);
|
|
64
|
+
}
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
// One top-level navbar link. Its own component (like SidebarNode) so the active
|
|
2
|
+
// state is a reactive binding in the element's own build — it updates on SPA
|
|
3
|
+
// navigation without re-rendering the whole navbar. `external` links render as a
|
|
4
|
+
// plain anchor (no SPA nav, no active state); internal links get the accent
|
|
5
|
+
// underline when the current route matches (exactly, or as a section prefix).
|
|
6
|
+
|
|
7
|
+
import { Link, router } from "@opentf/afw";
|
|
8
|
+
import NavIcon from "./NavIcon.jsx";
|
|
9
|
+
|
|
10
|
+
export default function NavbarLink(props) {
|
|
11
|
+
const link = props.link || {};
|
|
12
|
+
|
|
13
|
+
return link.external ? (
|
|
14
|
+
<a href={link.href} target="_blank" rel="noreferrer" class="afwd-navbar-link">
|
|
15
|
+
{link.icon ? <NavIcon name={link.icon} /> : null}
|
|
16
|
+
{link.label}
|
|
17
|
+
</a>
|
|
18
|
+
) : (
|
|
19
|
+
<Link
|
|
20
|
+
href={link.href}
|
|
21
|
+
aria-current={
|
|
22
|
+
(link.href === "/"
|
|
23
|
+
? router.pathname === "/"
|
|
24
|
+
: router.pathname === link.href || router.pathname.startsWith(link.href + "/"))
|
|
25
|
+
? "page"
|
|
26
|
+
: null
|
|
27
|
+
}
|
|
28
|
+
class={
|
|
29
|
+
(link.href === "/"
|
|
30
|
+
? router.pathname === "/"
|
|
31
|
+
: router.pathname === link.href || router.pathname.startsWith(link.href + "/"))
|
|
32
|
+
? "afwd-navbar-link afwd-active"
|
|
33
|
+
: "afwd-navbar-link"
|
|
34
|
+
}
|
|
35
|
+
>
|
|
36
|
+
{link.icon ? <NavIcon name={link.icon} /> : null}
|
|
37
|
+
{link.label}
|
|
38
|
+
</Link>
|
|
39
|
+
);
|
|
40
|
+
}
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
// Prev / next page links, derived from a depth-first flatten of the nav tree.
|
|
2
|
+
|
|
3
|
+
import { Link, router } from "@opentf/afw";
|
|
4
|
+
|
|
5
|
+
export default function Pagination(props) {
|
|
6
|
+
const nav = props.nav || [];
|
|
7
|
+
|
|
8
|
+
const flat = [];
|
|
9
|
+
const walk = (items) => {
|
|
10
|
+
for (const it of items) {
|
|
11
|
+
if (it.path) flat.push(it);
|
|
12
|
+
if (it.items) walk(it.items);
|
|
13
|
+
}
|
|
14
|
+
};
|
|
15
|
+
walk(nav);
|
|
16
|
+
|
|
17
|
+
const adjacent = (path) => {
|
|
18
|
+
const i = flat.findIndex((x) => x.path === path);
|
|
19
|
+
return {
|
|
20
|
+
prev: i > 0 ? flat[i - 1] : null,
|
|
21
|
+
next: i >= 0 && i < flat.length - 1 ? flat[i + 1] : null,
|
|
22
|
+
};
|
|
23
|
+
};
|
|
24
|
+
|
|
25
|
+
// A single reactive signal (not a `{() => …}` thunk): `pos` is in scope for the
|
|
26
|
+
// hoisted branch builders, and recomputes on `router.pathname`.
|
|
27
|
+
const pos = $derived(adjacent(router.pathname));
|
|
28
|
+
|
|
29
|
+
return (
|
|
30
|
+
<nav class="afwd-pagination" aria-label="Pagination">
|
|
31
|
+
{pos.prev ? (
|
|
32
|
+
<Link href={pos.prev?.path} class="afwd-page-link afwd-page-prev">
|
|
33
|
+
<span class="afwd-page-dir">← Previous</span>
|
|
34
|
+
<span class="afwd-page-title">{pos.prev?.title}</span>
|
|
35
|
+
</Link>
|
|
36
|
+
) : (
|
|
37
|
+
<span class="afwd-page-spacer" />
|
|
38
|
+
)}
|
|
39
|
+
{pos.next ? (
|
|
40
|
+
<Link href={pos.next?.path} class="afwd-page-link afwd-page-next">
|
|
41
|
+
<span class="afwd-page-dir">Next →</span>
|
|
42
|
+
<span class="afwd-page-title">{pos.next?.title}</span>
|
|
43
|
+
</Link>
|
|
44
|
+
) : (
|
|
45
|
+
<span class="afwd-page-spacer" />
|
|
46
|
+
)}
|
|
47
|
+
</nav>
|
|
48
|
+
);
|
|
49
|
+
}
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
// A blog post's header: title, optional description, and the metadata row. Rendered
|
|
2
|
+
// by BlogLayout above the post's prose body, driven by the post record so the MDX
|
|
3
|
+
// file stays pure content (no hand-written title/date in the body).
|
|
4
|
+
import PostMeta from "./PostMeta.jsx";
|
|
5
|
+
|
|
6
|
+
export default function PostBanner(props) {
|
|
7
|
+
const post = props.post || props;
|
|
8
|
+
return (
|
|
9
|
+
<header class="afwd-post-banner">
|
|
10
|
+
{post.cover ? (
|
|
11
|
+
<img class="afwd-post-cover" src={post.cover} alt={post.title} />
|
|
12
|
+
) : null}
|
|
13
|
+
<h1 class="afwd-post-title">{post.title}</h1>
|
|
14
|
+
{post.description ? <p class="afwd-post-desc">{post.description}</p> : null}
|
|
15
|
+
<PostMeta post={post} />
|
|
16
|
+
{post.tags && post.tags.length ? (
|
|
17
|
+
<div class="afwd-post-tags">
|
|
18
|
+
{post.tags.map((tag) => (
|
|
19
|
+
<span class="afwd-post-tag">{tag}</span>
|
|
20
|
+
))}
|
|
21
|
+
</div>
|
|
22
|
+
) : null}
|
|
23
|
+
</header>
|
|
24
|
+
);
|
|
25
|
+
}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
// One post in the blog index: a link to the post with its meta + title + excerpt.
|
|
2
|
+
import { Link } from "@opentf/afw";
|
|
3
|
+
import PostMeta from "./PostMeta.jsx";
|
|
4
|
+
|
|
5
|
+
export default function PostCard(props) {
|
|
6
|
+
const post = props.post;
|
|
7
|
+
return (
|
|
8
|
+
<Link href={post.path} class={post.cover ? "afwd-post-card afwd-has-cover" : "afwd-post-card"}>
|
|
9
|
+
{post.cover ? (
|
|
10
|
+
<img class="afwd-post-card-cover" src={post.cover} alt={post.title} loading="lazy" />
|
|
11
|
+
) : null}
|
|
12
|
+
<div class="afwd-post-card-body">
|
|
13
|
+
<PostMeta post={post} />
|
|
14
|
+
<div class="afwd-post-card-title">{post.title}</div>
|
|
15
|
+
{post.description ? <p class="afwd-post-card-desc">{post.description}</p> : null}
|
|
16
|
+
</div>
|
|
17
|
+
</Link>
|
|
18
|
+
);
|
|
19
|
+
}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
// The blog index listing: renders a PostCard per post. Pass the list from
|
|
2
|
+
// `@opentf/afw-docs/posts`:
|
|
3
|
+
//
|
|
4
|
+
// import { posts } from "@opentf/afw-docs/posts";
|
|
5
|
+
// <PostList posts={posts} />
|
|
6
|
+
import PostCard from "./PostCard.jsx";
|
|
7
|
+
|
|
8
|
+
export default function PostList(props) {
|
|
9
|
+
const posts = props.posts || [];
|
|
10
|
+
return (
|
|
11
|
+
<div class="afwd-post-list">
|
|
12
|
+
{posts.length
|
|
13
|
+
? posts.map((post) => <PostCard post={post} />)
|
|
14
|
+
: <p class="afwd-post-empty">No posts yet.</p>}
|
|
15
|
+
</div>
|
|
16
|
+
);
|
|
17
|
+
}
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
// A post's metadata row: date · author · reading time. Pass a post record (from
|
|
2
|
+
// `@opentf/afw-docs/posts`) as `post`, or the fields directly. Missing fields are
|
|
3
|
+
// omitted. Used in both the post banner and the index cards.
|
|
4
|
+
import ReadingTime from "./ReadingTime.jsx";
|
|
5
|
+
import { formatDate } from "./format.js";
|
|
6
|
+
|
|
7
|
+
export default function PostMeta(props) {
|
|
8
|
+
const post = props.post || props;
|
|
9
|
+
return (
|
|
10
|
+
<div class="afwd-post-meta">
|
|
11
|
+
{post.author ? (
|
|
12
|
+
<span class="afwd-post-author">
|
|
13
|
+
{post.authorAvatar ? (
|
|
14
|
+
<img class="afwd-post-avatar" src={post.authorAvatar} alt={post.author} loading="lazy" />
|
|
15
|
+
) : null}
|
|
16
|
+
<span class="afwd-post-author-name">{post.author}</span>
|
|
17
|
+
{post.authorRole ? <span class="afwd-post-author-role">{post.authorRole}</span> : null}
|
|
18
|
+
</span>
|
|
19
|
+
) : null}
|
|
20
|
+
{post.date ? (
|
|
21
|
+
<time class="afwd-post-date" datetime={String(post.date)}>
|
|
22
|
+
{formatDate(post.date)}
|
|
23
|
+
</time>
|
|
24
|
+
) : null}
|
|
25
|
+
{post.readingTime ? <ReadingTime minutes={post.readingTime} /> : null}
|
|
26
|
+
</div>
|
|
27
|
+
);
|
|
28
|
+
}
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
// Reading-time label, e.g. "4 min read". `minutes` is precomputed at build time by
|
|
2
|
+
// the blog posts plugin (see build/reading-time.js).
|
|
3
|
+
export default function ReadingTime(props) {
|
|
4
|
+
const minutes = props.minutes ?? 1;
|
|
5
|
+
return <span class="afwd-reading-time">{minutes} min read</span>;
|
|
6
|
+
}
|
|
@@ -0,0 +1,191 @@
|
|
|
1
|
+
// AFW Search-backed modal. The navbar's `SearchTrigger` and the global
|
|
2
|
+
// ⌘K / Ctrl+K shortcut open it via `window.__afwOpenSearch`, which this component
|
|
3
|
+
// installs on mount. The static index is generated after a release build (the `siteOutputPlugin`
|
|
4
|
+
// output hook, with `docs.search.provider === "afw"`) lives at `/_search/`; the reader is lazy so
|
|
5
|
+
// pages without a search never fetch its index.
|
|
6
|
+
//
|
|
7
|
+
// Note: results only exist against a built site (`dist/`). In dev there is no index,
|
|
8
|
+
// so the modal opens but reports no results — expected.
|
|
9
|
+
import { onCleanup, onMount, router, Portal } from "@opentf/afw";
|
|
10
|
+
import { createSearch, excerptParts } from "../search.js";
|
|
11
|
+
|
|
12
|
+
const search = createSearch({ base: "/_search/" });
|
|
13
|
+
|
|
14
|
+
export default function Search() {
|
|
15
|
+
let open = $state(false);
|
|
16
|
+
let query = $state("");
|
|
17
|
+
let results = $state([]);
|
|
18
|
+
let active = $state(0);
|
|
19
|
+
let loading = $state(false);
|
|
20
|
+
let error = $state("");
|
|
21
|
+
let controller;
|
|
22
|
+
const inputRef = $ref();
|
|
23
|
+
|
|
24
|
+
let timer;
|
|
25
|
+
let token = 0;
|
|
26
|
+
|
|
27
|
+
async function runSearch(q) {
|
|
28
|
+
const mine = ++token;
|
|
29
|
+
controller?.abort();
|
|
30
|
+
controller = new AbortController();
|
|
31
|
+
error = "";
|
|
32
|
+
if (!q.trim()) {
|
|
33
|
+
results = [];
|
|
34
|
+
loading = false;
|
|
35
|
+
return;
|
|
36
|
+
}
|
|
37
|
+
loading = true;
|
|
38
|
+
try {
|
|
39
|
+
const found = await search.query(q, { limit: 10, signal: controller.signal });
|
|
40
|
+
if (mine !== token) return; // a newer query superseded this one
|
|
41
|
+
results = found.results;
|
|
42
|
+
active = 0;
|
|
43
|
+
} catch (e) {
|
|
44
|
+
if (mine === token && e?.name !== "AbortError") {
|
|
45
|
+
results = [];
|
|
46
|
+
error = "Search is unavailable. Please try again.";
|
|
47
|
+
}
|
|
48
|
+
} finally {
|
|
49
|
+
if (mine === token) loading = false;
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
$effect(() => {
|
|
54
|
+
const q = query;
|
|
55
|
+
clearTimeout(timer);
|
|
56
|
+
timer = setTimeout(() => runSearch(q), 150);
|
|
57
|
+
});
|
|
58
|
+
|
|
59
|
+
const focusInput = () => {
|
|
60
|
+
const el = inputRef;
|
|
61
|
+
if (el && typeof requestAnimationFrame !== "undefined") requestAnimationFrame(() => el.focus());
|
|
62
|
+
};
|
|
63
|
+
const openModal = () => {
|
|
64
|
+
open = true;
|
|
65
|
+
focusInput();
|
|
66
|
+
};
|
|
67
|
+
const close = () => {
|
|
68
|
+
++token;
|
|
69
|
+
controller?.abort();
|
|
70
|
+
clearTimeout(timer);
|
|
71
|
+
loading = false;
|
|
72
|
+
error = "";
|
|
73
|
+
open = false;
|
|
74
|
+
query = "";
|
|
75
|
+
results = [];
|
|
76
|
+
active = 0;
|
|
77
|
+
};
|
|
78
|
+
const go = (url) => {
|
|
79
|
+
close();
|
|
80
|
+
router.push(url);
|
|
81
|
+
};
|
|
82
|
+
|
|
83
|
+
onMount(() => {
|
|
84
|
+
if (typeof window === "undefined") return;
|
|
85
|
+
window.__afwOpenSearch = openModal;
|
|
86
|
+
const onKey = (e) => {
|
|
87
|
+
const k = e.key;
|
|
88
|
+
if ((e.metaKey || e.ctrlKey) && k.toLowerCase() === "k") {
|
|
89
|
+
e.preventDefault();
|
|
90
|
+
openModal();
|
|
91
|
+
return;
|
|
92
|
+
}
|
|
93
|
+
if (!open) return;
|
|
94
|
+
if (k === "Escape") close();
|
|
95
|
+
else if (k === "ArrowDown") {
|
|
96
|
+
e.preventDefault();
|
|
97
|
+
active = results.length ? (active + 1) % results.length : 0;
|
|
98
|
+
} else if (k === "ArrowUp") {
|
|
99
|
+
e.preventDefault();
|
|
100
|
+
active = results.length ? (active - 1 + results.length) % results.length : 0;
|
|
101
|
+
} else if (k === "Enter" && results[active]) {
|
|
102
|
+
e.preventDefault();
|
|
103
|
+
go(results[active].url);
|
|
104
|
+
}
|
|
105
|
+
};
|
|
106
|
+
window.addEventListener("keydown", onKey);
|
|
107
|
+
return () => {
|
|
108
|
+
window.removeEventListener("keydown", onKey);
|
|
109
|
+
if (window.__afwOpenSearch === openModal) delete window.__afwOpenSearch;
|
|
110
|
+
};
|
|
111
|
+
});
|
|
112
|
+
|
|
113
|
+
onCleanup(() => {
|
|
114
|
+
++token;
|
|
115
|
+
clearTimeout(timer);
|
|
116
|
+
controller?.abort();
|
|
117
|
+
});
|
|
118
|
+
|
|
119
|
+
// Portal to <body>: the navbar (our render parent) sets `backdrop-filter`, which
|
|
120
|
+
// establishes a containing block for fixed-position descendants — so without this the
|
|
121
|
+
// `position: fixed` overlay would collapse to the navbar's box instead of the viewport.
|
|
122
|
+
return (
|
|
123
|
+
<Portal>
|
|
124
|
+
<div
|
|
125
|
+
class={open ? "afwd-search-modal is-open" : "afwd-search-modal"}
|
|
126
|
+
onclick={(e) => {
|
|
127
|
+
if (e.target === e.currentTarget) close();
|
|
128
|
+
}}
|
|
129
|
+
>
|
|
130
|
+
<div class="afwd-search-panel" role="dialog" aria-label="Search docs">
|
|
131
|
+
<div class="afwd-search-field">
|
|
132
|
+
<svg width="16" height="16" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" aria-hidden="true">
|
|
133
|
+
<circle cx="11" cy="11" r="7" />
|
|
134
|
+
<line x1="21" y1="21" x2="16.65" y2="16.65" stroke-linecap="round" />
|
|
135
|
+
</svg>
|
|
136
|
+
<input
|
|
137
|
+
ref={inputRef}
|
|
138
|
+
class="afwd-search-input-field"
|
|
139
|
+
type="search"
|
|
140
|
+
placeholder="Search docs…"
|
|
141
|
+
aria-label="Search docs"
|
|
142
|
+
value={query}
|
|
143
|
+
oninput={(e) => (query = e.target.value)}
|
|
144
|
+
/>
|
|
145
|
+
</div>
|
|
146
|
+
<ul class="afwd-search-results">
|
|
147
|
+
{results.map((r, i) => (
|
|
148
|
+
<li>
|
|
149
|
+
<a
|
|
150
|
+
href={r.url}
|
|
151
|
+
class={i === active ? "afwd-search-result is-active" : "afwd-search-result"}
|
|
152
|
+
onclick={(e) => {
|
|
153
|
+
e.preventDefault();
|
|
154
|
+
go(r.url);
|
|
155
|
+
}}
|
|
156
|
+
onmouseenter={() => (active = i)}
|
|
157
|
+
>
|
|
158
|
+
{r.meta?.breadcrumb ? <span class="afwd-search-result-crumb">{r.meta.breadcrumb}</span> : null}
|
|
159
|
+
<span class="afwd-search-result-title">{r.title}</span>
|
|
160
|
+
{r.section ? <span class="afwd-search-result-section">{r.section}</span> : null}
|
|
161
|
+
<span class="afwd-search-result-excerpt">
|
|
162
|
+
{excerptParts(r.excerpt, r.highlights).map((part) => <span>{part.match ? <mark>{part.text}</mark> : part.text}</span>)}
|
|
163
|
+
</span>
|
|
164
|
+
</a>
|
|
165
|
+
</li>
|
|
166
|
+
))}
|
|
167
|
+
</ul>
|
|
168
|
+
{error ? <div class="afwd-search-empty" role="status">{error}</div> : null}
|
|
169
|
+
{query.trim() && !loading && !error && results.length === 0 ? (
|
|
170
|
+
<div class="afwd-search-empty">No results for “{query}”.</div>
|
|
171
|
+
) : null}
|
|
172
|
+
<div class="afwd-search-hint">
|
|
173
|
+
<span class="afwd-search-hint-item">
|
|
174
|
+
<kbd>↑</kbd>
|
|
175
|
+
<kbd>↓</kbd>
|
|
176
|
+
navigate
|
|
177
|
+
</span>
|
|
178
|
+
<span class="afwd-search-hint-item">
|
|
179
|
+
<kbd>↵</kbd>
|
|
180
|
+
select
|
|
181
|
+
</span>
|
|
182
|
+
<span class="afwd-search-hint-item">
|
|
183
|
+
<kbd>esc</kbd>
|
|
184
|
+
close
|
|
185
|
+
</span>
|
|
186
|
+
</div>
|
|
187
|
+
</div>
|
|
188
|
+
</div>
|
|
189
|
+
</Portal>
|
|
190
|
+
);
|
|
191
|
+
}
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
// Search box trigger in the navbar. Calls the global opener that the AFW Search-backed
|
|
2
|
+
// <Search> modal installs on `window` (the ⌘K / Ctrl+K shortcut opens it too). Shows
|
|
3
|
+
// the shortcut as a hint; the modifier resolves to ⌘ on Apple platforms, Ctrl
|
|
4
|
+
// elsewhere, on mount.
|
|
5
|
+
|
|
6
|
+
import { onMount } from "@opentf/afw";
|
|
7
|
+
|
|
8
|
+
export default function SearchTrigger() {
|
|
9
|
+
let mod = $state("Ctrl");
|
|
10
|
+
|
|
11
|
+
onMount(() => {
|
|
12
|
+
const ua = navigator.platform || navigator.userAgent || "";
|
|
13
|
+
if (/Mac|iPhone|iPad|iPod/.test(ua)) mod = "⌘";
|
|
14
|
+
});
|
|
15
|
+
|
|
16
|
+
const open = () => {
|
|
17
|
+
if (typeof window !== "undefined" && typeof window.__afwOpenSearch === "function") {
|
|
18
|
+
window.__afwOpenSearch();
|
|
19
|
+
}
|
|
20
|
+
};
|
|
21
|
+
|
|
22
|
+
return (
|
|
23
|
+
<button class="afwd-search-trigger" onclick={open} aria-label="Search docs">
|
|
24
|
+
<svg width="15" height="15" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2">
|
|
25
|
+
<circle cx="11" cy="11" r="7" />
|
|
26
|
+
<line x1="21" y1="21" x2="16.65" y2="16.65" stroke-linecap="round" />
|
|
27
|
+
</svg>
|
|
28
|
+
<span class="afwd-search-label">Search</span>
|
|
29
|
+
<kbd class="afwd-search-kbd">{() => `${mod} K`}</kbd>
|
|
30
|
+
</button>
|
|
31
|
+
);
|
|
32
|
+
}
|