import { readFileSync } from 'node:fs' import { join } from 'node:path' import { unified } from '@astrojs/markdown-remark' import starlight from '@astrojs/starlight' import { defineConfig } from 'astro/config' import { BASE, FONTS, pages, REPO, root, specPages, title } from './content.mjs' import { remarkLinks } from './plugins.mjs' const all = pages() const titleOf = (source) => title(readFileSync(join(root, source), 'utf8'), source) const slugOf = (source) => all.find((p) => p.source === source).slug // The guides in the order docs/README.md lists them; any it does not, after. const guides = all.filter((p) => p.source.startsWith('docs/guide/')) const listed = [...readFileSync(join(root, 'docs/README.md'), 'utf8').matchAll(/\]\((guide\/[^)#]+\.md)\)/g)].map( (m) => `docs/${m[1]}`, ) const guideOrder = [ ...new Set([...listed, ...guides.map((p) => p.source)].filter((s) => guides.some((p) => p.source === s))), ] // The specification's areas, in spec/PDS.md's order. A page not named here // is listed under "More", so a new one is never left out. const AREAS = [ ['Accounts and sessions', ['ACCOUNTS', 'SESSIONS', 'EMAIL', 'LIFECYCLE', 'MIGRATION']], ['Repository and sync', ['REPO', 'VALIDATION', 'SYNC', 'FEDERATION', 'IDENTITY', 'BLOBS', 'PROXY']], ['Spaces', ['SPACES', 'SPACES-REPO', 'SPACES-CREDENTIALS', 'SPACES-POLICIES', 'SPACES-EXPORT', 'SPACES-SYNC']], ['OAuth', ['OAUTH', 'OAUTH-SCOPES', 'OAUTH-CLIENTS', 'OAUTH-PAGES', 'OAUTH-PERMISSION-SETS', 'OAUTH-MCP', 'OAUTH-ACCOUNT', 'PASSKEYS']], ['Running on the internet', ['DURABILITY', 'STORE', 'LIMITS', 'OPERATIONS']], ['Calling and comparing', ['COMMANDS', 'COMPAT']], ] const named = new Set(['PDS', ...AREAS.flatMap(([, names]) => names)]) const more = specPages() .map((f) => f.replace(/\.md$/, '')) .filter((n) => !named.has(n)) /** A spec page's label: its title up to its colon, or, under an area its title starts with, what follows. */ function specLabel(area, name) { const [head, ...rest] = titleOf(`spec/${name}.md`).split(': ') if (!rest.length) return head if (head !== area) return head const tail = rest.join(': ') return tail[0].toUpperCase() + tail.slice(1) } const specItem = (area) => (name) => ({ label: specLabel(area, name), slug: slugOf(`spec/${name}.md`) }) export default defineConfig({ site: 'https://chadtmiller-com.knotless.page', base: BASE || '/', markdown: { processor: unified({ remarkPlugins: [remarkLinks] }), }, integrations: [ starlight({ title: 'Monolith PDS', description: 'Monolith, an atproto PDS: built from its specification and checked against the reference PDS.', customCss: ['./src/theme.css'], // Preloaded, so the text is drawn in them from the first paint, not // swapped in once the stylesheet asks for them. head: FONTS.map((href) => ({ tag: 'link', attrs: { rel: 'preload', href, as: 'font', type: 'font/woff2', crossorigin: '' }, })), components: { ThemeSelect: './src/ThemeSelect.astro' }, social: [{ icon: 'seti:git', label: 'The repository', href: REPO }], lastUpdated: false, // Code as the landing page shows it: light on near-black, in JetBrains Mono. expressiveCode: { themes: ['github-dark'], defaultProps: { frame: 'none' }, styleOverrides: { borderRadius: '0', borderColor: 'var(--m-line)', codeBackground: 'var(--m-panel)', codeFontFamily: 'var(--m-mono)', codeFontSize: '0.875rem', uiFontFamily: 'var(--m-sans)', frames: { frameBoxShadowCssValue: 'none' }, }, }, pagination: true, sidebar: [ { label: 'Overview', slug: 'overview' }, { label: 'Guides', items: guideOrder.map((s) => ({ label: titleOf(s), slug: slugOf(s) })) }, { label: 'Specification', items: [ { label: 'The PDS', slug: 'spec' }, ...AREAS.map(([area, names]) => ({ label: area, items: names.map(specItem(area)) })), ...(more.length ? [{ label: 'More', items: more.map(specItem('More')) }] : []), ], }, { label: 'Reference', items: [ { label: 'Methods', slug: 'reference/methods' }, { label: 'Environment variables', slug: 'reference/variables' }, { label: 'The compatibility check', slug: 'reference/compat' }, { label: 'Compatibility results', slug: 'reference/compat-results' }, { label: 'The benchmark', slug: 'reference/bench' }, { label: 'Benchmark results', slug: 'reference/bench-results' }, ], }, ], }), ], })