# W7: add to duplicate-canonical pages $repo = Split-Path -Parent (Split-Path -Parent $PSScriptRoot) $dupFile = Join-Path $repo 'seo-audit-2026-05-27\gsc\duplicate-canonical.txt' if (-not (Test-Path $dupFile)) { Write-Host "Missing $dupFile"; exit 1 } $urls = (Get-Content $dupFile) | Where-Object { $_ -match '^https://' } Write-Host "Total duplicate-canonical URLs: $($urls.Count)" function UrlToLocal([string]$url, [string]$repo) { $p = $url -replace '^https?://www\.odoo-expertos\.com', '' $p = $p.Split('#')[0].Split('?')[0] if ($p -eq '' -or $p -eq '/') { return (Join-Path $repo 'index.html') } if ($p -match '\.html?$') { return (Join-Path $repo ($p.TrimStart('/').Replace('/','\'))) } $p = $p.TrimEnd('/') return (Join-Path $repo ($p.TrimStart('/').Replace('/','\') + '\index.html')) } $opts = [System.Text.RegularExpressions.RegexOptions]::IgnoreCase $noindexed = 0 $missing = 0 foreach ($u in $urls) { $lf = UrlToLocal $u $repo if (-not (Test-Path $lf)) { $missing++; continue } $c = [System.IO.File]::ReadAllText($lf) if (-not $c) { continue } # Check if noindex already present if ([regex]::IsMatch($c, 'name="robots"[^>]*noindex', $opts)) { continue } # If a exists, replace its content; else inject new meta $existing = [regex]::Match($c, '', $opts) if ($existing.Success) { $repl = '' $c = $c.Substring(0, $existing.Index) + $repl + $c.Substring($existing.Index + $existing.Length) } else { # Inject before $c = [regex]::Replace($c, '', '' + "`r`n", $opts) } [System.IO.File]::WriteAllText($lf, $c) $noindexed++ } Write-Host "Pages noindexed: $noindexed; missing local: $missing"