-
Notifications
You must be signed in to change notification settings - Fork 155
fix images/iframes for remote substreams docs #373
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -18,24 +18,39 @@ export async function getStaticPaths() { | |
export async function getStaticProps({ params: { slug = ['README'] } }) { | ||
const baseURL = 'https://raw.githubusercontent.com/streamingfast/substreams/develop/docs/' | ||
const paths = slug.join('/') | ||
let response = await fetch(`${baseURL}${paths}.md`) | ||
let fileURL = `${paths}.md` | ||
let response = await fetch(baseURL + fileURL) | ||
if (response.status === 404 && paths !== 'README') { | ||
response = await fetch(`${baseURL}${paths}/README.md`) | ||
fileURL = `$${paths}/README.md` | ||
response = await fetch(baseURL + fileURL) | ||
} | ||
const data = await response.text() | ||
const data = (await response.text()) | ||
// replace {% embed ... %} with <iframe /> | ||
.replaceAll( | ||
/{%\s+embed\s+url="(.*?)"\s+%}/g, | ||
(...m) => | ||
`<iframe src="${m[1].replace( | ||
// we need enhance YouTube links, otherwise they will be not loaded in iframe | ||
'youtube.com/watch?v=', | ||
'youtube.com/embed/' | ||
)}" style={{aspectRatio: 16/9, width: '100%'}}/>` | ||
) | ||
Comment on lines
+28
to
+37
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. |
||
// remove gitbook {% ... %} elements | ||
.replaceAll(/{%.*?%}/g, '') | ||
// close img tags only if he doesn't point to .gitbook | ||
.replaceAll(/<img(.*?)>/g, (...m) => (m[1].includes('src=".gitbook') ? '' : `<img${m[1]}/>`)) | ||
// fixes http://localhost:3000/en/substreams/reference-and-specs/authentication/ | ||
.replaceAll('<pre class="language-bash" data-overflow="wrap"><code class="lang-bash">', '```bash\n') | ||
Comment on lines
+42
to
+43
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. we need remove |
||
// fixes http://localhost:3000/en/substreams/developers-guide/modules/inputs/ | ||
.replaceAll('<pre class="language-yaml" data-title="manifest excerpt"><code class="lang-yaml">', '```yaml\n') | ||
.replaceAll('</code></pre>', '```') | ||
Comment on lines
+44
to
+46
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. we need remove |
||
const mdx = await buildDynamicMDX(data, { | ||
mdxOptions: { | ||
format: 'md', | ||
// 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 | ||
format: paths.endsWith('/change-log') ? 'md' : 'mdx', | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Why this? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. due to this line https://github.com/streamingfast/substreams/blob/f7bfe8fc45f860a935c2346bcd43b7b35bd76430/docs/release-notes/change-log.md?plain=1#L139 mdx2 treat
dimaMachina marked this conversation as resolved.
Show resolved
Hide resolved
|
||
remarkPlugins: [ | ||
() => (tree, _file, done) => { | ||
const GITBOOK_CALLOUT_REGEX = /{%.*?%}/ | ||
visit(tree, 'paragraph', (node) => { | ||
for (const child of node.children) { | ||
if (child.value) { | ||
child.value = child.value.replace(GITBOOK_CALLOUT_REGEX, '') | ||
} | ||
} | ||
}) | ||
// enhance links | ||
visit(tree, 'link', (node) => { | ||
if (node.url.startsWith('./')) { | ||
node.url = node.url.slice(2) | ||
|
@@ -59,6 +74,7 @@ export async function getStaticProps({ params: { slug = ['README'] } }) { | |
...mdx, | ||
__nextra_pageMap: await getPageMap('en'), | ||
hideLocaleSwitcher: true, | ||
remoteFilePath: `https://github.com/streamingfast/substreams/tree/develop/docs/${fileURL}`, | ||
}, | ||
} | ||
} | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this fix react warning about missing key