Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Preserve excerpt #946

Merged
merged 8 commits into from Apr 12, 2013
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
16 changes: 12 additions & 4 deletions lib/jekyll/post.rb
Expand Up @@ -19,10 +19,10 @@ def self.valid?(name)
end

attr_accessor :site
attr_accessor :data, :excerpt, :content, :output, :ext
attr_accessor :data, :extracted_excerpt, :content, :output, :ext
attr_accessor :date, :slug, :published, :tags, :categories

attr_reader :name
attr_reader :name, :excerpt
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this shouldn't be here if you have the method below, right? :)


# Initialize this Post instance.
#
Expand Down Expand Up @@ -80,10 +80,18 @@ def containing_dir(source, dir)
# Returns nothing.
def read_yaml(base, name)
super(base, name)
self.excerpt = self.extract_excerpt
self.extracted_excerpt = self.extract_excerpt
self.data['layout'] = 'post' unless self.data.has_key?('layout')
end

# The post excerpt. This is either a custom excerpt
# set in YAML front matter or the result of extract_excerpt.
#
# Returns excerpt string.
def excerpt
self.data['excerpt'] ? converter.convert(self.data['excerpt']) : self.extracted_excerpt
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should I also move the conversion of self.data['excerpt'] to transform or is it fine that way? Was not sure if one is supposed to modify self.data...

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why are you converting self.data['excerpt']?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

To allow basic markdown etc. (as in the first test) in the excerpt.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd do something like

if self.data.has_key? "excerpt"
  self.data['excerpt']
else
  self.extracted_excerpt
end

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think that's a good idea. I'd prefer not to convert the excerpt! The excerpt in your front-matter shouldn't be long or complex enough to warrant conversion.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done!

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We convert the extracted excerpt. Why not convert the excerpt that's in the
YAML front matter?

On Thu, Apr 11, 2013 at 2:03 PM, maul-esel notifications@github.com wrote:

In lib/jekyll/post.rb:

   self.data['layout'] = 'post' unless self.data.has_key?('layout')
 end
  • The post excerpt. This is either a custom excerpt

  • set in YAML front matter or the result of extract_excerpt.

  • Returns excerpt string.

  • def excerpt
  •  self.data['excerpt'] ? converter.convert(self.data['excerpt']) : self.extracted_excerpt
    

Done!


Reply to this email directly or view it on GitHubhttps://github.com//pull/946/files#r3759594
.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It will modify the current expected behaviour for one, and I feel like it shouldn't be so long as to require any sort of markdown format. The former reason is the reason I'm to stick with, though :)

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I could see people wanting to have a bit of emphasis on their extracted excerpt, but I don't feel strongly enough about it to be all like "no, we shouldn't merge this, we gotta have converted excerpts". We can just add it later if it gets asked for. 😀

end

# Compares Post objects. First compares the Post date. If the dates are
# equal, it compares the Post slugs.
#
Expand Down Expand Up @@ -117,7 +125,7 @@ def process(name)
# Returns nothing.
def transform
super
self.excerpt = converter.convert(self.excerpt)
self.extracted_excerpt = converter.convert(self.extracted_excerpt)
end

# The generated directory into which the post will be placed
Expand Down
8 changes: 8 additions & 0 deletions test/source/_posts/2013-04-11-custom-excerpt.markdown
@@ -0,0 +1,8 @@
---
layout: ~
excerpt: 'I can set a custom excerpt with *markdown*'
---

This is not my excerpt.

Neither is this.
2 changes: 1 addition & 1 deletion test/test_generated_site.rb
Expand Up @@ -14,7 +14,7 @@ class TestGeneratedSite < Test::Unit::TestCase
end

should "ensure post count is as expected" do
assert_equal 31, @site.posts.size
assert_equal 32, @site.posts.size
end

should "insert site.posts into the index" do
Expand Down
15 changes: 15 additions & 0 deletions test/test_post.rb
Expand Up @@ -320,6 +320,21 @@ def do_render(post)
assert !@post.excerpt.include?("---"), "does not contains separator"
end
end

context "with custom excerpt" do
setup do
file = "2013-04-11-custom-excerpt.markdown"
@post.process(file)
@post.read_yaml(@source, file)
@post.transform
end

should "use custom excerpt" do
assert_equal("<p>I can set a custom excerpt with <em>markdown</em></p>", @post.excerpt)
end

end

end
end

Expand Down