Seo poprawki
This commit is contained in:
50
src/pages/sitemap.xml.js
Normal file
50
src/pages/sitemap.xml.js
Normal file
@@ -0,0 +1,50 @@
|
||||
import { globby } from 'globby';
|
||||
|
||||
export async function GET() {
|
||||
const base = "https://www.fuz.pl";
|
||||
|
||||
// Pobieramy wszystkie pliki .astro
|
||||
const files = await globby([
|
||||
"src/pages/**/*.astro",
|
||||
"!src/pages/_*.astro", // pomiń pliki zaczynające się od _
|
||||
"!src/pages/**/[...*", // pomiń catch-all
|
||||
"!src/pages/**/[**", // pomiń dynamiczne parametry
|
||||
"!src/pages/sitemap.xml.js", // pomiń samą sitemapę
|
||||
"!src/pages/api/**" // pomiń API endpoints
|
||||
]);
|
||||
|
||||
// Konwersja ścieżek plikowych → URL-e
|
||||
const urls = files.map((file) => {
|
||||
let url = file
|
||||
.replace("src/pages", "")
|
||||
.replace(".astro", "");
|
||||
|
||||
// obsługa index: /index.astro → /
|
||||
if (url.endsWith("/index")) {
|
||||
url = url.replace("/index", "");
|
||||
}
|
||||
|
||||
return url;
|
||||
});
|
||||
|
||||
// Budowa XML
|
||||
const body = `<?xml version="1.0" encoding="UTF-8"?>
|
||||
<urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9">
|
||||
${urls
|
||||
.map((url) => {
|
||||
return `
|
||||
<url>
|
||||
<loc>${base}${url}</loc>
|
||||
<changefreq>weekly</changefreq>
|
||||
<priority>${url === "/" ? "1.0" : "0.8"}</priority>
|
||||
</url>`;
|
||||
})
|
||||
.join("")}
|
||||
</urlset>`;
|
||||
|
||||
return new Response(body, {
|
||||
headers: {
|
||||
"Content-Type": "application/xml",
|
||||
},
|
||||
});
|
||||
}
|
||||
Reference in New Issue
Block a user