Skip to content

Instantly share code, notes, and snippets.

@ckxng
Last active November 25, 2020 15:02
Show Gist options
  • Save ckxng/5fba350bc22e8dd981d7d5a01b5b1daa to your computer and use it in GitHub Desktop.
Save ckxng/5fba350bc22e8dd981d7d5a01b5b1daa to your computer and use it in GitHub Desktop.
#!/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