Skip to content

Commit

Permalink
Merge pull request #33 from tilde-nlp/fix/canonical-tag-fix
Browse files Browse the repository at this point in the history
added head !== null check SEO
  • Loading branch information
gunpuz authored Aug 15, 2024
2 parents 7d94a28 + 660b101 commit 8da4e80
Showing 1 changed file with 11 additions and 9 deletions.
20 changes: 11 additions & 9 deletions src/js/lib/SearchEngineOptimization.ts
Original file line number Diff line number Diff line change
Expand Up @@ -111,15 +111,17 @@ export class SearchEngineOptimization {

for (const locale of availableLocales) {
const localizedUrl = this.localizeUrl(new URL(doc.URL), locale)
const existingLink = doc.head.querySelector(`link[rel="alternate"][hreflang="${locale}"]`)

if (!existingLink) {
link = document.createElement('link')
link.rel = 'alternate'
link.hreflang = locale
link.href = localizedUrl

doc.head.appendChild(link)
if (doc.head !== null) {
const existingLink = doc.head.querySelector(`link[rel="alternate"][hreflang="${locale}"]`)

if (!existingLink) {
link = document.createElement('link')
link.rel = 'alternate'
link.hreflang = locale
link.href = localizedUrl

doc.head.appendChild(link)
}
}
}
}
Expand Down

0 comments on commit 8da4e80

Please sign in to comment.