diff --git a/.gitignore b/.gitignore index f5ad5bc2..baf9f1df 100644 --- a/.gitignore +++ b/.gitignore @@ -12,6 +12,7 @@ gh-pages/ site/_site/ coverage .ruby-version +.ruby-gemset .sass-cache tmp/* .jekyll-metadata diff --git a/lib/jekyll/excerpt.rb b/lib/jekyll/excerpt.rb index 41d4976c..347be217 100644 --- a/lib/jekyll/excerpt.rb +++ b/lib/jekyll/excerpt.rb @@ -105,8 +105,7 @@ module Jekyll # # Returns excerpt String def extract_excerpt(post_content) - separator = site.config['excerpt_separator'] - head, _, tail = post_content.to_s.partition(separator) + head, _, tail = post_content.to_s.partition(post.excerpt_separator) "" << head << "\n\n" << tail.scan(/^\[[^\]]+\]:.+$/).join("\n") end diff --git a/lib/jekyll/post.rb b/lib/jekyll/post.rb index 09ffbd44..dddcd2f2 100644 --- a/lib/jekyll/post.rb +++ b/lib/jekyll/post.rb @@ -23,6 +23,7 @@ module Jekyll ATTRIBUTES_FOR_LIQUID = EXCERPT_ATTRIBUTES_FOR_LIQUID + %w[ content excerpt + excerpt_separator ] # Post name validator. Post filenames must be like: @@ -118,6 +119,14 @@ module Jekyll data.fetch('title') { titleized_slug } end + # Public: the Post excerpt_separator, from the YAML Front-Matter or site default + # excerpt_separator value + # + # Returns the post excerpt_separator + def excerpt_separator + (data['excerpt_separator'] || site.config['excerpt_separator']).to_s + end + # Turns the post slug into a suitable title def titleized_slug slug.split('-').select {|w| w.capitalize! || w }.join(' ') @@ -307,7 +316,7 @@ module Jekyll end def generate_excerpt? - !(site.config['excerpt_separator'].to_s.empty?) + !excerpt_separator.empty? end end end diff --git a/site/_docs/posts.md b/site/_docs/posts.md index b1508c3e..ccdd76ad 100644 --- a/site/_docs/posts.md +++ b/site/_docs/posts.md @@ -169,6 +169,16 @@ your `excerpt_separator` to `""`. Also, as with any output generated by Liquid tags, you can pass the `| strip_html` flag to remove any html tags in the output. This is particularly helpful if you wish to output a post excerpt as a `meta="description"` tag within the post `head`, or anywhere else having html tags along with the content is not desirable. +Additionally you are able to specify per-post `excerpt_separator` value if it is required just only the the selected post. Just specify the `excerpt_separator` with the same way as `excerpt` in the post's YAML head: + + --- + excerpt_separator: + --- + + Excerpt + + Out-of-excerpt + ## Highlighting code snippets Jekyll also has built-in support for syntax highlighting of code snippets using diff --git a/test/source/_posts/2015-01-08-post-excerpt-separator.markdown b/test/source/_posts/2015-01-08-post-excerpt-separator.markdown new file mode 100644 index 00000000..e8b7ddd9 --- /dev/null +++ b/test/source/_posts/2015-01-08-post-excerpt-separator.markdown @@ -0,0 +1,15 @@ +--- +layout: ~ +title: Post Excerpt Separator +excerpt_separator: "\n---\n" +--- + +First paragraph with [link ref][link]. + +Second paragraph + +--- + +Third paragraph + +[link]: http://www.jekyllrb.com/ diff --git a/test/test_generated_site.rb b/test/test_generated_site.rb index 0b157e85..03669b90 100644 --- a/test/test_generated_site.rb +++ b/test/test_generated_site.rb @@ -14,7 +14,7 @@ class TestGeneratedSite < Test::Unit::TestCase end should "ensure post count is as expected" do - assert_equal 44, @site.posts.size + assert_equal 45, @site.posts.size end should "insert site.posts into the index" do diff --git a/test/test_post.rb b/test/test_post.rb index f03c5d49..f1448e12 100644 --- a/test/test_post.rb +++ b/test/test_post.rb @@ -422,6 +422,22 @@ class TestPost < Test::Unit::TestCase end end + context "with page's excerpt_separator setting" do + setup do + file = "2015-01-08-post-excerpt-separator.markdown" + + @post.process(file) + @post.read_yaml(@source, file) + @post.transform + end + + should "respect given separator" do + assert @post.excerpt.include?("First paragraph"), "contains first paragraph" + assert @post.excerpt.include?("Second paragraph"), "contains second paragraph" + assert !@post.excerpt.include?("Third paragraph"), "does not contains third paragraph" + end + end + context "with custom excerpt" do setup do file = "2013-04-11-custom-excerpt.markdown"