diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 418e8f88..092fcc11 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -14,6 +14,10 @@ jobs: steps: - name: 'Checkout' uses: actions/checkout@v7 + with: + # The whole history: each page's "Last updated", sitemap date and JSON-LD dates come + # from git (lastModified in source.config.ts). A shallow clone gives every page the same date. + fetch-depth: 0 # Bun installs and runs the scripts; Next.js itself still builds on Node. - name: 'Setup Bun' @@ -46,6 +50,6 @@ jobs: run: bun run typecheck # prebuild runs check:content again (Netlify builds run it there); - # postbuild runs check:paths on out/. + # postbuild runs check:paths and check:links on out/. - name: 'Build' run: bun run build diff --git a/.github/workflows/publish-docs.yml b/.github/workflows/publish-docs.yml index 0d15d911..76cc3575 100644 --- a/.github/workflows/publish-docs.yml +++ b/.github/workflows/publish-docs.yml @@ -30,6 +30,10 @@ jobs: steps: - name: 'Checkout' uses: actions/checkout@v7 + with: + # The whole history: each page's "Last updated", sitemap date and JSON-LD dates come + # from git (lastModified in source.config.ts). A shallow clone gives every page the same date. + fetch-depth: 0 - name: 'Setup Bun' uses: oven-sh/setup-bun@v2 @@ -58,7 +62,7 @@ jobs: - name: 'Typecheck' run: bun run typecheck - # prebuild checks the content, postbuild checks every file lands where it should. + # prebuild checks the content, postbuild checks every file lands where it should and every link works. - name: 'Build' run: bun run build diff --git a/AGENTS.md b/AGENTS.md index cb862b67..add8a264 100644 --- a/AGENTS.md +++ b/AGENTS.md @@ -19,7 +19,7 @@ This block is written and re-added by `next dev` — verify at `node_modules/nex - Before opening a pull request: `bun test`, `bun run typecheck`, `bun run build`. The build checks the pages before it (`check:content`), refreshes the egg data (`sync:eggs`, which uses the network and rewrites `data/eggs.json`, `public/data/eggs/`, `public/img/eggs/`, `public/img/games/`: don't - commit those unless the task is about eggs), and checks the paths after it (`check:paths`). + commit those unless the task is about eggs), and checks the paths and the links after it (`check:paths`, `check:links`). - The paths this build serves on pelican.dev are in one file, `router/paths.mjs`. Change them there, and in the Hub's `DocsBuildService::ROOT_FILES` for the root files. - A new MDX component goes in `mdx-components.tsx` and in `COMPONENTS` in diff --git a/README.md b/README.md index 6189c547..72615e46 100644 --- a/README.md +++ b/README.md @@ -11,7 +11,7 @@ You need Node.js 22 or newer (Next.js builds on Node) and [Bun](https://bun.com) ```sh bun install bun run dev # http://localhost:3000, reloads as you edit -bun run build # the production site, written to out/ (checks the pages first, the paths after) +bun run build # the production site, written to out/ (checks the pages first, the paths and links after) bun test # the tests for scripts/ and router/ ``` diff --git a/app/docs/[[...slug]]/page.tsx b/app/docs/[[...slug]]/page.tsx index 77047dce..94590721 100644 --- a/app/docs/[[...slug]]/page.tsx +++ b/app/docs/[[...slug]]/page.tsx @@ -6,7 +6,7 @@ import { EditOnGitHub, PageLastUpdate, } from 'fumadocs-ui/layouts/docs/page'; -import { createRelativeLink } from 'fumadocs-ui/mdx'; +import defaultMdxComponents from 'fumadocs-ui/mdx'; import { getBreadcrumbItems } from 'fumadocs-core/breadcrumb'; import { notFound } from 'next/navigation'; import type { Metadata } from 'next'; @@ -14,7 +14,9 @@ import { githubEditUrl, source } from '@/lib/source'; import { docsBreadcrumbJsonLd, jsonLdScript, ogImage, pageMetadata, techArticleJsonLd } from '@/lib/og'; import { getMDXComponents } from '@/mdx-components'; import { PageActions } from '@/components/docs/page-actions'; -import { markdownPath } from '@/lib/llms'; +import { markdownPath, SITE_URL } from '@/lib/llms'; +import { resolveDocsHref } from '@/lib/docs-href'; +import { firstCommitDate } from '@/lib/git-dates'; export const dynamicParams = false; @@ -33,6 +35,7 @@ export default async function Page(props: PageProps<'/docs/[[...slug]]'>) { image: ogImage.docs(page.slugs), section: docsSection(page.url), lastModified: page.data.lastModified, + published: firstCommitDate(`content/docs/${page.path}`), }), ); @@ -55,8 +58,11 @@ export default async function Page(props: PageProps<'/docs/[[...slug]]'>) { ( + + ), })} /> @@ -87,6 +93,8 @@ export async function generateMetadata(props: PageProps<'/docs/[[...slug]]'>): P image: ogImage.docs(page.slugs), type: isIndex ? 'website' : 'article', modifiedTime: page.data.lastModified, + // The page as Markdown, for AI tools (lib/llms.ts). /docs/md/… is the built file behind it. + markdown: `${SITE_URL}${markdownPath(page)}`, }); } diff --git a/app/docs/layout.tsx b/app/docs/layout.tsx index df141d4d..2619b903 100644 --- a/app/docs/layout.tsx +++ b/app/docs/layout.tsx @@ -2,12 +2,14 @@ import { DocsLayout } from 'fumadocs-ui/layouts/docs'; import { docsOptions } from '@/lib/layout.shared'; import { source } from '@/lib/source'; import { DocsTopBar } from '@/components/docs/docs-top-bar'; +import { SidebarModal } from '@/components/docs/sidebar-modal'; export default function Layout({ children }: LayoutProps<'/docs'>) { return (
+ {children}
diff --git a/app/docs/llms.txt/route.ts b/app/docs/llms.txt/route.ts new file mode 100644 index 00000000..915bd829 --- /dev/null +++ b/app/docs/llms.txt/route.ts @@ -0,0 +1,8 @@ +import { llmsTxt } from '@/lib/llms'; + +// /docs/llms.txt: the same index as /llms.txt, for tools that look for it next to the docs. +export const dynamic = 'force-static'; + +export function GET() { + return new Response(llmsTxt(), { headers: { 'Content-Type': 'text/plain; charset=utf-8' } }); +} diff --git a/app/global.css b/app/global.css index 80ceb1bd..f486d208 100644 --- a/app/global.css +++ b/app/global.css @@ -75,6 +75,12 @@ } } +/* The search dialog's input: Fumadocs turns its outline off; give it one back. */ +input[aria-controls='fd-search-list']:focus-visible { + outline: 2px solid var(--color-fd-ring); + outline-offset: 2px; +} + /* Values filled in from the reader's are underlined, so it is clear which parts of a config file came from them. */ [data-setup][data-filled] { @@ -182,9 +188,35 @@ figure.shiki { outline-offset: 2px; } -/* The search box shows focus with its caret; the dialog's edge already frames it. */ +/* The search box gets the same ring (Fumadocs turns its outline off). */ :root:has(.dt-root) [role='dialog'] input:focus-visible { - outline: none; + outline: 3px solid var(--pl-fg); + outline-offset: 2px; +} + +/* Dark theme: edges of controls (search box, buttons, theme switch) at 3:1 or more against + the bar and the cards, so they can be told apart (WCAG 1.4.11). --pl-edge is 1.9:1 there. */ +:root.dark:has(.dt-root) { + --dt-control-edge: #5b7a8c; +} + +/* "Skip to content" (components/docs/docs-top-bar.tsx): off screen until focused. */ +.dt-skip { + position: fixed; + top: 12px; + left: 12px; + z-index: 100; + padding: 12px 16px; + border: 3px solid var(--pl-ink); + background: var(--pl-sky); + color: var(--pl-ink); + font: 700 15px/1 var(--font-sans); + text-decoration: none; + transform: translateY(-200%); +} + +.dt-skip:focus { + transform: none; } .dt-root ::selection { @@ -265,7 +297,7 @@ figure.shiki { } .dark .dt-bar__search { - border-color: var(--pl-edge) !important; + border-color: var(--dt-control-edge) !important; background: var(--pl-card) !important; } @@ -338,7 +370,7 @@ figure.shiki { } .dark .dt-root [data-theme-toggle] { - border-color: var(--pl-edge); + border-color: var(--dt-control-edge); background: var(--pl-card); } @@ -373,7 +405,7 @@ figure.shiki { } .dark .dt-btn { - border-color: var(--pl-edge); + border-color: var(--dt-control-edge); background: var(--pl-card); color: var(--pl-fg); } @@ -942,6 +974,10 @@ figure.shiki { color: var(--pl-kicker); } +.dark .dt-root .dt-action { + border-color: var(--dt-control-edge); +} + .dt-root .dt-action:hover { background: var(--pl-hover); } diff --git a/app/layout.tsx b/app/layout.tsx index 7fc358e0..20a3cfbe 100644 --- a/app/layout.tsx +++ b/app/layout.tsx @@ -2,6 +2,7 @@ import './global.css'; import { RootProvider } from 'fumadocs-ui/provider/next'; import type { Metadata } from 'next'; import { Bricolage_Grotesque, Instrument_Sans, JetBrains_Mono } from 'next/font/google'; +import { DocsSearchDialog } from '@/components/docs/search-dialog'; import { ExternalLinkGuard } from '@/components/external-link-guard'; import { ASSET_URL, IS_PRODUCTION, OG_SIZE, SITE_NAME, ogImage } from '@/lib/og'; @@ -43,9 +44,9 @@ export default function RootLayout({ children }: LayoutProps<'/'>) { {children} diff --git a/components/docs/docs-top-bar.tsx b/components/docs/docs-top-bar.tsx index 79c16064..42adafc1 100644 --- a/components/docs/docs-top-bar.tsx +++ b/components/docs/docs-top-bar.tsx @@ -12,31 +12,37 @@ import { navOutsideDocs, siteNav } from '@/lib/nav'; */ export function DocsTopBar() { return ( -
- {/* Plain links: / and the paths in the site nav are the Hub's pages, not this app's. */} - - {/* eslint-disable-next-line @next/next/no-img-element */} - - Pelican - Docs + <> + {/* First on the page for keyboard users; shown when focused. #nd-page is Fumadocs' article. */} + + Skip to content - - - -
+ + +
+ + + {(project.stars / 1000).toFixed(1)}k + + + {siteNav.cta.label} + +
+ + ); } diff --git a/components/docs/page-actions.tsx b/components/docs/page-actions.tsx index de676768..e0ff5074 100644 --- a/components/docs/page-actions.tsx +++ b/components/docs/page-actions.tsx @@ -21,7 +21,9 @@ export function PageActions({ markdownUrl, githubUrl }: { markdownUrl: string; g } title="Copy every docs page as one Markdown file (about 60,000 tokens)"> Copy all docs - + + Open in… + ); } diff --git a/components/docs/search-dialog.tsx b/components/docs/search-dialog.tsx new file mode 100644 index 00000000..494c43b7 --- /dev/null +++ b/components/docs/search-dialog.tsx @@ -0,0 +1,68 @@ +'use client'; + +import { useRef } from 'react'; +import type { SharedProps } from 'fumadocs-ui/contexts/search'; +import { + SearchDialog, + SearchDialogClose, + SearchDialogContent, + SearchDialogHeader, + SearchDialogIcon, + SearchDialogInput, + SearchDialogList, + SearchDialogOverlay, +} from 'fumadocs-ui/components/dialog/search'; +import { useStaticSearch } from 'fumadocs-core/search/client/orama-static'; + +/** + * Fumadocs' default search dialog (components/dialog/search-default), with three fixes for + * keyboard and screen reader users: + * - on close, focus goes back to what opened it (a search button), not to ; + * - "N results" is announced in a live region while results show; + * - the input has a visible focus ring (app/global.css). + * The index is the static file built with the site (app/docs/search.json). + */ +export function DocsSearchDialog({ open, onOpenChange }: SharedProps) { + const search = useStaticSearch({ from: '/docs/search.json' }); + const opener = useRef(null); + + return ( + + + { + const focused = document.activeElement; + // Opened with ⌘K/Ctrl K, or a click that didn't focus the button (Safari): use a visible search button. + opener.current = + focused instanceof HTMLElement && focused !== document.body + ? focused + : (Array.from(document.querySelectorAll('[data-search-full], [data-search]')).find( + (button) => button.offsetParent !== null, + ) ?? null); + }} + onCloseAutoFocus={(event) => { + if (!opener.current?.isConnected) return; + event.preventDefault(); + opener.current.focus(); + }} + > + + + + + + +

+ {resultsMessage(search.search, search.isLoading, search.data?.items)} +

+
+
+ ); +} + +function resultsMessage(query: string, isLoading: boolean, items: { type: string; rows?: unknown[] }[] | undefined) { + if (!query.trim() || isLoading || !items) return ''; + const count = items.reduce((n, item) => n + (item.type === 'table' ? (item.rows?.length ?? 0) : 1), 0); + return count === 0 ? 'No results' : `${count} result${count === 1 ? '' : 's'}`; +} diff --git a/components/docs/sidebar-modal.tsx b/components/docs/sidebar-modal.tsx new file mode 100644 index 00000000..f2d6d272 --- /dev/null +++ b/components/docs/sidebar-modal.tsx @@ -0,0 +1,82 @@ +'use client'; + +import { useEffect, useRef } from 'react'; +import { useSidebar } from 'fumadocs-ui/layouts/docs/slots/sidebar'; + +const DRAWER = 'nd-sidebar-mobile'; + +/** + * Makes Fumadocs' phone sidebar (#nd-sidebar-mobile) behave as the modal dialog it looks + * like: Escape closes it, everything behind it is `inert` (Tab can't reach the hidden page, + * screen readers don't read it), focus moves into it when it opens and back to the + * "Open Sidebar" button when it closes. Renders nothing; it only follows the sidebar's state. + */ +export function SidebarModal() { + const { open, setOpen, mode } = useSidebar(); + const active = open && mode === 'drawer'; + const wasActive = useRef(false); + + useEffect(() => { + if (!active) { + if (wasActive.current) { + wasActive.current = false; + // Back to the button that opened it, unless focus already went somewhere on purpose. + const focused = document.activeElement; + if (!focused || focused === document.body || focused.closest(`#${DRAWER}`)) { + document.querySelector(`[aria-controls="${DRAWER}"]:not(#${DRAWER} *)`)?.focus(); + } + } + return; + } + wasActive.current = true; + + let undo: (() => void) | undefined; + // The drawer mounts with this render; wait a frame for it. + const frame = requestAnimationFrame(() => { + const drawer = document.getElementById(DRAWER); + if (!drawer) return; + undo = makeModal(drawer); + drawer.querySelector('a[href], button:not([disabled]), input, [tabindex]:not([tabindex="-1"])')?.focus(); + }); + + const onKeyDown = (event: KeyboardEvent) => { + if (event.key === 'Escape' && !event.defaultPrevented) { + event.preventDefault(); + setOpen(false); + } + }; + document.addEventListener('keydown', onKeyDown); + + return () => { + cancelAnimationFrame(frame); + document.removeEventListener('keydown', onKeyDown); + undo?.(); + }; + }, [active, setOpen]); + + return null; +} + +/** + * Marks the drawer as a modal dialog and makes everything else on the page inert: each + * sibling of the drawer and of its ancestors, except the backdrop (a click on it closes the + * drawer). Returns a function that undoes it. + */ +function makeModal(drawer: HTMLElement): () => void { + const backdrop = drawer.previousElementSibling?.hasAttribute('data-state') ? drawer.previousElementSibling : null; + const made: Element[] = []; + for (let node: HTMLElement | null = drawer; node && node !== document.body; node = node.parentElement) { + for (const sibling of Array.from(node.parentElement?.children ?? [])) { + if (sibling === node || sibling === backdrop || sibling.hasAttribute('inert')) continue; + sibling.setAttribute('inert', ''); + made.push(sibling); + } + } + drawer.setAttribute('role', 'dialog'); + drawer.setAttribute('aria-modal', 'true'); + drawer.setAttribute('aria-label', 'Docs navigation'); + return () => { + for (const element of made) element.removeAttribute('inert'); + drawer.removeAttribute('aria-modal'); + }; +} diff --git a/components/home/feature-panel.tsx b/components/home/feature-panel.tsx index 6d20e1d9..882edec4 100644 --- a/components/home/feature-panel.tsx +++ b/components/home/feature-panel.tsx @@ -63,7 +63,7 @@ export function FeaturePanel() {
{/* eslint-disable-next-line @next/next/no-img-element */} - + Pelican / Servers / Minecraft SMP diff --git a/components/home/sections.tsx b/components/home/sections.tsx index 922b8bcc..25c51c03 100644 --- a/components/home/sections.tsx +++ b/components/home/sections.tsx @@ -195,7 +195,7 @@ export function FeaturesSection() {
{/* eslint-disable-next-line @next/next/no-img-element */} - + Panel Web UI + API @@ -480,7 +480,7 @@ export function SiteFooterNav() {
{/* eslint-disable-next-line @next/next/no-img-element */} - + Pelican

A free, open-source game server panel, built by its community.

diff --git a/components/home/site-header.tsx b/components/home/site-header.tsx index 99516c0c..d47412df 100644 --- a/components/home/site-header.tsx +++ b/components/home/site-header.tsx @@ -22,7 +22,7 @@ export function SiteHeader() {
{/* eslint-disable-next-line @next/next/no-img-element */} - + Pelican