Latest post is chosen first in related posts

This commit is contained in:
Anand Narayan 2013-07-06 15:11:52 +05:30
parent c688ee67b6
commit dfca2c6edc
2 changed files with 8 additions and 2 deletions

View File

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

View File

@ -13,7 +13,12 @@ class TestRelatedPosts < Test::Unit::TestCase
should "use the most recent posts for related posts" do
@site.reset
@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