Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/bin/sh
- BLOGTITLE="test blog"
- BLOGSUBTITLE="super cool!!!"
- POSTSDIR="posts"
- DEFTAG="uncategorized"
- getparam() {
- # Thanks to the site below for this bit of sed:
- # http://foxlx.acmesystems.it/?id=165
- echo $QUERY_STRING | sed -n "s/^.*$1=\([^&]*\).*$/\1/p" | sed 's/%20/ /g'
- }
- getposts() {
- ls -t $(find -iname '*.md' | sed 's,^\./,,')
- }
- posttitle() {
- echo $1 | sed -n 's/^\([^-]*\).*\.md$/\1/p'
- }
- posttags() {
- TAGS=$(echo $1 | sed -n 's/^[^-]*-\(.*\)\.md$/\1/p' | sed 's/-/ /g')
- [ -z "$TAGS" ] && TAGS="$DEFTAG" # Apply default tag to untagged posts
- echo $TAGS
- }
- recentposts() {
- POSTS=$(getposts | head -$1)
- for p in $POSTS; do
- TITLE=$(posttitle $p)
- cat << POSTLINK
- <a href="s.cgi?post=$TITLE">$(echo $TITLE | sed 's/_/ /g')</a>
- <br>
- POSTLINK
- done
- }
- gettags() {
- POSTS=$(getposts)
- TAGS="$DEFTAG"
- for p in $POSTS; do
- for t in $(posttags $p); do
- [ -z "$(echo $TAGS | grep $t)" ] && TAGS="$TAGS $t"
- done
- done
- echo $TAGS
- }
- taglinks() {
- for t in $*; do
- echo "<a href=\"s.cgi?tag=$t\">$t</a>"
- done
- }
- showpost() {
- TITLE=$(posttitle $1)
- TAGS=$(posttags $1)
- cat << BLOGPOST
- <h3 style="display: inline; float: left; margin: 0;">
- $(echo $TITLE | sed 's/_/ /g')
- </h3>
- <p style="display: inline; float: right; font-size: 80%; margin: 0;">
- $(taglinks $TAGS)
- </p>
- <div style="clear: both;">
- <!-- markdown output begins... -->
- $(../md2html.awk $1)
- <!-- ...and ends -->
- </div>
- BLOGPOST
- }
- showtag() {
- echo "<h3>Posts tagged \"$TAGNAME\"</h3>"
- for p in $(getposts); do
- if [ -n "$(posttags $p | grep $TAGNAME)" ]; then
- TITLE=$(posttitle $p)
- cat << POSTLINK
- <a href="s.cgi?post=$TITLE">$(echo $TITLE | sed 's/_/ /g')</a>
- <br>
- POSTLINK
- fi
- done
- }
- echo "Content-type: text/html"
- echo
- # Nobody wants to see an empty blog...
- if [ -z "$POSTSDIR" ] || [ ! -d $POSTSDIR ]; then
- echo "Nothing to see here!"
- exit 1
- fi
- cd $POSTSDIR
- cat << HEADER
- <!DOCTYPE html>
- <html>
- <head>
- <title>$BLOGTITLE</title>
- <meta charset="utf-8">
- <!-- link to user-defined stylesheet will go here -->
- </head>
- <body>
- <h1 style="margin-bottom: 0;">
- <a href="s.cgi" style="color: #000; text-decoration: none;">$BLOGTITLE</a>
- </h1>
- <p style="margin: 0; font-style: italic;">$BLOGSUBTITLE</p>
- <hr>
- <div style="display: inline; float: left; width: 65%">
- HEADER
- POSTNAME=$(getparam post)
- TAGNAME=$(getparam tag)
- if [ -n "$POSTNAME" ]; then
- P=$(ls $POSTNAME*.md)
- if [ -n "$P" ]; then
- showpost $P
- else
- echo "Post ($POSTNAME) doesn't exist"
- fi
- elif [ -n "$TAGNAME" ]; then
- showtag $TAGNAME
- else
- showpost $(ls -t *.md | head -1)
- fi
- cat << FOOTER
- </div>
- <div style="display: inline; float: right; width: 33%;">
- <h4>Recent posts</h4>
- <p>$(recentposts 10)<p>
- <hr>
- <h4>Tags</h4>
- <p>$(taglinks $(gettags))</p>
- </div>
- <div style="clear: both; text-align: center;">
- <hr>
- <p>Pretty footer text goes here</p>
- </div>
- </body>
- </html>
- FOOTER
Advertisement
Add Comment
Please, Sign In to add comment