From 26dc14881c444198f2c57d740d8ab126525a5b67 Mon Sep 17 00:00:00 2001 From: Parker Moore Date: Mon, 22 Jul 2013 11:31:15 +0200 Subject: [PATCH] Moving data around to make sure excerpts have no layouts but that they are still converted with liquid and the proper converter --- lib/jekyll/excerpt.rb | 43 +++++++++++++++++++++++++------------------ lib/jekyll/post.rb | 24 ++++++++++++++---------- 2 files changed, 39 insertions(+), 28 deletions(-) diff --git a/lib/jekyll/excerpt.rb b/lib/jekyll/excerpt.rb index 682bf135..768acd97 100644 --- a/lib/jekyll/excerpt.rb +++ b/lib/jekyll/excerpt.rb @@ -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. diff --git a/lib/jekyll/post.rb b/lib/jekyll/post.rb index 387c2752..693517a6 100644 --- a/lib/jekyll/post.rb +++ b/lib/jekyll/post.rb @@ -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)