Skip to content

Instantly share code, notes, and snippets.

@louisswarren
Last active November 2, 2018 10:03
Show Gist options
  • Save louisswarren/4548f58f563a3a0ba67aaa7994bd2404 to your computer and use it in GitHub Desktop.
Save louisswarren/4548f58f563a3a0ba67aaa7994bd2404 to your computer and use it in GitHub Desktop.
Void content management system
#!/bin/sh
(
flock -x 200
trap 'rm idlock' 0
typeset id=$(cat ds/id)
let id++
echo "$id" | tee ds/id
) 200>idlock
#!/bin/sh
# Surpress errors from file not existing - could have no threads
echo "<html>"
echo "<head>"
echo "<title>View thread</title>"
echo "</head>"
echo "<body>"
cat $@ 2> /dev/null
echo "</body>"
echo "</html>"
exit 0
.PHONY: index
index: www/index.html
ds/posts:
mkdir -p ds/posts
ds/threads:
mkdir -p ds/threads
ds/id:
echo "0" > ds/id
www:
mkdir -p www
.PHONY: setup
setup: ds/posts ds/threads ds/id www
www/index.html: setup indexer $(wildcard ds/threads/*.html)
./indexer ds/threads/*.html > $@
www/%.html: setup threader ds/threads/%.html $(wildcard ds/posts/%-*.html)
./threader ds/threads/$(*F).html ds/posts/$(*F)-*.html > $@
.PHONY: clean
clean:
rm -f www/*.html
# Just for testing
.PHONY: deleteall
deleteall:
rm -r www ds
.PHONY: test
test: setup
echo "This is the first thread!" | ./newthread
echo "This is the first reply!" | ./newpost 1
echo "Your reply is pointless." | ./newpost 1
echo "Thread two: where \"<html>\" is escaped." | ./newthread
make www/index.html
make www/1.html
make www/4.html
#!/bin/sh
threadid="$1"
postid=$(./freshid)
target="ds/posts/$threadid-$postid.html"
echo "<div id=\"$postid\" class=\"post\">" > $target
cat - | recode ascii..html >> $target
echo "</div>" >> $target
#!/bin/sh
threadid=$(./freshid)
target="ds/threads/$threadid.html"
echo "<div id=\"$threadid\" class=\"thread\">" > $target
echo "Thread $threadid [<a href=\"$threadid.html\">Reply</a>]<br>" > $target
cat - | recode ascii..html >> $target
echo "</div><br>" >> $target
#!/bin/sh
# Surpress errors from file not existing - thread could be empty
echo "<html>"
echo "<head>"
echo "<title>View thread</title>"
echo "</head>"
echo "<body>"
echo "[<a href="index.html">Return</a>]<br>"
cat $@ 2> /dev/null
echo "</body>"
echo "</html>"
exit 0
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment