Skip to content

Commit 386283e

Browse files
benfacedimaMachina
andauthored
Add buildGetStaticProps utility function to be more DRY (#564)
* Add `buildGetStaticProps` utility function to be more DRY (WIP) * extract getStaticPropsForSupportedNetworks polish * Update dependencies --------- Co-authored-by: Dimitri POSTOLOV <[email protected]>
1 parent 24d1f7c commit 386283e

File tree

36 files changed

+1455
-1942
lines changed

36 files changed

+1455
-1942
lines changed

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222
},
2323
"devDependencies": {
2424
"@edgeandnode/eslint-config": "^2.0.3",
25-
"eslint": "^8.55.0",
25+
"eslint": "^8.56.0",
2626
"eslint-plugin-mdx": "^2.2.0",
2727
"husky": "^8.0.3",
2828
"lint-staged": "^15.2.0",

packages/nextra-theme/package.json

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,8 @@
2525
"typecheck": "tsc --noEmit"
2626
},
2727
"peerDependencies": {
28-
"@edgeandnode/gds": "3.0.0-global-header-1701913779061-6ea902d",
29-
"@edgeandnode/go": "4.0.0-global-header-1701913779061-6ea902d",
28+
"@edgeandnode/gds": "3.0.0-global-header-1703167287784-4d7f05b34403f749b2baf2c11af2882b2acb4b11",
29+
"@edgeandnode/go": "4.0.0-global-header-1703167287784-4d7f05b34403f749b2baf2c11af2882b2acb4b11",
3030
"@emotion/react": "^11.11",
3131
"next": "^13",
3232
"next-seo": "^6",
@@ -43,12 +43,12 @@
4343
"react-use": "^17.4.2"
4444
},
4545
"devDependencies": {
46-
"@edgeandnode/gds": "3.0.0-global-header-1701913779061-6ea902d",
47-
"@edgeandnode/go": "4.0.0-global-header-1701913779061-6ea902d",
46+
"@edgeandnode/gds": "3.0.0-global-header-1703167287784-4d7f05b34403f749b2baf2c11af2882b2acb4b11",
47+
"@edgeandnode/go": "4.0.0-global-header-1703167287784-4d7f05b34403f749b2baf2c11af2882b2acb4b11",
4848
"@emotion/react": "^11.11.1",
4949
"@types/lodash": "^4.14.202",
50-
"@types/react": "^18.2.44",
51-
"@types/react-dom": "^18.2.17",
50+
"@types/react": "^18.2.45",
51+
"@types/react-dom": "^18.2.18",
5252
"next": "^14.0.4",
5353
"next-seo": "^6.4.0",
5454
"nextra": "^2.13.2",

packages/og-image/package.json

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,12 +16,12 @@
1616
"yoga-wasm-web": "0.3.3"
1717
},
1818
"devDependencies": {
19-
"@cloudflare/workers-types": "^4.20231121.0",
20-
"@types/react": "^18.2.44",
19+
"@cloudflare/workers-types": "^4.20231218.0",
20+
"@types/react": "^18.2.45",
2121
"jest-image-snapshot": "^6.4.0",
22-
"tsx": "^4.6.2",
22+
"tsx": "^4.7.0",
2323
"typescript": "^5.3.3",
2424
"vitest": "^0.34.6",
25-
"wrangler": "^3.20.0"
25+
"wrangler": "^3.22.1"
2626
}
2727
}

pnpm-lock.yaml

Lines changed: 1286 additions & 1551 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

website/next.config.js

Lines changed: 15 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
import nextra from 'nextra'
22

3-
// If you need to make a commit just to force a redeploy when creating a new release, increase this
4-
const _forceRedeploy = 1
3+
import { defaultLocale, extractLocaleFromPath } from '@edgeandnode/gds'
54

