@@ -41,6 +41,15 @@ def format_date(date, format)
41
41
end
42
42
date_formatted
43
43
end
44
+
45
+ # Returns the date-specific liquid attributes
46
+ def liquid_date_attributes
47
+ date_format = self . site . config [ 'date_format' ]
48
+ date_attributes = { }
49
+ date_attributes [ 'date_formatted' ] = format_date ( self . data [ 'date' ] , date_format ) if self . data . has_key? ( 'date' )
50
+ date_attributes [ 'updated_formatted' ] = format_date ( self . data [ 'updated' ] , date_format ) if self . data . has_key? ( 'updated' )
51
+ date_attributes
52
+ end
44
53
45
54
end
46
55
end
@@ -51,48 +60,22 @@ module Jekyll
51
60
class Post
52
61
include Octopress ::Date
53
62
54
- # Convert this post into a Hash for use in Liquid templates .
55
- #
56
- # Returns <Hash>
63
+ # Convert this Convertible's data to a Hash suitable for use by Liquid.
64
+ # Overrides the default return data and adds any date-specific liquid attributes
65
+ alias :super_to_liquid :to_liquid
57
66
def to_liquid
58
- date_format = self . site . config [ 'date_format' ]
59
- self . data . deep_merge ( {
60
- "title" => self . data [ 'title' ] || self . slug . split ( '-' ) . select { |w | w . capitalize! || w } . join ( ' ' ) ,
61
- "url" => self . url ,
62
- "date" => self . date ,
63
- # Monkey patch
64
- "date_formatted" => format_date ( self . date , date_format ) ,
65
- "updated_formatted" => self . data . has_key? ( 'updated' ) ? format_date ( self . data [ 'updated' ] , date_format ) : nil ,
66
- "id" => self . id ,
67
- "categories" => self . categories ,
68
- "next" => self . next ,
69
- "previous" => self . previous ,
70
- "tags" => self . tags ,
71
- "content" => self . content } )
67
+ super_to_liquid . deep_merge ( liquid_date_attributes )
72
68
end
73
69
end
74
70
75
71
class Page
76
72
include Octopress ::Date
77
73
78
- # Initialize a new Page.
79
- #
80
- # site - The Site object.
81
- # base - The String path to the source.
82
- # dir - The String path between the source and the file.
83
- # name - The String filename of the file.
84
- def initialize ( site , base , dir , name )
85
- @site = site
86
- @base = base
87
- @dir = dir
88
- @name = name
89
-
90
- self . process ( name )
91
- self . read_yaml ( File . join ( base , dir ) , name )
92
- # Monkey patch
93
- date_format = self . site . config [ 'date_format' ]
94
- self . data [ 'date_formatted' ] = format_date ( self . data [ 'date' ] , date_format ) if self . data . has_key? ( 'date' )
95
- self . data [ 'updated_formatted' ] = format_date ( self . data [ 'updated' ] , date_format ) if self . data . has_key? ( 'updated' )
74
+ # Convert this Convertible's data to a Hash suitable for use by Liquid.
75
+ # Overrides the default return data and adds any date-specific liquid attributes
76
+ alias :super_to_liquid :to_liquid
77
+ def to_liquid
78
+ super_to_liquid . deep_merge ( liquid_date_attributes )
96
79
end
97
80
end
98
81
end
0 commit comments