about summary refs log tree commit diff stats
path: root/mynah
diff options
context:
space:
mode:
authorelioat@tilde.institute <eli@newstartmobile.com>2023-01-10 22:18:29 -0500
committerelioat@tilde.institute <eli@newstartmobile.com>2023-01-10 22:18:29 -0500
commit0b233305f90a815992a840bc687f18f2eaa0d456 (patch)
treee886df7e711eccdb3b06f93ff199b4cffdd2921c /mynah
downloadwiki-0b233305f90a815992a840bc687f18f2eaa0d456.tar.gz
gonna try to do the wiki thing
Diffstat (limited to 'mynah')
-rwxr-xr-xmynah149
1 files changed, 149 insertions, 0 deletions
diff --git a/mynah b/mynah
new file mode 100755
index 0000000..e42250d
--- /dev/null
+++ b/mynah
@@ -0,0 +1,149 @@
+#!/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=$(<updated)
+fi
+TIMESTAMP=$(gdate +"%s")
+RFC822=$(gdate -R)
+RSSHEADER='<?xml version="1.0" encoding="UTF-8"?>
+<rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0">
+<channel>
+<title>
+<![CDATA[ '${SITENAME}']]>
+</title>
+<link>'${SITEURL}'</link>
+<atom:link href="'${SITEURL}'/feed.rss" rel="self" type="application/rss+xml"/>
+<description>
+<![CDATA[ '${SITEDESCRIPTION}' ]]>
+</description>'
+RSSEND='</channel></rss>'
+
+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='<item>
+<title>
+<![CDATA[ the page "'${file%.*}'" was updated! ]]>
+</title>
+<link>'${SITEURL}'/'${file%.*}.html'</link>
+<guid>'${SITEURL}/${file%.*}.html#$(uuidgen)'</guid>
+<pubDate>'${RFC822}'</pubDate>
+<description>
+<![CDATA[ 
+<p><a href="'${SITEURL}/${file%.*}.html'">'${file%.*}'</a> updated!</p><br><br><pre><code>'$(fold -sw 80 <"$file")'</code></pre>  ]]>
+</description>
+</item>'
+            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 "$@"