Skip to content

Commit dabe0d5

Browse files
committed
Fix cross-reference paths to use absolute URLs from site root
1 parent 48bd558 commit dabe0d5

2 files changed

Lines changed: 18 additions & 17 deletions

File tree

src/lib/components/api/TypeRef.svelte

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
<script lang="ts">
22
import { goto } from '$app/navigation';
3+
import { base } from '$app/paths';
34
import { lookupRef } from '$lib/utils/crossref';
45
import { searchTarget } from '$lib/stores/searchNavigation';
56
@@ -52,12 +53,13 @@
5253
type: target.type as 'class' | 'function' | 'method' | 'module'
5354
});
5455
55-
goto(target.path);
56+
// target.path is absolute like /pathsim/api#ClassName, prepend base for deployment
57+
goto(`${base}${target.path}`);
5658
}
5759
</script>
5860

5961
<span class="type-ref">{#each parts as part}{#if part.isLink && part.target}<a
60-
href={part.target.path}
62+
href="{base}{part.target.path}"
6163
class="type-link"
6264
onclick={(e) => handleClick(e, part.target)}
6365
>{part.text}</a>{:else}{part.text}{/if}{/each}</span>

src/lib/utils/crossref.ts

Lines changed: 14 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -18,39 +18,40 @@ 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
2122
*/
2223
function buildCrossRefIndex(): Map<string, CrossRefTarget> {
2324
const index = new Map<string, CrossRefTarget>();
2425

2526
for (const [packageId, pkg] of Object.entries(apiData)) {
26-
const basePath = `${packageId}/api`;
27+
// Absolute path from site root
28+
const apiPath = `/${packageId}/api`;
2729

2830
for (const [moduleName, module] of Object.entries(pkg.modules)) {
2931
// Add module
30-
const moduleShortName = moduleName.split('.').pop() || moduleName;
3132
index.set(moduleName, {
3233
name: moduleName,
3334
type: 'module',
3435
packageId,
3536
moduleName,
36-
path: `${basePath}#${moduleName.replace(/\./g, '-')}`
37+
path: `${apiPath}#${moduleName.replace(/\./g, '-')}`
3738
});
3839

3940
// Add classes
4041
for (const cls of module.classes) {
4142
// Full path: pathsim.blocks.integrator.Integrator
42-
const fullPath = `${moduleName}.${cls.name}`;
43+
const fullModulePath = `${moduleName}.${cls.name}`;
4344
const target: CrossRefTarget = {
4445
name: cls.name,
4546
type: 'class',
4647
packageId,
4748
moduleName,
48-
path: `${basePath}#${cls.name}`
49+
path: `${apiPath}#${cls.name}`
4950
};
5051

5152
// Index by multiple keys for flexible lookup
5253
index.set(cls.name, target); // Just class name
53-
index.set(fullPath, target); // Full path
54+
index.set(fullModulePath, target); // Full path
5455
index.set(`${packageId}.${cls.name}`, target); // package.ClassName
5556

5657
// Add methods
@@ -63,7 +64,7 @@ function buildCrossRefIndex(): Map<string, CrossRefTarget> {
6364
packageId,
6465
moduleName,
6566
parentClass: cls.name,
66-
path: `${basePath}#${method.name}`
67+
path: `${apiPath}#${method.name}`
6768
};
6869

6970
// Index by ClassName.method_name
@@ -73,17 +74,17 @@ function buildCrossRefIndex(): Map<string, CrossRefTarget> {
7374

7475
// Add functions
7576
for (const func of module.functions) {
76-
const fullPath = `${moduleName}.${func.name}`;
77+
const fullModulePath = `${moduleName}.${func.name}`;
7778
const target: CrossRefTarget = {
7879
name: func.name,
7980
type: 'function',
8081
packageId,
8182
moduleName,
82-
path: `${basePath}#${func.name}`
83+
path: `${apiPath}#${func.name}`
8384
};
8485

8586
index.set(func.name, target);
86-
index.set(fullPath, target);
87+
index.set(fullModulePath, target);
8788
}
8889
}
8990
}
@@ -121,11 +122,9 @@ export function lookupRef(name: string): CrossRefTarget | undefined {
121122
export function processCrossRefs(html: string, basePath: string = '', currentPackageId?: string): string {
122123
const index = getCrossRefIndex();
123124

124-
// Helper to build full path with base - ensure it starts with /
125-
const fullPath = (path: string) => {
126-
const full = `${basePath}/${path}`;
127-
return full.startsWith('/') ? full : `/${full}`;
128-
};
125+
// Helper to build full URL: basePath (deployment prefix) + path (absolute from site root)
126+
// path is already absolute like /pathsim/api#ClassName
127+
const fullPath = (path: string) => `${basePath}${path}`;
129128

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

0 commit comments

Comments
 (0)