mirror of
https://github.com/trafficlunar/tomodachi-share.git
synced 2026-09-27 19:41:46 +00:00
feat: split sitemap
This commit is contained in:
parent
152576e524
commit
253edc0d1a
3 changed files with 89 additions and 60 deletions
24
backend/src/app/sitemap-index.xml/route.ts
Normal file
24
backend/src/app/sitemap-index.xml/route.ts
Normal file
|
|
@ -0,0 +1,24 @@
|
|||
import { prisma } from "@/lib/prisma";
|
||||
import { CHUNK_SIZE } from "../sitemap";
|
||||
import { NextResponse } from "next/server";
|
||||
|
||||
export async function GET() {
|
||||
const baseUrl = process.env.NEXT_PUBLIC_FRONTEND_URL!;
|
||||
|
||||
const total = await prisma.mii.count({
|
||||
where: { in_queue: false, quarantined: false },
|
||||
});
|
||||
const miiChunks = Math.ceil(total / CHUNK_SIZE);
|
||||
const totalSitemaps = miiChunks + 1; // +1 for the static-routes sitemap
|
||||
|
||||
const sitemapEntries = Array.from({ length: totalSitemaps }, (_, i) => `<sitemap><loc>${baseUrl}/sitemap/${i}.xml</loc></sitemap>`).join("");
|
||||
|
||||
const xml = `<?xml version="1.0" encoding="UTF-8"?>
|
||||
<sitemapindex xmlns="http://www.sitemaps.org/schemas/sitemap/0.9">
|
||||
${sitemapEntries}
|
||||
</sitemapindex>`;
|
||||
|
||||
return new NextResponse(xml, {
|
||||
headers: { "Content-Type": "application/xml" },
|
||||
});
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue