1
1
import BrowserOnly from '@docusaurus/BrowserOnly' ;
2
2
import React , { useEffect , useRef , useState } from 'react' ;
3
3
import './cai-addon.css' ;
4
- const referenceCAI = require ( '!!raw-loader!./reference-cai.html' ) ?. default ;
5
4
6
- const ManifestReference = ( ) => {
5
+ // Import all possible HTML files statically
6
+ const htmlFiles = {
7
+ './reference-cai.html' : require ( '!!raw-loader!./reference-cai.html' ) ?. default ,
8
+ // Add other HTML files here as needed
9
+ } ;
10
+
11
+ const ManifestReference = ( { htmlPath } ) => {
7
12
const myRef = useRef ( null ) ;
8
13
const [ refAquired , setRefAquired ] = useState ( false ) ;
14
+ const [ htmlContent , setHtmlContent ] = useState ( '' ) ;
15
+
9
16
useEffect ( ( ) => {
10
17
setRefAquired ( true ) ;
11
18
} , [ ] ) ;
12
19
20
+ useEffect ( ( ) => {
21
+ // Get the HTML content from our static imports
22
+ const content = htmlFiles [ htmlPath ] ;
23
+ if ( content ) {
24
+ setHtmlContent ( content ) ;
25
+ } else {
26
+ console . error ( `HTML file not found: ${ htmlPath } ` ) ;
27
+ setHtmlContent ( '<div>Error: HTML file not found</div>' ) ;
28
+ }
29
+ } , [ htmlPath ] ) ;
30
+
13
31
useEffect ( ( ) => {
14
32
if ( myRef . current ) {
15
33
for ( const link of myRef . current . querySelectorAll ( 'a' ) ) {
@@ -21,12 +39,12 @@ const ManifestReference = () => {
21
39
}
22
40
}
23
41
}
24
- } , [ refAquired ] ) ;
42
+ } , [ refAquired , htmlContent ] ) ;
25
43
26
44
return (
27
45
< BrowserOnly >
28
46
{ ( ) => (
29
- < div ref = { myRef } dangerouslySetInnerHTML = { { __html : referenceCAI } } />
47
+ < div ref = { myRef } dangerouslySetInnerHTML = { { __html : htmlContent } } />
30
48
) }
31
49
</ BrowserOnly >
32
50
) ;
0 commit comments