No layouts for excerpt #1339

Merged
merged 16 commits into from Jul 24, 2013

Projects

None yet

4 participants

@parkr
Member
parkr commented Jul 22, 2013

Aims to fix #1321.

  • Don't put excerpts in layouts
  • Convert layouts with converter
  • Render liquid
  • Write tests so it never happens again
  • Fix shitty tests so it really never happens again
@parkr parkr commented on the diff Jul 22, 2013
lib/jekyll/post.rb
@@ -249,12 +252,13 @@ def render(layouts, site_payload)
# construct payload
payload = {
"site" => { "related_posts" => related_posts(site_payload["site"]["posts"]) },
- "page" => self.to_liquid
+ "page" => self.to_liquid(EXCERPT_ATTRIBUTES_FOR_LIQUID)
@parkr
parkr Jul 22, 2013 Member

@mattr- The key to get it to convert was to make sure Post#excerpt was not called before the excerpt was converted. This seems to fix all the things!

@parkr
Member
parkr commented Jul 22, 2013

@benbalter this will likely be my last PR for v1.1.1 so we can get it shipped today or (at the very latest) tomorrow.

@benbalter benbalter commented on an outdated diff Jul 22, 2013
features/post_excerpts.feature
@@ -0,0 +1,50 @@
+Feature: Post excerpts
+ As a hacker who likes to blog
+ I want to be able to make a static sitej
@benbalter
benbalter Jul 22, 2013 Contributor

s/sitej/site/

@benbalter benbalter commented on the diff Jul 22, 2013
lib/jekyll/stevenson.rb
@@ -15,6 +15,16 @@ class Stevenson
def initialize(level = INFO)
@log_level = level
end
+
+ # Public: Print a jekyll debug message to stdout
@benbalter
benbalter Jul 22, 2013 Contributor

Is this intended to be in this pull request? Don't see debug called at all.

@parkr
parkr Jul 22, 2013 Member

I used it in a couple places while debugging but opted to take those out. Before we can have log levels, we need to come up with useful output.

@parkr
parkr Jul 22, 2013 Member

But I figured if I wrote the method, I may as well include it for later use.

@mattr- mattr- commented on the diff Jul 22, 2013
features/post_excerpts.feature
+
+ Scenario: An excerpt without a layout
+ Given I have an "index.html" page that contains "{% for post in site.posts %}{{ post.excerpt }}{% endfor %}"
+ And I have a _posts directory
+ And I have the following posts:
+ | title | date | layout | content |
+ | entry1 | 2007-12-31 | post | content for entry1. |
+ When I run jekyll
+ Then the _site directory should exist
+ And I should see exactly "<p>content for entry1.</p>" in "_site/index.html"
+
+ Scenario: An excerpt from a post with a layout
+ Given I have an "index.html" page that contains "{% for post in site.posts %}{{ post.excerpt }}{% endfor %}"
+ And I have a _posts directory
+ And I have a _layouts directory
+ And I have a post layout that contains "{{ page.excerpt }}"
@mattr-
mattr- Jul 22, 2013 Member

should this be {{ post.excerpt }} for consistency?

@parkr
parkr Jul 23, 2013 Member

No, the variable used in the layout is page, not post

@mattr-
mattr- Jul 23, 2013 Member

😕 Why is it page and not post? Seems weird to me.

@parkr
parkr Jul 23, 2013 Member

It's to be consistent so you can use the same layout for pages and for posts if you want.

Always the same variable for the #to_liquid hash

@mattr-
mattr- Jul 24, 2013 Member

Ah, got it. Merging shortly.

@mattr- mattr- commented on an outdated diff Jul 22, 2013
lib/jekyll/excerpt.rb
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")
@mattr-
mattr- Jul 22, 2013 Member

Just @data.delete("layout") is fine here. If the key does not exist, we'll get the default value.

@mattr-
Member
mattr- commented Jul 22, 2013

Just the one fixup and I think this should be good.

@parkr
Member
parkr commented Jul 23, 2013

@mattr- Please merge when ready :)

@parkr parkr referenced this pull request Jul 23, 2013
Merged

Minor refactors #1341

@mattr- mattr- merged commit d68d29c into master Jul 24, 2013

1 check passed

default The Travis CI build passed
Details
@mattr- mattr- added a commit that referenced this pull request Jul 24, 2013
@mattr- mattr- Update history to reflect merge of #1339 8e0a4e9
@parkr parkr deleted the no-layouts-for-excerpt branch Jul 24, 2013
@nitoyon
Contributor

Because Array#concat is destructive, ATTRIBUTES_FOR_LIQUID and EXCERPT_ATTRIBUTES_FOR_LIQUID refers to the same array.

irb(main):001:0> a = [1]
=> [1]
irb(main):002:0> a.concat [2]
=> [1, 2]
irb(main):003:0> a
=> [1, 2]

You should write as following:

ATTRIBUTES_FOR_LIQUID = EXCERPT_ATTRIBUTES_FOR_LIQUID + %w[
  content
  excerpt
]
Member

Bollocks, you're right. It doesn't look like it's a problem so far, but I'll fix that per this info. Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment