Resolve links
Rewrites internal link targets using the content source map so links survive the build.
ResolveLinksPlugin normalises internal Markdown links ([text](., [text](../other/page)) using the content source map built at startup. It is opt-in — see Config below to enable it.
What it does
During the mdast phase, before any HTML is produced, the plugin walks every Link node. For each relative link:
Resolves the path relative to the current source file.
Looks up the resolved path in the content source map.
If found, rewrites the
urlto the final output URL for that entry.If not found, emits a warning diagnostic and leaves the link unchanged.
This ensures that link targets written as relative file paths (the natural way to cross-link content while editing locally) produce correct output URLs in the built site, regardless of how the file-to-URL mapping is configured.
Config
Link resolution does nothing unless you opt in with resolveMarkdownLinks: { enabled: true } in zfb.config.ts:
export default defineConfig({
resolveMarkdownLinks: {
enabled: true,
docsDir: "src/content/docs",
},
});| Option | Default | Description |
|---|---|---|
enabled | false | Turns the plugin on. Every other option below has no effect until this is true. |
docsDir | "" | Legacy single-dir shape — scans this directory against the hard-coded / route prefix. Ignored when dirs is non-empty. |
dirs | [] | Explicit { dir, routePrefix } entries, one per source collection. Takes precedence over docsDir when non-empty — required for projects with more than one docs root (e.g. locale mirrors), since docsDir can only represent a single / prefix. |
onBrokenLinks | "warn" | What happens when a .md/.mdx link can't be resolved: "warn" logs and continues, "error" fails the build after reporting every broken link found during the walk, "ignore" does neither. |
For a project with more than one docs collection (e.g. EN + JA), use dirs so each collection maps to its own route prefix:
export default defineConfig({
resolveMarkdownLinks: {
enabled: true,
dirs: [
{ dir: "src/content/docs", routePrefix: "/docs/" },
{ dir: "src/content/docs-ja", routePrefix: "/ja/docs/" },
],
},
});See also
Link validation — opt-in plugin that treats broken internal links as hard build errors.
External links — companion Core plugin for outbound links.