fix: use page to provide robot txt

This commit is contained in:
KazooTTT
2024-11-23 23:29:58 +08:00
parent 25fb1cc0cb
commit 7292415765
4 changed files with 29 additions and 23 deletions

26
src/pages/robots.txt.ts Normal file
View File

@ -0,0 +1,26 @@
import type { APIRoute } from 'astro'
import { siteConfig } from '../site.config'
const robotsTxt = `
User-agent: *
Allow: /
HOST: ${siteConfig.site}
# Sitemaps
Sitemap: ${siteConfig.site}/sitemap.xml
# Disallow system and error pages
Disallow: /api/
Disallow: /_astro/
Disallow: /404
Disallow: /500
`
export const GET: APIRoute = () => {
return new Response(robotsTxt.trim(), {
headers: {
'Content-Type': 'text/plain; charset=utf-8',
},
})
}