65
const env = {
76
ENVIRONMENT: process.env.ENVIRONMENT,
@@ -23,16 +22,21 @@ const withNextra = nextra({
2322
codeHighlight: false,
2423
defaultShowCopyCode: false,
2524
transform(result, { route }) {
26-
if (route && !result.includes('getStaticProps')) {
27-
const banner = `
28-
import { getPageMap } from '@/src/getPageMap'
25+
if (!route) return result
2926

30-
export const getStaticProps = async context => ({
31-
props: {
32-
__nextra_pageMap: await getPageMap('${route.split('/')[1]}')
33-
}
34-
})`
35-
result += banner
27+
const { locale } = extractLocaleFromPath(route)
28+
29+
result = `
30+
globalThis.__graph_docs_locale = '${locale ?? defaultLocale}'
31+
${result}
32+
`
33+
34+
if (!result.includes('getStaticProps')) {
35+
result = `
36+
import { buildGetStaticProps } from '@/src/buildGetStaticProps'
37+
${result}
38+
export const getStaticProps = buildGetStaticProps()
39+
`
3640
}
3741

3842
return result

website/package.json

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,9 @@
1313
"typecheck": "tsc --noEmit"
1414
},
1515
"dependencies": {
16-
"@edgeandnode/common": "^5.28.1",
17-
"@edgeandnode/gds": "3.0.0-global-header-1701913779061-6ea902d",
18-
"@edgeandnode/go": "4.0.0-global-header-1701913779061-6ea902d",
16+
"@edgeandnode/common": "^5.29.1",
17+
"@edgeandnode/gds": "3.0.0-global-header-1703167287784-4d7f05b34403f749b2baf2c11af2882b2acb4b11",
18+
"@edgeandnode/go": "4.0.0-global-header-1703167287784-4d7f05b34403f749b2baf2c11af2882b2acb4b11",
1919
"@emotion/react": "^11.11.1",
2020
"@graphprotocol/nextra-theme": "workspace:*",
2121
"mixpanel-browser": "^2.48.1",
@@ -32,11 +32,11 @@
3232
"@graphprotocol/client-cli": "^3.0.0",
3333
"@types/mdast": "^4.0.3",
3434
"@types/mixpanel-browser": "^2.47.5",
35-
"@types/react": "^18.2.44",
36-
"@types/react-dom": "^18.2.17",
35+
"@types/react": "^18.2.45",
36+
"@types/react-dom": "^18.2.18",
3737
"fast-xml-parser": "^4.3.2",
3838
"graphql": "^16.8.1",
39-
"tsx": "^4.6.2",
39+
"tsx": "^4.7.0",
4040
"unified": "^11.0.4"
4141
},
4242
"nextBundleAnalysis": {

website/pages/[locale]/index.mdx

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,8 @@ export const getStaticPaths = () => {
1717
}
1818
}
1919

20+
{/* Only in dynamic route we can't use `buildGetStaticProps` function, because route is based on filename of mdx page */}
21+
2022
export const getStaticProps = async ({ params: { locale } }) => {
2123
const t = key => translate(translations, locale, key)
2224
const rawMdx = `---

website/pages/ar/developing/supported-networks.mdx

Lines changed: 4 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -2,21 +2,10 @@
22
title: الشبكات المدعومة
33
---
44

5-
import { getPageMap } from '@/src/getPageMap'
6-
import { getSupportedNetworks, SupportedNetworksTable } from '@/src/supportedNetworks'
7-
8-
export const getStaticProps = async () => {
9-
return {
10-
props: {
11-
__nextra_pageMap: await getPageMap('ar'),
12-
ssg: {
13-
networks: await getSupportedNetworks(),
14-
},
15-
},
16-
}
17-
}
18-
19-
<SupportedNetworksTable />
5+
export { getStaticPropsForSupportedNetworks as getStaticProps } from '@/src/buildGetStaticProps'
6+
import { SupportedNetworksTable } from '@/src/supportedNetworks'
7+
8+
<SupportedNetworksTable networks={props.networks} />
209

2110
The hosted service relies on the stability and reliability of the underlying technologies, namely the provided JSON RPC endpoints.
2211

website/pages/cs/developing/supported-networks.mdx

Lines changed: 4 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -2,21 +2,10 @@
22
title: Supported Networks
33
---
44

5-
import { getPageMap } from '@/src/getPageMap'
6-
import { getSupportedNetworks, SupportedNetworksTable } from '@/src/supportedNetworks'
7-
8-
export const getStaticProps = async () => {
9-
return {
10-
props: {
11-
__nextra_pageMap: await getPageMap('cs'),
12-
ssg: {
13-
networks: await getSupportedNetworks(),
14-
},
15-
},
16-
}
17-
}
18-
19-
<SupportedNetworksTable />
5+
export { getStaticPropsForSupportedNetworks as getStaticProps } from '@/src/buildGetStaticProps'
6+
import { SupportedNetworksTable } from '@/src/supportedNetworks'
7+
8+
<SupportedNetworksTable networks={props.networks} />
209

2110
The hosted service relies on the stability and reliability of the underlying technologies, namely the provided JSON RPC endpoints.
2211

website/pages/de/developing/supported-networks.mdx

Lines changed: 4 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -2,21 +2,10 @@
22
title: Supported Networks
33
---
44

5-
import { getPageMap } from '@/src/getPageMap'
6-
import { getSupportedNetworks, SupportedNetworksTable } from '@/src/supportedNetworks'
7-
8-
export const getStaticProps = async () => {
9-
return {
10-
props: {
11-
__nextra_pageMap: await getPageMap('de'),
12-
ssg: {
13-
networks: await getSupportedNetworks(),
14-
},
15-
},
16-
}
17-
}
18-
19-
<SupportedNetworksTable />
5+
export { getStaticPropsForSupportedNetworks as getStaticProps } from '@/src/buildGetStaticProps'
6+
import { SupportedNetworksTable } from '@/src/supportedNetworks'
7+
8+
<SupportedNetworksTable networks={props.networks} />
209

2110
The hosted service relies on the stability and reliability of the underlying technologies, namely the provided JSON RPC endpoints.
2211

0 commit comments

Comments
 (0)