feat: better robots.txt

This commit is contained in:
tresabhi committed 2025-04-03 12:23:53 -05:00
1 parent 21a37ec6cc
commit c3d8f15a2a
3 files changed
+12 -15

No files matched your search

+1
View File
@@ -130,6 +130,7 @@
"outdir", "outdir",
"outfile", "outfile",
"ownedtanks", "ownedtanks",
"partytown",
"PIXELFORMAT", "PIXELFORMAT",
"playerachievements", "playerachievements",
"playerinfo", "playerinfo",
BIN
View File
Binary file not shown.
+11 -15
View File
@@ -1,23 +1,19 @@
import { assertSecret } from '@blitzkit/core'; import { assertSecret } from '@blitzkit/core';
import type { APIContext } from 'astro'; import type { APIContext } from 'astro';
export async function GET({}: APIContext) { export async function GET({ request }: APIContext) {
const allowRobots = assertSecret(import.meta.env.ALLOW_ROBOTS) === 'true'; const allowRobots = assertSecret(import.meta.env.ALLOW_ROBOTS) === 'true';
const site = assertSecret(import.meta.env.SITE); const flags: Record<string, string | null> = {
'User-agent': '*',
[allowRobots ? 'Allow' : 'Disallow']: '/',
space: null,
Sitemap: `${new URL(request.url).origin}/sitemap-index.xml`,
};
return new Response( return new Response(
` Object.entries(flags)
User-agent: * .map(([key, value]) => (value === null ? '' : `${key}: ${value}`))
Allow: / .join('\n'),
${
allowRobots
? `
Host: ${site}
Sitemap: ${site}/sitemap-index.xml
`
: ''
}
`.trim(),
); );
} }