Skip to content

Commit 13c8f23

Browse files
committed
aa
1 parent 55f11d5 commit 13c8f23

File tree

4 files changed

+53
-13
lines changed

4 files changed

+53
-13
lines changed

packages/nextra-theme/src/index.tsx

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ import { ReactElement, useCallback, useMemo } from 'react'
88
import { useSet } from 'react-use'
99
import { ThemeUICSSObject } from 'theme-ui'
1010

11-
import { Divider, DividerProps, Flex, Spacing, useI18n } from '@edgeandnode/gds'
11+
import { Divider, DividerProps, Flex, Spacing } from '@edgeandnode/gds'
1212

1313
import {
1414
Callout,
@@ -64,9 +64,9 @@ const mdxStyles: ThemeUICSSObject = {
6464

6565
export { Heading, Image, LinkInline, Paragraph }
6666

67-
export default function NextraLayout({ children, pageOpts }: NextraThemeLayoutProps): ReactElement {
67+
// @ts-expect-error TODO: pageProps
68+
export default function NextraLayout({ children, pageOpts, pageProps = {} }: NextraThemeLayoutProps): ReactElement {
6869
const { frontMatter, filePath, pageMap, headings, title } = pageOpts
69-
const { locale, defaultLocale } = useI18n<any>()
7070
const fsPath = useFSRoute()
7171

7272
const args = useMemo(() => {
@@ -137,7 +137,6 @@ export default function NextraLayout({ children, pageOpts }: NextraThemeLayoutPr
137137
}
138138

139139
return (
140-
// @ts-expect-error TODO: pageProps
141140
<NavContext.Provider value={{ filePath: pageProps.remoteFilePath || filePath, ...args }}>
142141
<DocumentContext.Provider value={{ frontMatter, headings, markOutlineItem, highlightedOutlineItemId }}>
143142
<NextSeo {...seo} />

website/next.config.js

Lines changed: 46 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,10 +14,24 @@ const env = {
1414

1515
const withNextra = nextra({
1616
theme: '@graphprotocol/nextra-theme',
17-
staticImage: true,
1817
search: false,
1918
codeHighlight: false,
2019
defaultShowCopyCode: false,
20+
transform(result, { route }) {
21+
if (route && !result.includes('getStaticProps')) {
22+
const banner = `
23+
import { getPageMap } from '@/src/getPageMap'
24+
25+
export const getStaticProps = async context => ({
26+
props: {
27+
__nextra_pageMap: await getPageMap('${route.split('/')[1]}')
28+
}
29+
})`
30+
result += banner
31+
}
32+
33+
return result
34+
},
2135
})
2236

2337
export default withNextra({
@@ -67,4 +81,35 @@ export default withNextra({
6781
images: {
6882
unoptimized: true,
6983
},
84+
i18n: {
85+
defaultLocale: 'en',
86+
locales: [
87+
'ar',
88+
'de',
89+
'en',
90+
'es',
91+
'fr',
92+
'hi',
93+
'it',
94+
'ja',
95+
'ko',
96+
'mr',
97+
'nl',
98+
'pl',
99+
'pt',
100+
'ru',
101+
'sv',
102+
'tr',
103+
'uk',
104+
'ur',
105+
'vi',
106+
'zh',
107+
// I added new lang otherwise build fails with
108+
// Module not found: Can't resolve '/Users/dmytro/Desktop/GUILD/graph-docs/website/.next/static/chunks/nextra-page-map-ro.mjs'
109+
'cs',
110+
'ha',
111+
'ro',
112+
'yo',
113+
],
114+
},
70115
})

website/src/getPageMap.ts

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { Folder, MetaJsonFile, PageMapItem } from 'nextra'
1+
import { MetaJsonFile, PageMapItem } from 'nextra'
22
import { buildDynamicMeta } from 'nextra/remote'
33

44
import { Locale, translate } from '@edgeandnode/gds'
@@ -12,17 +12,13 @@ export async function getPageMap(locale: Locale = Locale.ENGLISH) {
1212

1313
const { __nextra_pageMap } = await buildDynamicMeta()
1414

15-
const pageMap = __nextra_pageMap.find(
16-
(pageItem): pageItem is Folder => pageItem.kind === 'Folder' && pageItem.name === (locale as string),
17-
)!.children
18-
19-
const resultPageMap = [
20-
...pageMap,
15+
const resultPageMap: PageMapItem[] = [
16+
...__nextra_pageMap,
2117
// add missing dynamic "[locale]/index.mdx" page
2218
{ kind: 'MdxPage', name: 'index', route: `/${locale}` },
2319
]
2420

25-
const metaIndex = pageMap.findIndex((pageItem) => pageItem.kind === 'Meta')
21+
const metaIndex = __nextra_pageMap.findIndex((pageItem) => pageItem.kind === 'Meta')
2622
;(resultPageMap[metaIndex] as MetaJsonFile).data.index = translate(translations, locale, 'index.title')
2723

2824
return resultPageMap

0 commit comments

Comments
 (0)