fix(seo): generate robots.txt from Astro.site at build
Replace the hardcoded public/robots.txt with src/pages/robots.txt.ts so the Sitemap URL always matches the configured site (no drift between the file and astro.config.mjs).
This commit is contained in:
@@ -1,4 +0,0 @@
|
||||
User-agent: *
|
||||
Allow: /
|
||||
|
||||
Sitemap: https://www.eivissaenvironmentalwatch.es/sitemap-index.xml
|
||||
@@ -0,0 +1,18 @@
|
||||
import type { APIContext } from 'astro';
|
||||
|
||||
export function GET(context: APIContext) {
|
||||
const site = (context.site ?? new URL(context.url.origin)).toString().replace(/\/$/, '');
|
||||
const body = [
|
||||
'User-agent: *',
|
||||
'Allow: /',
|
||||
'',
|
||||
`Sitemap: ${site}/sitemap-index.xml`,
|
||||
'',
|
||||
].join('\n');
|
||||
|
||||
return new Response(body, {
|
||||
headers: {
|
||||
'Content-Type': 'text/plain; charset=utf-8',
|
||||
},
|
||||
});
|
||||
}
|
||||
Reference in New Issue
Block a user