From 63523534703c1f95ac070452001070e2c3f74d5d Mon Sep 17 00:00:00 2001 From: tanishqmanuja Date: Wed, 27 Sep 2023 15:53:39 +0530 Subject: [PATCH] feat: dynamically generate robots.txt --- public/robots.txt | 5 ----- src/pages/robots.txt.ts | 17 +++++++++++++++++ 2 files changed, 17 insertions(+), 5 deletions(-) delete mode 100644 public/robots.txt create mode 100644 src/pages/robots.txt.ts diff --git a/public/robots.txt b/public/robots.txt deleted file mode 100644 index da95c4e..0000000 --- a/public/robots.txt +++ /dev/null @@ -1,5 +0,0 @@ -User-agent: Googlebot -Disallow: /nogooglebot/ - -User-agent: * -Allow: / \ No newline at end of file diff --git a/src/pages/robots.txt.ts b/src/pages/robots.txt.ts new file mode 100644 index 0000000..0475e01 --- /dev/null +++ b/src/pages/robots.txt.ts @@ -0,0 +1,17 @@ +import type { APIRoute } from "astro"; +import { SITE } from "@config"; + +const robots = ` +User-agent: Googlebot +Disallow: /nogooglebot/ + +User-agent: * +Allow: / + +Sitemap: ${new URL("sitemap-index.xml", SITE.website).href} +`.trim(); + +export const GET: APIRoute = () => + new Response(robots, { + headers: { "Content-Type": "text/plain" }, + });