Skip to content

Commit 309f603

Browse files
committed
Route assets and counters through useBaseUrl for preview deploy compatibility
Components and pages hardcoded /RMC-Software-Documentation/ for figure/video src paths, counter JSON fetches, bibliography lookups, and version metadata. Under PR preview builds the active baseUrl differs, so those requests resolved against the production deploy instead — breaking new figures, captions, cross-references, and citations on preview builds. React components and pages now use useBaseUrl(); the analyticsEvents client module uses siteConfig.baseUrl from @generated/docusaurus.config.
1 parent 00ba013 commit 309f603

30 files changed

Lines changed: 131 additions & 83 deletions

src/clientModules/analyticsEvents.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,9 @@
1010
* search_query — when a user searches via Algolia DocSearch
1111
*/
1212

13-
const BASE_PATH = '/RMC-Software-Documentation/';
13+
import siteConfig from '@generated/docusaurus.config';
14+
15+
const BASE_PATH = siteConfig.baseUrl;
1416

1517
// ── Latest versions cache ───────────────────────────────────────────
1618

src/components/Bibliography.js

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,21 @@
11
import React, { useState, useEffect } from "react";
22
import { useLocation } from "@docusaurus/router";
3+
import useBaseUrl from "@docusaurus/useBaseUrl";
34
import { useReportId } from "../contexts/ReportIdContext";
45

