$repoPath = (Get-Item $PSScriptRoot).parent

# Create an output directory
New-Item -Path $repoPath -Name "out" -ItemType "directory"

# Compile markdown to html
Get-ChildItem -Path $repoPath -Recurse -Include *.md  | ForEach-Object{
    Write-Output $_

    $html= $_.directoryname+"/out/" + $_.basename+".html"
    $basename = $_.BaseName

    pandoc --standalone --mathjax --metadata "title: $basename" -f markdown -t html5 -s $_.name -o $html --lua-filter=misc/links-to-html.lua
}

# Copy images
Copy-Item -Path $repoPath/images -Destination $repoPath/out/images -Recurse

# Rename README.html to index.html
Rename-Item -Path $repoPath/out/README.html -NewName $repoPath/out/index.html

# Compress output into a zip
if(Test-Path $repoPath/report.zip){
    Remove-Item -Path $repoPath/report.zip
}
Compress-Archive -Path $repoPath/out -DestinationPath $repoPath/report.zip