$reportPath = "site\report.html"
$html = Get-Content $reportPath -Raw

# In report.html, we injected the blog slider which was copied from a file inside tools/
# So the relative paths like "../assets/" and "../blog/" are broken because report.html is in the root directory!
# We will fix the paths only within the blog slider block to avoid breaking anything else.

# The blog slider block starts with <div class="blog-slider-head">
$blogRegex = '(?s)(<div class="blog-slider-head">.*?)<footer'
$blogMatch = [regex]::Match($html, $blogRegex)

if ($blogMatch.Success) {
    $blogHtml = $blogMatch.Groups[1].Value
    # Fix image sources
    $blogHtml = $blogHtml -replace '"\.\./assets/', '"assets/'
    # Fix article links
    $blogHtml = $blogHtml -replace '"\.\./blog/', '"blog/'

    $html = $html -replace $blogRegex, "$blogHtml<footer"
    Set-Content -Path $reportPath -Value $html -Encoding UTF8
    Write-Host "Fixed broken image and article paths in report.html blog slider!"
} else {
    Write-Host "Could not find blog slider in report.html"
}
