@opentf/afw-docs 0.0.0-stage → 0.31.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.
Files changed (61) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +141 -2
  3. package/build/blog-posts-plugin.js +154 -0
  4. package/build/docs-nav-plugin.js +200 -0
  5. package/build/feed.js +176 -0
  6. package/build/frontmatter.js +45 -0
  7. package/build/host.js +54 -0
  8. package/build/index.js +13 -0
  9. package/build/last-updated-plugin.js +107 -0
  10. package/build/last-updated.js +40 -0
  11. package/build/llms.js +176 -0
  12. package/build/publish.js +29 -0
  13. package/build/reading-time.js +16 -0
  14. package/build/search.js +27 -0
  15. package/components/BlogLayout.jsx +104 -0
  16. package/components/Breadcrumbs.jsx +71 -0
  17. package/components/Callout.jsx +29 -0
  18. package/components/Card.jsx +21 -0
  19. package/components/Cards.jsx +11 -0
  20. package/components/CodeBlock.jsx +39 -0
  21. package/components/DocsLayout.jsx +106 -0
  22. package/components/FeedLinks.jsx +47 -0
  23. package/components/Footer.jsx +25 -0
  24. package/components/LastUpdated.jsx +20 -0
  25. package/components/NavIcon.jsx +34 -0
  26. package/components/Navbar.jsx +64 -0
  27. package/components/NavbarLink.jsx +40 -0
  28. package/components/Pagination.jsx +49 -0
  29. package/components/PostBanner.jsx +25 -0
  30. package/components/PostCard.jsx +24 -0
  31. package/components/PostList.jsx +25 -0
  32. package/components/PostMeta.jsx +37 -0
  33. package/components/ReadingTime.jsx +6 -0
  34. package/components/Search.jsx +191 -0
  35. package/components/SearchTrigger.jsx +32 -0
  36. package/components/Sidebar.jsx +199 -0
  37. package/components/SidebarNode.jsx +143 -0
  38. package/components/SidebarToggle.jsx +47 -0
  39. package/components/Steps.jsx +14 -0
  40. package/components/Table.jsx +10 -0
  41. package/components/Tabs.jsx +77 -0
  42. package/components/ThemeToggle.jsx +164 -0
  43. package/components/Toc.jsx +106 -0
  44. package/components/Tooltip.jsx +19 -0
  45. package/components/format.js +21 -0
  46. package/components/post-dates.js +21 -0
  47. package/components/sidebar-collapse.js +38 -0
  48. package/config.js +77 -0
  49. package/index.js +69 -0
  50. package/nav-virtual.js +18 -0
  51. package/package.json +79 -4
  52. package/posts-virtual.js +17 -0
  53. package/search.js +285 -0
  54. package/theme/index.css +1843 -0
  55. package/types/config.d.ts +39 -0
  56. package/types/index.d.ts +70 -0
  57. package/types/nav.d.ts +9 -0
  58. package/types/posts.d.ts +17 -0
  59. package/types/search.d.ts +28 -0
  60. package/types/updated.d.ts +4 -0
  61. package/updated-virtual.js +10 -0
@@ -0,0 +1,27 @@
1
+ // Build-time AFW Search indexing; called after prerendering by the finish plugin.
2
+
3
+ import { join } from "runtime:path";
4
+ import { Command } from "runtime:system";
5
+ import { afwcPath } from "@opentf/afw-compiler";
6
+
7
+ /**
8
+ * Build the index from prerendered HTML using the unified native toolchain.
9
+ * Published toolchains ship one afwc binary; source checkouts build it
10
+ * from `cargo build -p afw_cli`.
11
+ */
12
+ export async function indexWithAfwSearch({ siteDir, afwc }) {
13
+ const binary = afwc || await afwcPath();
14
+ const out = new Command(binary, {
15
+ args: ["docs", "index", siteDir, "--out", join(siteDir, "_search"), "--root", "main"],
16
+ stdout: "piped",
17
+ stderr: "piped",
18
+ inheritEnv: true,
19
+ });
20
+ const result = await out.output();
21
+ if (!result.success) throw new Error(new TextDecoder().decode(result.stderr).trim() || "afwc docs index failed");
22
+ const message = new TextDecoder().decode(result.stderr);
23
+ const indexed = /indexed\s+(\d+)\s+page/.exec(message);
24
+ if (!indexed) throw new Error("afwc docs index did not report an index. Install the updated @opentf/afw-compiler containing the docs indexing command.");
25
+ const pages = Number(indexed[1]);
26
+ return { pages };
27
+ }
@@ -0,0 +1,104 @@
1
+ // Blog section layout. Wraps both the index (`/blog`) and individual posts
2
+ // (`/blog/<slug>`). It identifies the current page by matching `router.pathname`
3
+ // against the post list (from `@opentf/afw-docs/posts`):
4
+ //
5
+ // import BlogLayout from "@opentf/afw-docs"; // BlogLayout
6
+ // import { posts } from "@opentf/afw-docs/posts";
7
+ // import config from "../../afw.config.js";
8
+ // export default function (props) {
9
+ // return <BlogLayout config={config.docs} posts={posts} frame={false}>{props.children}</BlogLayout>;
10
+ // }
11
+ //
12
+ // On a post it renders the PostBanner (from the post's frontmatter) above the prose
13
+ // body, plus a reusable "On this page" TOC; on the index it just renders the children
14
+ // (typically a <PostList/>). `frame` (default true) adds the navbar/footer chrome;
15
+ // pass `frame={false}` when nesting inside a site layout that already provides them.
16
+ //
17
+ // The layout factory re-runs on every navigation (the router rebuilds the route +
18
+ // layout chain), so reading `router.pathname` resolves to the page being shown.
19
+ import { Link, RawHtml, router } from "@opentf/afw";
20
+
21
+ import Navbar from "./Navbar.jsx";
22
+ import Footer from "./Footer.jsx";
23
+ import Toc from "./Toc.jsx";
24
+ import PostBanner from "./PostBanner.jsx";
25
+ import FeedLinks from "./FeedLinks.jsx";
26
+ import { editedAfterPublish } from "./post-dates.js";
27
+
28
+ // Structured data for crawlers: the current post as a BlogPosting, emitted in
29
+ // the body (JSON-LD is discovered wherever it sits). `siteUrl` (optional site
30
+ // origin) absolutizes the post/cover URLs. Fields the post lacks are omitted. The
31
+ // site (`config.title`, `config.logo`) is the publisher, as Google's article
32
+ // guidelines ask.
33
+ function blogPostingJsonLd(post, siteUrl, dateModified, config = {}) {
34
+ const base = (siteUrl || "").replace(/\/+$/, "");
35
+ const abs = (p) => (p ? base + p : undefined);
36
+ const article = { "@context": "https://schema.org", "@type": "BlogPosting" };
37
+ if (post.title) article.headline = post.title;
38
+ if (post.description) article.description = post.description;
39
+ if (post.path) {
40
+ article.url = abs(post.path) || post.path;
41
+ article.mainEntityOfPage = { "@type": "WebPage", "@id": article.url };
42
+ }
43
+ if (post.cover) article.image = abs(post.cover) || post.cover;
44
+ if (post.date) article.datePublished = post.date;
45
+ if (dateModified) article.dateModified = dateModified;
46
+ if (post.author) article.author = { "@type": "Person", name: post.author };
47
+ if (config.title) {
48
+ article.publisher = { "@type": "Organization", name: config.title };
49
+ if (config.logo) article.publisher.logo = { "@type": "ImageObject", url: abs(config.logo) || config.logo };
50
+ }
51
+ const json = JSON.stringify(article).replace(/</g, "\\u003c");
52
+ return `<script type="application/ld+json">${json}</script>`;
53
+ }
54
+
55
+ export default function BlogLayout(props) {
56
+ const config = props.config || {};
57
+ const posts = props.posts || [];
58
+ const frame = props.frame !== false;
59
+ const indexPath = props.indexPath || "/blog";
60
+ const siteUrl = props.siteUrl || "";
61
+ // Subscribe links on the index and under each post; `feeds={false}` turns them off.
62
+ const feeds = props.feeds !== false;
63
+
64
+ const post = posts.find((p) => p.path === router.pathname);
65
+ // The post's own frontmatter `updated`, shown in the banner. Never git: see blog-posts-plugin.js.
66
+ const editedIso = post && editedAfterPublish(post.updated, post.date) ? post.updated : null;
67
+
68
+ const body = post ? (
69
+ <div class="afwd-blog afwd-blog-post">
70
+ {/* `afw-content` so the shared Toc can read this article's headings. */}
71
+ <main id="afw-content" class="afwd-blog-main" data-afw-search-body>
72
+ {/* Give blog posts a search breadcrumb too (docs get theirs from <Breadcrumbs>),
73
+ so a result looks the same whether it's a doc or a post. Inline `key:value`
74
+ syntax sets the meta literally, independent of visible text. */}
75
+ <span data-afw-search-meta="breadcrumb:Blog" hidden></span>
76
+ <Link href={indexPath} class="afwd-blog-back" data-afw-search-ignore>
77
+ ← {config.title ? `${config.title} Blog` : "Blog"}
78
+ </Link>
79
+ <PostBanner post={post} showUpdated />
80
+ <RawHtml html={blogPostingJsonLd(post, siteUrl, editedIso || post.date, config)} />
81
+ <article class="afwd-prose">{props.children}</article>
82
+ {feeds ? <FeedLinks base={indexPath} variant="inline" /> : null}
83
+ </main>
84
+ <Toc />
85
+ </div>
86
+ ) : (
87
+ <div class="afwd-blog afwd-blog-index">
88
+ <main class="afwd-blog-main">
89
+ {feeds ? <FeedLinks base={indexPath} /> : null}
90
+ {props.children}
91
+ </main>
92
+ </div>
93
+ );
94
+
95
+ return frame ? (
96
+ <div class="afwd-shell">
97
+ <Navbar config={config} />
98
+ <div class="afwd-shell-body">{body}</div>
99
+ <Footer config={config} />
100
+ </div>
101
+ ) : (
102
+ body
103
+ );
104
+ }
@@ -0,0 +1,71 @@
1
+ // Breadcrumb trail for the current page, derived from the nav tree + router path.
2
+
3
+ import { Link, RawHtml, router } from "@opentf/afw";
4
+
5
+ // Structured data for crawlers: the visible trail above as a BreadcrumbList.
6
+ // Emitted beside the nav (JSON-LD is discovered wherever it sits). `siteUrl`
7
+ // (optional site origin) absolutizes the item URLs; without it they stay
8
+ // route-relative. `<` is escaped so the payload can't break out of the script.
9
+ function breadcrumbJsonLd(trail, siteUrl) {
10
+ if (!trail.length) return "";
11
+ const base = (siteUrl || "").replace(/\/+$/, "");
12
+ const items = trail.map((it, i) => {
13
+ const entry = {
14
+ "@type": "ListItem",
15
+ position: i + 1,
16
+ name: it.title,
17
+ };
18
+ if (it.path) entry.item = base + it.path;
19
+ return entry;
20
+ });
21
+ const json = JSON.stringify({
22
+ "@context": "https://schema.org",
23
+ "@type": "BreadcrumbList",
24
+ itemListElement: items,
25
+ }).replace(/</g, "\\u003c");
26
+ return `<script type="application/ld+json">${json}</script>`;
27
+ }
28
+
29
+ export default function Breadcrumbs(props) {
30
+ const nav = props.nav || [];
31
+ const siteUrl = props.siteUrl || "";
32
+
33
+ const findTrail = (items, path, trail) => {
34
+ for (const it of items) {
35
+ const next = trail.concat(it);
36
+ if (it.path === path) return next;
37
+ if (it.items) {
38
+ const found = findTrail(it.items, path, next);
39
+ if (found) return found;
40
+ }
41
+ }
42
+ return null;
43
+ };
44
+
45
+ // Direct-child `.map` (not wrapped in a `{() => …}` thunk) so the compiler
46
+ // lowers it to a reactive list whose item renderer receives `it`/`i`. The
47
+ // source re-runs on `router.pathname`, so the trail tracks navigation.
48
+ // `data-afw-search-meta="breadcrumb"` exposes this trail to the search index, so each
49
+ // result can show which page (and section) it belongs to.
50
+ // The JSON-LD trail below re-reads the same source (a second subscription, kept
51
+ // out of the list so the lowering above is untouched).
52
+ return (
53
+ <nav class="afwd-breadcrumbs" aria-label="Breadcrumb" data-afw-search-meta="breadcrumb">
54
+ <RawHtml
55
+ html={breadcrumbJsonLd(findTrail(nav, router.pathname, []) || [], siteUrl)}
56
+ />
57
+ {(findTrail(nav, router.pathname, []) || []).map((it, i) => (
58
+ <span class="afwd-crumb">
59
+ {i > 0 ? <span class="afwd-crumb-sep">/</span> : null}
60
+ {it.path ? (
61
+ <Link href={it.path} class="afwd-crumb-link">
62
+ {it.title}
63
+ </Link>
64
+ ) : (
65
+ <span class="afwd-crumb-text">{it.title}</span>
66
+ )}
67
+ </span>
68
+ ))}
69
+ </nav>
70
+ );
71
+ }
@@ -0,0 +1,29 @@
1
+ // Admonition / callout box. `type` is note | tip | info | warning | danger.
2
+ //
3
+ // <Callout type="warning" title="Heads up">…</Callout>
4
+
5
+ const ICONS = {
6
+ note: "✎",
7
+ tip: "💡",
8
+ info: "🛈",
9
+ warning: "⚠",
10
+ danger: "⛔",
11
+ };
12
+
13
+ export default function Callout(props) {
14
+ const type = props.type || "note";
15
+ const title = props.title || type.charAt(0).toUpperCase() + type.slice(1);
16
+ const icon = ICONS[type] || ICONS.note;
17
+
18
+ return (
19
+ <div class={"afwd-callout afwd-callout-" + type}>
20
+ <span class="afwd-callout-icon" aria-hidden="true">
21
+ {icon}
22
+ </span>
23
+ <div class="afwd-callout-content">
24
+ <div class="afwd-callout-title">{title}</div>
25
+ <div class="afwd-callout-body">{props.children}</div>
26
+ </div>
27
+ </div>
28
+ );
29
+ }
@@ -0,0 +1,21 @@
1
+ // A single tile in a <Cards> grid: a title, an optional description, and a link. An
2
+ // internal `href` uses SPA navigation (<Link>); an `external` href is a plain anchor.
3
+ // `desc` (prop) or children supply the body.
4
+
5
+ import { Link } from "@opentf/afw";
6
+
7
+ export default function Card(props) {
8
+ return props.external ? (
9
+ <a href={props.href} target="_blank" rel="noreferrer" class="afwd-card">
10
+ <span class="afwd-card-title">{props.title}</span>
11
+ {props.desc ? <span class="afwd-card-desc">{props.desc}</span> : null}
12
+ {props.children}
13
+ </a>
14
+ ) : (
15
+ <Link href={props.href} class="afwd-card">
16
+ <span class="afwd-card-title">{props.title}</span>
17
+ {props.desc ? <span class="afwd-card-desc">{props.desc}</span> : null}
18
+ {props.children}
19
+ </Link>
20
+ );
21
+ }
@@ -0,0 +1,11 @@
1
+ // A responsive grid of <Card>s. Used on index/landing docs pages (e.g. the API
2
+ // reference overview) to present a set of links as tiles instead of a bullet list.
3
+ //
4
+ // import { Cards, Card } from "@opentf/afw-docs";
5
+ // <Cards>
6
+ // <Card title="Core" href="/docs/api/core" desc="Runtime API." />
7
+ // </Cards>
8
+
9
+ export default function Cards(props) {
10
+ return <div class="afwd-cards">{props.children}</div>;
11
+ }
@@ -0,0 +1,39 @@
1
+ // A code block matching the MDX front-end's `.afw-code` structure (header bar with
2
+ // an optional language/filename label and a copy button, above a `<pre>`). Use it for
3
+ // code that doesn't come from a Markdown fence — e.g. a code panel inside `Tabs`:
4
+ // `{ label, content: <CodeBlock code="…" /> }`. The text is NOT syntax-highlighted —
5
+ // highlighting is a build-time (syntect) pass that only sees literal Markdown fences,
6
+ // not a runtime string prop; runtime highlighting here is deferred future work. The
7
+ // copy button owns its own behavior via `onclick` (see `copyWithFeedback`), so it
8
+ // works in any layout — not just the docs shell. The icon glyphs go through `RawHtml`
9
+ // because inline `<svg>` would be created in the HTML namespace and not render.
10
+ import { RawHtml, copyWithFeedback } from "@opentf/afw";
11
+
12
+ const COPY_SVG =
13
+ '<svg class="afw-copy-icon" viewBox="0 0 24 24" width="13" height="13" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true"><rect x="9" y="9" width="11" height="11" rx="2"/><path d="M5 15H4a2 2 0 0 1-2-2V4a2 2 0 0 1 2-2h9a2 2 0 0 1 2 2v1"/></svg>';
14
+ const CHECK_SVG =
15
+ '<svg class="afw-check-icon" viewBox="0 0 24 24" width="13" height="13" fill="none" stroke="currentColor" stroke-width="2.5" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true"><path d="M20 6 9 17l-5-5"/></svg>';
16
+ const ICONS = COPY_SVG + CHECK_SVG;
17
+
18
+ export default function CodeBlock(props) {
19
+ return (
20
+ <div class="afw-code">
21
+ <div class="afw-code-head">
22
+ {props.lang ? <span class="afw-code-lang">{props.lang}</span> : null}
23
+ {props.name ? <span class="afw-code-name">{props.name}</span> : null}
24
+ <button
25
+ class="afw-copy"
26
+ type="button"
27
+ aria-label="Copy code"
28
+ onclick={(e) => copyWithFeedback(e.currentTarget, props.code)}
29
+ >
30
+ <RawHtml html={ICONS} />
31
+ <span class="afw-copy-label">Copy</span>
32
+ </button>
33
+ </div>
34
+ <pre>
35
+ <code>{props.code}</code>
36
+ </pre>
37
+ </div>
38
+ );
39
+ }
@@ -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,47 @@
1
+ // Subscribe links for a blog's RSS and Atom feeds (`<base>/rss.xml`, `<base>/atom.xml`,
2
+ // written by the release build). Plain anchors, not <Link>: a feed is a file for the
3
+ // browser or a reader app, not a route the client router can render.
4
+ //
5
+ // `variant="icons"` (the index) shows an icon and the format name per feed;
6
+ // `variant="inline"` (a post's foot) is a one-line "Subscribe: RSS · Atom".
7
+
8
+ const FEEDS = [
9
+ { file: "rss.xml", label: "RSS", type: "application/rss+xml" },
10
+ { file: "atom.xml", label: "Atom", type: "application/atom+xml" },
11
+ ];
12
+
13
+ function FeedIcon() {
14
+ return (
15
+ <svg class="afwd-feed-icon" viewBox="0 0 24 24" width="14" height="14" aria-hidden="true" fill="currentColor">
16
+ <circle cx="5" cy="19" r="2.2" />
17
+ <path d="M3 10.5v3a7.5 7.5 0 0 1 7.5 7.5h3A10.5 10.5 0 0 0 3 10.5Z" />
18
+ <path d="M3 3.5v3A14.5 14.5 0 0 1 17.5 21h3A17.5 17.5 0 0 0 3 3.5Z" />
19
+ </svg>
20
+ );
21
+ }
22
+
23
+ export default function FeedLinks(props) {
24
+ const base = (props.base || "/blog").replace(/\/+$/, "");
25
+ return props.variant === "inline" ? (
26
+ <p class="afwd-feed-inline">
27
+ Subscribe:{" "}
28
+ <a href={`${base}/rss.xml`} type="application/rss+xml">RSS</a>
29
+ {" · "}
30
+ <a href={`${base}/atom.xml`} type="application/atom+xml">Atom</a>
31
+ </p>
32
+ ) : (
33
+ <nav class="afwd-feed-links" aria-label="Subscribe">
34
+ {FEEDS.map((feed) => (
35
+ <a
36
+ class="afwd-feed-link"
37
+ href={`${base}/${feed.file}`}
38
+ type={feed.type}
39
+ aria-label={`Subscribe via ${feed.label}`}
40
+ >
41
+ <FeedIcon />
42
+ <span>{feed.label}</span>
43
+ </a>
44
+ ))}
45
+ </nav>
46
+ );
47
+ }
@@ -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,20 @@
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 label = props.label || "Last updated on";
12
+ return props.date ? (
13
+ <div class="afwd-last-updated">
14
+ {label}{" "}
15
+ <time class="afwd-last-updated-time" datetime={String(props.date)}>
16
+ {formatDate(props.date)}
17
+ </time>
18
+ </div>
19
+ ) : null;
20
+ }
@@ -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" width="28" height="28" /> : 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
+ }