-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathastro.config.mjs
More file actions
75 lines (70 loc) · 2.89 KB
/
Copy pathastro.config.mjs
File metadata and controls
75 lines (70 loc) · 2.89 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
75
import { defineConfig } from "astro/config";
import tailwindcss from "@tailwindcss/vite";
import GithubSlugger from "github-slugger";
/**
* Tiny rehype plugin: append a "#" anchor to every h2/h3 so deep links are
* discoverable. Astro's user rehype plugins run BEFORE its built-in heading
* id pass, so ids aren't on the nodes yet — we slug with github-slugger (the
* same package/algorithm Astro uses) and write the ids ourselves. Astro's
* pass then finds ids already present and leaves them alone; our hrefs match
* exactly, dedup sequences included (our docs use no h1/h4+, so the slug
* sequences are identical).
*/
function anchorHeadings() {
/** Full rendered text of a hast node — INCLUDING inline elements
* (code spans, links). Astro's own slugger uses full text; matching it
* keeps ids stable for headings like `Member-exit policy: \`onNsMemberExit\``
* (text-node-only slugging produced trailing-dash ids and broke the
* cross-page anchors that link to them). */
const textOf = (node) =>
Array.isArray(node.children)
? node.children.map(textOf).join("")
: node.type === "text"
? node.value
: "";
return (tree) => {
const slugger = new GithubSlugger();
const walk = (node) => {
if (Array.isArray(node.children)) node.children.forEach(walk);
if (node.type !== "element") return;
if (node.tagName !== "h2" && node.tagName !== "h3") return;
if (node.properties?.id) return; // already slugged
const id = slugger.slug(textOf(node));
node.properties = { ...node.properties, id };
node.children.push({
type: "element",
tagName: "a",
// NOTE: the decorative "#" must stay out of the search index (it
// pollutes sub-result titles and excerpts). Astro's markdown
// serializer drops data-* attributes from rehype properties, so
// this is handled at the pagefind CLI layer instead:
// --exclude-selectors .anchor (see package.json build script)
properties: { class: "anchor", href: `#${id}`, ariaLabel: "Link to this section" },
children: [{ type: "text", value: "#" }],
});
};
walk(tree);
};
}
// https://astro.build/config
export default defineConfig({
// Canonical origin — used for sitemap/canonical URLs. Change this if the
// docs end up living elsewhere (e.g. procboss.com/docs).
site: "https://docs.procboss.com",
// Static output (default): every page is prerendered HTML, zero runtime —
// exactly what Cloudflare Pages wants from us.
output: "static",
vite: {
plugins: [tailwindcss()],
},
markdown: {
rehypePlugins: [anchorHeadings],
// Single dark theme — code blocks are dark terminals on the light paper
// page (the brand pattern). global.css forces the ink-black background
// and adds the brutal chrome.
shikiConfig: {
theme: "github-dark",
wrap: false,
},
},
});