Skip to content
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

3/4 Refactor _meta.js to prefer sidebarTitle #733

Merged
merged 27 commits into from
Aug 15, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
6 changes: 3 additions & 3 deletions .eslintrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,10 @@ module.exports = {
// Only lint the English pages because the Markdown for the other languages is auto-generated from English (via Crowdin).
// But include all languages when running the ESLint extension in VS Code (in case the user has "eslint.validate": ["mdx"]),
// otherwise there will be random errors since the non-English files don't match any ruleset.
files: [`website/pages/${isVSCode ? '' : 'en/'}**/*.{md,mdx}`],
files: [`website/src/pages/${isVSCode ? '' : 'en/'}**/*.{md,mdx}`],
excludedFiles: [
`website/pages/${isVSCode ? '' : 'en/'}developing/graph-ts/*.md`,
`website/pages/${isVSCode ? '' : 'en/'}querying/graph-client/*.md`,
`website/src/pages/${isVSCode ? '' : 'en/'}developing/graph-ts/*.md`,
`website/src/pages/${isVSCode ? '' : 'en/'}querying/graph-client/*.md`,
],
parser: 'eslint-mdx',
processor: 'mdx/remark',
Expand Down
2 changes: 1 addition & 1 deletion .nvmrc
Original file line number Diff line number Diff line change
@@ -1 +1 @@
22.5.1
22.6.0
4 changes: 2 additions & 2 deletions .prettierignore
Original file line number Diff line number Diff line change
Expand Up @@ -6,5 +6,5 @@ dist/
website/.graphclient/

# ignore below md since they are fetched from GitHub
website/pages/en/developing/graph-ts/*.md
website/pages/en/querying/graph-client/*.md
website/src/pages/en/developing/graph-ts/*.md
website/src/pages/en/querying/graph-client/*.md
10 changes: 5 additions & 5 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

48 changes: 24 additions & 24 deletions website/i18n.ts
Original file line number Diff line number Diff line change
@@ -1,29 +1,29 @@
import { Locale, type NestedStrings, type Translations, useI18n as _useI18n } from '@edgeandnode/gds'

import ar from '@/pages/ar/translations'
import cs from '@/pages/cs/translations'
import de from '@/pages/de/translations'
import en from '@/pages/en/translations'
import es from '@/pages/es/translations'
import fr from '@/pages/fr/translations'
import ha from '@/pages/ha/translations'
import hi from '@/pages/hi/translations'
import it from '@/pages/it/translations'
import ja from '@/pages/ja/translations'
import ko from '@/pages/ko/translations'
import mr from '@/pages/mr/translations'
import nl from '@/pages/nl/translations'
import pl from '@/pages/pl/translations'
import pt from '@/pages/pt/translations'
import ro from '@/pages/ro/translations'
import ru from '@/pages/ru/translations'
import sv from '@/pages/sv/translations'
import tr from '@/pages/tr/translations'
import uk from '@/pages/uk/translations'
import ur from '@/pages/ur/translations'
import vi from '@/pages/vi/translations'
import yo from '@/pages/yo/translations'
import zh from '@/pages/zh/translations'
import ar from '@/src/pages/ar/translations'
import cs from '@/src/pages/cs/translations'
import de from '@/src/pages/de/translations'
import en from '@/src/pages/en/translations'
import es from '@/src/pages/es/translations'
import fr from '@/src/pages/fr/translations'
import ha from '@/src/pages/ha/translations'
import hi from '@/src/pages/hi/translations'
import it from '@/src/pages/it/translations'
import ja from '@/src/pages/ja/translations'
import ko from '@/src/pages/ko/translations'
import mr from '@/src/pages/mr/translations'
import nl from '@/src/pages/nl/translations'
import pl from '@/src/pages/pl/translations'
import pt from '@/src/pages/pt/translations'
import ro from '@/src/pages/ro/translations'
import ru from '@/src/pages/ru/translations'
import sv from '@/src/pages/sv/translations'
import tr from '@/src/pages/tr/translations'
import uk from '@/src/pages/uk/translations'
import ur from '@/src/pages/ur/translations'
import vi from '@/src/pages/vi/translations'
import yo from '@/src/pages/yo/translations'
import zh from '@/src/pages/zh/translations'

const appLocales = [
Locale.ARABIC,
Expand Down
129 changes: 61 additions & 68 deletions website/next.config.js
Original file line number Diff line number Diff line change
@@ -1,12 +1,10 @@
import nextra from 'nextra'
import path from 'node:path'
import { visit } from 'unist-util-visit'

import { translate } from '@edgeandnode/gds'

// Compile `i18n.ts` to `i18n.js` since we can't import `ts` files in `next.config.js`
import { translations } from './dist/i18n.js'
import { remarkReplaceLinks } from './src/remarkReplaceLinks.js'
import { remarkTransformRemoteGitHub } from './src/remarkTransformRemoteGitHub.js'

const env = {
ENVIRONMENT: process.env.ENVIRONMENT,
Expand All @@ -23,56 +21,78 @@ const env = {
}

const withNextra = nextra({
theme: './src/nextra-theme/index.tsx',
theme: './src/NextraLayout.tsx',
search: false,
codeHighlight: false,
defaultShowCopyCode: false,
readingTime: true,
transformPageMap(pageMap) {
const locale = pageMap[0].data.slice(0, 2)
const locale = pageMap[0].route.slice(1, 3)
benface marked this conversation as resolved.
Show resolved Hide resolved
const t = (key) => translate(translations, locale, `global.sidebar.${key}`)

const metaFile = {
index: t('index'),
'---1': {
type: 'separator',
},
about: '',
network: t('network'),
sunrise: '',
billing: '',
glossary: '',
tokenomics: '',
arbitrum: t('arbitrum'),
'---2': {
type: 'separator',
},
'###1': {
type: 'heading',
title: t('subgraphs'),
},
'quick-start': '',
developing: t('developing'),
deploying: t('deploying'),
publishing: t('publishing'),
managing: t('managing'),
querying: t('querying'),
cookbook: t('cookbook'),
'release-notes': t('releaseNotes'),
'---3': {
type: 'separator',
},
benface marked this conversation as resolved.
Show resolved Hide resolved
'###2': {
type: 'heading',
title: t('substreams'),
},
substreams: '',
'---4': {
type: 'separator',
},
'###3': {
type: 'heading',
title: t('indexing'),
},
'operating-graph-node': '',
'chain-integration-overview': '',
'supported-network-requirements': '',
'new-chain-integration': '',
firehose: '',
graphcast: '',
'mips-faqs': '',
}

return [
...pageMap,
{ data: metaFile },
{
route: `/${locale}`,
name: 'index',
frontMatter: {
title: translate(translations, locale, 'index.title'),
},
frontMatter: {},
benface marked this conversation as resolved.
Show resolved Hide resolved
},
...pageMap,
]
},
mdxOptions: {
remarkPlugins: [
() => (tree, file) => {
const filePath = path.relative(process.cwd(), file.history[0])
const [fileName, directory] = filePath.split('/').reverse()

let user
let repo
let branch
let basePath
if (directory === 'graph-ts') {
user = 'graphprotocol'
repo = 'graph-tooling'
branch = 'main'
basePath = '/developing/graph-ts/'
} else if (directory === 'graph-client') {
user = 'graphprotocol'
repo = 'graph-client'
branch = 'main'
basePath = '/querying/graph-client/'
}
if (user) {
visit(tree, 'link', (node) => {
if (node.url.startsWith('../')) {
const GO_BACK_REPEATED_REGEX = /(\.\.\/)+/
node.url = node.url.replace(GO_BACK_REPEATED_REGEX, `https://github.com/${user}/${repo}/tree/${branch}/`)
}
})
remarkReplaceLinks({ foundPath: fileName, basePath })(tree, file)
}
},
],
remarkPlugins: [remarkTransformRemoteGitHub],
benface marked this conversation as resolved.
Show resolved Hide resolved
},
})

Expand Down Expand Up @@ -126,33 +146,6 @@ export default withNextra({
},
i18n: {
defaultLocale: 'en',
locales: [
'ar',
'de',
'en',
'es',
'fr',
'hi',
'it',
'ja',
'ko',
'mr',
'nl',
'pl',
'pt',
'ru',
'sv',
'tr',
'uk',
'ur',
'vi',
'zh',
// I added new lang otherwise build fails with
// Module not found: Can't resolve '/Users/dmytro/Desktop/GUILD/graph-docs/website/.next/static/chunks/nextra-page-map-ro.mjs'
'cs',
'ha',
'ro',
'yo',
],
locales: Object.keys(translations),
},
})
2 changes: 1 addition & 1 deletion website/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
"next": "^14.2.5",
"next-seo": "^6.5.0",
"next-sitemap": "^4.2.3",
"nextra": "^3.0.0-alpha.30",
"nextra": "^3.0.0-alpha.31",
"react": "^18.3.1",
"react-dom": "^18.3.1",
"react-ga4": "^2.1.0",
Expand Down
5 changes: 0 additions & 5 deletions website/pages/ar/_meta.js

This file was deleted.

5 changes: 0 additions & 5 deletions website/pages/cs/_meta.js

This file was deleted.

5 changes: 0 additions & 5 deletions website/pages/de/_meta.js

This file was deleted.

50 changes: 0 additions & 50 deletions website/pages/en/_meta.js

This file was deleted.

5 changes: 0 additions & 5 deletions website/pages/en/developing/graph-ts/_meta.js

This file was deleted.

14 changes: 0 additions & 14 deletions website/pages/en/global.json

This file was deleted.

22 changes: 0 additions & 22 deletions website/pages/es/_meta.js

This file was deleted.

Loading
Loading