mirror of
https://github.com/moparisthebest/www.moparscape.org
synced 2024-11-16 06:15:13 -05:00
Add custom date format to pages, add 'updated' field again
Reverts changes of c2a68cc
where I accidentally removed support for 'updated' field, see comments of issue #164 for details.
This commit is contained in:
parent
262eb52bc5
commit
987dccee76
@ -2,6 +2,14 @@
|
|||||||
{% capture date_formatted %}{{ page.date_formatted }}{{ post.date_formatted }}{% endcapture %}
|
{% capture date_formatted %}{{ page.date_formatted }}{{ post.date_formatted }}{% endcapture %}
|
||||||
{% capture has_date %}{{ date | size }}{% endcapture %}
|
{% capture has_date %}{{ date | size }}{% endcapture %}
|
||||||
|
|
||||||
|
{% capture updated %}{{ page.updated }}{{ post.updated }}{% endcapture %}
|
||||||
|
{% capture updated_formatted %}{{ page.updated_formatted }}{{ post.updated_formatted }}{% endcapture %}
|
||||||
|
{% capture was_updated %}{{ updated | size }}{% endcapture %}
|
||||||
|
|
||||||
{% if has_date != '0' %}
|
{% if has_date != '0' %}
|
||||||
{% capture time %}<time datetime="{{ date | datetime | date_to_xmlschema }}" pubdate>{{ date_formatted }}</time>{% endcapture %}
|
{% capture time %}<time datetime="{{ date | datetime | date_to_xmlschema }}" pubdate{% if updated %} data-updated="true"{% endif %}>{{ date_formatted }}</time>{% endcapture %}
|
||||||
{% endif %}
|
{% endif %}
|
||||||
|
|
||||||
|
{% if was_updated != '0' %}
|
||||||
|
{% capture updated %}<time datetime="{{ updated | datetime | date_to_xmlschema }}" class="updated">Updated {{ updated_formatted }}</time>{% endcapture %}
|
||||||
|
{% else %}{% assign updated = false %}{% endif %}
|
@ -15,7 +15,7 @@ layout: default
|
|||||||
<footer>
|
<footer>
|
||||||
{% if page.date or page.author %}<p class="meta">
|
{% if page.date or page.author %}<p class="meta">
|
||||||
{% if page.author %}{% include post/author.html %}{% endif %}
|
{% if page.author %}{% include post/author.html %}{% endif %}
|
||||||
{% include post/date.html %}{{ time }}
|
{% include post/date.html %}{% if updated %}{{ updated }}{% else %}{{ time }}{% endif %}
|
||||||
{% if page.categories %}{% include post/categories.html %}{% endif %}
|
{% if page.categories %}{% include post/categories.html %}{% endif %}
|
||||||
</p>{% endif %}
|
</p>{% endif %}
|
||||||
{% unless page.sharing == false %}
|
{% unless page.sharing == false %}
|
||||||
|
@ -9,7 +9,7 @@ single: true
|
|||||||
<footer>
|
<footer>
|
||||||
<p class="meta">
|
<p class="meta">
|
||||||
{% include post/author.html %}
|
{% include post/author.html %}
|
||||||
{% include post/date.html %}{{ time }}
|
{% include post/date.html %}{% if updated %}{{ updated }}{% else %}{{ time }}{% endif %}
|
||||||
{% include post/categories.html %}
|
{% include post/categories.html %}
|
||||||
</p>
|
</p>
|
||||||
{% unless page.sharing == false %}
|
{% unless page.sharing == false %}
|
||||||
|
@ -29,6 +29,16 @@ module Octopress
|
|||||||
end
|
end
|
||||||
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
|
||||||
end
|
end
|
||||||
|
|
||||||
@ -38,25 +48,18 @@ module Jekyll
|
|||||||
class Post
|
class Post
|
||||||
include Octopress::Date
|
include Octopress::Date
|
||||||
|
|
||||||
attr_accessor :date_formatted
|
|
||||||
|
|
||||||
# Convert this post into a Hash for use in Liquid templates.
|
# Convert this post into a Hash for use in Liquid templates.
|
||||||
#
|
#
|
||||||
# Returns <Hash>
|
# Returns <Hash>
|
||||||
def to_liquid
|
def to_liquid
|
||||||
format = self.site.config['date_format']
|
date_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
|
|
||||||
|
|
||||||
self.data.deep_merge({
|
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,
|
"url" => self.url,
|
||||||
"date" => self.date,
|
"date" => self.date,
|
||||||
# Monkey patch
|
# 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,
|
"id" => self.id,
|
||||||
"categories" => self.categories,
|
"categories" => self.categories,
|
||||||
"next" => self.next,
|
"next" => self.next,
|
||||||
@ -64,6 +67,29 @@ module Jekyll
|
|||||||
"tags" => self.tags,
|
"tags" => self.tags,
|
||||||
"content" => self.content })
|
"content" => self.content })
|
||||||
end
|
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
|
||||||
end
|
end
|
Loading…
Reference in New Issue
Block a user