Skip to content

Commit 23749f5

Browse files
authored
Fix links in remote content (#455)
1 parent 1437d84 commit 23749f5

File tree

4 files changed

+12
-9
lines changed

4 files changed

+12
-9
lines changed

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

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
11
import { RemoteContent } from 'nextra/data'
22
import { buildDynamicMDX } from 'nextra/remote'
3+
import { getPageMap } from '@/src/getPageMap'
4+
import { remarkReplaceLinks } from '@/src/remarkReplaceLinks'
35
import { Mermaid } from 'nextra/components'
46
import { visit } from 'unist-util-visit'
5-
import { getPageMap } from '@/src/getPageMap'
67
import json from '@/remote-files/graph-client.json'
78

89
export const getStaticPaths = () => ({
@@ -20,9 +21,8 @@ export async function getStaticProps({ params }) {
2021
const foundPath = filePaths.find((filePath) => filePath.startsWith(paths))
2122
const baseURL = `https://raw.githubusercontent.com/${user}/${repo}/${branch}/${docsPath}${foundPath}`
2223
const response = await fetch(baseURL)
23-
const data = await response.text()
24-
const mdx = await buildDynamicMDX(data, {
25-
codeHighlight: false,
24+
const content = await response.text()
25+
const mdx = await buildDynamicMDX(content, {
2626
mdxOptions: {
2727
remarkPlugins: [
2828
() => (tree, _file, done) => {
@@ -33,8 +33,10 @@ export async function getStaticProps({ params }) {
3333
})
3434
done()
3535
},
36+
[remarkReplaceLinks, { foundPath, basePath: '/querying/graph-client/' }],
3637
],
3738
},
39+
codeHighlight: false,
3840
})
3941
return {
4042
props: {

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,8 @@ export async function getStaticProps({ params }) {
2424
const content = await response.text()
2525
const mdx = await buildDynamicMDX(replaceGitBookContent({ content }), {
2626
mdxOptions: {
27-
// change-log contains `{variable}` text that is thrown an error by MDX2 parser since he treats
28-
// it as variable injection, to fix it we parse chang-log with the Markdown parser
27+
// change-log contains `{variable}` text that is thrown an error by MDX2 parser since it treats
28+
// it as variable injection, to fix it we parse `change-log` with the Markdown parser
2929
format: paths.endsWith('/change-log') ? 'md' : 'mdx',
3030
remarkPlugins: [
3131
[remarkReplaceLinks, { foundPath, basePath: '/substreams/' }],

website/src/remarkReplaceImages.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import { Plugin } from 'unified'
33
import { visit } from 'unist-util-visit'
44

55
export const remarkReplaceImages: Plugin<[{ assetsBasePath: string }], Root> = ({ assetsBasePath }) => {
6-
if (!assetsBasePath) throw new Error('remarkReplaceLinks: assetsBasePath is required')
6+
if (!assetsBasePath) throw new Error('remarkReplaceImages: assetsBasePath is required')
77

88
return (tree, _file, done) => {
99
visit(

website/src/remarkReplaceLinks.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
1+
import path from 'path'
2+
13
import { Root } from 'mdast'
2-
import path from 'node:path'
34
import { Plugin } from 'unified'
45
import { visit } from 'unist-util-visit'
56

@@ -22,7 +23,7 @@ export const remarkReplaceLinks: Plugin<[{ foundPath: string; basePath: string }
2223
node.url = node.url.replace('/', basePath)
2324
} else {
2425
// Relative to the current path, e.g. (foo)[bar] or (foo)[./bar] or (foo)[../bar]
25-
node.url = path.join(path.dirname(foundPath), node.url)
26+
node.url = path.join(basePath + path.dirname(foundPath), node.url)
2627
}
2728
})
2829
done()

0 commit comments

Comments
 (0)