From 6648d1d7d5fedd4b6fc8e9f5cee649f10bffdb38 Mon Sep 17 00:00:00 2001 From: Jeffrey Hales Date: Mon, 13 Jul 2026 12:48:14 -0700 Subject: [PATCH] fix(seo): noindex staging builds by default - add PUBLIC_ALLOW_INDEXING as an explicit production indexing opt-in - emit robots meta noindex,nofollow unless indexing is enabled - generate robots.txt from the same indexing flag - document staging SEO behavior for migration preview hosts --- www/.env.example | 1 + www/README.md | 10 +++++++--- www/public/robots.txt | 3 --- www/src/components/Seo.astro | 13 ++++++++++++- www/src/pages/robots.txt.ts | 23 +++++++++++++++++++++++ 5 files changed, 43 insertions(+), 7 deletions(-) delete mode 100644 www/public/robots.txt create mode 100644 www/src/pages/robots.txt.ts diff --git a/www/.env.example b/www/.env.example index fb28bfe..b7818e2 100644 --- a/www/.env.example +++ b/www/.env.example @@ -1 +1,2 @@ PUBLIC_AIA_API_BASE=https://api.azinstitute4autism.com +PUBLIC_ALLOW_INDEXING=false diff --git a/www/README.md b/www/README.md index bfc3dcd..dd00160 100644 --- a/www/README.md +++ b/www/README.md @@ -38,19 +38,23 @@ cd www npm install ``` -Copy the example environment file when testing the like/view counter: +Copy the example environment file when testing the like/view counter or staging +SEO behavior: ```sh cp .env.example .env ``` -The default value is: +The default values are: ```txt PUBLIC_AIA_API_BASE=https://api.azinstitute4autism.com +PUBLIC_ALLOW_INDEXING=false ``` -The site still renders when that API is unavailable. +The site still renders when the AIA API is unavailable. Migration and staging +builds emit `noindex,nofollow` by default; set `PUBLIC_ALLOW_INDEXING=true` +only for production builds on the canonical domain. ## View And Build diff --git a/www/public/robots.txt b/www/public/robots.txt deleted file mode 100644 index b0fe257..0000000 --- a/www/public/robots.txt +++ /dev/null @@ -1,3 +0,0 @@ -User-agent: * -Allow: / -Sitemap: https://www.azinstitute4autism.com/sitemap.xml diff --git a/www/src/components/Seo.astro b/www/src/components/Seo.astro index c776d0e..497146a 100644 --- a/www/src/components/Seo.astro +++ b/www/src/components/Seo.astro @@ -6,12 +6,23 @@ interface Props { image?: string; lang?: string; type?: 'website' | 'article'; + robots?: string; } -const { title, description = '', canonical, image, lang = 'en', type = 'website' } = Astro.props; +const { + title, + description = '', + canonical, + image, + lang = 'en', + type = 'website', + robots +} = Astro.props; +const defaultRobots = import.meta.env.PUBLIC_ALLOW_INDEXING === 'true' ? 'index,follow' : 'noindex,nofollow'; const absoluteImage = image ? new URL(image, Astro.site ?? Astro.url).href : undefined; --- {title} + {canonical && } diff --git a/www/src/pages/robots.txt.ts b/www/src/pages/robots.txt.ts new file mode 100644 index 0000000..8e880e2 --- /dev/null +++ b/www/src/pages/robots.txt.ts @@ -0,0 +1,23 @@ +const allowIndexing = import.meta.env.PUBLIC_ALLOW_INDEXING === 'true'; + +const body = allowIndexing + ? [ + 'User-agent: *', + 'Allow: /', + 'Sitemap: https://www.azinstitute4autism.com/sitemap.xml', + '' + ].join('\n') + : [ + 'User-agent: *', + 'Allow: /', + '# Staging and migration builds emit meta robots noindex,nofollow.', + '' + ].join('\n'); + +export function GET() { + return new Response(body, { + headers: { + 'Content-Type': 'text/plain; charset=utf-8' + } + }); +}