nuxt-simple-sitemap
Version:
Powerfully flexible XML Sitemaps that integrate seamlessly, for Nuxt.
24 lines (23 loc) • 790 B
JavaScript
import { defineNitroPlugin } from "nitropack/dist/runtime/plugin";
import { withLeadingSlash } from "ufo";
import { useSimpleSitemapRuntimeConfig } from "../../utils.mjs";
export default defineNitroPlugin((nitroApp) => {
const { sitemaps } = useSimpleSitemapRuntimeConfig();
const queue = [];
const sitemapsWithRoutes = Object.entries(sitemaps).filter(([, sitemap]) => sitemap._route);
for (const [, sitemap] of sitemapsWithRoutes)
queue.push(() => nitroApp.localFetch(withLeadingSlash(sitemap._route), {}));
setTimeout(
() => {
const next = async () => {
if (queue.length === 0)
return;
await queue.shift()();
setTimeout(next, 1e3);
};
next();
},
2500
/* https://github.com/unjs/nitro/pull/1906 */
);
});