lib/jekyll/post.rb in jsjohnst-jekyll-0.4.1.999.4 vs lib/jekyll/post.rb in jsjohnst-jekyll-0.4.1.999.6

- old
+ new

@@ -18,22 +18,24 @@ name =~ MATCHER end attr_accessor :date, :slug, :ext, :categories, :topics, :published attr_accessor :data, :content, :output - attr_accessor :previous, :next + attr_accessor :previous, :next, :numericid, :archivedate # Initialize this Post instance. # +base+ is the String path to the dir containing the post file # +name+ is the String filename of the post file # +categories+ is an Array of Strings for the categories for this post # # Returns <Post> def initialize(source, dir, name) @base = File.join(source, dir, '_posts') @name = name - + + self.numericid = 0 + self.categories = dir.split('/').reject { |x| x.empty? } parts = name.split('/') self.topics = parts.size > 1 ? parts[0..-2] : [] @@ -44,40 +46,36 @@ self.published = false else self.published = true end - self.data['topics'] = if self.topics.empty? - if self.data.has_key?('topic') - self.topics << self.data['topic'] - elsif self.data.has_key?('topics') - if self.data['topics'].kind_of? Array - self.topics = self.topics['topics'] - elsif self.data['topics'].kind_of? String - self.topics = self.data['topics'].split - else - self.topics = [] - end + if self.data.has_key?('topic') + self.topics << self.data['topic'] + elsif self.data.has_key?('topics') + if self.data['topics'].kind_of? Array + self.topics = self.data['topics'] + elsif self.data['topics'].kind_of? String + self.topics = self.data['topics'].split + else + self.topics = [] end end - - - if self.categories.empty? - if self.data.has_key?('category') - self.categories << self.data['category'] - elsif self.data.has_key?('categories') - # Look for categories in the YAML-header, either specified as - # an array or a string. - if self.data['categories'].kind_of? Array - self.categories = self.data['categories'] - elsif self.data['categories'].kind_of? String - self.categories = self.data['categories'].split - else - self.categories = [] - end + + if self.data.has_key?('category') + self.categories << self.data['category'] + elsif self.data.has_key?('categories') + # Look for categories in the YAML-header, either specified as + # an array or a string. + if self.data['categories'].kind_of? Array + self.categories = self.data['categories'] + elsif self.data['categories'].kind_of? String + self.categories = self.data['categories'].split + else + self.categories = [] end end + end # Spaceship is based on Post#date # # Returns -1, 0, 1 @@ -90,10 +88,11 @@ # # Returns nothing def process(name) m, cats, date, slug, ext = *name.match(MATCHER) self.date = Time.parse(date) + self.archivedate = self.date.month.to_s + "-" + self.date.year.to_s self.slug = slug self.ext = ext end # The generated directory into which the post will be placed @@ -214,11 +213,14 @@ # # Returns <Hash> def to_liquid { "title" => self.data["title"] || self.slug.split('-').select {|w| w.capitalize! || w }.join(' '), "url" => self.url, + "topleveldir" => self.url.split("/")[1], "date" => self.date, + "archivedate" => self.archivedate, "id" => self.id, + "numericid" => self.numericid, "topics" => self.topics, "folded" => (self.content.match("<hr") ? true : false), "content" => self.content, "categories" => self.categories }.deep_merge(self.data) end