mirror of
https://github.com/goauthentik/authentik
synced 2026-04-27 09:57:31 +02:00
* website: Flesh out version picker. Port 3.8 theme. * website: Update Dockerfile to include compose. * website: Flesh out branch override. Tidy list items.
37 lines
967 B
JavaScript
37 lines
967 B
JavaScript
/**
|
|
* @import { Root } from "mdast";
|
|
*/
|
|
|
|
import { SKIP, visit } from "unist-util-visit";
|
|
|
|
/**
|
|
* @typedef {[pattern: string | RegExp, replacement: string]} Rewrite
|
|
*/
|
|
|
|
/**
|
|
* Remark plugin to transform relative links to docs to absolute URLs
|
|
* @param {Iterable<[string, string]>} rewrites Map of urls to rewrite where the key is the prefix to check for and the value is the domain to add
|
|
*/
|
|
export function remarkLinkRewrite(rewrites) {
|
|
const map = new Map(rewrites);
|
|
|
|
return () => {
|
|
/**
|
|
* @param {Root} tree The MDAST tree to transform.
|
|
*/
|
|
return (tree) => {
|
|
visit(tree, "link", (node) => {
|
|
for (const [pattern, replacement] of map) {
|
|
if (!node.url.startsWith(pattern)) continue;
|
|
|
|
node.url = node.url.replace(pattern, replacement);
|
|
}
|
|
|
|
return SKIP;
|
|
});
|
|
};
|
|
};
|
|
}
|
|
|
|
export default remarkLinkRewrite;
|