@@ -5,7 +5,28 @@ import type * as Preset from '@docusaurus/preset-classic';
5
5
import remarkGithubAdmonitionsToDirectives from "remark-github-admonitions-to-directives" ;
6
6
import path from "path" ;
7
7
import YAML from "yaml" ;
8
- import { readFileSync } from "node:fs" ;
8
+ import { existsSync , readFileSync } from "node:fs" ;
9
+ import { Tag } from "@docusaurus/utils" ;
10
+
11
+ type VariablesType = { [ key : string ] : string }
12
+ const variablesCache : { [ key : string ] : VariablesType } = { } ;
13
+
14
+ function getDocVariables ( filePath : string ) : VariablesType | null {
15
+ let vars = variablesCache [ filePath ] ;
16
+ if ( ! vars ) {
17
+ const px = filePath . match ( / ( ^ .+ \/ v e r s i o n - \d + \. \d + ) \/ / )
18
+ if ( ! px ) {
19
+ return null ;
20
+ }
21
+ const vp = path . join ( px [ 1 ] , "variables.yml" ) ;
22
+ if ( ! existsSync ( vp ) ) {
23
+ return null ;
24
+ }
25
+ vars = YAML . parse ( readFileSync ( vp , "utf-8" ) )
26
+ variablesCache [ filePath ] = vars ;
27
+ }
28
+ return vars
29
+ }
9
30
10
31
const config : Config = {
11
32
title : 'Telepresence' ,
@@ -146,10 +167,20 @@ const config: Config = {
146
167
} ,
147
168
} satisfies Preset . ThemeConfig ,
148
169
170
+ markdown : {
171
+ preprocessor ( { filePath, fileContent} ) {
172
+ const vars = getDocVariables ( filePath ) ;
173
+ return vars ? fileContent . replace ( / \$ ( \S + ) \$ / g, ( match , key ) => {
174
+ const value = vars [ key ] ;
175
+ return ( typeof value !== 'undefined' ) ? value : match ;
176
+ } ) : fileContent ;
177
+ } ,
178
+ } ,
179
+
149
180
plugins : [ "docusaurus-plugin-sass" , "./src/plugins/configure-svgo.ts" ] ,
150
181
151
182
customFields : {
152
- canonicalBaseUrl : "https://www.getambassador.io"
183
+ canonicalBaseUrl : "https://www.getambassador.io" ,
153
184
}
154
185
} ;
155
186
0 commit comments