More SEO garbage

This commit is contained in:
MotorTruck1221 2024-12-04 05:14:54 -07:00
parent 6c0cbf2737
commit 6de99225c4
No known key found for this signature in database
GPG key ID: 08F417E2B8B61EA4

View file

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