mirror of
https://github.com/jekyll/jekyll.git
synced 2026-04-28 03:01:03 -04:00
Adds excerpt to posts
This commit is contained in:
14
test/source/_posts/2013-01-02-post-excerpt.markdown
Normal file
14
test/source/_posts/2013-01-02-post-excerpt.markdown
Normal file
@@ -0,0 +1,14 @@
|
||||
---
|
||||
layout: ~
|
||||
title: Post Excerpt
|
||||
---
|
||||
|
||||
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
|
||||
|
||||
should "ensure post count is as expected" do
|
||||
assert_equal 30, @site.posts.size
|
||||
assert_equal 31, @site.posts.size
|
||||
end
|
||||
|
||||
should "insert site.posts into the index" do
|
||||
|
||||
@@ -252,6 +252,52 @@ class TestPost < Test::Unit::TestCase
|
||||
|
||||
assert_equal "<h1>{{ page.title }}</h1>\n<p>Best <strong>post</strong> ever</p>", @post.content
|
||||
end
|
||||
|
||||
context "#excerpt" do
|
||||
setup do
|
||||
file = "2013-01-02-post-excerpt.markdown"
|
||||
@post.process(file)
|
||||
@post.read_yaml(@source, file)
|
||||
@post.transform
|
||||
end
|
||||
|
||||
should "return first paragraph by default" do
|
||||
assert @post.excerpt.include?("First paragraph"), "contains first paragraph"
|
||||
assert !@post.excerpt.include?("Second paragraph"), "does not contains second paragraph"
|
||||
assert !@post.excerpt.include?("Third paragraph"), "does not contains third paragraph"
|
||||
end
|
||||
|
||||
should "correctly resolve link references" do
|
||||
assert @post.excerpt.include?("www.jekyllrb.com"), "contains referenced link URL"
|
||||
end
|
||||
|
||||
should "return rendered HTML" do
|
||||
assert_equal "<p>First paragraph with <a href='http://www.jekyllrb.com/'>link ref</a>.</p>",
|
||||
@post.excerpt
|
||||
end
|
||||
|
||||
context "with excerpt_separator setting" do
|
||||
setup do
|
||||
file = "2013-01-02-post-excerpt.markdown"
|
||||
|
||||
@post.site.config['excerpt_separator'] = "\n---\n"
|
||||
|
||||
@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
|
||||
|
||||
should "replace separator with new-lines" do
|
||||
assert !@post.excerpt.include?("---"), "does not contains separator"
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
context "when in a site" do
|
||||
|
||||
Reference in New Issue
Block a user