Merge pull request #946 from maul-esel/preserve_excerpt
Preserve 'excerpt` in YAML Front-Matter
This commit is contained in:
commit
bee8cd9d77
|
@ -19,7 +19,7 @@ module Jekyll
|
||||||
end
|
end
|
||||||
|
|
||||||
attr_accessor :site
|
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_accessor :date, :slug, :published, :tags, :categories
|
||||||
|
|
||||||
attr_reader :name
|
attr_reader :name
|
||||||
|
@ -80,10 +80,22 @@ module Jekyll
|
||||||
# Returns nothing.
|
# Returns nothing.
|
||||||
def read_yaml(base, name)
|
def read_yaml(base, name)
|
||||||
super(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')
|
self.data['layout'] = 'post' unless self.data.has_key?('layout')
|
||||||
end
|
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
|
||||||
|
if self.data.has_key? 'excerpt'
|
||||||
|
self.data['excerpt']
|
||||||
|
else
|
||||||
|
self.extracted_excerpt
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
# Compares Post objects. First compares the Post date. If the dates are
|
# Compares Post objects. First compares the Post date. If the dates are
|
||||||
# equal, it compares the Post slugs.
|
# equal, it compares the Post slugs.
|
||||||
#
|
#
|
||||||
|
@ -117,7 +129,7 @@ module Jekyll
|
||||||
# Returns nothing.
|
# Returns nothing.
|
||||||
def transform
|
def transform
|
||||||
super
|
super
|
||||||
self.excerpt = converter.convert(self.excerpt)
|
self.extracted_excerpt = converter.convert(self.extracted_excerpt)
|
||||||
end
|
end
|
||||||
|
|
||||||
# The generated directory into which the post will be placed
|
# The generated directory into which the post will be placed
|
||||||
|
|
|
@ -0,0 +1,10 @@
|
||||||
|
---
|
||||||
|
layout: ~
|
||||||
|
excerpt: 'I can set a custom excerpt'
|
||||||
|
---
|
||||||
|
|
||||||
|
This is not my excerpt.
|
||||||
|
|
||||||
|
Neither is this.
|
||||||
|
|
||||||
|
I can use the excerpt: <quote>{{page.excerpt}}</quote>
|
|
@ -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 31, @site.posts.size
|
assert_equal 32, @site.posts.size
|
||||||
end
|
end
|
||||||
|
|
||||||
should "insert site.posts into the index" do
|
should "insert site.posts into the index" do
|
||||||
|
|
|
@ -320,6 +320,24 @@ class TestPost < Test::Unit::TestCase
|
||||||
assert !@post.excerpt.include?("---"), "does not contains separator"
|
assert !@post.excerpt.include?("---"), "does not contains separator"
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
context "with custom excerpt" do
|
||||||
|
setup do
|
||||||
|
file = "2013-04-11-custom-excerpt.markdown"
|
||||||
|
@post = setup_post(file)
|
||||||
|
do_render(@post)
|
||||||
|
end
|
||||||
|
|
||||||
|
should "use custom excerpt" do
|
||||||
|
assert_equal("I can set a custom excerpt", @post.excerpt)
|
||||||
|
end
|
||||||
|
|
||||||
|
should "expose custom excerpt to liquid" do
|
||||||
|
assert @post.content.include?("I can use the excerpt: <quote>I can set a custom excerpt</quote>"), "Exposes incorrect excerpt to liquid."
|
||||||
|
end
|
||||||
|
|
||||||
|
end
|
||||||
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue