$reportPath = "site\report.html"
$sitemapPath = "site\tools\sitemap-generator.html"

# Extract the exact sidebar from sitemap-generator.html
$sitemapHtml = Get-Content $sitemapPath -Raw
$sidebarRegex = '(?s)<aside class="tools-sidebar".*?</aside>'
$sidebar = [regex]::Match($sitemapHtml, $sidebarRegex).Value

# Read report.html
$reportHtml = Get-Content $reportPath -Raw

# 1. Wrap the wrap-mid in page-with-sidebar and page-main
# Find: <div class="wrap-mid" style="padding-top:34px;padding-bottom:100px;" data-report>
$reportHtml = $reportHtml -replace '(<div class="wrap-mid" style="padding-top:34px;padding-bottom:100px;" data-report>)', "<div class=`"page-with-sidebar`">`n<div class=`"page-main`">`n`$1"

# 2. Find the closing </div> of that wrap-mid, which is right before <footer
# We need to insert </div></div> $sidebar right before <footer
$reportHtml = $reportHtml -replace '(?s)</div>\s*<footer class="footer wrap"', "</div>`n</div>`n</div>`n$sidebar`n</div>`n<footer class=`"footer wrap`""

Set-Content -Path $reportPath -Value $reportHtml -Encoding UTF8
Write-Host "Injected sidebar into report.html"
