fix: canonical urlにクエリが含まれるのを修正

This commit is contained in:
kakkokari-gtyih 2024-03-12 09:54:46 +09:00
parent ad07837ad8
commit f9dac8ba37

11
app.vue
View File

@ -77,24 +77,25 @@ const head = useLocaleHead({
addSeoAttributes: true, addSeoAttributes: true,
}); });
const i18nLinks = computed(() => head.value.link?.map((e) => { const i18nLinks = computed(() => head.value.link?.map((e: any) => {
if (e.rel === 'alternate') { if (e.rel === 'alternate') {
let href = e.href; let href = e.href;
const url = parseURL(href);
if (typeof e.hreflang === 'string' && (e.hreflang.includes('ja') || e.hreflang === 'x-default') && e.hreflang !== 'ja-KS') { if (typeof e.hreflang === 'string' && (e.hreflang.includes('ja') || e.hreflang === 'x-default') && e.hreflang !== 'ja-KS') {
const url = parseURL(href);
url.pathname = joinURL('/ja/', url.pathname); url.pathname = joinURL('/ja/', url.pathname);
href = cleanDoubleSlashes(withTrailingSlash(stringifyParsedURL(url)));
} else {
href = cleanDoubleSlashes(withTrailingSlash(href));
} }
url.search = '';
href = cleanDoubleSlashes(withTrailingSlash(stringifyParsedURL(url)));
return { ...e, rel: e.rel, href, hreflang: e.hreflang }; return { ...e, rel: e.rel, href, hreflang: e.hreflang };
} else if (e.rel === 'canonical' && locale.value === 'ja') { } else if (e.rel === 'canonical' && locale.value === 'ja') {
let href = e.href; let href = e.href;
const url = parseURL(href); const url = parseURL(href);
url.pathname = joinURL('/ja/', url.pathname); url.pathname = joinURL('/ja/', url.pathname);
url.search = '';
href = cleanDoubleSlashes(withTrailingSlash(stringifyParsedURL(url))); href = cleanDoubleSlashes(withTrailingSlash(stringifyParsedURL(url)));
return { ...e, rel: e.rel, href, hreflang: e.hreflang }; return { ...e, rel: e.rel, href, hreflang: e.hreflang };
} }
return e; return e;
})); }));