feat: add tackle pages to sitemap
This commit is contained in:
@@ -1,5 +1,5 @@
|
||||
import type { APIRoute } from "astro";
|
||||
import { api, type DictionaryItem } from "../lib/api";
|
||||
import { api, type DictionaryItem, type PaginatedRigs, type PaginatedTackleItems } from "../lib/api";
|
||||
|
||||
const escapeXml = (value: string) => value.replace(/[<>&'"]/g, c => ({ "<": "<", ">": ">", "&": "&", "'": "'", '"': """ })[c] ?? c);
|
||||
let lastGood: { origin: string; xml: string; at: number } | undefined;
|
||||
@@ -9,7 +9,7 @@ export const GET: APIRoute = async ({ site }) => {
|
||||
const output = (xml: string) => new Response(xml, { headers: { "Content-Type": "application/xml; charset=utf-8", "Cache-Control": "public, max-age=1800" } });
|
||||
if (lastGood?.origin === origin && Date.now() - lastGood.at < 1800000) return output(lastGood.xml);
|
||||
try {
|
||||
const paths = new Set(["/", "/records", "/report", "/status", "/rules", "/privacy", "/fish", "/waterbodies", "/media"]);
|
||||
const paths = new Set(["/", "/records", "/report", "/status", "/rules", "/privacy", "/fish", "/waterbodies", "/media", "/tackle"]);
|
||||
for (const [endpoint, prefix] of [["fishes", "fish"], ["waterbodies", "waterbodies"]]) {
|
||||
for (let offset = 0; ; offset += 500) {
|
||||
const rows = await api<DictionaryItem[]>(`/api/v1/${endpoint}?limit=500&offset=${offset}`);
|
||||
@@ -18,6 +18,18 @@ export const GET: APIRoute = async ({ site }) => {
|
||||
if (rows.length < 500) break;
|
||||
}
|
||||
}
|
||||
for (let offset = 0; ; offset += 100) {
|
||||
const page = await api<PaginatedTackleItems>(`/api/v1/tackle/items?limit=100&offset=${offset}`);
|
||||
page.items.forEach(item => paths.add(`/tackle/items/${item.id}`));
|
||||
if (paths.size > 49000) throw new Error("Sitemap index required");
|
||||
if (page.items.length < page.limit) break;
|
||||
}
|
||||
for (let offset = 0; ; offset += 100) {
|
||||
const page = await api<PaginatedRigs>(`/api/v1/tackle/rigs?limit=100&offset=${offset}`);
|
||||
page.items.forEach(rig => paths.add(`/tackle/rigs/${rig.id}`));
|
||||
if (paths.size > 49000) throw new Error("Sitemap index required");
|
||||
if (page.items.length < page.limit) break;
|
||||
}
|
||||
for (let offset = 0; ; offset += 500) {
|
||||
const rows = await api<string[]>(`/api/v1/public-spot-pages?limit=500&offset=${offset}`);
|
||||
rows.forEach(path => paths.add(path));
|
||||
|
||||
Reference in New Issue
Block a user