Skip to content

Commit 25bad0e

Browse files
author
Dimitri POSTOLOV
authored
move substreams docs to own sidebar section (#372)
1 parent 1a8b940 commit 25bad0e

File tree

22 files changed

+70
-42
lines changed

22 files changed

+70
-42
lines changed

packages/nextra-theme/src/components/EditPageLink.tsx

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -24,13 +24,15 @@ export const EditPageLink = ({ mobile = false, ...props }: EditPageLinkProps) =>
2424

2525
// If the current page is in a language other than English, link to the English version, as translations are handled by Crowdin
2626
const { filePath } = useContext(NavContext)!
27-
const pagePathSegments = filePath.split('/')
28-
pagePathSegments[1] = ['en', '[locale]'].includes(pagePathSegments[1]) ? pagePathSegments[1] : 'en'
29-
const pagePath = pagePathSegments.join('/')
30-
27+
const [, fileLocale, ...filePathSegments] = filePath.split('/')
28+
const path = filePath.startsWith('https')
29+
? filePath
30+
: `https://github.com/graphprotocol/docs/blob/main/website/pages/${
31+
['en', '[locale]'].includes(fileLocale) ? fileLocale : 'en'
32+
}/${filePathSegments.join('/')}`
3133
return (
3234
<Link
33-
href={`https://github.com/graphprotocol/docs/blob/main/website/${pagePath}`}
35+
href={path}
3436
target="_blank"
3537
sx={{
3638
display: 'block',

packages/nextra-theme/src/index.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ const mdxStyles: ThemeUIStyleObject = {
6060

6161
export { Heading, Image, Link, LinkInline, Paragraph }
6262

63-
export default function NextraLayout({ children, pageOpts }: NextraThemeLayoutProps): ReactElement {
63+
export default function NextraLayout({ children, pageOpts, pageProps }: NextraThemeLayoutProps): ReactElement {
6464
const { frontMatter, filePath, pageMap, headings, title } = pageOpts
6565
const { locale, defaultLocale } = useI18n()
6666
const fsPath = useFSRoute()
@@ -138,7 +138,7 @@ export default function NextraLayout({ children, pageOpts }: NextraThemeLayoutPr
138138
}
139139

140140
return (
141-
<NavContext.Provider value={{ filePath, ...args }}>
141+
<NavContext.Provider value={{ filePath: pageProps.remoteFilePath || filePath, ...args }}>
142142
<DocumentContext.Provider value={{ frontMatter, headings, markOutlineItem, highlightedOutlineItemId }}>
143143
<NextSeo {...seo} />
144144

packages/nextra-theme/src/layout/MDXLayoutNav.tsx

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import { keyframes } from '@emotion/react'
33
import * as Collapsible from '@radix-ui/react-collapsible'
44
import { useRouter } from 'next/router'
55
import { Item } from 'nextra/normalize-pages'
6-
import { PropsWithChildren, useContext, useEffect, useState } from 'react'
6+
import { Fragment, PropsWithChildren, useContext, useEffect, useState } from 'react'
77

88
import { BorderRadius, buildTransition, Flex, Icon, NestedStrings, Spacing, Text, useI18n } from '@edgeandnode/gds'
99

@@ -185,6 +185,10 @@ export const MDXLayoutNav = ({ mobile = false }: { mobile?: boolean }) => {
185185
return <NavTree.Heading key={pageItem.name}>{pageItem.title}</NavTree.Heading>
186186
}
187187
if ('children' in pageItem && pageItem.children) {
188+
if (pageItem.type === 'children') {
189+
return <Fragment key={pageItem.name}>{pageItem.children.map(renderSidebar)}</Fragment>
190+
}
191+
188192
return (
189193
<NavTree.Group key={pageItem.name} active={activePage.route.startsWith(`${pageItem.route}/`)}>
190194
<NavTree.Group.Heading

website/next.config.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ const withNextra = nextra({
1717
transform(result, { route }) {
1818
if (route && !result.includes('getStaticProps')) {
1919
const banner = `
20-
import { getPageMap } from '@/components/get-page-map'
20+
import { getPageMap } from '@/src/getPageMap'
2121
2222
export const getStaticProps = async context => ({
2323
props: {

website/pages/[locale]/index.mdx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,8 @@ import { buildDynamicMDX } from 'nextra/remote'
77
import { RemoteContent } from 'nextra/data'
88
import { supportedLocales, translations } from '@/i18n'
99

10-
import { Intro, NetworkRoles, Products, SupportedNetworks } from '@/components/IndexPage'
11-
import { getPageMap } from '@/components/get-page-map'
10+
import { Intro, NetworkRoles, Products, SupportedNetworks } from '@/src/IndexPage'
11+
import { getPageMap } from '@/src/getPageMap'
1212

1313
export const getStaticPaths = () => {
1414
return {

website/pages/_app.mdx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,4 +2,4 @@
22

33
{/* _app.mdx is used in nextra for better performance and smallest bundle size. */}
44

5-
export { default } from '../components/_app'
5+
export { default } from '../src/_app'

website/pages/ar/_meta.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import meta from '../en/_meta.js'
22

33
export default {
4-
...meta,
4+
...structuredClone(meta),
55
}

website/pages/en/_meta.js

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,11 +27,17 @@ export default {
2727
type: 'separator',
2828
},
2929
'###2': {
30+
type: 'heading',
31+
title: 'Substreams',
32+
},
33+
substreams: {
34+
type: 'children',
35+
},
36+
'###3': {
3037
type: 'heading',
3138
title: 'Indexing',
3239
},
3340
'operating-graph-node': '',
34-
substreams: 'Substreams',
3541
firehose: '',
3642
'---4': {
3743
type: 'separator',

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

Lines changed: 29 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import { visit } from 'unist-util-visit'
22
import { RemoteContent } from 'nextra/data'
33
import { buildDynamicMDX } from 'nextra/remote'
44
import { listFiles } from './_meta.js'
5-
import { getPageMap } from '@/components/get-page-map'
5+
import { getPageMap } from '@/src/getPageMap'
66

77
export async function getStaticPaths() {
88
const files = await listFiles()
@@ -18,24 +18,39 @@ export async function getStaticPaths() {
1818
export 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
}

website/pages/es/_meta.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import meta from '../en/_meta.js'
22

33
export default {
4-
...meta,
4+
...structuredClone(meta),
55
network: 'The Graph Network',
66
'###1': {
77
type: 'heading',
@@ -13,7 +13,7 @@ export default {
1313
managing: 'Administrando',
1414
querying: 'Consultando',
1515
cookbook: 'Recetario',
16-
'###2': {
16+
'###3': {
1717
type: 'heading',
1818
title: 'Indexación',
1919
},

website/pages/fr/_meta.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import meta from '../en/_meta.js'
22

33
export default {
4-
...meta,
4+
...structuredClone(meta),
55
}

website/pages/hi/_meta.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import meta from '../en/_meta.js'
22

33
export default {
4-
...meta,
4+
...structuredClone(meta),
55
}

website/pages/ja/_meta.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import meta from '../en/_meta.js'
22

33
export default {
4-
...meta,
4+
...structuredClone(meta),
55
network: 'グラフネットワーク',
66
'###1': {
77
type: 'heading',
@@ -13,7 +13,7 @@ export default {
1313
managing: '管理します',
1414
querying: 'クエリ',
1515
cookbook: 'クックブック',
16-
'###2': {
16+
'###3': {
1717
type: 'heading',
1818
title: 'インデキシング',
1919
},

website/pages/ko/_meta.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import meta from '../en/_meta.js'
22

33
export default {
4-
...meta,
4+
...structuredClone(meta),
55
}

website/pages/ru/_meta.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import meta from '../en/_meta.js'
22

33
export default {
4-
...meta,
4+
...structuredClone(meta),
55
tokenomics: 'Токеномика',
66
}

website/pages/uk/_meta.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import meta from '../en/_meta.js'
22

33
export default {
4-
...meta,
4+
...structuredClone(meta),
55
network: 'Graph мережа',
66
'###1': {
77
type: 'heading',
@@ -13,7 +13,7 @@ export default {
1313
managing: 'Управління',
1414
querying: 'Запити',
1515
cookbook: 'Книга поетапних порад',
16-
'###2': {
16+
'###3': {
1717
type: 'heading',
1818
title: 'Індексація',
1919
},

website/pages/ur/_meta.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import meta from '../en/_meta.js'
22

33
export default {
4-
...meta,
4+
...structuredClone(meta),
55
network: 'گراف نیٹورک',
66
'###1': {
77
type: 'heading',
@@ -13,7 +13,7 @@ export default {
1313
managing: 'انتظام',
1414
querying: 'استفسار کرنا',
1515
cookbook: 'ہدایت نامہ',
16-
'###2': {
16+
'###3': {
1717
type: 'heading',
1818
title: 'انڈیکسنگ',
1919
},

website/pages/vi/_meta.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import meta from '../en/_meta.js'
22

33
export default {
4-
...meta,
4+
...structuredClone(meta),
55
}

website/pages/zh/_meta.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import meta from '../en/_meta.js'
22

33
export default {
4-
...meta,
4+
...structuredClone(meta),
55
network: 'Graph网络',
66
'###1': {
77
type: 'heading',
@@ -13,7 +13,7 @@ export default {
1313
managing: '管理',
1414
querying: '查询',
1515
cookbook: '导览',
16-
'###2': {
16+
'###3': {
1717
type: 'heading',
1818
title: '索引',
1919
},
File renamed without changes.
File renamed without changes.
File renamed without changes.

0 commit comments

Comments
 (0)