Skip to content

Commit

Permalink
Add buildGetStaticProps utility function to be more DRY (#564)
Browse files Browse the repository at this point in the history
* Add `buildGetStaticProps` utility function to be more DRY (WIP)

* extract getStaticPropsForSupportedNetworks

polish

* Update dependencies

---------

Co-authored-by: Dimitri POSTOLOV <dmytropostolov@gmail.com>
  • Loading branch information
benface and dimaMachina committed Dec 21, 2023
1 parent 24d1f7c commit 386283e
Show file tree
Hide file tree
Showing 36 changed files with 1,455 additions and 1,942 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
},
"devDependencies": {
"@edgeandnode/eslint-config": "^2.0.3",
"eslint": "^8.55.0",
"eslint": "^8.56.0",
"eslint-plugin-mdx": "^2.2.0",
"husky": "^8.0.3",
"lint-staged": "^15.2.0",
Expand Down
12 changes: 6 additions & 6 deletions packages/nextra-theme/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,8 @@
"typecheck": "tsc --noEmit"
},
"peerDependencies": {
"@edgeandnode/gds": "3.0.0-global-header-1701913779061-6ea902d",
"@edgeandnode/go": "4.0.0-global-header-1701913779061-6ea902d",
"@edgeandnode/gds": "3.0.0-global-header-1703167287784-4d7f05b34403f749b2baf2c11af2882b2acb4b11",
"@edgeandnode/go": "4.0.0-global-header-1703167287784-4d7f05b34403f749b2baf2c11af2882b2acb4b11",
"@emotion/react": "^11.11",
"next": "^13",
"next-seo": "^6",
Expand All @@ -43,12 +43,12 @@
"react-use": "^17.4.2"
},
"devDependencies": {
"@edgeandnode/gds": "3.0.0-global-header-1701913779061-6ea902d",
"@edgeandnode/go": "4.0.0-global-header-1701913779061-6ea902d",
"@edgeandnode/gds": "3.0.0-global-header-1703167287784-4d7f05b34403f749b2baf2c11af2882b2acb4b11",
"@edgeandnode/go": "4.0.0-global-header-1703167287784-4d7f05b34403f749b2baf2c11af2882b2acb4b11",
"@emotion/react": "^11.11.1",
"@types/lodash": "^4.14.202",
"@types/react": "^18.2.44",
"@types/react-dom": "^18.2.17",
"@types/react": "^18.2.45",
"@types/react-dom": "^18.2.18",
"next": "^14.0.4",
"next-seo": "^6.4.0",
"nextra": "^2.13.2",
Expand Down
8 changes: 4 additions & 4 deletions packages/og-image/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,12 @@
"yoga-wasm-web": "0.3.3"
},
"devDependencies": {
"@cloudflare/workers-types": "^4.20231121.0",
"@types/react": "^18.2.44",
"@cloudflare/workers-types": "^4.20231218.0",
"@types/react": "^18.2.45",
"jest-image-snapshot": "^6.4.0",
"tsx": "^4.6.2",
"tsx": "^4.7.0",
"typescript": "^5.3.3",
"vitest": "^0.34.6",
"wrangler": "^3.20.0"
"wrangler": "^3.22.1"
}
}
2,837 changes: 1,286 additions & 1,551 deletions pnpm-lock.yaml

Large diffs are not rendered by default.

26 changes: 15 additions & 11 deletions website/next.config.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import nextra from 'nextra'

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

