Skip to content

Commit 03a81cb

Browse files
committed
Fix broken download links.
Signed-off-by: Thomas Hallgren <thomas@tada.se>
1 parent 47e216f commit 03a81cb

File tree

4 files changed

+38
-4
lines changed

4 files changed

+38
-4
lines changed

docusaurus.config.ts

Lines changed: 33 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,28 @@ import type * as Preset from '@docusaurus/preset-classic';
55
import remarkGithubAdmonitionsToDirectives from "remark-github-admonitions-to-directives";
66
import path from "path";
77
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(/(^.+\/version-\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+
}
930

1031
const config: Config = {
1132
title: 'Telepresence',
@@ -146,10 +167,20 @@ const config: Config = {
146167
},
147168
} satisfies Preset.ThemeConfig,
148169

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+
149180
plugins: ["docusaurus-plugin-sass", "./src/plugins/configure-svgo.ts"],
150181

151182
customFields: {
152-
canonicalBaseUrl: "https://www.getambassador.io"
183+
canonicalBaseUrl: "https://www.getambassador.io",
153184
}
154185
};
155186

src/theme/DocItem/Metadata/index.tsx

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,13 +5,16 @@ import type {WrapperProps} from '@docusaurus/types';
55
import useDocusaurusContext from '@docusaurus/useDocusaurusContext';
66
import Head from "@docusaurus/Head";
77
import {useLocation} from "@docusaurus/router";
8+
import {useDoc} from '@docusaurus/plugin-content-docs/client';
89

910
type Props = WrapperProps<typeof MetadataType>;
1011

1112
export default function MetadataWrapper(props: Props): JSX.Element {
1213
const { siteConfig: {customFields}} = useDocusaurusContext()
1314
const { pathname } = useLocation();
14-
const canonical = `${customFields['canonicalBaseUrl']}${pathname}`
15+
const { metadata } = useDoc();
16+
const vpath = pathname.replace(/^\/docs\//, `/docs/telepresence/${metadata.version}/`)
17+
const canonical = `${customFields['canonicalBaseUrl']}${vpath}`
1518

1619
return (
1720
<>

tsconfig.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,5 +8,5 @@
88
"plugins": [{ "name": "typescript-plugin-css-modules" }],
99
"types": ["docusaurus-plugin-sass"]
1010
},
11-
"include": ["sidebars.ts", "docusaurus.config.ts", "src/components", "src/plugin", "src/theme", "src/custom.d.ts"]
11+
"include": ["sidebars.ts", "docusaurus.config.ts", "src"]
1212
}
File renamed without changes.

0 commit comments

Comments
 (0)