Skip to content

Commit

Permalink
Fix broken download links.
Browse files Browse the repository at this point in the history
Signed-off-by: Thomas Hallgren <thomas@tada.se>
  • Loading branch information
thallgren committed Oct 1, 2024
1 parent 47e216f commit 03a81cb
Show file tree
Hide file tree
Showing 4 changed files with 38 additions and 4 deletions.
35 changes: 33 additions & 2 deletions docusaurus.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,28 @@ import type * as Preset from '@docusaurus/preset-classic';
import remarkGithubAdmonitionsToDirectives from "remark-github-admonitions-to-directives";
import path from "path";
import YAML from "yaml";
import {readFileSync} from "node:fs";
import {existsSync, readFileSync} from "node:fs";
import {Tag} from "@docusaurus/utils";

type VariablesType = { [key: string]: string }
const variablesCache: { [key: string]: VariablesType } = {};

function getDocVariables(filePath: string): VariablesType|null {
let vars = variablesCache[filePath];
if (!vars) {
const px = filePath.match(/(^.+\/version-\d+\.\d+)\//)
if (!px) {
return null;
}
const vp = path.join(px[1], "variables.yml");
if (!existsSync(vp)) {
return null;
}
vars = YAML.parse(readFileSync(vp, "utf-8"))
variablesCache[filePath] = vars;
}
return vars
}

const config: Config = {
title: 'Telepresence',
Expand Down Expand Up @@ -146,10 +167,20 @@ const config: Config = {
},
} satisfies Preset.ThemeConfig,

markdown: {
preprocessor({filePath, fileContent}) {
const vars = getDocVariables(filePath);
return vars? fileContent.replace(/\$(\S+)\$/g, (match, key) => {
const value = vars[key];
return (typeof value !== 'undefined') ? value : match;
}): fileContent;
},
},

plugins: ["docusaurus-plugin-sass", "./src/plugins/configure-svgo.ts"],

customFields: {
canonicalBaseUrl: "https://www.getambassador.io"
canonicalBaseUrl: "https://www.getambassador.io",
}
};

Expand Down
5 changes: 4 additions & 1 deletion src/theme/DocItem/Metadata/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,16 @@ import type {WrapperProps} from '@docusaurus/types';
import useDocusaurusContext from '@docusaurus/useDocusaurusContext';
import Head from "@docusaurus/Head";
import {useLocation} from "@docusaurus/router";
import {useDoc} from '@docusaurus/plugin-content-docs/client';

type Props = WrapperProps<typeof MetadataType>;

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

return (
<>
Expand Down
2 changes: 1 addition & 1 deletion tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,5 +8,5 @@
"plugins": [{ "name": "typescript-plugin-css-modules" }],
"types": ["docusaurus-plugin-sass"]
},
"include": ["sidebars.ts", "docusaurus.config.ts", "src/components", "src/plugin", "src/theme", "src/custom.d.ts"]
"include": ["sidebars.ts", "docusaurus.config.ts", "src"]
}
File renamed without changes.

0 comments on commit 03a81cb

Please sign in to comment.