|
|
@ -29,6 +29,16 @@ module Octopress |
|
|
|
end |
|
|
|
end |
|
|
|
|
|
|
|
def format_date(date, format) |
|
|
|
date = datetime(date) |
|
|
|
if format.nil? || format.empty? || format == "ordinal" |
|
|
|
date_formatted = ordinalize(date) |
|
|
|
else |
|
|
|
date_formatted = date.strftime(format) |
|
|
|
end |
|
|
|
date_formatted |
|
|
|
end |
|
|
|
|
|
|
|
end |
|
|
|
end |
|
|
|
|
|
|
@ -38,25 +48,18 @@ module Jekyll |
|
|
|
class Post |
|
|
|
include Octopress::Date |
|
|
|
|
|
|
|
attr_accessor :date_formatted |
|
|
|
|
|
|
|
# Convert this post into a Hash for use in Liquid templates. |
|
|
|
# |
|
|
|
# Returns <Hash> |
|
|
|
def to_liquid |
|
|
|
format = self.site.config['date_format'] |
|
|
|
if format.nil? || format.empty? || format == "ordinal" |
|
|
|
date_formatted = ordinalize(self.date) |
|
|
|
else |
|
|
|
date_formatted = self.date.strftime(format) |
|
|
|
end |
|
|
|
|
|
|
|
date_format = self.site.config['date_format'] |
|
|
|
self.data.deep_merge({ |
|
|
|
"title" => self.data["title"] || self.slug.split('-').select {|w| w.capitalize! || w }.join(' '), |
|
|
|
"title" => self.data['title'] || self.slug.split('-').select {|w| w.capitalize! || w }.join(' '), |
|
|
|
"url" => self.url, |
|
|
|
"date" => self.date, |
|
|
|
# Monkey patch |
|
|
|
"date_formatted" => date_formatted, |
|
|
|
"date_formatted" => format_date(self.date, date_format), |
|
|
|
"updated_formatted" => self.data.has_key?('updated') ? format_date(self.data['updated'], date_format) : nil, |
|
|
|
"id" => self.id, |
|
|
|
"categories" => self.categories, |
|
|
|
"next" => self.next, |
|
|
@ -64,6 +67,29 @@ module Jekyll |
|
|
|
"tags" => self.tags, |
|
|
|
"content" => self.content }) |
|
|
|
end |
|
|
|
end |
|
|
|
|
|
|
|
class Page |
|
|
|
include Octopress::Date |
|
|
|
|
|
|
|
# Initialize a new Page. |
|
|
|
# |
|
|
|
# site - The Site object. |
|
|
|
# base - The String path to the source. |
|
|
|
# dir - The String path between the source and the file. |
|
|
|
# name - The String filename of the file. |
|
|
|
def initialize(site, base, dir, name) |
|
|
|
@site = site |
|
|
|
@base = base |
|
|
|
@dir = dir |
|
|
|
@name = name |
|
|
|
|
|
|
|
self.process(name) |
|
|
|
self.read_yaml(File.join(base, dir), name) |
|
|
|
# Monkey patch |
|
|
|
date_format = self.site.config['date_format'] |
|
|
|
self.data['date_formatted'] = format_date(self.data['date'], date_format) if self.data.has_key?('date') |
|
|
|
self.data['updated_formatted'] = format_date(self.data['updated'], date_format) if self.data.has_key?('updated') |
|
|
|
end |
|
|
|
end |
|
|
|
end |