#!/usr/bin/env bash # requires pandoc # coreutils # uuidgen # tidy # the_silver_searcher (could use grep instead) set -o errexit set -o nounset set -o pipefail if [[ "${TRACE-0}" == "1" ]]; then set -o xtrace fi SITENAME="wiki" SITEURL="https://elioat.tilde.institute/wiki" SITEDESCRIPTION="a little wiki" if [[ -f updated ]]; then LASTUPDATE=$( '${SITEURL}' ' RSSEND='' build_logs() { pandoc changelog.md -o public/changelog.html cd content rm ../archive.md echo -e "# Archive\n" > ../archive.md for file in *; do archive_entry="- [${file%.*}](${SITEURL}/${file%.*}.html)" echo -e "$archive_entry" >> ../archive.md done cd .. pandoc archive.md -o public/archive.html } build() { cd content i=0 rm ../public/feed.xml touch ../public/feed.xml echo -e "${RSSHEADER}" > ../public/feed.xml for file in *; do file_last_updated=$(stat -f %m "$file") if [ "$file_last_updated" -gt "$LASTUPDATE" ]; then (( i++ )) updated_at="- [${file%.*}](${SITEURL}/${file%.*}.html), ${RFC822}" echo -e "$updated_at\n$(cat ../changelog.md)" > ../changelog.md pandoc "${file}" -o ../public/"${file%.*}".html rss_entry=' <![CDATA[ the page "'${file%.*}'" was updated! ]]> '${SITEURL}'/'${file%.*}.html' '${SITEURL}/${file%.*}.html#$(uuidgen)' '${RFC822}' '${file%.*}' updated!



'$(fold -sw 80 <"$file")'
]]>
' echo -e "$rss_entry" >> ../public/feed.xml fi done cd .. echo -e "$RSSEND" >> public/feed.xml # this is stupid and superfluous, but I was bugged by the weirdly formatted RSS output tidy \ -xml \ --show-body-only yes \ --indent auto \ --indent-spaces 2 \ --quiet yes \ -w 80 \ -m \ --force-output y \ --wrap 0 \ public/feed.xml if [ $i -gt 0 ]; then build_logs "$@" fi echo "$TIMESTAMP" > updated echo "updated" $i "items." } help_text() { echo ' mynah, a little wiki bird usage: ./mynah -b(uild)....to build the site -s(earch)...to search for a pattern across all wiki entries -d(eploy)...to publish the public directory to a host -h(elp).....to display this message -n(est).....to start a new wiki ' } if [[ "${1-}" =~ ^-*h(elp)?$ ]]; then help_text "$@" exit elif [[ "${1-}" =~ ^-*b(uild)?$ ]]; then build "$@" exit elif [[ "${1-}" =~ ^-*s(earch)?$ ]]; then ag "$2" content/* exit elif [[ "${1-}" =~ ^-*d(eploy)?$ ]]; then scp -r public/* elioat@tilde.institute:~/public_html/wiki/ exit elif [[ "${1-}" =~ ^-*n(est)?$ ]]; then if [[ -f content ]]; then echo -e " a content directory already exists so you can't build a new nest here " else mkdir content public touch archive.md changelog.md updated public/feed.xml fi exit fi cd "$(dirname "$0")" main() { help_text "$@" } main "$@"