56
const Bibliography = () => {
67
const [citations, setCitations] = useState([]);
78
const location = useLocation();
89
const reportId = useReportId ? useReportId() : null;
10+
const docsBase = useBaseUrl("docs/");
11+
const bibsBase = useBaseUrl("bibliographies/");
12+
const countersBase = useBaseUrl("counters/");
913

1014
// Extract the current path from the URL
1115
const pathname = location.pathname;
12-
const reportPath = pathname.replace(/^\/RMC-Software-Documentation\/docs\//, "/RMC-Software-Documentation/bibliographies/").replace(/\/[^/]*$/, "");
16+
const reportPath = pathname.replace(docsBase, bibsBase).replace(/\/[^/]*$/, "");
1317
const bibFilePath = `${reportPath}/bib.json`;
14-
const countersFilePath = reportId ? `/RMC-Software-Documentation/counters/${reportId}.json` : null;
18+
const countersFilePath = reportId ? `${countersBase}${reportId}.json` : null;
1519

1620
useEffect(() => {
1721
let isMounted = true;

src/components/Citation.js

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import { useLocation } from '@docusaurus/router';
2+
import useBaseUrl from '@docusaurus/useBaseUrl';
23
import { useEffect, useState, useSyncExternalStore } from 'react';
34
import { useReportId } from '../contexts/ReportIdContext';
45
import '../css/custom.css';
@@ -70,14 +71,13 @@ const Citation = ({ citationKey }) => {
7071
const location = useLocation();
7172
const pathname = location.pathname; // treat as docId
7273
const reportId = useReportId ? useReportId() : null;
74+
const docsBase = useBaseUrl('docs/');
75+
const bibsBase = useBaseUrl('bibliographies/');
76+
const countersBase = useBaseUrl('counters/');
7377

74-
const reportPath = pathname
75-
.replace(/^\/RMC-Software-Documentation\/docs\//, '/RMC-Software-Documentation/bibliographies/')
76-
.replace(/\/[^/]*$/, '');
78+
const reportPath = pathname.replace(docsBase, bibsBase).replace(/\/[^/]*$/, '');
7779
const bibFilePath = `${reportPath}/bib.json`;
78-
const countersFilePath = reportId
79-
? `/RMC-Software-Documentation/counters/${reportId}.json`
80-
: null;
80+
const countersFilePath = reportId ? `${countersBase}${reportId}.json` : null;
8181

8282
// Number comes from counters (original logic)
8383
useEffect(() => {

src/components/CitationFootnote.js

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import React, { useState, useEffect } from "react";
22
import { useUsedCitations } from "./Citation";
33
import { useLocation } from "@docusaurus/router";
4+
import useBaseUrl from "@docusaurus/useBaseUrl";
45
import { useReportId } from "../contexts/ReportIdContext";
56
import "../css/custom.css";
67

@@ -9,10 +10,13 @@ const CitationFootnote = () => {
910
const location = useLocation();
1011
const pathname = location.pathname; // docId
1112
const reportId = useReportId ? useReportId() : null;
13+
const docsBase = useBaseUrl("docs/");
14+
const bibsBase = useBaseUrl("bibliographies/");
15+
const countersBase = useBaseUrl("counters/");
1216

13-
const reportPath = pathname.replace(/^\/RMC-Software-Documentation\/docs\//, "/RMC-Software-Documentation/bibliographies/").replace(/\/[^/]*$/, "");
17+
const reportPath = pathname.replace(docsBase, bibsBase).replace(/\/[^/]*$/, "");
1418
const bibFilePath = `${reportPath}/bib.json`;
15-
const countersFilePath = reportId ? `/RMC-Software-Documentation/counters/${reportId}.json` : null;
19+
const countersFilePath = reportId ? `${countersBase}${reportId}.json` : null;
1620

1721
// Subscribe to per-page used keys (for filtering to only those used here)
1822
const usedKeys = useUsedCitations(pathname);

src/components/Equation.js

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import useBaseUrl from '@docusaurus/useBaseUrl';
12
import 'katex/dist/katex.min.css';
23
import { useCallback, useEffect, useRef, useState } from 'react';
34
import { BlockMath, InlineMath } from 'react-katex';
@@ -10,10 +11,11 @@ const Equation = ({ equationKey, equation, inline = false, id }) => {
1011
const reportId = useReportId();
1112
const equationId = id || equationKey;
1213
const mathRef = useRef(null);
14+
const countersBase = useBaseUrl('counters/');
1315

1416
useEffect(() => {
1517
if (!reportId) return;
16-
const jsonPath = `/RMC-Software-Documentation/counters/${reportId}.json`;
18+
const jsonPath = `${countersBase}${reportId}.json`;
1719
(async () => {
1820
try {
1921
const res = await fetch(jsonPath);
@@ -26,7 +28,7 @@ const Equation = ({ equationKey, equation, inline = false, id }) => {
2628
console.error('Error loading counters:', e);
2729
}
2830
})();
29-
}, [reportId, equationKey]);
31+
}, [reportId, equationKey, countersBase]);
3032

3133
const scaleEquation = useCallback(() => {
3234
const wrapper = mathRef.current;

src/components/EquationReference.js

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,19 @@
1+
import useBaseUrl from '@docusaurus/useBaseUrl';
12
import { useEffect, useMemo, useState } from 'react';
23
import { useReportId } from '../contexts/ReportIdContext';
34
import '../css/custom.css';
45

5-
const STATIC_BASE = '/RMC-Software-Documentation';
6-
const DOCS_ROUTE_BASE = '/RMC-Software-Documentation/docs';
7-
86
const toDocSlug = (docId = '') => docId.replace(/\.mdx$/i, '').replace(/^\d{1,3}-/, '');
97

108
const EquationReference = ({ equationKey }) => {
119
const [equationInfo, setEquationInfo] = useState(null);
1210
const reportId = useReportId();
11+
const countersBase = useBaseUrl('counters/');
12+
const docsRouteBase = useBaseUrl('docs');
1313

1414
useEffect(() => {
1515
if (!reportId) return;
16-
const jsonPath = `${STATIC_BASE}/counters/${reportId}.json`;
16+
const jsonPath = `${countersBase}${reportId}.json`;
1717
(async () => {
1818
try {
1919
const res = await fetch(jsonPath);
@@ -26,16 +26,16 @@ const EquationReference = ({ equationKey }) => {
2626
console.error('Error loading counters:', e);
2727
}
2828
})();
29-
}, [reportId, equationKey]);
29+
}, [reportId, equationKey, countersBase]);
3030

3131
const targetId = equationKey;
3232

3333
const docSlug = useMemo(() => toDocSlug(equationInfo?.docId), [equationInfo?.docId]);
3434

3535
const targetDocPath = useMemo(() => {
3636
if (!equationInfo?.parentDocPath || !docSlug) return '';
37-
return `${DOCS_ROUTE_BASE}/${equationInfo.parentDocPath}/${docSlug}`;
38-
}, [equationInfo?.parentDocPath, docSlug]);
37+
return `${docsRouteBase}/${equationInfo.parentDocPath}/${docSlug}`;
38+
}, [equationInfo?.parentDocPath, docSlug, docsRouteBase]);
3939

4040
const isSamePage = useMemo(() => {
4141
const normalize = (p) => (p?.endsWith('/') ? p.slice(0, -1) : p || '');

src/components/Figure.js

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import useBaseUrl from '@docusaurus/useBaseUrl';
12
import { useEffect, useState } from 'react';
23
import { useReportId } from '../contexts/ReportIdContext'; // Import the context hook to retrieve the reportId
34
import imageDimensions from '../imageDimensions';
@@ -6,6 +7,8 @@ import '../css/custom.css';
67
const Figure = ({ figKey, src, alt, caption, width = '80%', background = 'filled', id }) => {
78
const [figInfo, setFigInfo] = useState(null);
89
const reportId = useReportId(); // Get the reportId from the context
10+
const imgUrl = useBaseUrl(src);
11+
const countersBase = useBaseUrl('counters/');
912

1013
// If id is not passed, fall back to figKey
1114
const figureId = id || figKey;
@@ -17,7 +20,7 @@ const Figure = ({ figKey, src, alt, caption, width = '80%', background = 'filled
1720
useEffect(() => {
1821
if (!reportId) return; // If reportId is not available, don't fetch
1922

20-
const jsonPath = `/RMC-Software-Documentation/counters/${reportId}.json`; // Use reportId to determine the path
23+
const jsonPath = `${countersBase}${reportId}.json`;
2124

2225
const loadCounters = async () => {
2326
try {
@@ -43,13 +46,13 @@ const Figure = ({ figKey, src, alt, caption, width = '80%', background = 'filled
4346
};
4447

4548
loadCounters();
46-
}, [reportId, figKey]);
49+
}, [reportId, figKey, countersBase]);
4750

4851
const imgBgClass = background === 'transparent' ? '' : 'bg-surface-page dark:bg-white';
4952

5053
return (
5154
<figure id={figureId} className="my-[1em] ml-0 mr-auto w-full justify-items-start border-y border-border-color py-5">
52-
<img src={`/RMC-Software-Documentation/${src}`} alt={alt} className={`block h-auto ${imgBgClass}`} style={{ maxWidth: width }} width={dims?.width} height={dims?.height} />
55+
<img src={imgUrl} alt={alt} className={`block h-auto ${imgBgClass}`} style={{ maxWidth: width }} width={dims?.width} height={dims?.height} />
5356
<figcaption className="mt-[1em] max-w-full text-left font-usace text-caption italic text-gray-500 dark:text-gray-400">
5457
{figInfo ? `Figure ${figInfo.figNumber}` : 'Figure'}: {caption}
5558
</figcaption>

src/components/FigureInline.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
1+
import useBaseUrl from "@docusaurus/useBaseUrl";
12
import React from "react";
23
import "../css/custom.css";
34

45
const FigureInline = ({ src }) => {
5-
const imgSrc = `/RMC-Software-Documentation/${src}`;
6+
const imgSrc = useBaseUrl(src);
67

78
return <img src={imgSrc} className="inline-block !h-[1em] !w-auto align-middle" />;
89
};

src/components/FigureNoRef.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import useBaseUrl from '@docusaurus/useBaseUrl';
12
import imageDimensions from '../imageDimensions';
23
import '../css/custom.css';
34

@@ -6,11 +7,12 @@ const FigureNoRef = ({ src, alt, width = '80%', background = 'filled' }) => {
67

78
const normalizedSrc = src.replace(/^\//, '');
89
const dims = imageDimensions[normalizedSrc];
10+
const imgUrl = useBaseUrl(src);
911

1012
return (
1113
<figure className="my-[1em] ml-0 mr-auto w-full justify-items-start border-y border-border-color py-5">
1214
<img
13-
src={`/RMC-Software-Documentation/${src}`}
15+
src={imgUrl}
1416
alt={alt}
1517
className={`block h-auto ${imgBgClass}`}
1618
style={{ maxWidth: width }}

src/components/FigureReference.js

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,8 @@
1+
import useBaseUrl from '@docusaurus/useBaseUrl';
12
import { useCallback, useEffect, useMemo, useRef, useState } from 'react';
23
import { useReportId } from '../contexts/ReportIdContext';
34
import '../css/custom.css';
45

5-
const STATIC_BASE = '/RMC-Software-Documentation'; // for /static assets like /counters
6-
const DOCS_ROUTE_BASE = '/RMC-Software-Documentation/docs'; // for doc pages
7-
86
// strip ".mdx" and any leading "digits-" prefix (e.g., "05-schmertmann" -> "schmertmann")
97
const toDocSlug = (docId = '') => docId.replace(/\.mdx$/i, '').replace(/^\d{1,3}-/, '');
108

@@ -17,10 +15,13 @@ const FigReference = ({ figKey, suffix }) => {
1715
const reportId = useReportId();
1816
const showTimer = useRef(null);
1917
const hideTimer = useRef(null);
18+
const countersBase = useBaseUrl('counters/');
19+
const staticBase = useBaseUrl('/');
20+
const docsRouteBase = useBaseUrl('docs');
2021

2122
useEffect(() => {
2223
if (!reportId) return;
23-
const jsonPath = `${STATIC_BASE}/counters/${reportId}.json`;
24+
const jsonPath = `${countersBase}${reportId}.json`;
2425
(async () => {
2526
try {
2627
const res = await fetch(jsonPath);
@@ -33,16 +34,16 @@ const FigReference = ({ figKey, suffix }) => {
3334
console.error('Error loading counters:', e);
3435
}
3536
})();
36-
}, [reportId, figKey]);
37+
}, [reportId, figKey, countersBase]);
3738

3839
const targetId = figKey;
3940

4041
const docSlug = useMemo(() => toDocSlug(figInfo?.docId), [figInfo?.docId]);
4142

4243
const targetDocPath = useMemo(() => {
4344
if (!figInfo?.parentDocPath || !docSlug) return '';
44-
return `${DOCS_ROUTE_BASE}/${figInfo.parentDocPath}/${docSlug}`;
45-
}, [figInfo?.parentDocPath, docSlug]);
45+
return `${docsRouteBase}/${figInfo.parentDocPath}/${docSlug}`;
46+
}, [figInfo?.parentDocPath, docSlug, docsRouteBase]);
4647

4748
const isSamePage = useMemo(() => {
4849
const normalize = (p) => (p?.endsWith('/') ? p.slice(0, -1) : p || '');
@@ -75,7 +76,7 @@ const FigReference = ({ figKey, suffix }) => {
7576

7677
if (!figInfo) return <span className="font-usace text-normal whitespace-nowrap">Figure</span>;
7778

78-
const imgSrc = figInfo.src ? `${STATIC_BASE}/${figInfo.src}` : '';
79+
const imgSrc = figInfo.src ? `${staticBase}${figInfo.src.replace(/^\//, '')}` : '';
7980

8081
return (
8182
<span className="relative inline whitespace-nowrap" onMouseEnter={handleEnter} onMouseLeave={handleLeave}>

0 commit comments

Comments
 (0)