From a217d0a96aed8c2ce431c72b05487d7542b3c23b Mon Sep 17 00:00:00 2001 From: Eugene Fox Date: Wed, 21 Aug 2024 12:08:54 +0000 Subject: [PATCH] fix: DOMAIN_NAME variable partially baked in on build time --- app/_data/metadata.ts | 66 +++++++++++++++++++++------------------- app/attribution/page.tsx | 12 +++++--- app/layout.tsx | 6 ++-- app/not-found.tsx | 12 +++++--- 4 files changed, 53 insertions(+), 43 deletions(-) diff --git a/app/_data/metadata.ts b/app/_data/metadata.ts index f8f3b76..23b0d5c 100644 --- a/app/_data/metadata.ts +++ b/app/_data/metadata.ts @@ -1,7 +1,8 @@ +import Package from "@/../package.json"; import { Metadata } from "next"; +import { unstable_noStore } from "next/cache"; import bio from "./bio"; import socials from "./socials"; -import Package from "@/../package.json"; export const canonicalName: URL = new URL(`https://${process.env.DOMAIN_NAME}`); const baseTitle: string = "Eugene Fox - Software developer"; @@ -12,37 +13,40 @@ const keywords: string[] = ["Eugene Fox", "software developer", ".net", "react", export const getTitle = (pageTitle: string, customBase?: string): string => pageTitle + " - " + (customBase ?? baseTitle); -export const metadata: Metadata = +export async function generateMetadata(): Promise { - title: baseTitle, - description: bio[0], - metadataBase: canonicalName, - openGraph: - { + unstable_noStore(); + return { title: baseTitle, description: bio[0], - type: "profile", - firstName: Package.author.name.split(" ")[0], - lastName: Package.author.name.split(" ")[1], - gender, - username: socials["Twitter"].username, - siteName: canonicalName.hostname, - locale: "en_US" - }, - twitter: - { - site: socials["Twitter"].username, - card: "summary_large_image" - }, - alternates: - { - canonical: canonicalName.href - }, - authors: [ + metadataBase: canonicalName, + openGraph: { - name: Package.author.name, - url: socials["LinkedIn"].href - } - ], - keywords -}; + title: baseTitle, + description: bio[0], + type: "profile", + firstName: Package.author.name.split(" ")[0], + lastName: Package.author.name.split(" ")[1], + gender, + username: socials["Twitter"].username, + siteName: canonicalName.hostname, + locale: "en_US" + }, + twitter: + { + site: socials["Twitter"].username, + card: "summary_large_image" + }, + alternates: + { + canonical: canonicalName.href + }, + authors: [ + { + name: Package.author.name, + url: socials["LinkedIn"].href + } + ], + keywords + }; +} diff --git a/app/attribution/page.tsx b/app/attribution/page.tsx index a993c44..e30c5bf 100644 --- a/app/attribution/page.tsx +++ b/app/attribution/page.tsx @@ -6,14 +6,18 @@ import ThirdPartyAttribution from "@/_data/ThirdPartyAttributiont"; import { analyticsEnabled } from "@/_utils/analytics/server"; import { ArrowLeft24Regular, ArrowRight24Regular } from "@fluentui/react-icons"; import { Metadata } from "next"; +import { unstable_noStore } from "next/cache"; import React from "react"; import cls from "./page.module.scss"; -export const metadata: Metadata = +export async function generateMetadata(): Promise { - title: getTitle("Attributions & information", canonicalName.hostname), - robots: "noindex" -}; + unstable_noStore(); + return { + title: getTitle("Attributions & information", canonicalName.hostname), + robots: "noindex" + }; +} const AttributionPage: React.FC = () => (
diff --git a/app/layout.tsx b/app/layout.tsx index fa698f1..2d28ecf 100644 --- a/app/layout.tsx +++ b/app/layout.tsx @@ -1,5 +1,5 @@ -import { metadata as myMetadata } from "@/_data/metadata"; -import type { Metadata, Viewport } from "next"; +export { generateMetadata } from "@/_data/metadata"; +import type { Viewport } from "next"; import Script from "next/script"; import { PropsWithChildren } from "react"; import CookieBanner from "./_components/CookieBanner"; @@ -19,8 +19,6 @@ export const viewport: Viewport = colorScheme: "light dark" }; -export const metadata: Metadata = myMetadata; - export default function RootLayout(props: PropsWithChildren) { return ( diff --git a/app/not-found.tsx b/app/not-found.tsx index 8514f78..f807ffe 100644 --- a/app/not-found.tsx +++ b/app/not-found.tsx @@ -1,6 +1,7 @@ import { textCorrection } from "@/_assets/decorations"; import { Home24Regular } from "@fluentui/react-icons"; import { Metadata } from "next"; +import { unstable_noStore } from "next/cache"; import Image from "next/image"; import React from "react"; import { notFoundImage } from "./_assets/illustrations"; @@ -8,11 +9,14 @@ import Button from "./_components/Button"; import { canonicalName, getTitle } from "./_data/metadata"; import cls from "./not-found.module.scss"; -export const metadata: Metadata = +export async function generateMetadata(): Promise { - title: getTitle("Page not found", canonicalName.hostname), - robots: "noindex" -}; + unstable_noStore(); + return { + title: getTitle("Page not found", canonicalName.hostname), + robots: "noindex" + }; +} // [SPECIAL]