UNPKG

nuxt-simple-sitemap

Version:

Powerfully flexible XML Sitemaps that integrate seamlessly, for Nuxt.

22 lines (21 loc) 679 B
import { createDefu } from "defu"; import { withLeadingSlash } from "ufo"; const merger = createDefu((obj, key, value) => { if (Array.isArray(obj[key]) && Array.isArray(value)) obj[key] = Array.from(/* @__PURE__ */ new Set([...obj[key], ...value])); return obj[key]; }); export function mergeOnKey(arr, key) { const res = {}; arr.forEach((item) => { const k = item[key]; res[k] = merger(item, res[k] || {}); }); return Object.values(res); } export function splitForLocales(path, locales) { const prefix = withLeadingSlash(path).split("/")[1]; if (locales.includes(prefix)) return [prefix, path.replace(`/${prefix}`, "")]; return [null, path]; }