Skip to content

Commit 1243ba9

Browse files
Dimitri POSTOLOVbenface
andauthored
add Graph Client README.md doc + fix network diagram for substreams/README (#408)
Co-authored-by: Benoît Rouleau <benoit.rouleau@icloud.com>
1 parent 0ca85bc commit 1243ba9

File tree

6 files changed

+88
-50
lines changed

6 files changed

+88
-50
lines changed

website/pages/en/firehose/[[...slug]].mdx

Lines changed: 17 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import { RemoteContent } from 'nextra/data'
22
import { buildDynamicMDX } from 'nextra/remote'
33
import { getPageMap } from '@/src/getPageMap'
44
import { remarkReplaceLinks } from '@/src/remarkReplaceLinks'
5+
import { replaceGitBookContent } from '@/src/replaceGitBookContent'
56
import json from '@/remote-files/firehose.json'
67

78
export const getStaticPaths = () => ({
@@ -19,29 +20,22 @@ 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-
// Replaces all the relative paths of images to absolute paths to the repo
36-
.replaceAll('../assets', `https://raw.githubusercontent.com/${user}/${repo}/${branch}/assets/`)
37-
// close img tags only if he doesn't point to .gitbook
38-
.replaceAll(/<img(.*?)>/g, (...m) => (m[1].includes('src=".gitbook') ? '' : `<img${m[1]}/>`))
39-
const mdx = await buildDynamicMDX(data, {
40-
mdxOptions: {
41-
remarkPlugins: [[remarkReplaceLinks, { foundPath, basePath: '/firehose/' }]],
42-
},
43-
codeHighlight: false,
44-
})
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+
remarkPlugins: [[remarkReplaceLinks, { foundPath, basePath: '/firehose/' }]],
35+
},
36+
codeHighlight: false,
37+
}
38+
)
4539
const parsedData = JSON.parse(mdx.__nextra_dynamic_opts)
4640
// remove title from frontMatter if it's the same as the title of the page
4741
if (parsedData.title === parsedData.frontMatter.title) {

website/pages/en/querying/graph-client/[[...slug]].mdx

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import { RemoteContent } from 'nextra/data'
22
import { buildDynamicMDX } from 'nextra/remote'
33
import { Mermaid } from 'nextra/components'
4+
import { visit } from 'unist-util-visit'
45
import { getPageMap } from '@/src/getPageMap'
56
import json from '@/remote-files/graph-client.json'
67

@@ -22,6 +23,18 @@ export async function getStaticProps({ params }) {
2223
const data = await response.text()
2324
const mdx = await buildDynamicMDX(data, {
2425
codeHighlight: false,
26+
mdxOptions: {
27+
remarkPlugins: [
28+
() => (tree, _file, done) => {
29+
visit(tree, 'link', (node) => {
30+
if (node.url.startsWith('../')) {
31+
node.url = node.url.replace('../', `https://github.com/${user}/${repo}/tree/${branch}/`)
32+
}
33+
})
34+
done()
35+
},
36+
],
37+
},
2538
})
2639
return {
2740
props: {

website/pages/en/querying/graph-client/_meta.js

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,4 +2,7 @@ import { createCatchAllMeta } from 'nextra/catch-all'
22

33
import json from '../../../../remote-files/graph-client.json' assert { type: 'json' }
44

5-
export default () => createCatchAllMeta(json.filePaths)
5+
export default () =>
6+
createCatchAllMeta(json.filePaths, {
7+
README: 'Introduction',
8+
})

website/pages/en/substreams/[[...slug]].mdx

Lines changed: 20 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import { RemoteContent } from 'nextra/data'
22
import { buildDynamicMDX } from 'nextra/remote'
33
import { getPageMap } from '@/src/getPageMap'
44
import { remarkReplaceLinks } from '@/src/remarkReplaceLinks'
5+
import { replaceGitBookContent } from '@/src/replaceGitBookContent'
56
import json from '@/remote-files/substreams.json'
67

78
export 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,

website/remote-files/graph-client.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
"branch": "main",
55
"docsPath": "docs/",
66
"filePaths": [
7+
"README.md",
78
"architecture.md",
89
"live.md"
910
]

website/src/replaceGitBookContent.ts

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
type ReplaceGitBookContentParams = {
2+
content: string
3+
user: string
4+
repo: string
5+
branch: string
6+
docsPath: string
7+
}
8+
9+
export function replaceGitBookContent({ content, user, repo, branch, docsPath }: ReplaceGitBookContentParams): string {
10+
return (
11+
content
12+
// replace {% embed ... %} with <iframe />
13+
.replaceAll(
14+
/{%\s+embed\s+url="(.*?)"\s+%}/g,
15+
(...m) =>
16+
`<iframe src="${m[1].replace(
17+
// we need to enhance YouTube links, otherwise they will be not loaded in iframe
18+
'youtube.com/watch?v=',
19+
'youtube.com/embed/'
20+
)}" style={{ aspectRatio: 16/9, width: '100%' }} />`
21+
)
22+
// remove gitbook {% ... %} elements
23+
.replaceAll(/{%.*?%}/g, '')
24+
// close unclosed img tags
25+
.replaceAll(/<img((?:(?!\/>)[^>])*?)>/g, (...m) => `<img${m[1]}/>`)
26+
// Replaces all the relative paths of images to absolute paths to the repo
27+
.replaceAll('../assets', `https://raw.githubusercontent.com/${user}/${repo}/${branch}/assets/`)
28+
.replaceAll(
29+
'.gitbook/assets/',
30+
`https://raw.githubusercontent.com/${user}/${repo}/${branch}/${docsPath}.gitbook/assets/`
31+
)
32+
)
33+
}

0 commit comments

Comments
 (0)