Skip to content

Instantly share code, notes, and snippets.

@ckxng

ckxng/microsite.cgi

Last active Nov 25, 2020
Embed
What would you like to do?
#!/bin/sh
# parse the page and pagepath from QUERY_STRING
page=$(
echo "${QUERY_STRING}" | \
sed -n 's/^.*page=\([^&]*\).*$/\1/p' | \
sed 's/[^a-zA-Z0-9\/\-_]/X/g'
)
if [ "${page}" = '' ]; then
page='index'
fi
pagepath="../pages/${page}.txt"
# return 404 if the page does not exist
if test -f $pagepath; then
content=$(../../go/bin/markdown $pagepath)
else
echo "Status: 404 Not Found
Content-type: text/html
Page \"${page}\" not found.
"
exit
fi
# render the page
echo "Content-type: text/html
... page template ...
${content}
... page template ...
"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment