Skip to content

Commit

Permalink
More SEO garbage
Browse files Browse the repository at this point in the history
  • Loading branch information
MotorTruck1221 committed Dec 4, 2024
1 parent 6c0cbf2 commit 6de9922
Showing 1 changed file with 15 additions and 3 deletions.
18 changes: 15 additions & 3 deletions src/pages/robots.txt.ts
Original file line number Diff line number Diff line change
@@ -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: *
Expand All @@ -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);
};

0 comments on commit 6de9922

Please sign in to comment.