#!/bin/bash set -euo pipefail shopt -s globstar tree_output=$(mktemp "/tmp/${USER:-lucidiot-wiki}.XXXXXXXXXX") tree_file=$(mktemp "/tmp/${USER:-lucidiot-wiki}.XXXXXXXXXX") trap "rm \"$tree_output\" \"$tree_file\"" EXIT # Variables included in the pandoc template now="$(date -Iseconds)" generator="$(pandoc --version | head -n1)" function convert { # Usage: convert input_file output_file output_format if [ "$3" = html ]; then pandoc \ --read markdown \ --write html \ --standalone \ --table-of-contents \ --template template.html \ --highlight-style zenburn \ --css "/~${USER:-lucidiot}/theme.css" \ --variable generator="$generator" \ --variable now="$now" \ -o "$2" \ "$1" else pandoc \ --read markdown \ --write "$3" \ --table-of-contents \ -o "$2" \ "$1" fi chmod 644 "$2" } function convert_all_md { # Usage: convert_all_md output_directory file_extension pandoc_output_format local file local output echo "Converting all Markdown files to .$2 files under $1/" for file in content/**/*.md; do output="${file/#content/$1}" output="${output/%.md/.$2}" mkdir -p "$(dirname "$output")" chmod 755 "$(dirname "$output")" echo " $file -> $output" convert "$file" "$output" "$3" done } convert_all_md html html html convert_all_md gopher txt plain function link_assets { echo "Copying assets from $1 to $2" for path in $1/*; do echo " $path -> $2" cp -dr --no-preserve=mode "$path" "$2" done echo " Fixing asset attributes" find "$1" -type d | sed "s|^$1|$2|" | xargs chmod 755 find "$1" -type f | sed "s|^$1|$2|" | xargs chmod 644 } link_assets assets html link_assets assets gopher link_assets html_assets html link_assets gopher_assets gopher # Build the 'everything' page and CDF feed echo 'Building article list' pushd html >/dev/null tree --du --si -X --prune -P '*.html' > "$tree_output" popd >/dev/null echo "--- title: everything --- " > "$tree_file" xsltproc xsl/tree-html.xsl "$tree_output" >> "$tree_file" convert "$tree_file" "html/everything.html" html xsltproc xsl/tree-cdf.xsl "$tree_output" | xmllint --format - > "html/everything.cdf" xmllint --noout --schema "assets/xsd/cdf.xsd" "html/everything.cdf" chmod 644 "html/everything.cdf" # Build an RSS feed echo 'Building RSS feed' echo ' ~lucidiot'"'"'s wiki https://envs.net/~lucidiot/ latest articles on ~lucidiot'"'"'s personal wiki en-FR Creative Commons BY 4.0 International, ~lucidiot lucidiot@envs.net (lucidiot) lucidiot@envs.net (lucidiot) https://www.rssboard.org/rss-specification ' > html/rss.xml for file in content/**/*.md; do link="${file##content/}" link="https://envs.net/~lucidiot/${link/%.md/.html}" echo ' '"$(sed -n 's|\s*title:\s*\(.*\)$|\1|p' "$file")"' '"$(date -Rd "@$(stat -c%Y "$file")")"' '"$link"' '"$link"' ' >> html/rss.xml done echo ' ' >> html/rss.xml chmod 644 html/rss.xml