diff options
author | Luke Shumaker <LukeShu@sbcglobal.net> | 2013-12-21 23:15:06 -0500 |
---|---|---|
committer | Luke Shumaker <LukeShu@sbcglobal.net> | 2013-12-21 23:15:06 -0500 |
commit | 58af7f60bf6cf3700109124568273e00e1d6e674 (patch) | |
tree | 54ec77fb6297c08a1457169cfd8458f4ab919876 | |
parent | 3644a310dd3b1081ea864f3bafce385beb657491 (diff) |
index: sort the posts by date
I originally didn't want posts to be tied to the date (inspired by
<http://swombat.com/2011/5/26/real-value-we>). But, I've realized that for
several reasons, dates are important. I've waffled quite a bit on this
decision.
-rw-r--r-- | Makefile | 2 | ||||
-rwxr-xr-x | index.rb | 29 |
2 files changed, 25 insertions, 6 deletions
@@ -8,6 +8,6 @@ all: public/index.html $(addsuffix .html,$(articles)) public/%.html: public/%.md pagerender.rb template.erb Makefile ./pagerender.rb $< > $@ public/index.md: $(addsuffix .md,$(articles)) index.rb Makefile - ./index.rb $(sort $(filter-out Makefile index.rb public/index.md,$^)) > $@ + ./index.rb $(filter-out Makefile index.rb public/index.md,$^) > $@ clean: rm -f -- public/*.html public/index.md @@ -2,12 +2,31 @@ # -*- coding: utf-8 -*- load 'pandoc.rb' require 'erb' +require 'date' -markdown = "Web log entries\n=====\n\n" +puts "Web log entries\n=====\n" + +puts '<style> +li { + list-style-type: none; +} +time { + color: #AAAAAA; + font-family: monospace; +} +</style>' + +articles = [] for filename in ARGV do input = File.read(filename) - title = Pandoc::load('markdown',input)["title"] || input.split("\n",2).first - slug = filename.sub(/^public\//,'').sub(/\.md$/,'') - markdown += " * [`#{slug}`](./#{slug}.html) — #{title}\n" + doc = Pandoc::load('markdown',input) + articles.push({ + :title => doc["title"] || input.split("\n",2).first, + :date => Date.parse(doc['date']), + :slug => filename.sub(/^public\//,'').sub(/\.md$/,''), + }) +end + +articles.sort_by{|a| a[:date]}.reverse.each do |a| + puts " * <time>#{a[:date].strftime('%Y-%m-%d')}</time> - [#{a[:title]}](./#{a[:slug]}.html)" end -puts markdown |