UNPKG

@scayle/storefront-nuxt

Version:

Nuxt integration for the SCAYLE Commerce Engine and Storefront API

29 lines (28 loc) 881 B
import { parseURL, stringifyParsedURL, parseQuery, stringifyQuery } from "ufo"; const CANONICAL_PARAMS_WHITELIST = ["page"]; export const sanitizeCanonicalURL = (url, whitelistParams = CANONICAL_PARAMS_WHITELIST) => { const parsedURL = parseURL(url); if (!parsedURL.search) { return url; } const parsedQuery = parseQuery(parsedURL.search); const purifiedQuery = Object.fromEntries( Object.entries(parsedQuery).filter( ([key]) => whitelistParams.includes(key) ) ); return stringifyParsedURL({ ...parsedURL, search: stringifyQuery(purifiedQuery) }); }; export const generateCategoryBreadcrumbSchema = (breadcrumbs) => ({ "@context": "https://schema.org", "@type": "BreadcrumbList", itemListElement: breadcrumbs.map((item, index) => ({ "@type": "ListItem", position: index + 1, name: item.value, item: item.to })) });