web/src/app/sitemap.js

30 lines
680 B
JavaScript

import xml2js from "xml2js";
async function getData(id) {
const res = await fetch(`https://storage.vesmeh.com/site-maps/site-map.xml`, {
cache: "no-cache",
});
const xml = await res.text();
return xml;
}
async function parseXml(xml) {
const parser = new xml2js.Parser();
const result = await parser.parseStringPromise(xml);
return result;
}
export default async function Sitemap() {
const xml = await getData();
const parsedXml = await parseXml(xml);
// Construct your sitemap using the parsed XML data
const urls = parsedXml.sitemapindex.sitemap.map((entry) => ({
url: entry.loc[0],
lastModified: entry.lastmod[0],
}));
return urls;
}