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:
2026-07-26 21:28:03 +02:00
parent 1d380d5cb5
commit f4be17ccf5
2 changed files with 18 additions and 4 deletions
-4
View File
@@ -1,4 +0,0 @@
User-agent: *
Allow: /
Sitemap: https://www.eivissaenvironmentalwatch.es/sitemap-index.xml
+18
View File
@@ -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',
},
});
}