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:
commit
84cfc1ceff
|
@ -12,6 +12,7 @@ gh-pages/
|
||||||
site/_site/
|
site/_site/
|
||||||
coverage
|
coverage
|
||||||
.ruby-version
|
.ruby-version
|
||||||
|
.ruby-gemset
|
||||||
.sass-cache
|
.sass-cache
|
||||||
tmp/*
|
tmp/*
|
||||||
.jekyll-metadata
|
.jekyll-metadata
|
||||||
|
|
|
@ -105,8 +105,7 @@ module Jekyll
|
||||||
#
|
#
|
||||||
# Returns excerpt String
|
# Returns excerpt String
|
||||||
def extract_excerpt(post_content)
|
def extract_excerpt(post_content)
|
||||||
separator = site.config['excerpt_separator']
|
head, _, tail = post_content.to_s.partition(post.excerpt_separator)
|
||||||
head, _, tail = post_content.to_s.partition(separator)
|
|
||||||
|
|
||||||
"" << head << "\n\n" << tail.scan(/^\[[^\]]+\]:.+$/).join("\n")
|
"" << head << "\n\n" << tail.scan(/^\[[^\]]+\]:.+$/).join("\n")
|
||||||
end
|
end
|
||||||
|
|
|
@ -23,6 +23,7 @@ module Jekyll
|
||||||
ATTRIBUTES_FOR_LIQUID = EXCERPT_ATTRIBUTES_FOR_LIQUID + %w[
|
ATTRIBUTES_FOR_LIQUID = EXCERPT_ATTRIBUTES_FOR_LIQUID + %w[
|
||||||
content
|
content
|
||||||
excerpt
|
excerpt
|
||||||
|
excerpt_separator
|
||||||
]
|
]
|
||||||
|
|
||||||
# Post name validator. Post filenames must be like:
|
# Post name validator. Post filenames must be like:
|
||||||
|
@ -118,6 +119,14 @@ module Jekyll
|
||||||
data.fetch('title') { titleized_slug }
|
data.fetch('title') { titleized_slug }
|
||||||
end
|
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
|
# Turns the post slug into a suitable title
|
||||||
def titleized_slug
|
def titleized_slug
|
||||||
slug.split('-').select {|w| w.capitalize! || w }.join(' ')
|
slug.split('-').select {|w| w.capitalize! || w }.join(' ')
|
||||||
|
@ -307,7 +316,7 @@ module Jekyll
|
||||||
end
|
end
|
||||||
|
|
||||||
def generate_excerpt?
|
def generate_excerpt?
|
||||||
!(site.config['excerpt_separator'].to_s.empty?)
|
!excerpt_separator.empty?
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -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.
|
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
|
## Highlighting code snippets
|
||||||
|
|
||||||
Jekyll also has built-in support for syntax highlighting of code snippets using
|
Jekyll also has built-in support for syntax highlighting of code snippets using
|
||||||
|
|
|
@ -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/
|
|
@ -14,7 +14,7 @@ class TestGeneratedSite < Test::Unit::TestCase
|
||||||
end
|
end
|
||||||
|
|
||||||
should "ensure post count is as expected" do
|
should "ensure post count is as expected" do
|
||||||
assert_equal 44, @site.posts.size
|
assert_equal 45, @site.posts.size
|
||||||
end
|
end
|
||||||
|
|
||||||
should "insert site.posts into the index" do
|
should "insert site.posts into the index" do
|
||||||
|
|
|
@ -422,6 +422,22 @@ class TestPost < Test::Unit::TestCase
|
||||||
end
|
end
|
||||||
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
|
context "with custom excerpt" do
|
||||||
setup do
|
setup do
|
||||||
file = "2013-04-11-custom-excerpt.markdown"
|
file = "2013-04-11-custom-excerpt.markdown"
|
||||||
|
|
Loading…
Reference in New Issue