@@ -4,100 +4,32 @@ import tailwind from "@astrojs/tailwind";
44import starlightDocSearch from "@astrojs/starlight-docsearch" ;
55import starlightImageZoom from "starlight-image-zoom" ;
66import liveCode from "astro-live-code" ;
7- import rehypeMermaid from "rehype-mermaid" ;
8- import rehypeAutolinkHeadings , {
9- type Options as rehypeAutolinkHeadingsOptions ,
10- } from "rehype-autolink-headings" ;
11- import rehypeExternalLinks from "rehype-external-links" ;
127import starlightLinksValidator from "starlight-links-validator" ;
13- import { h } from "hastscript" ;
14- import { readdir } from "fs/promises" ;
158import icon from "astro-icon" ;
169import sitemap from "@astrojs/sitemap" ;
1710import react from "@astrojs/react" ;
11+
1812import rehypeTitleFigure from "rehype-title-figure" ;
19- import rehypeHeadingSlugs from "./plugins/rehype/heading-slugs" ;
13+ import rehypeMermaid from "./src/plugins/rehype/mermaid.ts" ;
14+ import rehypeAutolinkHeadings from "./src/plugins/rehype/autolink-headings.ts" ;
15+ import rehypeExternalLinks from "./src/plugins/rehype/external-links.ts" ;
16+ import rehypeHeadingSlugs from "./src/plugins/rehype/heading-slugs.ts" ;
2017
21- const runLinkCheck = process . env . RUN_LINK_CHECK || false ;
18+ import { sidebar } from "./src/util/sidebar.ts" ;
2219
23- async function autogenSections ( ) {
24- const sections = (
25- await readdir ( "./src/content/docs/" , {
26- withFileTypes : true ,
27- } )
28- )
29- . filter ( ( x ) => x . isDirectory ( ) )
30- . map ( ( x ) => x . name ) ;
31- return sections . map ( ( x ) => {
32- return {
33- label : x ,
34- autogenerate : {
35- directory : x ,
36- collapsed : true ,
37- } ,
38- } ;
39- } ) ;
40- }
41- const AnchorLinkIcon = h (
42- "span" ,
43- {
44- ariaHidden : "true" ,
45- class : "anchor-icon" ,
46- } ,
47- h (
48- "svg" ,
49- {
50- width : 16 ,
51- height : 16 ,
52- viewBox : "0 0 24 24" ,
53- } ,
54- h ( "path" , {
55- fill : "currentcolor" ,
56- d : "m12.11 15.39-3.88 3.88a2.52 2.52 0 0 1-3.5 0 2.47 2.47 0 0 1 0-3.5l3.88-3.88a1 1 0 0 0-1.42-1.42l-3.88 3.89a4.48 4.48 0 0 0 6.33 6.33l3.89-3.88a1 1 0 1 0-1.42-1.42Zm8.58-12.08a4.49 4.49 0 0 0-6.33 0l-3.89 3.88a1 1 0 0 0 1.42 1.42l3.88-3.88a2.52 2.52 0 0 1 3.5 0 2.47 2.47 0 0 1 0 3.5l-3.88 3.88a1 1 0 1 0 1.42 1.42l3.88-3.89a4.49 4.49 0 0 0 0-6.33ZM8.83 15.17a1 1 0 0 0 1.1.22 1 1 0 0 0 .32-.22l4.92-4.92a1 1 0 0 0-1.42-1.42l-4.92 4.92a1 1 0 0 0 0 1.42Z" ,
57- } ) ,
58- ) ,
59- ) ;
60- const autolinkConfig : rehypeAutolinkHeadingsOptions = {
61- properties : {
62- class : "anchor-link" ,
63- } ,
64- behavior : "after" ,
65- group : ( { tagName } ) =>
66- h ( "div" , {
67- tabIndex : - 1 ,
68- class : `heading-wrapper level-${ tagName } ` ,
69- } ) ,
70- content : ( ) => [ AnchorLinkIcon ] ,
71- } ;
20+ const runLinkCheck = process . env . RUN_LINK_CHECK || false ;
7221
7322// https://astro.build/config
7423export default defineConfig ( {
7524 site : "https://developers.cloudflare.com" ,
7625 markdown : {
7726 smartypants : false ,
7827 rehypePlugins : [
79- [
80- rehypeMermaid ,
81- {
82- strategy : "pre-mermaid" ,
83- } ,
84- ] ,
85- [
86- rehypeExternalLinks ,
87- {
88- content : {
89- type : "text" ,
90- value : " ↗" ,
91- } ,
92- properties : {
93- target : "_blank" ,
94- } ,
95- rel : [ "noopener" ] ,
96- } ,
97- ] ,
28+ rehypeMermaid ,
29+ rehypeExternalLinks ,
9830 rehypeHeadingSlugs ,
99- [ rehypeAutolinkHeadings , autolinkConfig ] ,
100- // @ts -expect-error TODO: fix types
31+ rehypeAutolinkHeadings ,
32+ // @ts -expect-error plugins types are outdated but functional
10133 rehypeTitleFigure ,
10234 ] ,
10335 } ,
@@ -116,29 +48,15 @@ export default defineConfig({
11648 src : "./src/assets/logo.svg" ,
11749 } ,
11850 favicon : "/favicon.png" ,
119- head : [
120- {
121- tag : "meta" ,
122- attrs : {
123- name : "image" ,
124- content : "https://developers.cloudflare.com/cf-twitter-card.png" ,
125- } ,
126- } ,
127- {
51+ head : [ "image" , "og:image" , "twitter:image" ] . map ( ( name ) => {
52+ return {
12853 tag : "meta" ,
12954 attrs : {
130- name : "og:image" ,
55+ name,
13156 content : "https://developers.cloudflare.com/cf-twitter-card.png" ,
13257 } ,
133- } ,
134- {
135- tag : "meta" ,
136- attrs : {
137- name : "twitter:image" ,
138- content : "https://developers.cloudflare.com/cf-twitter-card.png" ,
139- } ,
140- } ,
141- ] ,
58+ } ;
59+ } ) ,
14260 social : {
14361 github : "https://github.com/cloudflare/cloudflare-docs" ,
14462 "x.com" : "https://x.com/cloudflare" ,
@@ -161,18 +79,17 @@ export default defineConfig({
16179 SkipLink : "./src/components/overrides/SkipLink.astro" ,
16280 TableOfContents : "./src/components/overrides/TableOfContents.astro" ,
16381 } ,
164- sidebar : await autogenSections ( ) ,
82+ sidebar,
16583 customCss : [
16684 "./src/asides.css" ,
16785 "./src/code.css" ,
86+ "./src/footnotes.css" ,
16887 "./src/headings.css" ,
16988 "./src/input.css" ,
170- "./src/littlefoot.css" ,
17189 "./src/mermaid.css" ,
17290 "./src/table.css" ,
17391 "./src/tailwind.css" ,
17492 "./src/title.css" ,
175- "./src/tooltips.css" ,
17693 ] ,
17794 pagination : false ,
17895 plugins : [
0 commit comments