Last active
April 27, 2022 07:48
-
-
Save altavir/a9f4f54cfb7d660067a7c7dbbc71e833 to your computer and use it in GitHub Desktop.
PowerShell + Lua to build report from markdown.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| $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 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| # links-to-html.lua | |
| function Link(el) | |
| el.target = string.gsub(el.target, "%.md", ".html") | |
| return el | |
| end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment