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
This commit is contained in:
@@ -1 +1,2 @@
|
||||
PUBLIC_AIA_API_BASE=https://api.azinstitute4autism.com
|
||||
PUBLIC_ALLOW_INDEXING=false
|
||||
|
||||
+7
-3
@@ -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
|
||||
|
||||
|
||||
@@ -1,3 +0,0 @@
|
||||
User-agent: *
|
||||
Allow: /
|
||||
Sitemap: https://www.azinstitute4autism.com/sitemap.xml
|
||||
@@ -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>{title}</title>
|
||||
<meta name="description" content={description} />
|
||||
<meta name="robots" content={robots ?? defaultRobots} />
|
||||
{canonical && <link rel="canonical" href={canonical} />}
|
||||
<meta property="og:type" content={type} />
|
||||
<meta property="og:title" content={title} />
|
||||
|
||||
@@ -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'
|
||||
}
|
||||
});
|
||||
}
|
||||
Reference in New Issue
Block a user