Files
2026-08-28 10:11:11 -03:00

18 lines
1.1 KiB
PowerShell

# W10: extract second inline <style> block from index.html to external CSS file
$repo = Split-Path -Parent (Split-Path -Parent $PSScriptRoot)
$idx = Join-Path $repo 'index.html'
$c = [System.IO.File]::ReadAllText($idx)
$matches = [regex]::Matches($c, '(?s)<style[^>]*>(.*?)</style>')
if ($matches.Count -lt 2) { Write-Host "Not enough style blocks"; exit 0 }
$second = $matches[1]
$cssContent = $second.Groups[1].Value
$cssPath = Join-Path $repo 'css\homepage-extra.min.css'
[System.IO.File]::WriteAllText($cssPath, $cssContent)
# Replace the second <style>...</style> with link tag
$replacement = '<link rel="stylesheet" href="/css/homepage-extra.min.css">'
$newC = $c.Substring(0, $second.Index) + $replacement + $c.Substring($second.Index + $second.Length)
[System.IO.File]::WriteAllText($idx, $newC)
$newMatches = [regex]::Matches($newC, '(?s)<style[^>]*>(.*?)</style>')
$total = ($newMatches | ForEach-Object { $_.Groups[1].Value.Length } | Measure-Object -Sum).Sum
Write-Host "Extracted $($cssContent.Length) bytes to css/homepage-extra.min.css; inline CSS now: $total bytes"