const env = {
ENVIRONMENT: process.env.ENVIRONMENT,
Expand All @@ -23,16 +22,21 @@ const withNextra = nextra({
codeHighlight: false,
defaultShowCopyCode: false,
transform(result, { route }) {
if (route && !result.includes('getStaticProps')) {
const banner = `
import { getPageMap } from '@/src/getPageMap'
if (!route) return result

export const getStaticProps = async context => ({
props: {
__nextra_pageMap: await getPageMap('${route.split('/')[1]}')
}
})`
result += banner
const { locale } = extractLocaleFromPath(route)

result = `
globalThis.__graph_docs_locale = '${locale ?? defaultLocale}'
${result}
`

if (!result.includes('getStaticProps')) {
result = `
import { buildGetStaticProps } from '@/src/buildGetStaticProps'
${result}
export const getStaticProps = buildGetStaticProps()
`
}

return result
Expand Down
12 changes: 6 additions & 6 deletions website/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,9 @@
"typecheck": "tsc --noEmit"
},
"dependencies": {
"@edgeandnode/common": "^5.28.1",
"@edgeandnode/gds": "3.0.0-global-header-1701913779061-6ea902d",
"@edgeandnode/go": "4.0.0-global-header-1701913779061-6ea902d",
"@edgeandnode/common": "^5.29.1",
"@edgeandnode/gds": "3.0.0-global-header-1703167287784-4d7f05b34403f749b2baf2c11af2882b2acb4b11",
"@edgeandnode/go": "4.0.0-global-header-1703167287784-4d7f05b34403f749b2baf2c11af2882b2acb4b11",
"@emotion/react": "^11.11.1",
"@graphprotocol/nextra-theme": "workspace:*",
"mixpanel-browser": "^2.48.1",
Expand All @@ -32,11 +32,11 @@
"@graphprotocol/client-cli": "^3.0.0",
"@types/mdast": "^4.0.3",
"@types/mixpanel-browser": "^2.47.5",
"@types/react": "^18.2.44",
"@types/react-dom": "^18.2.17",
"@types/react": "^18.2.45",
"@types/react-dom": "^18.2.18",
"fast-xml-parser": "^4.3.2",
"graphql": "^16.8.1",
"tsx": "^4.6.2",
"tsx": "^4.7.0",
"unified": "^11.0.4"
},
"nextBundleAnalysis": {
Expand Down
2 changes: 2 additions & 0 deletions website/pages/[locale]/index.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@ export const getStaticPaths = () => {
}
}

{/* Only in dynamic route we can't use `buildGetStaticProps` function, because route is based on filename of mdx page */}

export const getStaticProps = async ({ params: { locale } }) => {
const t = key => translate(translations, locale, key)
const rawMdx = `---
Expand Down
19 changes: 4 additions & 15 deletions website/pages/ar/developing/supported-networks.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -2,21 +2,10 @@
title: الشبكات المدعومة
---

import { getPageMap } from '@/src/getPageMap'
import { getSupportedNetworks, SupportedNetworksTable } from '@/src/supportedNetworks'

export const getStaticProps = async () => {
return {
props: {
__nextra_pageMap: await getPageMap('ar'),
ssg: {
networks: await getSupportedNetworks(),
},
},
}
}

<SupportedNetworksTable />
export { getStaticPropsForSupportedNetworks as getStaticProps } from '@/src/buildGetStaticProps'
import { SupportedNetworksTable } from '@/src/supportedNetworks'

<SupportedNetworksTable networks={props.networks} />

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

Expand Down
19 changes: 4 additions & 15 deletions website/pages/cs/developing/supported-networks.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -2,21 +2,10 @@
title: Supported Networks
---

import { getPageMap } from '@/src/getPageMap'
import { getSupportedNetworks, SupportedNetworksTable } from '@/src/supportedNetworks'

export const getStaticProps = async () => {
return {
props: {
__nextra_pageMap: await getPageMap('cs'),
ssg: {
networks: await getSupportedNetworks(),
},
},
}
}

<SupportedNetworksTable />
export { getStaticPropsForSupportedNetworks as getStaticProps } from '@/src/buildGetStaticProps'
import { SupportedNetworksTable } from '@/src/supportedNetworks'

<SupportedNetworksTable networks={props.networks} />

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

Expand Down
19 changes: 4 additions & 15 deletions website/pages/de/developing/supported-networks.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -2,21 +2,10 @@
title: Supported Networks
---

import { getPageMap } from '@/src/getPageMap'
import { getSupportedNetworks, SupportedNetworksTable } from '@/src/supportedNetworks'

export const getStaticProps = async () => {
return {
props: {
__nextra_pageMap: await getPageMap('de'),
ssg: {
networks: await getSupportedNetworks(),
},
},
}
}

<SupportedNetworksTable />
export { getStaticPropsForSupportedNetworks as getStaticProps } from '@/src/buildGetStaticProps'
import { SupportedNetworksTable } from '@/src/supportedNetworks'

<SupportedNetworksTable networks={props.networks} />

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

Expand Down
2 changes: 2 additions & 0 deletions website/pages/en/developing/graph-ts/[[...slug]].mdx
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@ export const getStaticPaths = () => ({
})),
})

{/* Only in dynamic route we can't use `buildGetStaticProps` function, because route is based on filename of mdx page */}

export async function getStaticProps({ params }) {
const { filePaths, user, repo, branch, docsPath } = json
const paths = params?.slug?.join('/')
Expand Down
19 changes: 4 additions & 15 deletions website/pages/en/developing/supported-networks.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -2,21 +2,10 @@
title: Supported Networks
---

import { getPageMap } from '@/src/getPageMap'
import { getSupportedNetworks, SupportedNetworksTable } from '@/src/supportedNetworks'

export const getStaticProps = async () => {
return {
props: {
__nextra_pageMap: await getPageMap('en'),
ssg: {
networks: await getSupportedNetworks(),
},
},
}
}

<SupportedNetworksTable />
export { getStaticPropsForSupportedNetworks as getStaticProps } from '@/src/buildGetStaticProps'
import { SupportedNetworksTable } from '@/src/supportedNetworks'

<SupportedNetworksTable networks={props.networks} />

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

Expand Down
2 changes: 2 additions & 0 deletions website/pages/en/querying/graph-client/[[...slug]].mdx
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@ export const getStaticPaths = () => ({
})),
})

{/* Only in dynamic route we can't use `buildGetStaticProps` function, because route is based on filename of mdx page */}

export async function getStaticProps({ params }) {
const { filePaths, user, repo, branch, docsPath } = json
const paths = params?.slug?.join('/')
Expand Down
19 changes: 4 additions & 15 deletions website/pages/es/developing/supported-networks.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -2,21 +2,10 @@
title: Redes admitidas
---

import { getPageMap } from '@/src/getPageMap'
import { getSupportedNetworks, SupportedNetworksTable } from '@/src/supportedNetworks'

export const getStaticProps = async () => {
return {
props: {
__nextra_pageMap: await getPageMap('es'),
ssg: {
networks: await getSupportedNetworks(),
},
},
}
}

<SupportedNetworksTable />
export { getStaticPropsForSupportedNetworks as getStaticProps } from '@/src/buildGetStaticProps'
import { SupportedNetworksTable } from '@/src/supportedNetworks'

<SupportedNetworksTable networks={props.networks} />

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

Expand Down
19 changes: 4 additions & 15 deletions website/pages/fr/developing/supported-networks.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -2,21 +2,10 @@
title: Réseaux pris en charge
---

import { getPageMap } from '@/src/getPageMap'
import { getSupportedNetworks, SupportedNetworksTable } from '@/src/supportedNetworks'

export const getStaticProps = async () => {
return {
props: {
__nextra_pageMap: await getPageMap('fr'),
ssg: {
networks: await getSupportedNetworks(),
},
},
}
}

<SupportedNetworksTable />
export { getStaticPropsForSupportedNetworks as getStaticProps } from '@/src/buildGetStaticProps'
import { SupportedNetworksTable } from '@/src/supportedNetworks'

<SupportedNetworksTable networks={props.networks} />

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

Expand Down
19 changes: 4 additions & 15 deletions website/pages/ha/developing/supported-networks.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -2,21 +2,10 @@
title: Supported Networks
---

import { getPageMap } from '@/src/getPageMap'
import { getSupportedNetworks, SupportedNetworksTable } from '@/src/supportedNetworks'

export const getStaticProps = async () => {
return {
props: {
__nextra_pageMap: await getPageMap('ha'),
ssg: {
networks: await getSupportedNetworks(),
},
},
}
}

<SupportedNetworksTable />
export { getStaticPropsForSupportedNetworks as getStaticProps } from '@/src/buildGetStaticProps'
import { SupportedNetworksTable } from '@/src/supportedNetworks'

<SupportedNetworksTable networks={props.networks} />

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

Expand Down
19 changes: 4 additions & 15 deletions website/pages/hi/developing/supported-networks.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -2,21 +2,10 @@
title: समर्थित नेटवर्क्स
---

import { getPageMap } from '@/src/getPageMap'
import { getSupportedNetworks, SupportedNetworksTable } from '@/src/supportedNetworks'

export const getStaticProps = async () => {
return {
props: {
__nextra_pageMap: await getPageMap('hi'),
ssg: {
networks: await getSupportedNetworks(),
},
},
}
}

<SupportedNetworksTable />
export { getStaticPropsForSupportedNetworks as getStaticProps } from '@/src/buildGetStaticProps'
import { SupportedNetworksTable } from '@/src/supportedNetworks'

<SupportedNetworksTable networks={props.networks} />

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

Expand Down
19 changes: 4 additions & 15 deletions website/pages/it/developing/supported-networks.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -2,21 +2,10 @@
title: Supported Networks
---

import { getPageMap } from '@/src/getPageMap'
import { getSupportedNetworks, SupportedNetworksTable } from '@/src/supportedNetworks'

export const getStaticProps = async () => {
return {
props: {
__nextra_pageMap: await getPageMap('it'),
ssg: {
networks: await getSupportedNetworks(),
},
},
}
}

<SupportedNetworksTable />
export { getStaticPropsForSupportedNetworks as getStaticProps } from '@/src/buildGetStaticProps'
import { SupportedNetworksTable } from '@/src/supportedNetworks'

<SupportedNetworksTable networks={props.networks} />

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

Expand Down
Loading

0 comments on commit 386283e

Please sign in to comment.