From 3c1d45f45ff209d48b697caa390e1de33270d7a0 Mon Sep 17 00:00:00 2001 From: Aidan Feldman Date: Thu, 19 Dec 2013 01:02:25 -0500 Subject: [PATCH 1/3] Sort pages by name by default The order that files are returned differs across operating systems, so ensure that they're being sorted after the fact. --- lib/jekyll/site.rb | 2 ++ test/test_site.rb | 8 ++++++++ 2 files changed, 10 insertions(+) diff --git a/lib/jekyll/site.rb b/lib/jekyll/site.rb index d7149d70..8fee59cf 100644 --- a/lib/jekyll/site.rb +++ b/lib/jekyll/site.rb @@ -175,6 +175,8 @@ module Jekyll static_files << StaticFile.new(self, self.source, dir, f) end end + + pages.sort_by!(&:name) end # Read all the files in //_posts and create a new Post diff --git a/test/test_site.rb b/test/test_site.rb index 35359a2a..09d4ecff 100644 --- a/test/test_site.rb +++ b/test/test_site.rb @@ -154,6 +154,14 @@ class TestSite < Test::Unit::TestCase assert_equal @site.generators.sort_by(&:class).map{|g|g.class.priority}, @site.generators.map{|g|g.class.priority} end + should "sort pages in a consistent way" do + # The order that files are returned differs across operating systems, so ensure that they're being sorted after the fact. + stub.proxy(Dir).entries { |entries| entries.reverse } + @site.process + sorted_pages = %w(.htaccess about.html bar.html contacts.html deal.with.dots.html foo.md index.html index.html sitemap.xml symlinked-file) + assert_equal sorted_pages, @site.pages.map(&:name) + end + should "read layouts" do @site.read_layouts assert_equal ["default", "simple", "post/simple"].sort, @site.layouts.keys.sort From a6e1c400511496b06a5d5f1565a89b240d33e137 Mon Sep 17 00:00:00 2001 From: Aidan Feldman Date: Thu, 19 Dec 2013 01:05:00 -0500 Subject: [PATCH 2/3] link to Stack Overflow answer re: Dir sorting --- test/test_site.rb | 1 + 1 file changed, 1 insertion(+) diff --git a/test/test_site.rb b/test/test_site.rb index 09d4ecff..bf517ba1 100644 --- a/test/test_site.rb +++ b/test/test_site.rb @@ -156,6 +156,7 @@ class TestSite < Test::Unit::TestCase should "sort pages in a consistent way" do # The order that files are returned differs across operating systems, so ensure that they're being sorted after the fact. + # http://stackoverflow.com/a/5529966/358804 stub.proxy(Dir).entries { |entries| entries.reverse } @site.process sorted_pages = %w(.htaccess about.html bar.html contacts.html deal.with.dots.html foo.md index.html index.html sitemap.xml symlinked-file) From 45ee9f814a7816cb3b9cdfeec367487f745aca38 Mon Sep 17 00:00:00 2001 From: Aidan Feldman Date: Thu, 19 Dec 2013 13:46:43 -0500 Subject: [PATCH 3/3] clarify page sorting test --- test/test_site.rb | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/test/test_site.rb b/test/test_site.rb index bf517ba1..a530f9d0 100644 --- a/test/test_site.rb +++ b/test/test_site.rb @@ -154,9 +154,7 @@ class TestSite < Test::Unit::TestCase assert_equal @site.generators.sort_by(&:class).map{|g|g.class.priority}, @site.generators.map{|g|g.class.priority} end - should "sort pages in a consistent way" do - # The order that files are returned differs across operating systems, so ensure that they're being sorted after the fact. - # http://stackoverflow.com/a/5529966/358804 + should "sort pages alphabetically" do stub.proxy(Dir).entries { |entries| entries.reverse } @site.process sorted_pages = %w(.htaccess about.html bar.html contacts.html deal.with.dots.html foo.md index.html index.html sitemap.xml symlinked-file)