diff --git a/lib/jekyll/post.rb b/lib/jekyll/post.rb
index 50fd983c..e040fb02 100644
--- a/lib/jekyll/post.rb
+++ b/lib/jekyll/post.rb
@@ -19,7 +19,7 @@ module Jekyll
end
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_reader :name
@@ -80,10 +80,22 @@ module Jekyll
# Returns nothing.
def read_yaml(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')
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
# equal, it compares the Post slugs.
#
@@ -117,7 +129,7 @@ module Jekyll
# Returns nothing.
def transform
super
- self.excerpt = converter.convert(self.excerpt)
+ self.extracted_excerpt = converter.convert(self.extracted_excerpt)
end
# The generated directory into which the post will be placed
diff --git a/test/source/_posts/2013-04-11-custom-excerpt.markdown b/test/source/_posts/2013-04-11-custom-excerpt.markdown
new file mode 100644
index 00000000..023251fe
--- /dev/null
+++ b/test/source/_posts/2013-04-11-custom-excerpt.markdown
@@ -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: {{page.excerpt}}
\ No newline at end of file
diff --git a/test/test_generated_site.rb b/test/test_generated_site.rb
index abda0ba5..56413466 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 31, @site.posts.size
+ assert_equal 32, @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 b5b082a3..62da1343 100644
--- a/test/test_post.rb
+++ b/test/test_post.rb
@@ -320,6 +320,24 @@ class TestPost < Test::Unit::TestCase
assert !@post.excerpt.include?("---"), "does not contains separator"
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: I can set a custom excerpt
"), "Exposes incorrect excerpt to liquid."
+ end
+
+ end
+
end
end