From f71fdc13987a2ebc5967ee82265e7a689d01202f Mon Sep 17 00:00:00 2001 From: satnaing Date: Tue, 25 Feb 2025 20:36:22 +0700 Subject: [PATCH] chore: update robots.txt implementation --- src/pages/robots.txt.ts | 18 +++++++----------- 1 file changed, 7 insertions(+), 11 deletions(-) diff --git a/src/pages/robots.txt.ts b/src/pages/robots.txt.ts index 0475e01..4edef8b 100644 --- a/src/pages/robots.txt.ts +++ b/src/pages/robots.txt.ts @@ -1,17 +1,13 @@ import type { APIRoute } from "astro"; -import { SITE } from "@config"; - -const robots = ` -User-agent: Googlebot -Disallow: /nogooglebot/ +const getRobotsTxt = (sitemapURL: URL) => ` User-agent: * Allow: / -Sitemap: ${new URL("sitemap-index.xml", SITE.website).href} -`.trim(); +Sitemap: ${sitemapURL.href} +`; -export const GET: APIRoute = () => - new Response(robots, { - headers: { "Content-Type": "text/plain" }, - }); +export const GET: APIRoute = ({ site }) => { + const sitemapURL = new URL("sitemap-index.xml", site); + return new Response(getRobotsTxt(sitemapURL)); +};