Switch admin auth to mobile, restyle shell/login with Vuesax icons, and add product detail fields plus public product pages. Co-authored-by: Cursor <cursoragent@cursor.com>
30 lines
1.0 KiB
TypeScript
30 lines
1.0 KiB
TypeScript
import type { PublicProductRef } from "@imen/shared";
|
|
|
|
interface SitemapEntry {
|
|
loc: string;
|
|
priority: string;
|
|
lastmod?: string;
|
|
}
|
|
|
|
export default defineEventHandler(async (event) => {
|
|
const [categories, products] = await Promise.all([
|
|
fetchCategories(),
|
|
serverApi<PublicProductRef[]>("/public/products"),
|
|
]);
|
|
const pages: SitemapEntry[] = [
|
|
{ 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 = new Date().toISOString();
|
|
const urls = pages
|
|
.map(
|
|
(p) =>
|
|
`<url>\n<loc>${absUrl(p.loc)}</loc>\n<lastmod>${p.lastmod ?? lastmod}</lastmod>\n<changefreq>weekly</changefreq>\n<priority>${p.priority}</priority>\n</url>`,
|
|
)
|
|
.join("\n");
|
|
return `<?xml version="1.0" encoding="UTF-8"?>\n<urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9">\n${urls}\n</urlset>\n`;
|
|
});
|