nuxt-simple-sitemap
Version:
Powerfully flexible XML Sitemaps that integrate seamlessly, for Nuxt.
20 lines (19 loc) • 606 B
JavaScript
export function sortSitemapUrls(urls) {
return urls.sort(
(a, b) => {
const aLoc = typeof a === "string" ? a : a.loc;
const bLoc = typeof b === "string" ? b : b.loc;
return aLoc.localeCompare(bLoc, void 0, { numeric: true });
}
).sort((a, b) => {
const aLoc = (typeof a === "string" ? a : a.loc) || "";
const bLoc = (typeof b === "string" ? b : b.loc) || "";
const aSegments = aLoc.split("/").length;
const bSegments = bLoc.split("/").length;
if (aSegments > bSegments)
return 1;
if (aSegments < bSegments)
return -1;
return 0;
});
}