algolia-crawl
Version:
Crawl your site and sync your Algolia search index
24 lines • 911 B
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.generateSitemap = void 0;
const algolia_1 = require("./algolia");
const promises_1 = require("fs/promises");
const generateSitemap = async (path) => {
let hits = [];
await algolia_1.index.browseObjects({
query: "",
batch: (batch) => (hits = hits.concat(batch)),
});
let xml = `<?xml version="1.0" encoding="utf-8" ?>
<urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.sitemaps.org/schemas/sitemap/0.9 http://www.sitemaps.org/schemas/sitemap/0.9/sitemap.xsd">`;
hits.forEach((item) => (xml += `
<url>
<loc>${item.url}</loc>
</url>`));
xml += "\n</urlset>\n";
promises_1.writeFile(path, xml);
};
exports.generateSitemap = generateSitemap;
//# sourceMappingURL=sitemap.js.map