@@ -2,6 +2,7 @@ import { RemoteContent } from 'nextra/data'
2
2
import { buildDynamicMDX } from ' nextra/remote'
3
3
import { getPageMap } from ' @/src/getPageMap'
4
4
import { remarkReplaceLinks } from ' @/src/remarkReplaceLinks'
5
+ import { replaceGitBookContent } from ' @/src/replaceGitBookContent'
5
6
import json from ' @/remote-files/substreams.json'
6
7
7
8
export const getStaticPaths = () => ({
@@ -19,32 +20,25 @@ export async function getStaticProps({ params }) {
19
20
const foundPath = filePaths .find ((filePath ) => filePath .startsWith (paths ))
20
21
const baseURL = ` https://raw.githubusercontent.com/${user }/${repo }/${branch }/${docsPath }${foundPath } `
21
22
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
+ )
48
42
return {
49
43
props: {
50
44
... mdx ,
0 commit comments