48 lines
1.4 KiB
JavaScript
48 lines
1.4 KiB
JavaScript
import { c as defineEventHandler, h as setHeader } from '../_/nitro.mjs';
|
|
import { b as fetchCategories, s as serverApi, a as absUrl } from '../_/api.mjs';
|
|
import 'unhead/server';
|
|
import 'vue';
|
|
import 'unhead/legacy';
|
|
import 'unhead/plugins';
|
|
import 'node:http';
|
|
import 'node:https';
|
|
import 'node:events';
|
|
import 'node:buffer';
|
|
import 'node:fs';
|
|
import 'node:path';
|
|
import 'node:crypto';
|
|
import 'node:url';
|
|
|
|
const sitemap_xml = defineEventHandler(async (event) => {
|
|
const [categories, products] = await Promise.all([
|
|
fetchCategories(),
|
|
serverApi("/public/products")
|
|
]);
|
|
const pages = [
|
|
{ loc: "/", priority: "1" },
|
|
...categories.map((c) => ({ loc: `/categories/${c.slug}`, priority: "0.8" })),
|
|
...products.map((p) => ({ loc: `/products/${p.slug}`, priority: "0.6", lastmod: p.updatedAt }))
|
|
];
|
|
setHeader(event, "Content-Type", "application/xml; charset=utf-8");
|
|
const lastmod = (/* @__PURE__ */ new Date()).toISOString();
|
|
const urls = pages.map(
|
|
(p) => {
|
|
var _a;
|
|
return `<url>
|
|
<loc>${absUrl(p.loc)}</loc>
|
|
<lastmod>${(_a = p.lastmod) != null ? _a : lastmod}</lastmod>
|
|
<changefreq>weekly</changefreq>
|
|
<priority>${p.priority}</priority>
|
|
</url>`;
|
|
}
|
|
).join("\n");
|
|
return `<?xml version="1.0" encoding="UTF-8"?>
|
|
<urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9">
|
|
${urls}
|
|
</urlset>
|
|
`;
|
|
});
|
|
|
|
export { sitemap_xml as default };
|
|
//# sourceMappingURL=sitemap.xml.mjs.map
|