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); };