# W4: fix mislocated hreflang="es" hrefs + add hreflang block to 3 ES category pages $repo = Split-Path -Parent (Split-Path -Parent $PSScriptRoot) $excludePattern = '\\(\.git|node_modules|seo-audit-2026-05-27|website|directory)\\' $files = Get-ChildItem $repo -Recurse -Filter index.html -File -ErrorAction SilentlyContinue | Where-Object { $_.FullName -notmatch $excludePattern } $opts = [System.Text.RegularExpressions.RegexOptions]::IgnoreCase $changed = 0 foreach ($file in $files) { $c = [System.IO.File]::ReadAllText($file.FullName) if (-not $c) { continue } $orig = $c # Strip /en/ /de/ /fr/ /pt/ /ar/ segment in any hreflang="es" or hreflang="x-default" href value $c = [regex]::Replace($c, '(hreflang="(?:es|x-default)"[^>]*href="https://www\.odoo-expertos\.com)/(?:de|fr|pt|ar|en)/', '$1/', $opts) # Also handle the inverse order: href=... hreflang=es $c = [regex]::Replace($c, '(href="https://www\.odoo-expertos\.com)/(?:de|fr|pt|ar|en)/([^"]*"\s+hreflang="(?:es|x-default)")', '$1/$2', $opts) if ($c -ne $orig) { [System.IO.File]::WriteAllText($file.FullName, $c) $changed++ } } Write-Host "W4 hreflang-es fix: changed $changed of $($files.Count) files" # Inject hreflang block into ES category pages $cats = @{ 'odoo' = 'odoo/' 'odoo-hosting' = 'odoo-hosting/' 'odoo-ia' = 'odoo-ia/' } $injected = 0 foreach ($cat in $cats.Keys) { $catPath = Join-Path $repo "$cat\index.html" if (-not (Test-Path $catPath)) { continue } $c = [System.IO.File]::ReadAllText($catPath) if ($c -match 'hreflang=') { continue } $sub = $cats[$cat] $block = @" "@ # Insert after canonical link $new = [regex]::Replace($c, '(]*>)', "`$1`r`n$block", $opts) if ($new -eq $c) { # fallback: inject before $new = $c -replace '', "$block`r`n" } if ($new -ne $c) { [System.IO.File]::WriteAllText($catPath, $new) $injected++ Write-Host "Injected hreflang into $cat/index.html" } } Write-Host "W4 cat injection: $injected"