Moving data around to make sure excerpts have no layouts but that they are still converted with liquid and the proper converter

This commit is contained in:
Parker Moore 2013-07-22 11:31:15 +02:00
parent e359472870
commit 26dc14881c
2 changed files with 39 additions and 28 deletions

View File

@ -13,27 +13,41 @@ module Jekyll
#
# Returns the new Post.
def initialize(post)
@post = post
@content = extract_excerpt(post.content)
self.post = post
self.content = extract_excerpt(post.content)
end
%w[site name data ext].each do |meth|
%w[site name ext].each do |meth|
define_method(meth) do
post.send(meth)
end
end
def to_liquid
post.to_liquid(Post::EXCERPT_ATTRIBUTES_FOR_LIQUID)
end
# Fetch YAML front-matter data from related post, without layout key
#
# Returns Hash of post data
def data
@data ||= post.data.dup
@data.delete("layout") if @data.has_key?("layout")
@data
end
# 'Path' of the excerpt.
#
# Returns the path for the post this excerpt belongs to with #excerpt appended
def path
File.join(post.path, "#excerpt")
end
# Check if excerpt includes a string
#
# Returns true if the string passed in
def include?(something)
(output && output.include?(something)) || content.include?(something)
end
def render_all_layouts(layouts, payload, info)
output = content
Jekyll.logger.debug "Output of", "#{self.path} => '#{self.output}'"
(self.output && self.output.include?(something)) || self.content.include?(something)
end
# The UID for this post (useful in feeds).
@ -44,16 +58,9 @@ module Jekyll
File.join(post.dir, post.slug, "#excerpt")
end
# Convert this post into a Hash for use in Liquid templates.
#
# Returns the representative Hash.
def to_liquid
post.to_liquid
end
def to_s
Jekyll.logger.debug "Excerpt#to_s:", "#{output} || #{content}"
output || content
Jekyll.logger.debug "Excerpt#to_s:", "#{self.output} || #{content}"
self.output || self.content
end
# Returns the shorthand String identifier of this Post.

View File

@ -10,8 +10,7 @@ module Jekyll
# Valid post name regex.
MATCHER = /^(.+\/)*(\d+-\d+-\d+)-(.*)(\.[^.]+)$/
# Attributes for Liquid templates
ATTRIBUTES_FOR_LIQUID = %w[
EXCERPT_ATTRIBUTES_FOR_LIQUID = %w[
title
url
date
@ -20,11 +19,15 @@ module Jekyll
next
previous
tags
content
excerpt
path
]
# Attributes for Liquid templates
ATTRIBUTES_FOR_LIQUID = EXCERPT_ATTRIBUTES_FOR_LIQUID.concat(%w[
content
excerpt
])
# Post name validator. Post filenames must be like:
# 2008-11-05-my-awesome-post.textile
#
@ -109,7 +112,7 @@ module Jekyll
if self.data.has_key? 'excerpt'
self.data['excerpt']
else
self.extracted_excerpt.output || self.extracted_excerpt.to_s
self.extracted_excerpt.to_s
end
end
@ -249,12 +252,13 @@ module Jekyll
# construct payload
payload = {
"site" => { "related_posts" => related_posts(site_payload["site"]["posts"]) },
"page" => self.to_liquid
"page" => self.to_liquid(EXCERPT_ATTRIBUTES_FOR_LIQUID)
}.deep_merge(site_payload)
self.extracted_excerpt.do_layout(payload, layouts)
self.extracted_excerpt.do_layout(payload, {})
Jekyll.logger.info("", "#{self.excerpt}".green)
do_layout(payload, layouts)
do_layout(payload.merge({"page" => self.to_liquid}), layouts)
end
# Obtain destination path.
@ -272,8 +276,8 @@ module Jekyll
# Convert this post into a Hash for use in Liquid templates.
#
# Returns the representative Hash.
def to_liquid
further_data = Hash[ATTRIBUTES_FOR_LIQUID.map { |attribute|
def to_liquid(attrs = ATTRIBUTES_FOR_LIQUID)
further_data = Hash[attrs.map { |attribute|
[attribute, send(attribute)]
}]
data.deep_merge(further_data)