Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand Down Expand Up @@ -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
6 changes: 5 additions & 1 deletion .github/workflows/publish-docs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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

Expand Down
2 changes: 1 addition & 1 deletion AGENTS.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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/
```

Expand Down
16 changes: 12 additions & 4 deletions app/docs/[[...slug]]/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,17 @@ 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';
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;

Expand All @@ -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}`),
}),
);

Expand All @@ -55,8 +58,11 @@ export default async function Page(props: PageProps<'/docs/[[...slug]]'>) {
<DocsBody>
<MDX
components={getMDXComponents({
// Lets pages keep linking with relative paths like ./docker.
a: createRelativeLink(source, page),
// Pages link with relative paths like ../versioning or ./docker.mdx; resolve them
// against the page's folder, not its URL (which ends in /). See lib/docs-href.ts.
a: ({ href, ...rest }) => (
<defaultMdxComponents.a href={href ? resolveDocsHref(href, page.path) : href} {...rest} />
),
})}
/>
</DocsBody>
Expand Down Expand Up @@ -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)}`,
});
}

Expand Down
2 changes: 2 additions & 0 deletions app/docs/layout.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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 (
<div className="dt-root">
<DocsTopBar />
<DocsLayout tree={source.getPageTree()} {...docsOptions()}>
<SidebarModal />
{children}
</DocsLayout>
</div>
Expand Down
8 changes: 8 additions & 0 deletions app/docs/llms.txt/route.ts
Original file line number Diff line number Diff line change
@@ -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' } });
}
46 changes: 41 additions & 5 deletions app/global.css
Original file line number Diff line number Diff line change
Expand Up @@ -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 <SetupPanel /> are underlined, so it is
clear which parts of a config file came from them. */
[data-setup][data-filled] {
Expand Down Expand Up @@ -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 {
Expand Down Expand Up @@ -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;
}

Expand Down Expand Up @@ -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);
}

Expand Down Expand Up @@ -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);
}
Expand Down Expand Up @@ -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);
}
Expand Down
7 changes: 4 additions & 3 deletions app/layout.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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';

Expand Down Expand Up @@ -43,9 +44,9 @@ export default function RootLayout({ children }: LayoutProps<'/'>) {
<RootProvider
// Dark until the reader picks a theme with the switch in the docs bar (the Hub does the same).
theme={{ defaultTheme: 'dark' }}
// The search index is a static file built with the site (app/docs/search.json),
// under /docs/ like everything else the docs load.
search={{ options: { type: 'static', api: '/docs/search.json' } }}
// Fumadocs' dialog with focus return, a results count and a focus ring
// (components/docs/search-dialog.tsx); it searches the static index under /docs/.
search={{ SearchDialog: DocsSearchDialog }}
>
{children}
<ExternalLinkGuard />
Expand Down
54 changes: 30 additions & 24 deletions components/docs/docs-top-bar.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,31 +12,37 @@ import { navOutsideDocs, siteNav } from '@/lib/nav';
*/
export function DocsTopBar() {
return (
<header className="dt-bar">
{/* Plain links: / and the paths in the site nav are the Hub's pages, not this app's. */}
<a href="/" className="dt-bar__brand" aria-label="Pelican home">
{/* eslint-disable-next-line @next/next/no-img-element */}
<img src="/docs/img/logo.png" alt="" width={34} height={34} />
<span>Pelican</span>
<span className="dt-bar__section">Docs</span>
<>
{/* First on the page for keyboard users; shown when focused. #nd-page is Fumadocs' article. */}
<a href="#nd-page" className="dt-skip">
Skip to content
</a>
<FullSearchTrigger className="dt-bar__search" />
<nav className="dt-bar__links" aria-label="Site">
{navOutsideDocs.map((item) => (
<a key={item.href} href={item.href}>
{item.label}
</a>
))}
</nav>
<div className="dt-bar__actions">
<ThemeSwitch className="dt-bar__theme" />
<a href={links.github} className="dt-btn" aria-label={`Pelican on GitHub, ${project.stars} stars`}>
<Star size={15} strokeWidth={2.5} aria-hidden /> {(project.stars / 1000).toFixed(1)}k
<header className="dt-bar">
{/* Plain links: / and the paths in the site nav are the Hub's pages, not this app's. */}
<a href="/" className="dt-bar__brand" aria-label="Pelican Docs: home page">
{/* eslint-disable-next-line @next/next/no-img-element */}
<img src="/docs/img/logo-96.webp" alt="" width={34} height={34} />
<span>Pelican</span>
<span className="dt-bar__section">Docs</span>
</a>
<Link href={siteNav.cta.href} className="dt-btn dt-btn--ink">
{siteNav.cta.label}
</Link>
</div>
</header>
<FullSearchTrigger className="dt-bar__search" />
<nav className="dt-bar__links" aria-label="Site">
{navOutsideDocs.map((item) => (
<a key={item.href} href={item.href}>
{item.label}
</a>
))}
</nav>
<div className="dt-bar__actions">
<ThemeSwitch className="dt-bar__theme" />
<a href={links.github} className="dt-btn" aria-label={`Pelican on GitHub, ${project.stars} stars`}>
<Star size={15} strokeWidth={2.5} aria-hidden /> {(project.stars / 1000).toFixed(1)}k
</a>
<Link href={siteNav.cta.href} className="dt-btn dt-btn--ink">
{siteNav.cta.label}
</Link>
</div>
</header>
</>
);
}
4 changes: 3 additions & 1 deletion components/docs/page-actions.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,9 @@ export function PageActions({ markdownUrl, githubUrl }: { markdownUrl: string; g
<CopyButton url="/llms-full.txt" icon={<BookCopy />} title="Copy every docs page as one Markdown file (about 60,000 tokens)">
Copy all docs
</CopyButton>
<ViewOptionsPopover className="dt-action" markdownUrl={markdownUrl} githubUrl={githubUrl} />
<ViewOptionsPopover className="dt-action" markdownUrl={markdownUrl} githubUrl={githubUrl}>
Open in…
</ViewOptionsPopover>
</div>
);
}
Expand Down
68 changes: 68 additions & 0 deletions components/docs/search-dialog.tsx
Original file line number Diff line number Diff line change
@@ -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 <body>;
* - "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<HTMLElement | null>(null);

return (
<SearchDialog open={open} onOpenChange={onOpenChange} {...search}>
<SearchDialogOverlay />
<SearchDialogContent
// Called before focus moves into the dialog, so the focused element is still the opener.
onOpenAutoFocus={() => {
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<HTMLElement>('[data-search-full], [data-search]')).find(
(button) => button.offsetParent !== null,
) ?? null);
}}
onCloseAutoFocus={(event) => {
if (!opener.current?.isConnected) return;
event.preventDefault();
opener.current.focus();
}}
>
<SearchDialogHeader>
<SearchDialogIcon />
<SearchDialogInput />
<SearchDialogClose />
</SearchDialogHeader>
<SearchDialogList />
<p role="status" className="sr-only">
{resultsMessage(search.search, search.isLoading, search.data?.items)}
</p>
</SearchDialogContent>
</SearchDialog>
);
}

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'}`;
}
Loading