Merge branch 'majioa-devel'

* majioa-devel:
  Ensure Post#excerpt_separator always returns a string.
  get procedure for default excerpt separator for both cases site and page was moved to the post's specific method :excerpt_separator.
  Added per post excerpt_separator functionality, so you are able to specify :excerpt_separator (as well as just :excerpt) key direct inside the post YAML, to make an excerpt based on the value in the post. Tests were also added.
This commit is contained in:
Parker Moore 2015-01-17 15:01:20 -08:00
commit 84cfc1ceff
7 changed files with 54 additions and 4 deletions

1
.gitignore vendored
View File

@ -12,6 +12,7 @@ gh-pages/
site/_site/
coverage
.ruby-version
.ruby-gemset
.sass-cache
tmp/*
.jekyll-metadata

View File

@ -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

View File

@ -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

View File

@ -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: <!--more-->
---
Excerpt
<!--more-->
Out-of-excerpt
## Highlighting code snippets
Jekyll also has built-in support for syntax highlighting of code snippets using

View File

@ -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/

View File

@ -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

View File

@ -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"