
website: Copy files during build. website: Allow for mixed env builds. website: Reduce build size. website: Expose build. website: Add build memory debugging. WIP: Disable broken links check to compare memory usage. website: Update deps. website: Clean up API paths. website: Flesh out 3.8 fixes. Format. website: Update ignore paths. Website: Clean up integrations build. website: Fix paths. website: Optimize remark. website: Update deps. website: Format. website: Remove linking. website: Fix paths. wip: Attempt API only build. Prep. Migrate render to runtime. Tidy sidebar. Clean up templates. docs: Move directory. WIP docs: Flesh out split. website: Fix issue where routes have collisions.
36 lines
966 B
JavaScript
36 lines
966 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;
|