Skip to content

Commit 8fa9fcb

Browse files
Dimitri POSTOLOVbenface
andauthored
use Nextra's _meta.js for declaring sidebar titles and order (#314)
* just refactoring refactor refactor getNavItems from async to sync fixes for [locale] * I forget to remove these pages * rollback * try fix docker * rollback * prettier * pin pnpm in docker to v7 * apply review changes * Update website/pages/es/cookbook/migrating-a-subgraph.mdx Co-authored-by: Benoît Rouleau <[email protected]> --------- Co-authored-by: Benoît Rouleau <[email protected]>
1 parent 6794ab0 commit 8fa9fcb

File tree

130 files changed

+802
-817
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

130 files changed

+802
-817
lines changed

Dockerfile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ FROM node:18-alpine as builder
33
ENV PNPM_HOME="/usr/bin"
44

55
RUN apk add --no-cache git
6-
RUN npm install -g pnpm
6+
RUN npm install -g pnpm@7
77

88
WORKDIR /app
99

package.json

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,8 @@
77
"build": "pnpm -r build",
88
"start": "pnpm --filter @graphprotocol/docs start",
99
"export": "pnpm --filter @graphprotocol/docs export",
10-
"lint": "pnpm typecheck && eslint . --ext .js,.jsx,.ts,.tsx,.mjs --cache --max-warnings 0 && pnpm prettier:check",
11-
"lint:fix": "pnpm typecheck; eslint . --ext .js,.jsx,.ts,.tsx,.mjs --fix; pnpm prettier; exit 0",
10+
"lint": "pnpm typecheck && eslint --cache --ext .js,.jsx,.ts,.tsx,.mjs --max-warnings 0 . && pnpm prettier:check",
11+
"lint:fix": "pnpm typecheck && eslint --cache --ext .js,.jsx,.ts,.tsx,.mjs --fix . && pnpm prettier",
1212
"typecheck": "pnpm --filter @graphprotocol/docs typecheck",
1313
"prettier": "prettier . --loglevel warn --write",
1414
"prettier:check": "prettier . --loglevel warn --check",
@@ -28,7 +28,7 @@
2828
"typescript": "5.0.2"
2929
},
3030
"lint-staged": {
31-
"**/*.{js,jsx,ts,tsx,mjs}": "eslint --fix",
32-
"**/*.{js,jsx,ts,tsx,mjs,mdx,json}": "prettier --write"
31+
"**/*.{js,jsx,ts,tsx,mjs,cjs}": "eslint --fix",
32+
"**/*.{js,jsx,ts,tsx,mjs,cjs,md,mdx,yml,yaml,json}": "prettier --write"
3333
}
3434
}

pnpm-lock.yaml

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

website/components/EditPageLink.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,8 @@ export const EditPageLink = ({ mobile = false, ...props }: EditPageLinkProps) =>
1414
const { t } = useI18n()
1515

1616
// If the current page is in a language other than English, link to the English version, as translations are handled by Crowdin
17-
const { pagePath: _pagePath } = useContext(NavContext)!
18-
const pagePathSegments = _pagePath.split('/')
17+
const { filePath } = useContext(NavContext)!
18+
const pagePathSegments = filePath.split('/')
1919
pagePathSegments[1] = ['en', '[locale]'].includes(pagePathSegments[1]) ? pagePathSegments[1] : 'en'
2020
const pagePath = pagePathSegments.join('/')
2121

website/pages/[locale]/index.tsx renamed to website/components/IndexPage.tsx

Lines changed: 29 additions & 78 deletions
Original file line numberDiff line numberDiff line change
@@ -1,29 +1,11 @@
1-
import { GetStaticPaths, GetStaticProps, NextPage } from 'next'
2-
import { Heading as NextraHeading } from 'nextra'
3-
import { useMemo } from 'react'
1+
import { GetStaticPaths, GetStaticProps } from 'next'
42

