Skip to content

Commit

Permalink
Excerpt relative-path should match its path (#6597)
Browse files Browse the repository at this point in the history
Merge pull request 6597
  • Loading branch information
ashmaroli authored and jekyllbot committed Feb 20, 2018
1 parent da6a697 commit 5ebdc18
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 2 deletions.
9 changes: 8 additions & 1 deletion lib/jekyll/excerpt.rb
Expand Up @@ -8,7 +8,7 @@ class Excerpt
attr_accessor :content, :ext
attr_writer :output

def_delegators :@doc, :site, :name, :ext, :relative_path, :extname,
def_delegators :@doc, :site, :name, :ext, :extname,
:render_with_liquid?, :collection, :related_posts,
:url, :next_doc, :previous_doc

Expand Down Expand Up @@ -41,6 +41,13 @@ def path
File.join(doc.path, "#excerpt")
end

# 'Relative Path' of the excerpt.
#
# Returns the relative_path for the doc this excerpt belongs to with #excerpt appended
def relative_path
File.join(doc.relative_path, "#excerpt")
end

# Check if excerpt includes a string
#
# Returns true if the string passed in
Expand Down
11 changes: 10 additions & 1 deletion test/test_excerpt.rb
Expand Up @@ -78,6 +78,15 @@ def do_render(document)
end
end

context "#relative_path" do
should "return its document's relative path with '/#excerpt' appended" do
assert_equal "#{@excerpt.doc.relative_path}/#excerpt",
@excerpt.relative_path
assert_equal "_posts/2013-07-22-post-excerpt-with-layout.markdown/#excerpt",
@excerpt.relative_path
end
end

context "#to_liquid" do
should "contain the proper page data to mimic the post liquid" do
assert_equal "Post Excerpt with Layout", @excerpt.to_liquid["title"]
Expand All @@ -86,7 +95,7 @@ def do_render(document)
assert_equal Time.parse("2013-07-22"), @excerpt.to_liquid["date"]
assert_equal %w(bar baz z_category MixedCase), @excerpt.to_liquid["categories"]
assert_equal %w(first second third jekyllrb.com), @excerpt.to_liquid["tags"]
assert_equal "_posts/2013-07-22-post-excerpt-with-layout.markdown",
assert_equal "_posts/2013-07-22-post-excerpt-with-layout.markdown/#excerpt",
@excerpt.to_liquid["path"]
end
end
Expand Down

0 comments on commit 5ebdc18

Please sign in to comment.