seedproject-web/app/src/pages/sitemap.xml.js

75 lines
2.3 KiB
JavaScript
Raw Normal View History

import { SITE, authors, categories, sortedPosts, tags } from "../lib/blog-data.js";
import { getProjects } from "../lib/projects.js";
const BASE_URL = SITE.url || "";
export async function GET() {
const posts = await sortedPosts();
const projects = await getProjects();
const entries = [
{ path: "/", changefreq: "weekly", priority: "1.0" },
{ path: "/about", changefreq: "monthly", priority: "0.6" },
{ path: "/services", changefreq: "monthly", priority: "0.7" },
{ path: "/services/website-design", changefreq: "monthly", priority: "0.6" },
{ path: "/projects", changefreq: "weekly", priority: "0.8" },
{ path: "/resume", changefreq: "monthly", priority: "0.6" },
{ path: "/contact", changefreq: "monthly", priority: "0.5" },
{ path: "/faq", changefreq: "monthly", priority: "0.4" },
{ path: "/changelog", changefreq: "weekly", priority: "0.3" },
{ path: "/blog", changefreq: "daily", priority: "0.9" },
...projects.map((project) => ({
path: `/projects/${project.slug}`,
changefreq: "monthly",
priority: "0.7",
})),
...posts.map((post) => ({
path: `/blog/${post.slug}`,
lastmod: post.updated || post.date,
changefreq: "monthly",
priority: "0.8",
})),
...categories.map((category) => ({
path: `/categories/${category.slug}`,
changefreq: "weekly",
priority: "0.6",
})),
...tags.map((tag) => ({
path: `/tags/${tag.slug}`,
changefreq: "weekly",
priority: "0.4",
})),
...authors.map((author) => ({
path: `/authors/${author.slug}`,
changefreq: "monthly",
priority: "0.5",
})),
];
const urls = entries.map((entry) =>
[
" <url>",
` <loc>${BASE_URL}${entry.path}</loc>`,
entry.lastmod ? ` <lastmod>${entry.lastmod}</lastmod>` : null,
entry.changefreq ? ` <changefreq>${entry.changefreq}</changefreq>` : null,
entry.priority ? ` <priority>${entry.priority}</priority>` : null,
" </url>",
]
.filter(Boolean)
.join("\n"),
);
const xml = [
'<?xml version="1.0" encoding="UTF-8"?>',
'<urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9">',
...urls,
"</urlset>",
].join("\n");
return new Response(xml, {
headers: {
"Content-Type": "application/xml",
"Cache-Control": "public, max-age=3600",
},
});
}