Skip to content

Commit a55dee7

Browse files
authored
Merge pull request #15183 from ethereum/patch-intl-md
Patch - remove cache function
2 parents 07eae14 + 83e5245 commit a55dee7

File tree

7 files changed

+36
-211
lines changed

7 files changed

+36
-211
lines changed

app/[locale]/[...slug]/page.tsx

Lines changed: 26 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import I18nProvider from "@/components/I18nProvider"
66
import mdComponents from "@/components/MdComponents"
77

88
import { dataLoader } from "@/lib/utils/data/dataLoader"
9+
import { dateToString } from "@/lib/utils/date"
910
import { getPostSlugs } from "@/lib/utils/md"
1011
import { getRequiredNamespacesForPage } from "@/lib/utils/translations"
1112

@@ -18,6 +19,18 @@ import { getMdMetadata } from "@/lib/md/metadata"
1819

1920
const loadData = dataLoader([["gfissues", fetchGFIs]])
2021

22+
function getLayoutFromSlug(slug: string) {
23+
if (slug.includes("developers/docs")) {
24+
return "docs"
25+
}
26+
27+
if (slug.includes("developers/tutorials")) {
28+
return "tutorial"
29+
}
30+
31+
return "static"
32+
}
33+
2134
export default async function Page({
2235
params,
2336
}: {
@@ -49,6 +62,7 @@ export default async function Page({
4962
tocItems,
5063
lastEditLocaleTimestamp,
5164
isTranslated,
65+
contributors,
5266
} = await getPageData({
5367
locale,
5468
slug,
@@ -61,9 +75,14 @@ export default async function Page({
6175
})
6276

6377
// Determine the actual layout after we have the frontmatter
64-
const layout = frontmatter.template || "static"
78+
const layout = frontmatter.template || getLayoutFromSlug(slug)
6579
const Layout = layoutMapping[layout]
6680

81+
// If the page has a published date, format it
82+
if ("published" in frontmatter) {
83+
frontmatter.published = dateToString(frontmatter.published)
84+
}
85+
6786
// Get i18n messages
6887
const allMessages = await getMessages({ locale })
6988
const requiredNamespaces = getRequiredNamespacesForPage(slug, layout)
@@ -77,6 +96,9 @@ export default async function Page({
7796
tocItems={tocItems}
7897
lastEditLocaleTimestamp={lastEditLocaleTimestamp}
7998
contentNotTranslated={!isTranslated}
99+
contributors={contributors}
100+
// TODO: Remove this once we have a real timeToRead value
101+
timeToRead={2}
80102
>
81103
{content}
82104
</Layout>
@@ -85,7 +107,7 @@ export default async function Page({
85107
}
86108

87109
export async function generateStaticParams() {
88-
const slugs = await getPostSlugs("/", /\/developers/)
110+
const slugs = await getPostSlugs("/")
89111

90112
return LOCALES_CODES.flatMap((locale) =>
91113
slugs.map((slug) => ({
@@ -95,6 +117,8 @@ export async function generateStaticParams() {
95117
)
96118
}
97119

120+
export const dynamicParams = false
121+
98122
export async function generateMetadata({
99123
params,
100124
}: {

app/[locale]/developers/docs/[[...doc]]/page.tsx

Lines changed: 0 additions & 98 deletions
This file was deleted.

app/[locale]/developers/tutorials/[...tutorial]/page.tsx

Lines changed: 0 additions & 101 deletions
This file was deleted.

next.config.js

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -124,7 +124,6 @@ module.exports = (phase, { defaultConfig }) => {
124124
"node_modules/@swc/core-linux-x64-musl",
125125
"node_modules/@esbuild/linux-x64",
126126
"src/data",
127-
"src/intl",
128127
"public/**/*.jpg",
129128
"public/**/*.png",
130129
"public/**/*.webp",

src/i18n/loadMessages.ts

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,6 @@
11
import fs from "fs"
22
import path from "path"
33

4-
import { cache } from "react"
5-
64
function getNamespaces(localePath: string): string[] {
75
return fs
86
.readdirSync(localePath)
@@ -12,7 +10,7 @@ function getNamespaces(localePath: string): string[] {
1210

1311
const messagesCache: Record<string, Record<string, string>> = {}
1412

15-
async function loadMessages(locale: string) {
13+
export async function loadMessages(locale: string) {
1614
if (messagesCache[locale]) {
1715
return messagesCache[locale]
1816
}
@@ -32,6 +30,3 @@ async function loadMessages(locale: string) {
3230
messagesCache[locale] = messages
3331
return messages
3432
}
35-
36-
// Keep the React cache wrapper as well for RSC optimization
37-
export const getMessages = cache(loadMessages)

src/i18n/request.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import { getRequestConfig } from "next-intl/server"
33

44
import { Lang } from "@/lib/types"
55

6-
import { getMessages } from "./loadMessages"
6+
import { loadMessages } from "./loadMessages"
77
import { routing } from "./routing"
88

99
export default getRequestConfig(async ({ requestLocale }) => {
@@ -15,8 +15,8 @@ export default getRequestConfig(async ({ requestLocale }) => {
1515
locale = routing.defaultLocale
1616
}
1717

18-
const allLocaleMessages = await getMessages(locale)
19-
const allDefaultMessages = await getMessages(routing.defaultLocale)
18+
const allLocaleMessages = await loadMessages(locale)
19+
const allDefaultMessages = await loadMessages(routing.defaultLocale)
2020
const messages = merge(allDefaultMessages, allLocaleMessages)
2121

2222
return {

src/layouts/index.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
1+
import { docsComponents, DocsLayout } from "./Docs"
12
import * as mdLayouts from "./md"
23
import { staticComponents, StaticLayout } from "./Static"
4+
import { TutorialLayout, tutorialsComponents } from "./Tutorial"
35

46
export * from "./BaseLayout"
57
export * from "./Docs"
@@ -14,6 +16,8 @@ export const layoutMapping = {
1416
roadmap: mdLayouts.RoadmapLayout,
1517
upgrade: mdLayouts.UpgradeLayout,
1618
translatathon: mdLayouts.TranslatathonLayout,
19+
docs: DocsLayout,
20+
tutorial: TutorialLayout,
1721
}
1822

1923
export const componentsMapping = {
@@ -23,4 +27,6 @@ export const componentsMapping = {
2327
...mdLayouts.roadmapComponents,
2428
...mdLayouts.upgradeComponents,
2529
...mdLayouts.translatathonComponents,
30+
...docsComponents,
31+
...tutorialsComponents,
2632
} as const

0 commit comments

Comments
 (0)