From 08165994c884941c5592c92a36546f5c7d40a655 Mon Sep 17 00:00:00 2001 From: port dev <108868128+portdeveloper@users.noreply.github.com> Date: Fri, 1 Nov 2024 23:43:03 +0300 Subject: [PATCH] Add getmetadata template... in a weird way... --- ...etadata.ts => getMetadata.ts.template.mjs} | 20 +++++++++++++++---- 1 file changed, 16 insertions(+), 4 deletions(-) rename templates/base/packages/nextjs/utils/scaffold-eth/{getMetadata.ts => getMetadata.ts.template.mjs} (54%) diff --git a/templates/base/packages/nextjs/utils/scaffold-eth/getMetadata.ts b/templates/base/packages/nextjs/utils/scaffold-eth/getMetadata.ts.template.mjs similarity index 54% rename from templates/base/packages/nextjs/utils/scaffold-eth/getMetadata.ts rename to templates/base/packages/nextjs/utils/scaffold-eth/getMetadata.ts.template.mjs index ad531aea6..6212e0b55 100644 --- a/templates/base/packages/nextjs/utils/scaffold-eth/getMetadata.ts +++ b/templates/base/packages/nextjs/utils/scaffold-eth/getMetadata.ts.template.mjs @@ -1,9 +1,12 @@ +import { stringify, withDefaults } from '../../../../../utils.js' + +const contents = ({ titleTemplate, extraIcons, extraMetadata }) => ` import type { Metadata } from "next"; const baseUrl = process.env.VERCEL_PROJECT_PRODUCTION_URL - ? `https://${process.env.VERCEL_PROJECT_PRODUCTION_URL}` - : `http://localhost:${process.env.PORT || 3000}`; -const titleTemplate = "%s | Scaffold-ETH 2"; + ? \`https://\${process.env.VERCEL_PROJECT_PRODUCTION_URL}\` + : \`http://localhost:\${process.env.PORT || 3000}\`; +const titleTemplate = "${titleTemplate[0] || '%s | Scaffold-ETH 2'}"; export const getMetadata = ({ title, @@ -14,7 +17,7 @@ export const getMetadata = ({ description: string; imageRelativePath?: string; }): Metadata => { - const imageUrl = `${baseUrl}${imageRelativePath}`; + const imageUrl = \`\${baseUrl}\${imageRelativePath}\`; return { metadataBase: new URL(baseUrl), @@ -45,6 +48,15 @@ export const getMetadata = ({ }, icons: { icon: [{ url: "/favicon.png", sizes: "32x32", type: "image/png" }], + ${extraIcons[0] ? Object.entries(extraIcons[0]).map(([key, value]) => `${key}: ${JSON.stringify(value)}`).join(',\n ') : ''} }, + ${extraMetadata[0] ? Object.entries(extraMetadata[0]).map(([key, value]) => `${key}: ${JSON.stringify(value)}`).join(',\n ') : ''} }; }; +` + +export default withDefaults(contents, { + titleTemplate: '', + extraIcons: {}, + extraMetadata: {} +})