From 0980f0e0f88421e8b4a59345de114e8135d07273 Mon Sep 17 00:00:00 2001 From: Dominik Biedebach Date: Thu, 27 Jun 2024 12:49:56 +0200 Subject: [PATCH] added production check & robots rules --- .changeset/twelve-bugs-develop.md | 5 +++++ .env.example | 1 + src/server/createMetadata.ts | 2 ++ src/utils/constants.ts | 1 + src/utils/isProductionSite.ts | 8 ++++++++ 5 files changed, 17 insertions(+) create mode 100644 .changeset/twelve-bugs-develop.md create mode 100644 src/utils/isProductionSite.ts diff --git a/.changeset/twelve-bugs-develop.md b/.changeset/twelve-bugs-develop.md new file mode 100644 index 0000000..1f82bce --- /dev/null +++ b/.changeset/twelve-bugs-develop.md @@ -0,0 +1,5 @@ +--- +'tiptap-docs': patch +--- + +Added production check to disallow robots on non-production pages diff --git a/.env.example b/.env.example index cd62604..85fead0 100644 --- a/.env.example +++ b/.env.example @@ -11,5 +11,6 @@ NEXT_PUBLIC_DEMO_URL_PRO="https://embed-pro.tiptap.dev/preview" NEXT_PUBLIC_BASE_PATH="" NEXT_PUBLIC_DOMAIN="" NEXT_PUBLIC_GTM_ID="" +NEXT_PUBLIC_ENVIRONMENT="development" BASE_PATH="" \ No newline at end of file diff --git a/src/server/createMetadata.ts b/src/server/createMetadata.ts index a2e517c..fbf23c5 100644 --- a/src/server/createMetadata.ts +++ b/src/server/createMetadata.ts @@ -1,5 +1,6 @@ import { Metadata } from 'next' import { FULL_DOMAIN } from '@/utils/constants' +import { isProductionSite } from '@/utils/isProductionSite' export async function createMetadata({ title, @@ -17,6 +18,7 @@ export async function createMetadata({ return { title, description, + robots: isProductionSite() ? 'index, follow' : 'noindex, nofollow', openGraph: { title, description, diff --git a/src/utils/constants.ts b/src/utils/constants.ts index eb5e0f5..30cd01e 100644 --- a/src/utils/constants.ts +++ b/src/utils/constants.ts @@ -8,3 +8,4 @@ export const DOMAIN = process.env.NEXT_PUBLIC_DOMAIN || 'http://localhost:3000' export const FULL_DOMAIN = `${DOMAIN}${BASE_PATH}` export const GTM_ID = process.env.NEXT_PUBLIC_GTM_ID || null +export const ENVIRONMENT = process.env.NEXT_PUBLIC_ENVIRONMENT || 'development' diff --git a/src/utils/isProductionSite.ts b/src/utils/isProductionSite.ts new file mode 100644 index 0000000..4dc0511 --- /dev/null +++ b/src/utils/isProductionSite.ts @@ -0,0 +1,8 @@ +import { ENVIRONMENT } from './constants' +/** + * Checks if the site is in production + * @returns boolean + */ +export const isProductionSite = () => { + return ENVIRONMENT === 'production' +}