#!/bin/ksh #Site build script #vim: set colorcolumn=81 ft=sh:hi ColorColumn ctermbg=224 "------ # Due to ambiguity in the markup format, you probably intended to # go to a link labeled "$/build.sh". This is really a link to # "$/build.sh.txt" in the unformatted post. Here is a proper # link: $/build.sh.txt. This was # fixed in this document through a hack I'm not particularly # proud of. txt2html() { # cut off the modeline and title tail -n +3 | # convert lines starting with `##` to comments sed 's|^\(##.*\)$|\1|' | # convert <,> to HTML-compatible format sed 's|<|\<|g' | sed 's|>|\>|g' | # convert italics to html sed 's|\*{||g' | sed 's|}\*||g' | # convert bold to html sed 's|&{||g' | sed 's|}&||g' | # convert codeblocks into css-ified codeblocks sed 's|``[`]{|
|' | sed 's|}[`]``||' | # convert inline codeblocks into css-ified codeblocks sed 's|`[{]||g' | sed 's|[}]`||g' | # See next comment. $/url.txt -> /url.html sed 's|\([$]/\)\([^ \)]*\)[.]txt\([,.]\)|\1\2\3|g' | sed 's|\([$]/\)\([^ \)<>]*\)[.]txt|\1\2|g' | # convert `$/url` to html links relative to root domain #sed 's|\([$]/\)\([^ \)]*\)\([,.]\)|\1\2\3|g' | sed 's!^\([$]/\)\([^ \)<>]*\)!\1\2!g;s!\([^>]\)\([$]/\)\([^ \)<>]*\)!\1\2\3!g' | # See next comment. %/url.txt -> url.html sed 's|\(%/\)\([^ \)]*\)[.]txt\([,.]\)|\1\2\3|g' | sed 's|\(%/\)\([^ \)<>]*\)[.]txt|\1\2|g' | # convert `%/url` to html links relative to current directory sed 's!^\(%/\)\([^ \)<>]*\)!\1\2!g;s!\([^>]\)\(%/\)\([^ \)<>]*\)!\1\2\3!g' | # convert `#/url` to html links sed 's|\([#]/\)\([^ )]*\)\([,.)] \)|\1\2\3|g' | sed 's|\([#]/\)\([^ )<>]*\)|\1\2|g' | # convert `-[0-9]` into IDs sed 's|^\([ -]*\)\[\([0-9.][0-9.]*\)\]|\1[\2]|g' | # convert `[0-9]` into references to IDs sed 's|\([^\"#]\)\[\([0-9.][0-9.]*\)\]|\1[\2]|g' | # convert `-{0-9}` into references to footnotes sed 's|^\(- [^{]*\){\([0-9]*\)}|\1{\2}|g' | # convert `{0-9}` into footnotes sed 's|{\([0-9]*\)}|{\1}|g' | # set content sed '/%%CONTENT%%/r /dev/stdin' html_template | sed '/%%CONTENT%%/d' | # set title sed "s|%%TITLE%%|${1:-Index}|" } { # process arguments if available, else all *.txt [ $# -eq 0 ] && find . -name '*.txt' | grep -ve 'robots.txt$' | tee /dev/stderr while [ ! $# -eq 0 ]; do case "$1" in sitemap*) shift break ;; esac printf '%s\n' "$1" shift done } | while read -r PAGE; do title=$(sed '2p;d' "$PAGE") printf 'txt2html %s\n' "$title" txt2html "$title" < "$PAGE" > "${PAGE%%.txt}.html" [ "$PAGE" = ./build.sh.txt ] && sed -i 's|<|<|g;s|>|>|g' "${PAGE%%.txt}.html" done find . -type f ! -name \*.gz | while read -r FILE; do yes | gzip -9k "$FILE" >/dev/null 2>&1 done printf 'txt2html Sitemap\n' find . -name '*.html' | cut -d/ -f2- | grep -ve ^sitemap[.]html\$ -e ^latest[.]html\$ | while read -r PAGE; do printf '$/%s\n' "$PAGE" "$(sed '2p;d' "${PAGE%%.html}.txt")" done | sed '/%%CONTENT%%/r /dev/stdin' html_template | sed '/%%CONTENT%%/d' | sed 's|%%TITLE%%|Sitemap|' > sitemap.html