Merge pull request #1271 from sanandnarayan/related_posts

Latest post  first in related posts
This commit is contained in:
Parker Moore 2013-07-08 10:55:39 -07:00
commit e8d82fd88c
2 changed files with 8 additions and 2 deletions

View File

@ -46,7 +46,8 @@ module Jekyll
end end
def most_recent_posts def most_recent_posts
(self.site.posts - [self.post])[0..9] recent_posts = self.site.posts.reverse - [self.post]
recent_posts.first(10)
end end
def display(output) def display(output)

View File

@ -13,7 +13,12 @@ class TestRelatedPosts < Test::Unit::TestCase
should "use the most recent posts for related posts" do should "use the most recent posts for related posts" do
@site.reset @site.reset
@site.read @site.read
assert_equal @site.posts[0..9], Jekyll::RelatedPosts.new(@site.posts.last).build
last_post = @site.posts.last
related_posts = Jekyll::RelatedPosts.new(last_post).build
last_10_recent_posts = (@site.posts.reverse - [last_post]).first(10)
assert_equal last_10_recent_posts, related_posts
end end
end end