From 05daa7025eaa6d16fe62d4538a1ada865010eca7 Mon Sep 17 00:00:00 2001 From: enscribe Date: Sat, 14 Sep 2024 09:31:24 -0700 Subject: [PATCH] feat: auto-generate `robots.txt` --- src/components/Head.astro | 1 + src/pages/robots.txt.ts | 13 +++++++++++++ 2 files changed, 14 insertions(+) create mode 100644 src/pages/robots.txt.ts diff --git a/src/components/Head.astro b/src/components/Head.astro index e91937a..ab13591 100644 --- a/src/components/Head.astro +++ b/src/components/Head.astro @@ -23,6 +23,7 @@ const { title, description, image = '/static/twitter-card.png' } = Astro.props + {title} diff --git a/src/pages/robots.txt.ts b/src/pages/robots.txt.ts new file mode 100644 index 0000000..679a44d --- /dev/null +++ b/src/pages/robots.txt.ts @@ -0,0 +1,13 @@ +import type { APIRoute } from 'astro' + +const getRobotsTxt = (sitemapURL: URL) => ` +User-agent: * +Allow: / + +Sitemap: ${sitemapURL.href} +` + +export const GET: APIRoute = ({ site }) => { + const sitemapURL = new URL('sitemap-index.xml', site) + return new Response(getRobotsTxt(sitemapURL)) +}