Code Snippets & Oneliners
Main section of this blog build script
On my windows machine:
# .\build.ps1
$contetnDir = $(Get-Item -Path .\content).FullName
$buildDir = $(Get-Item -Path .\build).FullName
$defaultTemplate = $(Get-Item -Path .\templates\default.html).FullName
Get-ChildItem -Path .\content -Recurse -File | ForEach-Object {
$outputDir = $(New-Item -Path $_.DirectoryName.Replace($contetnDir, $buildDir) -ItemType Directory -Force).FullName
if ($_.Extension -eq ".md") {
.exe --standalone --template $defaultTemplate --output "$($outputDir)\$($_.BaseName).html" "$($_.FullName)"
pandoc} else {
Copy-Item -Path "$($_.FullName)" -Destination "$($outputDir)\$($_.Name)"
}
}
On builds.sr.ht:
# ./build.sh
find ./content -type f -print0 | while read -d $'\0' inputFile; do
inputDir=$( dirname $inputFile )
outputDir="./build${inputDir#./content}"
inputExtension="${inputFile##*.}"
inputFilename=$( basename ${inputFile} )
mkdir -p "${outputDir}"
if [ 'md' = "${inputExtension}" ]; then
outputFilename="${inputFilename/.md}.html"
pandoc --standalone --template "${defaultTemplate}" --output "${outputDir}/${outputFilename}" "${inputFile}"
else
cp "${inputFile}" "${outputDir}/${outputFilename}"
fi
done
Excel formula to convert from UNIX timestamp to date
=(((LEFT(A1,10) & "." & RIGHT(A1,3)/60)/60)/24)+DATE(1970,1,1)
Adapted from this stackoverflow answer