const sitemapRes = await fetch("https://example.com/sitemap.xml");
const sitemapXml = await sitemapRes.text();
const urls = Array.from(sitemapXml.matchAll(/<loc>([^<]+)<\/loc>/g)).map(
(m) => m[1],
);
// Submit in chunks of 1,000 (the max per request)
for (let i = 0; i < urls.length; i += 1000) {
const chunk = urls.slice(i, i + 1000);
const result = await client.read({
urls: chunk,
webhook: {
url: "https://your-app.example.com/hooks/reader",
events: ["job.completed"],
secret: process.env.READER_WEBHOOK_SECRET,
},
});
console.log(`submitted batch ${i / 1000 + 1}, job=${result.data.id}`);
}