new site
This commit is contained in:
@@ -0,0 +1,103 @@
|
||||
# W5: shorten titles >65 chars; guarantee unique meta descriptions across the corpus
|
||||
$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 }
|
||||
|
||||
function ToTitle([string]$slug) {
|
||||
$s = $slug -replace '-', ' '
|
||||
$s = (Get-Culture).TextInfo.ToTitleCase($s.ToLower())
|
||||
$s = $s -replace '\bOdoo\b','Odoo'
|
||||
$s = $s -replace '\bAi\b','AI'
|
||||
$s = $s -replace '\bErp\b','ERP'
|
||||
$s = $s -replace '\bIa\b','IA'
|
||||
$s = $s -replace '\bAws\b','AWS'
|
||||
$s = $s -replace '\bGcp\b','GCP'
|
||||
$s = $s -replace '\bVps\b','VPS'
|
||||
$s = $s -replace '\bSh\b','SH'
|
||||
$s = $s -replace '\bUk\b','UK'
|
||||
$s = $s -replace '\bUsa\b','USA'
|
||||
$s = $s -replace '\bSaas\b','SaaS'
|
||||
return $s
|
||||
}
|
||||
|
||||
function PathLang([string]$fullPath, [string]$repo) {
|
||||
$rel = $fullPath.Substring($repo.Length).TrimStart('\','/')
|
||||
$parts = $rel -split '[\\/]'
|
||||
if ($parts.Count -ge 1 -and ($parts[0] -in @('en','de','fr','pt','ar'))) {
|
||||
return $parts[0]
|
||||
}
|
||||
return 'es'
|
||||
}
|
||||
|
||||
# First pass — collect existing meta description counts (informational only)
|
||||
$metaCounts = @{}
|
||||
foreach ($file in $files) {
|
||||
$c = [System.IO.File]::ReadAllText($file.FullName)
|
||||
if (-not $c) { continue }
|
||||
$m = [regex]::Match($c, '<meta\s+name="description"\s+content="([^"]*)"')
|
||||
if ($m.Success) {
|
||||
$d = $m.Groups[1].Value.Trim()
|
||||
if ($d) {
|
||||
if ($metaCounts.ContainsKey($d)) { $metaCounts[$d]++ } else { $metaCounts[$d] = 1 }
|
||||
}
|
||||
}
|
||||
}
|
||||
Write-Host "Pre-existing duplicate meta strings: $((${metaCounts}.GetEnumerator() | Where-Object {$_.Value -gt 1}).Count)"
|
||||
|
||||
$titleChanged = 0
|
||||
$metaChanged = 0
|
||||
foreach ($file in $files) {
|
||||
$c = [System.IO.File]::ReadAllText($file.FullName)
|
||||
if (-not $c) { continue }
|
||||
$orig = $c
|
||||
|
||||
$dir = Split-Path -Parent $file.FullName
|
||||
$slug = Split-Path -Leaf $dir
|
||||
$pretty = ToTitle $slug
|
||||
if ($pretty.Length -gt 42) { $pretty = $pretty.Substring(0,42).TrimEnd() }
|
||||
$lang = (PathLang $file.FullName $repo).ToUpper()
|
||||
|
||||
# Title fix (shorten if >65 chars)
|
||||
$tm = [regex]::Match($c, '<title>(.*?)</title>', 'Singleline')
|
||||
if ($tm.Success) {
|
||||
$curTitle = $tm.Groups[1].Value.Trim()
|
||||
if ($curTitle.Length -gt 65) {
|
||||
$base = $pretty
|
||||
$newTitle = "$base | Odoo Expertos"
|
||||
if ($newTitle.Length -gt 60) {
|
||||
$maxBase = 60 - " | Odoo Expertos".Length
|
||||
if ($maxBase -lt 5) { $maxBase = 5 }
|
||||
$newTitle = $base.Substring(0, [Math]::Min($base.Length, $maxBase)).TrimEnd() + " | Odoo Expertos"
|
||||
}
|
||||
$c = $c.Substring(0, $tm.Index) + "<title>$newTitle</title>" + $c.Substring($tm.Index + $tm.Length)
|
||||
$titleChanged++
|
||||
}
|
||||
}
|
||||
|
||||
# Always make meta description unique by appending " - [Slug] | [LANG]"
|
||||
$dm = [regex]::Match($c, '<meta\s+name="description"\s+content="([^"]*)"')
|
||||
if ($dm.Success) {
|
||||
$curDesc = $dm.Groups[1].Value.Trim()
|
||||
if ($curDesc) {
|
||||
$suffix = " - $pretty | $lang"
|
||||
# Only add suffix if it isn't already there (idempotent)
|
||||
if (-not $curDesc.EndsWith($suffix)) {
|
||||
$base = $curDesc
|
||||
if (($base.Length + $suffix.Length) -gt 165) {
|
||||
$base = $base.Substring(0, [Math]::Max(1, 165 - $suffix.Length)).TrimEnd()
|
||||
}
|
||||
$newDesc = $base + $suffix
|
||||
$newDesc = $newDesc -replace '"', '"'
|
||||
$repl = '<meta name="description" content="' + $newDesc + '"'
|
||||
$c = $c.Substring(0, $dm.Index) + $repl + $c.Substring($dm.Index + $dm.Length)
|
||||
$metaChanged++
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if ($c -ne $orig) {
|
||||
[System.IO.File]::WriteAllText($file.FullName, $c)
|
||||
}
|
||||
}
|
||||
Write-Host "W5: titles shortened=$titleChanged; meta descriptions modified=$metaChanged"
|
||||
Reference in New Issue
Block a user