From 11c3b0a66f67324445a0cfe9ac0975cea65dc657 Mon Sep 17 00:00:00 2001 From: FreePoix <17864213831@163.com> Date: Tue, 19 Mar 2024 19:34:25 +0800 Subject: [PATCH] feat: og title --- configs/app/meta.ts | 1 + deploy/tools/envs-validator/schema.ts | 1 + docs/ENVS.md | 1 + lib/metadata/generate.ts | 2 +- 4 files changed, 4 insertions(+), 1 deletion(-) diff --git a/configs/app/meta.ts b/configs/app/meta.ts index 111860c2aa..a734cd9b16 100644 --- a/configs/app/meta.ts +++ b/configs/app/meta.ts @@ -6,6 +6,7 @@ const defaultImageUrl = app.baseUrl + '/static/og_placeholder.png'; const meta = Object.freeze({ promoteBlockscoutInTitle: parseEnvJson(getEnvValue('NEXT_PUBLIC_PROMOTE_BLOCKSCOUT_IN_TITLE')) ?? true, og: { + title: getEnvValue('NEXT_PUBLIC_OG_TITLE') || '', description: getEnvValue('NEXT_PUBLIC_OG_DESCRIPTION') || '', imageUrl: getExternalAssetFilePath('NEXT_PUBLIC_OG_IMAGE_URL') || defaultImageUrl, }, diff --git a/deploy/tools/envs-validator/schema.ts b/deploy/tools/envs-validator/schema.ts index 9ea412ff15..e85407cc04 100644 --- a/deploy/tools/envs-validator/schema.ts +++ b/deploy/tools/envs-validator/schema.ts @@ -496,6 +496,7 @@ const schema = yup NEXT_PUBLIC_AD_TEXT_PROVIDER: yup.string().oneOf(SUPPORTED_AD_TEXT_PROVIDERS), NEXT_PUBLIC_PROMOTE_BLOCKSCOUT_IN_TITLE: yup.boolean(), NEXT_PUBLIC_OG_DESCRIPTION: yup.string(), + NEXT_PUBLIC_OG_TITLE: yup.string().optional(), NEXT_PUBLIC_OG_IMAGE_URL: yup.string().test(urlTest), NEXT_PUBLIC_SAFE_TX_SERVICE_URL: yup.string().test(urlTest), NEXT_PUBLIC_IS_SUAVE_CHAIN: yup.boolean(), diff --git a/docs/ENVS.md b/docs/ENVS.md index 9cc6b2a63c..b087f2f24e 100644 --- a/docs/ENVS.md +++ b/docs/ENVS.md @@ -189,6 +189,7 @@ Settings for meta tags and OG tags | Variable | Type| Description | Compulsoriness | Default value | Example value | | --- | --- | --- | --- | --- | --- | | NEXT_PUBLIC_PROMOTE_BLOCKSCOUT_IN_TITLE | `boolean` | Set to `true` to promote Blockscout in meta and OG titles | - | `true` | `true` | +| NEXT_PUBLIC_OG_TITLE | `string` | Custom OG title | - | - | - | | NEXT_PUBLIC_OG_DESCRIPTION | `string` | Custom OG description | - | - | `Blockscout is the #1 open-source blockchain explorer available today. 100+ chains and counting rely on Blockscout data availability, APIs, and ecosystem tools to support their networks.` | | NEXT_PUBLIC_OG_IMAGE_URL | `string` | OG image url. Minimum image size is 200 x 20 pixels (recommended: 1200 x 600); maximum supported file size is 8 MB; 2:1 aspect ratio; supported formats: image/jpeg, image/gif, image/png | - | `static/og_placeholder.png` | `https://placekitten.com/1200/600` | diff --git a/lib/metadata/generate.ts b/lib/metadata/generate.ts index 8d24fd1606..a56894b0d1 100644 --- a/lib/metadata/generate.ts +++ b/lib/metadata/generate.ts @@ -27,7 +27,7 @@ export default function generate(route: R, apiData?: ApiData title: title, description, opengraph: { - title: title, + title: pageOgType !== 'Regular page' ? config.meta.og.title : '', description: pageOgType !== 'Regular page' ? config.meta.og.description : '', imageUrl: pageOgType !== 'Regular page' ? config.meta.og.imageUrl : '', },