@@ -2,7 +2,7 @@ import { visit } from 'unist-util-visit'
22import { RemoteContent } from ' nextra/data'
33import { buildDynamicMDX } from ' nextra/remote'
44import { listFiles } from ' ./_meta.js'
5- import { getPageMap } from ' @/components/get-page-map '
5+ import { getPageMap } from ' @/src/getPageMap '
66
77export async function getStaticPaths() {
88 const files = await listFiles ()
@@ -18,24 +18,39 @@ export async function getStaticPaths() {
1818export async function getStaticProps({ params : { slug = [' README' ] } }) {
1919 const baseURL = ' https://raw.githubusercontent.com/streamingfast/substreams/develop/docs/'
2020 const paths = slug .join (' /' )
21- let response = await fetch (` ${baseURL }${paths }.md ` )
21+ let fileURL = ` ${paths }.md `
22+ let response = await fetch (baseURL + fileURL )
2223 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 )
2426 }
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>' , ' ```' )
2647 const mdx = await buildDynamicMDX (data , {
2748 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' ,
2951 remarkPlugins: [
3052 () => (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
3954 visit (tree , ' link' , (node ) => {
4055 if (node .url .startsWith (' ./' )) {
4156 node .url = node .url .slice (2 )
@@ -59,6 +74,7 @@ export async function getStaticProps({ params: { slug = ['README'] } }) {
5974 ... mdx ,
6075 __nextra_pageMap: await getPageMap (' en' ),
6176 hideLocaleSwitcher: true ,
77+ remoteFilePath: ` https://github.com/streamingfast/substreams/tree/develop/docs/${fileURL } ` ,
6278 },
6379 }
6480}
0 commit comments