From 6de99225c46d6b7af2e596b5cd6f2e856ea4721b Mon Sep 17 00:00:00 2001 From: MotorTruck1221 Date: Wed, 4 Dec 2024 05:14:54 -0700 Subject: [PATCH] More SEO garbage --- src/pages/robots.txt.ts | 18 +++++++++++++++--- 1 file changed, 15 insertions(+), 3 deletions(-) diff --git a/src/pages/robots.txt.ts b/src/pages/robots.txt.ts index c3c15ae..6e90a7e 100644 --- a/src/pages/robots.txt.ts +++ b/src/pages/robots.txt.ts @@ -1,6 +1,10 @@ import type { APIRoute } from "astro"; import { SEO } from "astro:env/client"; -const SEOConfig = JSON.stringify(SEO); +interface config { + enabled: boolean; + domain: string; +} +const SEOConfig: config = JSON.parse(SEO); const genRobotsTXT = (sitemap: URL) => ` User-Agent: * @@ -10,8 +14,16 @@ Disallow: /uv SiteMap: ${sitemap.href} `; +const otherDomainTXT = ` +User-Agent: * +Disallow: /* +` + export const GET: APIRoute = ({ site, request }) => { const url = new URL('sitemap-index.xml', site); - console.log(new URL(request.url).host); -return new Response(genRobotsTXT(url)); + const host = new URL(request.url).host; + if (SEOConfig.enabled && host === SEOConfig.domain) { + return new Response(genRobotsTXT(url)); + } + return new Response(otherDomainTXT); };