Skip to content

Commit 6d5399b

Browse files
committed
unify dynamic pages and run a full build only in production envs
1 parent 43e7b39 commit 6d5399b

File tree

4 files changed

+46
-204
lines changed

4 files changed

+46
-204
lines changed

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

Lines changed: 40 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,11 @@ 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

12-
import { LOCALES_CODES } from "@/lib/constants"
13+
import { DEFAULT_LOCALE, LOCALES_CODES } from "@/lib/constants"
1314

1415
import { componentsMapping, layoutMapping } from "@/layouts"
1516
import { fetchGFIs } from "@/lib/api/fetchGFIs"
@@ -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
}: {
@@ -26,7 +39,7 @@ export default async function Page({
2639
const { locale, slug: slugArray } = await params
2740

2841
// Check if this specific path is in our valid paths
29-
const validPaths = await generateStaticParams()
42+
const validPaths = await pagesToBuild()
3043
const isValidPath = validPaths.some(
3144
(path) =>
3245
path.locale === locale && path.slug.join("/") === slugArray.join("/")
@@ -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,15 +96,18 @@ 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>
83105
</I18nProvider>
84106
)
85107
}
86108

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

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

120+
export async function generateStaticParams() {
121+
const allPages = await pagesToBuild()
122+
123+
if (process.env.IS_PREVIEW_DEPLOY === "true") {
124+
// Only build default locale
125+
return allPages.filter((page) => page.locale === DEFAULT_LOCALE)
126+
}
127+
128+
return allPages
129+
}
130+
131+
export const dynamicParams = true
132+
98133
export async function generateMetadata({
99134
params,
100135
}: {

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.

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)