1+ import useBaseUrl from '@docusaurus/useBaseUrl' ;
12import { useCallback , useEffect , useMemo , useRef , useState } from 'react' ;
23import { useReportId } from '../contexts/ReportIdContext' ;
34import '../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")
97const toDocSlug = ( docId = '' ) => docId . replace ( / \. m d x $ / 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