lib/jekyll/post.rb in nirvdrum-jekyll-0.6.1 vs lib/jekyll/post.rb in nirvdrum-jekyll-0.7.0

- old
+ new

@@ -16,17 +16,14 @@ # Returns <Bool> def self.valid?(name) name =~ MATCHER end - attr_accessor :site, :date, :slug, :ext, :published, :data, :content, :output, :tags - attr_writer :categories + attr_accessor :site + attr_accessor :data, :content, :output, :ext + attr_accessor :date, :slug, :published, :tags, :categories - def categories - @categories ||= [] - end - # Initialize this Post instance. # +site+ is the Site # +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 @@ -39,36 +36,27 @@ self.categories = dir.split('/').reject { |x| x.empty? } self.process(name) self.read_yaml(@base, name) + #If we've added a date and time to the yaml, use that instead of the filename date + #Means we'll sort correctly. + if self.data.has_key?('date') + # ensure Time via to_s and reparse + self.date = Time.parse(self.data["date"].to_s) + end + if self.data.has_key?('published') && self.data['published'] == false self.published = false else self.published = true end - if self.data.has_key?("tag") - self.tags = [self.data["tag"]] - elsif self.data.has_key?("tags") - self.tags = self.data['tags'] - else - self.tags = [] - end + self.tags = self.data.pluralized_array("tag", "tags") 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? String - self.categories = self.data['categories'].split - else - self.categories = self.data['categories'] - end - end + self.categories = self.data.pluralized_array('category', 'categories') end end # Spaceship is based on Post#date, slug # @@ -134,10 +122,10 @@ @url ||= { "year" => date.strftime("%Y"), "month" => date.strftime("%m"), "day" => date.strftime("%d"), "title" => CGI.escape(slug), - "categories" => categories.sort.join('/') + "categories" => categories.join('/') }.inject(template) { |result, token| result.gsub(/:#{token.first}/, token.last) }.gsub(/\/\//, "/") end