summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLuke Shumaker <LukeShu@sbcglobal.net>2013-12-21 23:15:06 -0500
committerLuke Shumaker <LukeShu@sbcglobal.net>2013-12-21 23:15:06 -0500
commit58af7f60bf6cf3700109124568273e00e1d6e674 (patch)
tree54ec77fb6297c08a1457169cfd8458f4ab919876
parent3644a310dd3b1081ea864f3bafce385beb657491 (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--Makefile2
-rwxr-xr-xindex.rb29
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 '<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