Skip to content

Commit 1de632f

Browse files
committed
feat: enhance namespace link resolution for directories and known routes
1 parent b60961f commit 1de632f

1 file changed

Lines changed: 14 additions & 1 deletion

File tree

vue-press/src/.vuepress/plugins/package-namespace-links-plugin.ts

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -102,10 +102,12 @@ export const createNamespaceRouteMap = (
102102
.relative(repoRoot, targetPath)
103103
.split(path.sep)
104104
.join('/');
105+
// A directory with its own README publishes there; otherwise it aggregates into the
106+
// linking wrapper's own page.
105107
const targetRoute =
106108
exact[targetSource] ??
107109
(existsSync(targetPath) && statSync(targetPath).isDirectory()
108-
? wrapperRoute
110+
? (exact[`${targetSource}/README.md`] ?? wrapperRoute)
109111
: undefined);
110112
// Missing files remain visible to link validation instead of falling back to a parent page.
111113
if (!targetRoute) {
@@ -166,6 +168,17 @@ export const rewriteNamespaceHref = (
166168
if (aliasedRoute) {
167169
return `${normalizedBase}${aliasedRoute}${suffix}`;
168170
}
171+
// Hand-authored absolute links to a real page are missing only the deployment base —
172+
// VuePress treats a base-less absolute path as external regardless of its extension.
173+
const knownRoute = [
174+
publicPath,
175+
`${publicPath}.html`,
176+
publicPath.replace(/\.md$/, '.html'),
177+
`${publicPath}/`,
178+
].find((candidate) => routeMaps.sourceByRoute[candidate] !== undefined);
179+
if (knownRoute) {
180+
return `${normalizedBase}${knownRoute}${suffix}`;
181+
}
169182
const namespaceMatch = pathname.match(/(?:^|\/)(packages|cookbooks)\/(.+)$/);
170183
// Ordinary relative and external links are outside this plugin's namespace contract.
171184
if (!namespaceMatch) {

0 commit comments

Comments
 (0)