Permalink
Browse files

Use date from post's filename when metadata[:created_at] is missing.

  • Loading branch information...
1 parent 2d2809d commit 7496b6aaceb0aeba3186510305c199ce9457322b @hotovson hotovson committed Mar 19, 2011
Showing with 10 additions and 0 deletions.
  1. +1 −0 bin/ace
  2. +9 −0 lib/ace.rb
View
@@ -43,6 +43,7 @@ rules.rules.each do |klass, files|
if File.binread(file).match(/^-{3,5}\s*$/)
puts "~ Read #{file} with parse"
raw_item = Ace::RawItem.new(file).tap(&:parse)
+ raw_item.check_metadata_created_at(file)
item = klass.create(raw_item.metadata, raw_item.content)
else
puts "~ Read #{file} without parse"
View
@@ -11,6 +11,7 @@
require "fileutils"
require "ace/filters/sass"
require "digest/sha1"
+require "date"
module Ace
module Helpers
@@ -23,6 +24,13 @@ def initialize(path)
@data = File.read(path)
end
+ def check_metadata_created_at(path)
+ if self.metadata[:title]
+ year, month, day = File.basename(path).slice(0,10).split('-')
+ self.metadata[:created_at] ||= Date.new(year.to_i, month.to_i, day.to_i)
+ end
+ end
+
def parse
pieces = @data.split(/^-{3,5}\s*$/)
# if pieces.size < 3
@@ -33,6 +41,7 @@ def parse
# Parse
self.metadata = YAML.load(pieces[1]).inject(Hash.new) { |metadata, pair| metadata.merge(pair[0].to_sym => pair[1]) } || Hash.new
+ # TODO: check metadata[:created_at] and supply it from filename
self.content = pieces[2..-1].join.strip
end
end

2 comments on commit 7496b6a

@botanicus
Owner

Thank you, but Ace is trying to be agnostic, so we don't really assume any created_at in the metadata, neither we do expect naming in some specified format. This should be definitely part of the blog repo, it has nothing to do with the general framework. Cheers.

@botanicus
Owner

Apart of this not being agnostic, it does break the code pretty badly if given soubor doesn't match the pattern. Therefore I'll revert this commit and put this either to a module or to the blog code.

Please sign in to comment.