Skip to content

Commit

Permalink
feat: add default canonicals and hreflangs (#19)
Browse files Browse the repository at this point in the history
  • Loading branch information
Monika Radosiewicz authored and mercs600 committed Oct 4, 2023
1 parent c9e0f97 commit 8ce9a37
Showing 1 changed file with 12 additions and 4 deletions.
16 changes: 12 additions & 4 deletions src/runtime/composables/useT3Meta.ts
Original file line number Diff line number Diff line change
Expand Up @@ -120,23 +120,31 @@ export const useT3Meta = (): {

if (baseUrl) {
data.value?.i18n.forEach((item: T3I18N) => {
if (!canonical.href && item.active) {
canonical.href = baseUrl + item.link
if (item.active) {
canonical.href = baseUrl + (canonical.href || item.link)
}

if (item.languageId === 0) {
link.push({
rel: 'alternate',
hreflang: 'x-default',
href: baseUrl + item.link
})
}

if (item.available) {
link.push({
rel: 'alternate',
hreflang: item.hreflang,
hreflang: item.twoLetterIsoCode,
href: baseUrl + item.link
})
}
})
}

if (canonical.href) {
link.push(canonical)
}

return link
})

Expand Down

0 comments on commit 8ce9a37

Please sign in to comment.