Skip to content

Commit 693056e

Browse files
committed
Fix double-slash in crossref URLs
1 parent bb4b5a5 commit 693056e

1 file changed

Lines changed: 9 additions & 6 deletions

File tree

src/lib/utils/crossref.ts

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -18,14 +18,14 @@ let crossRefIndex: Map<string, CrossRefTarget> | null = null;
1818

1919
/**
2020
* Build the cross-reference index from all API data
21-
* Paths are stored as absolute (starting with /) for single source of truth
21+
* Paths are stored without leading slash, joined with base path at render time
2222
*/
2323
function buildCrossRefIndex(): Map<string, CrossRefTarget> {
2424
const index = new Map<string, CrossRefTarget>();
2525

2626
for (const [packageId, pkg] of Object.entries(apiData)) {
27-
// Absolute path from site root
28-
const apiPath = `/${packageId}/api`;
27+
// Path without leading slash (base path handles the prefix)
28+
const apiPath = `${packageId}/api`;
2929

3030
for (const [moduleName, module] of Object.entries(pkg.modules)) {
3131
// Add module
@@ -120,9 +120,12 @@ export function lookupRef(name: string): CrossRefTarget | undefined {
120120
export function processCrossRefs(html: string, basePath: string = '', currentPackageId?: string): string {
121121
const index = getCrossRefIndex();
122122

123-
// Helper to build full URL: basePath (deployment prefix) + path (absolute from site root)
124-
// path is already absolute like /pathsim/api#ClassName
125-
const fullPath = (path: string) => `${basePath}${path}`;
123+
// Helper to build full URL: basePath (deployment prefix) + / + path
124+
// Handles edge cases with trailing/leading slashes
125+
const fullPath = (path: string) => {
126+
const base = basePath.endsWith('/') ? basePath.slice(0, -1) : basePath;
127+
return `${base}/${path}`;
128+
};
126129

127130
// 1. Handle RST role syntax: :class:`Name`, :func:`Name`, :meth:`Name`, :mod:`Name`
128131
// These often get converted to various forms by docutils

0 commit comments

Comments
 (0)