From 14eff512cf4537ba0bc625073877245174195c9f Mon Sep 17 00:00:00 2001 From: adriangohjw Date: Tue, 14 Jan 2025 01:40:06 +0800 Subject: [PATCH 1/4] add shouldBlockIndexing --- packages/components/src/engine/index.ts | 7 ++++++- packages/components/src/engine/metadata.ts | 6 ++++++ 2 files changed, 12 insertions(+), 1 deletion(-) diff --git a/packages/components/src/engine/index.ts b/packages/components/src/engine/index.ts index c3daf1462c..fc1db51a90 100644 --- a/packages/components/src/engine/index.ts +++ b/packages/components/src/engine/index.ts @@ -1,3 +1,8 @@ export { RenderEngine, renderComponentPreviewText } from "./render" -export { getMetadata, getRobotsTxt, getSitemapXml } from "./metadata" +export { + getMetadata, + shouldBlockIndexing, + getRobotsTxt, + getSitemapXml, +} from "./metadata" export * from "~/types" diff --git a/packages/components/src/engine/metadata.ts b/packages/components/src/engine/metadata.ts index 24f126e2f6..3efa5e3af4 100644 --- a/packages/components/src/engine/metadata.ts +++ b/packages/components/src/engine/metadata.ts @@ -111,6 +111,12 @@ export const getMetadata = (props: IsomerPageSchemaType) => { } } +export const shouldBlockIndexing = ( + environment: IsomerPageSchemaType["site"]["environment"], +): boolean => { + return environment === "staging" +} + export const getRobotsTxt = (props: IsomerPageSchemaType) => { const rules = [ { From e2426df4a416a9ed69721fc04a044860fe0ae44b Mon Sep 17 00:00:00 2001 From: adriangohjw Date: Tue, 14 Jan 2025 01:40:33 +0800 Subject: [PATCH 2/4] use shouldBlockIndexing for meta noIndex --- tooling/template/app/[[...permalink]]/page.tsx | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/tooling/template/app/[[...permalink]]/page.tsx b/tooling/template/app/[[...permalink]]/page.tsx index 5ee3058556..c2e4e6717c 100644 --- a/tooling/template/app/[[...permalink]]/page.tsx +++ b/tooling/template/app/[[...permalink]]/page.tsx @@ -10,6 +10,7 @@ import { getMetadata, getSitemapXml, RenderEngine, + shouldBlockIndexing, } from "@opengovsg/isomer-components" export const dynamic = "force-static" @@ -129,6 +130,13 @@ const Page = async (props: DynamicPageProps) => { assetsBaseUrl: process.env.NEXT_PUBLIC_ASSETS_BASE_URL, isomerGtmId: process.env.NEXT_PUBLIC_ISOMER_GOOGLE_TAG_MANAGER_ID, }} + meta={{ + // TODO: fixup all the typing errors + // @ts-ignore to fix when types are proper + noIndex: shouldBlockIndexing( + process.env.NEXT_PUBLIC_ISOMER_NEXT_ENVIRONMENT, + ), + }} LinkComponent={Link} ScriptComponent={Script} /> From 3704c7b29c2ba3bb012741f86e584d35e3e74618 Mon Sep 17 00:00:00 2001 From: adriangohjw Date: Tue, 14 Jan 2025 01:42:02 +0800 Subject: [PATCH 3/4] refactor to use shouldBlockIndexing --- packages/components/src/engine/metadata.ts | 13 ++++++------- 1 file changed, 6 insertions(+), 7 deletions(-) diff --git a/packages/components/src/engine/metadata.ts b/packages/components/src/engine/metadata.ts index 3efa5e3af4..956d69b2b3 100644 --- a/packages/components/src/engine/metadata.ts +++ b/packages/components/src/engine/metadata.ts @@ -127,13 +127,12 @@ export const getRobotsTxt = (props: IsomerPageSchemaType) => { return { sitemap: props.site.url ? `${props.site.url}/sitemap.xml` : undefined, - rules: - props.site.environment === "staging" - ? { - userAgent: "*", - disallow: "/", - } - : rules, + rules: shouldBlockIndexing(props.site.environment) + ? { + userAgent: "*", + disallow: "/", + } + : rules, } } From e810697509aba6b7547bf72e7408d3f126de1102 Mon Sep 17 00:00:00 2001 From: adriangohjw Date: Tue, 14 Jan 2025 18:00:31 +0800 Subject: [PATCH 4/4] switch from === "staging" to !== "production" --- packages/components/src/engine/metadata.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/components/src/engine/metadata.ts b/packages/components/src/engine/metadata.ts index 956d69b2b3..fb70ecfff8 100644 --- a/packages/components/src/engine/metadata.ts +++ b/packages/components/src/engine/metadata.ts @@ -114,7 +114,7 @@ export const getMetadata = (props: IsomerPageSchemaType) => { export const shouldBlockIndexing = ( environment: IsomerPageSchemaType["site"]["environment"], ): boolean => { - return environment === "staging" + return environment !== "production" } export const getRobotsTxt = (props: IsomerPageSchemaType) => {