[chore] Add a dynamic robots.txt and sitemap

This commit is contained in:
JasterV 2025-06-02 14:54:45 +02:00
commit bff554504e
5 changed files with 18 additions and 0 deletions

View file

@ -1,6 +1,8 @@
import { defineConfig } from "astro/config";
import icon from "astro-icon";
import sitemap from "@astrojs/sitemap";
// https://astro.build/config
export default defineConfig({
site: "https://jaster.xyz",
@ -12,5 +14,6 @@ export default defineConfig({
mdi: ["github", "linkedin"],
},
}),
sitemap(),
],
});

BIN
bun.lockb

Binary file not shown.

View file

@ -13,6 +13,7 @@
},
"dependencies": {
"@astrojs/check": "^0.9.4",
"@astrojs/sitemap": "^3.4.0",
"astro": "^5.8.1",
"astro-icon": "^1.1.5",
"typescript": "^5.8.3"

View file

@ -20,6 +20,7 @@ const backgroundImageUrl = `url('${optimizedBgImage.src}')`;
<link rel="icon" type="image/png" href="/favicon.png" />
<meta name="viewport" content="width=device-width" />
<meta name="generator" content={Astro.generator} />
<link rel="sitemap" href="/sitemap-index.xml" />
<title>{title}</title>
</head>
<body>

13
src/pages/robots.txt.ts Normal file
View file

@ -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));
};