From 58af7f60bf6cf3700109124568273e00e1d6e674 Mon Sep 17 00:00:00 2001 From: Luke Shumaker Date: Sat, 21 Dec 2013 23:15:06 -0500 Subject: index: sort the posts by date I originally didn't want posts to be tied to the date (inspired by ). But, I've realized that for several reasons, dates are important. I've waffled quite a bit on this decision. --- Makefile | 2 +- index.rb | 29 ++++++++++++++++++++++++----- 2 files changed, 25 insertions(+), 6 deletions(-) diff --git a/Makefile b/Makefile index c575f58..c573790 100644 --- a/Makefile +++ b/Makefile @@ -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 diff --git a/index.rb b/index.rb index 9511c28..61450d5 100755 --- a/index.rb +++ b/index.rb @@ -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 '' + +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 " * - [#{a[:title]}](./#{a[:slug]}.html)" end -puts markdown -- cgit v1.2.3