Skip to content

Commit

Permalink
added head !== null check SEO
Browse files Browse the repository at this point in the history
  • Loading branch information
Aleksandra Timofejeva authored and Aleksandra Timofejeva committed Aug 15, 2024
1 parent 8a806c7 commit 660b101
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 660b101

Please sign in to comment.