Skip to content

Commit

Permalink
Use date from filename to generate url.
Browse files Browse the repository at this point in the history
Keep things DRY: Override the date found in the metadata with the
date from the filename. If a date is given in the metadata, that
date will show up on the article page, but the url will use the date
from the filename.

This is needed to make sure toto actually finds the articles, which
it would previously not if the date in the metadata did not match
the date from the filename. In fact, with this patch it is no longer
necessary to put the date in the article metadata at all, you only
need it in the filename, which keep things DRY.
  • Loading branch information
sce authored and Alexis Sellier committed Feb 27, 2010
1 parent e793772 commit 1407af2
Showing 1 changed file with 4 additions and 1 deletion.
5 changes: 4 additions & 1 deletion lib/toto.rb
Original file line number Diff line number Diff line change
Expand Up @@ -228,7 +228,10 @@ def initialize obj, config = {}
def load
data = if @obj.is_a? String
meta, self[:body] = File.read(@obj).split(/\n\n/, 2)
YAML.load(meta)

# use the date from the filename, or else toto won't find the article
@obj =~ /\/(\d{4}-\d{2}-\d{2})[^\/]*$/
$1 ? YAML.load(meta).merge("date" => $1) : YAML.load(meta)
elsif @obj.is_a? Hash
@obj
end.inject({}) {|h, (k,v)| h.merge(k.to_sym => v) }
Expand Down

0 comments on commit 1407af2

Please sign in to comment.