// Links to the site's own pages from absolute CMS URLs: a URL on the site // URL's origin (or on the request origin) becomes its path, so it renders // as a NuxtLink; another http(s) URL stays as it is, and anything else // (javascript:, data: …) becomes '' so it is never rendered as a link. // Pure; names start with `seo` because app/utils is auto-imported. export function seoSitePath(url: string, ...origins: Array): string { if (typeof url !== 'string' || url === '') return '' if (url.startsWith('/') && !url.startsWith('//')) return url let parsed: URL try { parsed = new URL(url) } catch { return '' } if (parsed.protocol !== 'https:' && parsed.protocol !== 'http:') return '' for (const o of origins) { if (!o) continue try { if (new URL(o).origin === parsed.origin) return `${parsed.pathname}${parsed.search}` || '/' } catch { // not a URL } } return url }