@@ -2,6 +2,7 @@ import { RemoteContent } from 'nextra/data'
22import { buildDynamicMDX } from ' nextra/remote'
33import { getPageMap } from ' @/src/getPageMap'
44import { remarkReplaceLinks } from ' @/src/remarkReplaceLinks'
5+ import { replaceGitBookContent } from ' @/src/replaceGitBookContent'
56import json from ' @/remote-files/substreams.json'
67
78export const getStaticPaths = () => ({
@@ -19,32 +20,25 @@ export async function getStaticProps({ params }) {
1920 const foundPath = filePaths .find ((filePath ) => filePath .startsWith (paths ))
2021 const baseURL = ` https://raw.githubusercontent.com/${user }/${repo }/${branch }/${docsPath }${foundPath } `
2122 const response = await fetch (baseURL )
22- const data = (await response .text ())
23- // replace {% embed ... %} with <iframe />
24- .replaceAll (
25- / {%\s + embed\s + url="(. *? )"\s + %}/ g ,
26- (... m ) =>
27- ` <iframe src="${m [1 ].replace (
28- // we need enhance YouTube links, otherwise they will be not loaded in iframe
29- ' youtube.com/watch?v=' ,
30- ' youtube.com/embed/'
31- )}" style={{aspectRatio: 16/9, width: '100%'}}/> `
32- )
33- // remove gitbook {% ... %} elements
34- .replaceAll (/ {%. *? %}/ g , ' ' )
35- // close unclosed img tags
36- .replaceAll (/ <img((?:(?!\/ >)[^ >] )*? )>/ g , (... m ) => ` <img${m [1 ]}/> ` )
37- // fix gitbook image srcs
38- .replaceAll (/ src="[^ >"] * \. gitbook\/ (. * )"/ g , (... m ) => ` src="${baseURL }.gitbook/${m [1 ]}" ` )
39- const mdx = await buildDynamicMDX (data , {
40- mdxOptions: {
41- // change-log contains `{variable}` text that is thrown an error by MDX2 parser since he treats
42- // it as variable injection, to fix it we parse chang-log with the Markdown parser
43- format: paths .endsWith (' /change-log' ) ? ' md' : ' mdx' ,
44- remarkPlugins: [[remarkReplaceLinks , { foundPath , basePath: ' /substreams/' }]],
45- },
46- codeHighlight: false ,
47- })
23+ const content = await response .text ()
24+ const mdx = await buildDynamicMDX (
25+ replaceGitBookContent ({
26+ content ,
27+ user ,
28+ repo ,
29+ branch ,
30+ docsPath ,
31+ }),
32+ {
33+ mdxOptions: {
34+ // change-log contains `{variable}` text that is thrown an error by MDX2 parser since he treats
35+ // it as variable injection, to fix it we parse chang-log with the Markdown parser
36+ format: paths .endsWith (' /change-log' ) ? ' md' : ' mdx' ,
37+ remarkPlugins: [[remarkReplaceLinks , { foundPath , basePath: ' /substreams/' }]],
38+ },
39+ codeHighlight: false ,
40+ }
41+ )
4842 return {
4943 props: {
5044 ... mdx ,
0 commit comments