5-
import {
6-
BorderRadius,
7-
buildBorder,
8-
buildShadow,
9-
buildTransition,
10-
Flex,
11-
Spacing,
12-
Text,
13-
translate,
14-
} from '@edgeandnode/components'
3+
import { BorderRadius, buildBorder, buildShadow, buildTransition, Flex, Spacing, Text } from '@edgeandnode/components'
154

165
import { Heading, Image, Link, LinkInline, Paragraph } from '@/components'
17-
import { AppLocale, supportedLocales, translations, useI18n } from '@/i18n'
18-
import MDXLayout, { Frontmatter } from '@/layout'
19-
import { getNavItems, NavItem } from '@/navigation'
6+
import { supportedLocales, useI18n } from '@/i18n'
207

21-
export const frontmatter = (locale: AppLocale): Frontmatter => ({
22-
title: translate(translations, locale, 'index.title'),
23-
})
24-
25-
// TODO: Make DRY
26-
export const getStaticPaths: GetStaticPaths = async () => {
8+
export const getStaticPaths: GetStaticPaths = () => {
279
return {
2810
paths: supportedLocales.map((locale) => ({
2911
params: { locale },
@@ -32,55 +14,16 @@ export const getStaticPaths: GetStaticPaths = async () => {
3214
}
3315
}
3416

35-
// TODO: Make DRY
36-
export const getStaticProps: GetStaticProps = async (context) => {
37-
const locale = context.params!.locale as AppLocale
38-
const navItems = await getNavItems(locale)
39-
40-
return {
41-
props: {
42-
locale,
43-
navItems,
44-
},
45-
}
17+
export const getStaticProps: GetStaticProps = () => {
18+
return { props: {} }
4619
}
4720

48-
type IndexProps = { navItems: NavItem[] }
49-
50-
const Index: NextPage<IndexProps> = ({ navItems }: IndexProps) => {
51-
const { t, locale } = useI18n()
52-
53-
const headings: NextraHeading[] = useMemo(
54-
() => [
55-
{
56-
id: 'network-roles',
57-
value: t('index.networkRoles.title'),
58-
depth: 2,
59-
},
60-
{
61-
id: 'products',
62-
value: t('index.products.title'),
63-
depth: 2,
64-
},
65-
{
66-
id: 'supported-networks',
67-
value: t('index.supportedNetworks.title'),
68-
depth: 2,
69-
},
70-
],
71-
[t]
72-
)
21+
export default function IndexPage() {
22+
const { t } = useI18n()
7323

7424
return (
75-
<MDXLayout
76-
// @ts-expect-error: we don't need another properties
77-
pageOpts={{
78-
filePath: `pages/[locale]/index.tsx`,
79-
frontMatter: frontmatter(locale as AppLocale),
80-
headings,
81-
}}
82-
pageProps={{ navItems }}
83-
>
25+
<>
26+
<Heading.H1>{t('index.title')}</Heading.H1>
8427
<Paragraph>{t('index.intro')}</Paragraph>
8528
<ul
8629
sx={{
@@ -123,8 +66,8 @@ const Index: NextPage<IndexProps> = ({ navItems }: IndexProps) => {
12366
description: t('index.shortcuts.migrateFromHostedService.description'),
12467
href: '/cookbook/migrating-a-subgraph',
12568
},
126-
].map((card, index) => (
127-
<li key={index} sx={{ aspectRatio: '258/136' }}>
69+
].map((card) => (
70+
<li key={card.href} sx={{ aspectRatio: '258/136' }}>
12871
<Link
12972
href={card.href}
13073
sx={{
@@ -237,8 +180,8 @@ const Index: NextPage<IndexProps> = ({ navItems }: IndexProps) => {
237180
description: t('index.products.products.hostedService.description'),
238181
href: '/deploying/hosted-service',
239182
},
240-
].map((product, index) => (
241-
<Flex.Column as="li" key={index}>
183+
].map((product) => (
184+
<Flex.Column as="li" key={product.href}>
242185
<div sx={{ mb: Spacing['16px'] }}>
243186
<Text as="h3" weight="SEMIBOLD" size="20px" sx={{ textShadow: buildShadow('S') }}>
244187
{product.title}
@@ -315,7 +258,12 @@ const Index: NextPage<IndexProps> = ({ navItems }: IndexProps) => {
315258
<Image
316259
src={network.image}
317260
alt=""
318-
sx={{ mb: Spacing['8px'], width: '40px', height: '40px', transition: buildTransition('TRANSFORM') }}
261+
sx={{
262+
mb: Spacing['8px'],
263+
width: '40px',
264+
height: '40px',
265+
transition: buildTransition('TRANSFORM'),
266+
}}
319267
/>
320268
{network.title}
321269
{network.beta ? '*' : ''}
@@ -428,8 +376,8 @@ const Index: NextPage<IndexProps> = ({ navItems }: IndexProps) => {
428376
href: 'https://base.org/',
429377
beta: true,
430378
},
431-
].map((network, index) => (
432-
<Flex.Column as="li" key={index}>
379+
].map((network) => (
380+
<Flex.Column as="li" key={network.href}>
433381
<Text as="div" size="14px" color="White48" sx={{ textAlign: 'center' }}>
434382
<Link
435383
href={network.href}
@@ -446,7 +394,12 @@ const Index: NextPage<IndexProps> = ({ navItems }: IndexProps) => {
446394
<Image
447395
src={network.image}
448396
alt=""
449-
sx={{ mb: Spacing['8px'], width: '40px', height: '40px', transition: buildTransition('TRANSFORM') }}
397+
sx={{
398+
mb: Spacing['8px'],
399+
width: '40px',
400+
height: '40px',
401+
transition: buildTransition('TRANSFORM'),
402+
}}
450403
/>
451404
{network.title}
452405
{network.beta ? '*' : ''}
@@ -459,8 +412,6 @@ const Index: NextPage<IndexProps> = ({ navItems }: IndexProps) => {
459412
*{t('index.supportedNetworks.betaWarning')}
460413
</Text.P14>
461414
</div>
462-
</MDXLayout>
415+
</>
463416
)
464417
}
465-
466-
export default Index

website/components/_app.tsx

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@ import merge from 'lodash/merge'
22
import mixpanel from 'mixpanel-browser'
33
import { AppProps } from 'next/app'
44
import NextLink from 'next/link'
5-
import { useRouter } from 'next/router'
65
import { DefaultSeo, DefaultSeoProps } from 'next-seo'
76
import { useMemo } from 'react'
87

@@ -60,8 +59,7 @@ const DefaultSeoWithLocale = () => {
6059
return <DefaultSeo {...seoProps} />
6160
}
6261

63-
const MyApp = ({ Component, pageProps }: AppProps) => {
64-
const router = useRouter()
62+
const MyApp = ({ Component, pageProps, router }: AppProps) => {
6563
const localeSwitcher = useMemo(() => <LocaleSwitcher key="localeSwitcher" />, [])
6664

6765
return (

website/layout/DocumentContext.ts

Lines changed: 5 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,19 @@
11
import { NextSeoProps } from 'next-seo'
2-
import { Context, createContext } from 'react'
2+
import { Heading } from 'nextra'
3+
import { createContext } from 'react'
34

45
export type Frontmatter = {
56
title?: string
6-
navTitle?: string
77
description?: string
88
socialImage?: string
99
seo?: NextSeoProps
1010
}
1111

12-
export type OutlineItem = {
13-
id: string
14-
title: string
15-
level: 1 | 2 | 3 | 4 | 5 | 6
16-
}
17-
1812
export type DocumentContextProps = {
19-
frontmatter?: Frontmatter
20-
outline: OutlineItem[]
13+
frontMatter: Frontmatter
14+
headings: Heading[]
2115
markOutlineItem: (id: string, inOrAboveView: boolean) => void
2216
highlightedOutlineItemId: string | null
2317
}
2418

25-
export const DocumentContext = createContext(null) as Context<DocumentContextProps | null>
19+
export const DocumentContext = createContext<DocumentContextProps | null>(null)

0 commit comments

Comments
 (0)