better generate the summary for each blogpost

This commit is contained in:
Christine Dodrill 2015-02-15 20:19:56 -08:00
parent 58c7011783
commit 5d6fcd7a8a
2 changed files with 38 additions and 7 deletions

View File

@ -1,21 +1,23 @@
#!/bin/bash #!/bin/bash
set -e set -e
set -x
cd /tmp
wget http://www.frykholm.se/files/markdown.lua
cd /app/src/blog cd /app/src/blog
IFS=' export LOCATION=/app/src/static/markdown/blog.html
'
echo '<div class="row">' >> $LOCATION
for file in $(ls -t) for file in $(ls -t)
do do
title=$(head -n1 $file) 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}') linkname=$(echo $file | awk -F "." '{print $1}')
echo '<div class="post"><h2>'"$title"'</h2>'"$line"'<a href="/blog/'"$linkname"'">Read More</a></div>' >> /app/src/static/markdown/blog.html [[ -z "$line" ]] && false
echo '<div class="col-md-12 post"><h2>'"$title"'</h2>'"$line"'<a href="/blog/'"$linkname"'">Read More</a></div>' >> $LOCATION
echo "generated info for $file" echo "generated info for $file"
done done
echo '</div>' >> $LOCATION

29
init/summary.moon Normal file
View File

@ -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