Skip to content

Commit

Permalink
add "force-static" + use Promise params for interace
Browse files Browse the repository at this point in the history
  • Loading branch information
adriangohjw committed Nov 6, 2024
1 parent 514338c commit c151c70
Show file tree
Hide file tree
Showing 5 changed files with 19 additions and 12 deletions.
23 changes: 11 additions & 12 deletions tooling/template/app/[[...permalink]]/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,13 @@ import {
RenderEngine,
} from "@opengovsg/isomer-components"

export const dynamic = "force-static"

const INDEX_PAGE_PERMALINK = "_index"
interface DynamicPageProps {
params: {
permalink?: string[]
}
params: Promise<{
permalink: string[]
}>
}

const timeNow = new Date()
Expand All @@ -27,9 +29,8 @@ const lastUpdated =
" " +
timeNow.getFullYear()

const getSchema = async (
permalink: DynamicPageProps["params"]["permalink"],
) => {
const getSchema = async (paramsPromise: DynamicPageProps) => {
const { permalink } = await paramsPromise.params
const joinedPermalink = !!permalink ? permalink.join("/") : ""

const schema = (await import(`@/schema/${joinedPermalink}.json`)
Expand Down Expand Up @@ -72,11 +73,10 @@ export const generateStaticParams = () => {
}

export const generateMetadata = async (
{ params }: DynamicPageProps,
props: DynamicPageProps,
_parent: ResolvingMetadata,
): Promise<Metadata> => {
const { permalink } = params
const schema = await getSchema(permalink)
const schema = await getSchema(props)
schema.site = {
...config.site,
environment: process.env.NEXT_PUBLIC_ISOMER_NEXT_ENVIRONMENT,
Expand All @@ -93,9 +93,8 @@ export const generateMetadata = async (
return getMetadata(schema)
}

const Page = async ({ params }: DynamicPageProps) => {
const { permalink } = params
const renderSchema = await getSchema(permalink)
const Page = async (props: DynamicPageProps) => {
const renderSchema = await getSchema(props)

return (
<RenderEngine
Expand Down
2 changes: 2 additions & 0 deletions tooling/template/app/layout.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ import "@/styles/globals.css"

import type { Metadata } from "next"

export const dynamic = "force-static"

export const metadata: Metadata = {
title: {
template: "%s | " + config.site.siteName,
Expand Down
2 changes: 2 additions & 0 deletions tooling/template/app/not-found.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ import navbar from "@/data/navbar.json"
import sitemap from "@/sitemap.json"
import { getMetadata, RenderEngine } from "@opengovsg/isomer-components"

export const dynamic = "force-static"

const PAGE_TITLE = "404: Page not found"
const PAGE_DESCRIPTION = "The page that you are accessing does not exist"
const PAGE_SCHEMA_VERSION = "0.1.0"
Expand Down
2 changes: 2 additions & 0 deletions tooling/template/app/robots.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ import navbar from "@/data/navbar.json"
import sitemap from "@/sitemap.json"
import { getRobotsTxt } from "@opengovsg/isomer-components"

export const dynamic = "force-static"

const timeNow = new Date()
const lastUpdated =
timeNow.getDate().toString().padStart(2, "0") +
Expand Down
2 changes: 2 additions & 0 deletions tooling/template/app/sitemap.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ import config from "@/data/config.json"
import sitemapJson from "@/sitemap.json"
import { getSitemapXml } from "@opengovsg/isomer-components"

export const dynamic = "force-static"

export default function sitemap(): MetadataRoute.Sitemap {
// TODO: fixup all the typing errors
// @ts-expect-error to fix when types are proper
Expand Down

0 comments on commit c151c70

Please sign in to comment.