docs-site: fix link migration

This commit is contained in:
Glen Huang
2025-10-10 15:27:06 +08:00
parent 8779dc07f0
commit 2f05eccace
2 changed files with 4 additions and 2 deletions

View File

@@ -18,6 +18,7 @@ import transformerLineNumbers from "./shiki-transformer-line-numbers";
import remarkParse from "./remark-parse";
import remarkAdmonition from "./remark-admonition";
import rehypeWrapHeadings from "./rehype-wrap-headings";
import remarkLinkMigration from "./link-migration";
export type Options = {
codeLightTheme?: string;
@@ -39,6 +40,7 @@ export default function ({
const file = await unified()
.use(remarkParse)
.use(remarkLinkMigration)
.use(remarkGfm)
.use(remarkDirective)
.use(remarkAdmonition)

View File

@@ -6,7 +6,7 @@ import type { Nodes } from "mdast";
*
* For this to work the relative link must start at the docs root
*/
export default function linkMigration() {
export default function remarkLinkMigration() {
return (tree: Nodes) => {
visit(tree, ["link", "definition"], (node) => {
if (node.type !== "link" && node.type !== "definition") {
@@ -20,7 +20,7 @@ export default function linkMigration() {
if (!cleanUrl.startsWith("/")) {
throw new Error(`invalid doc link: ${cleanUrl}`);
}
node.url = `/docs/${cleanUrl}`;
node.url = `/docs${cleanUrl}`;
});
};
}