From 5d6fcd7a8aed0e7992180ae829bd958b60b06c5d Mon Sep 17 00:00:00 2001 From: Christine Dodrill Date: Sun, 15 Feb 2015 20:19:56 -0800 Subject: [PATCH] better generate the summary for each blogpost --- init/startup/00_generate_index.sh | 16 +++++++++------- init/summary.moon | 29 +++++++++++++++++++++++++++++ 2 files changed, 38 insertions(+), 7 deletions(-) create mode 100644 init/summary.moon diff --git a/init/startup/00_generate_index.sh b/init/startup/00_generate_index.sh index 7a574ee..ab4d0e3 100755 --- a/init/startup/00_generate_index.sh +++ b/init/startup/00_generate_index.sh @@ -1,21 +1,23 @@ #!/bin/bash set -e - -cd /tmp -wget http://www.frykholm.se/files/markdown.lua +set -x cd /app/src/blog -IFS=' -' +export LOCATION=/app/src/static/markdown/blog.html + +echo '
' >> $LOCATION for file in $(ls -t) do title=$(head -n1 $file) - line=$(head -n4 $file | tail -n1 | lua /tmp/markdown.lua -n) + line=$(moon /app/src/init/summary.moon $file) linkname=$(echo $file | awk -F "." '{print $1}') - echo '

'"$title"'

'"$line"'Read More
' >> /app/src/static/markdown/blog.html + [[ -z "$line" ]] && false + + echo '

'"$title"'

'"$line"'Read More
' >> $LOCATION echo "generated info for $file" done +echo '
' >> $LOCATION diff --git a/init/summary.moon b/init/summary.moon new file mode 100644 index 0000000..d833480 --- /dev/null +++ b/init/summary.moon @@ -0,0 +1,29 @@ +discount = require "discount" + +fname = arg[1] +if not arg[1] + error "Read the code" + +with io.open fname, "r" + -- Ignore the first three lines + \read "*l" + \read "*l" + \read "*l" + + -- Read everything else + local data + data = "" + + while true + line = \read "*l" + break if not line or line == "" -- Only render the first paragraph + + if line[#line] ~= " " + line = line .. " " + + data = data .. line + + -- render markdown + md = discount data + + print md