@@ -2,7 +2,7 @@ import { visit } from 'unist-util-visit'
2
2
import { RemoteContent } from ' nextra/data'
3
3
import { buildDynamicMDX } from ' nextra/remote'
4
4
import { listFiles } from ' ./_meta.js'
5
- import { getPageMap } from ' @/components/get-page-map '
5
+ import { getPageMap } from ' @/src/getPageMap '
6
6
7
7
export async function getStaticPaths() {
8
8
const files = await listFiles ()
@@ -18,24 +18,39 @@ export async function getStaticPaths() {
18
18
export async function getStaticProps({ params : { slug = [' README' ] } }) {
19
19
const baseURL = ' https://raw.githubusercontent.com/streamingfast/substreams/develop/docs/'
20
20
const paths = slug .join (' /' )
21
- let response = await fetch (` ${baseURL }${paths }.md ` )
21
+ let fileURL = ` ${paths }.md `
22
+ let response = await fetch (baseURL + fileURL )
22
23
if (response .status === 404 && paths !== ' README' ) {
23
- response = await fetch (` ${baseURL }${paths }/README.md ` )
24
+ fileURL = ` $${paths }/README.md `
25
+ response = await fetch (baseURL + fileURL )
24
26
}
25
- const data = await response .text ()
27
+ const data = (await response .text ())
28
+ // replace {% embed ... %} with <iframe />
29
+ .replaceAll (
30
+ / {%\s + embed\s + url="(. *? )"\s + %}/ g ,
31
+ (... m ) =>
32
+ ` <iframe src="${m [1 ].replace (
33
+ // we need enhance YouTube links, otherwise they will be not loaded in iframe
34
+ ' youtube.com/watch?v=' ,
35
+ ' youtube.com/embed/'
36
+ )}" style={{aspectRatio: 16/9, width: '100%'}}/> `
37
+ )
38
+ // remove gitbook {% ... %} elements
39
+ .replaceAll (/ {%. *? %}/ g , ' ' )
40
+ // close img tags only if he doesn't point to .gitbook
41
+ .replaceAll (/ <img(. *? )>/ g , (... m ) => (m [1 ].includes (' src=".gitbook' ) ? ' ' : ` <img${m [1 ]}/> ` ))
42
+ // fixes http://localhost:3000/en/substreams/reference-and-specs/authentication/
43
+ .replaceAll (' <pre class="language-bash" data-overflow="wrap"><code class="lang-bash">' , ' ```bash\n ' )
44
+ // fixes http://localhost:3000/en/substreams/developers-guide/modules/inputs/
45
+ .replaceAll (' <pre class="language-yaml" data-title="manifest excerpt"><code class="lang-yaml">' , ' ```yaml\n ' )
46
+ .replaceAll (' </code></pre>' , ' ```' )
26
47
const mdx = await buildDynamicMDX (data , {
27
48
mdxOptions: {
28
- format: ' md' ,
49
+ // change-log contains `{variable}` text that is thrown an error by MDX2 parser since he treat it as variable injection, to fix it we parse chang-log with the markdown parser
50
+ format: paths .endsWith (' /change-log' ) ? ' md' : ' mdx' ,
29
51
remarkPlugins: [
30
52
() => (tree , _file , done ) => {
31
- const GITBOOK_CALLOUT_REGEX = / {%. *? %}/
32
- visit (tree , ' paragraph' , (node ) => {
33
- for (const child of node .children ) {
34
- if (child .value ) {
35
- child .value = child .value .replace (GITBOOK_CALLOUT_REGEX , ' ' )
36
- }
37
- }
38
- })
53
+ // enhance links
39
54
visit (tree , ' link' , (node ) => {
40
55
if (node .url .startsWith (' ./' )) {
41
56
node .url = node .url .slice (2 )
@@ -59,6 +74,7 @@ export async function getStaticProps({ params: { slug = ['README'] } }) {
59
74
... mdx ,
60
75
__nextra_pageMap: await getPageMap (' en' ),
61
76
hideLocaleSwitcher: true ,
77
+ remoteFilePath: ` https://github.com/streamingfast/substreams/tree/develop/docs/${fileURL } ` ,
62
78
},
63
79
}
64
80
}
0 commit comments