Repository navigation
Expand file tree
/
Copy pathsource.config.ts
More file actions
74 lines (69 loc) · 3.57 KB
/
Copy pathsource.config.ts
File metadata and controls
74 lines (69 loc) · 3.57 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
import { defineConfig, defineDocs } from 'fumadocs-mdx/config';
import { pageSchema } from 'fumadocs-core/source/schema';
import { readFileSync } from 'node:fs';
import { z } from 'zod';
import { codeOptions, llmsOptions, rehypeTableLabels } from '@withmarfa/docs-kit/config';
import { apiMapMarkdown, buildApiMap, type Areas, type Spec } from './src/lib/api-map';
import { changelogMarkdown, remarkChangelogIndex, type Release } from './src/lib/changelog';
import { sseLanguage } from './src/lib/sse-language';
import { rehypeFieldTables } from './src/lib/field-tables';
import { remarkIcons } from './src/lib/remark-icons';
/** The releases the Changelog page draws, from the file `scripts/sync-changelog.ts` writes. */
function readReleases(): Release[] {
return JSON.parse(readFileSync('src/generated/changelog.json', 'utf8'));
}
/** The API map that the API reference's overview draws, from the API description and its areas. */
function readApiMap() {
const spec: Spec = JSON.parse(readFileSync('openapi.json', 'utf8'));
const areas: Areas = JSON.parse(readFileSync('src/lib/api-map-areas.json', 'utf8'));
return buildApiMap(spec, areas);
}
/**
* The Markdown copy of each page, which agents read at `<page>.md`, through the
* docs MCP server and in `llms-full.txt`. The kit writes the components it
* draws (`llmsOptions`); these are the site's own. A visual the page gives a
* `label`, its text form, is written as that label on a "Figure:" line.
*/
const llms = llmsOptions({
wrappers: ['ReferenceList'],
rewrites: {
// An icon is not text: the copy keeps only what a page says it stands for, such as a mark's ID.
Icon: ({ attribute }) => attribute('markdown') ?? '',
Sequence: ({ attribute, inner }) => `**${attribute('title') ?? ''}**\n\n${inner()}`,
// The component draws releases from a data file, so the copy writes the same releases as Markdown.
Changelog: () => changelogMarkdown(readReleases()),
// Drawn from the API description, so the copy writes every operation and its link.
ApiMap: () => apiMapMarkdown(readApiMap()),
},
});
export const docs = defineDocs({
dir: 'content/docs',
docs: {
// A Catalog type page names its type's identifier, which the header shows
// under the description and the Markdown copy under the title. `headTitle`
// names a page in browser tabs and search results (`headTitle` in `@withmarfa/docs-kit`).
// `sidebar_label` is a shorter name for the sidebar only (`sidebarLabelPlugin` in `@withmarfa/docs-kit/server`).
schema: pageSchema.extend({
identifier: z.string().optional(),
headTitle: z.string().optional(),
sidebar_label: z.string().min(1).optional(),
// The page's kind where neither its name nor page-limits.json says it (`@withmarfa/docs-kit/page-limits`), which search reads.
kind: z.string().optional(),
}),
postprocess: {
includeProcessedMarkdown: llms,
},
},
});
// The code highlighting is the kit's (`codeOptions`), with this site's `sse` grammar added.
export default defineConfig({
mdxOptions: {
// Before Fumadocs's structure step, which builds the search index: the Changelog page's releases are
// data the component draws, so the index would otherwise hold none of their notes.
remarkPlugins: [remarkChangelogIndex(readReleases), remarkIcons()],
// The icon a Catalog page's heading shows, which `remarkIcons` finds (src/lib/remark-icons.ts).
valueToExport: ['pageIcon'],
rehypePlugins: (plugins) => [...plugins, rehypeTableLabels, rehypeFieldTables],
rehypeCodeOptions: codeOptions({ langs: [sseLanguage as never] }),
},
});