From 90865d5fc173f5ed4af8bff0a975f720326b06d6 Mon Sep 17 00:00:00 2001 From: Jordon Bedwell Date: Wed, 18 Nov 2015 15:58:26 -0600 Subject: [PATCH] Fix #4082: Allow users to use .htm and .xhtml (XHTML5.) --- lib/jekyll/page.rb | 15 ++++++++++++--- test/test_page.rb | 20 ++++++++++++++++++++ 2 files changed, 32 insertions(+), 3 deletions(-) diff --git a/lib/jekyll/page.rb b/lib/jekyll/page.rb index ca5bb268..a62a9940 100644 --- a/lib/jekyll/page.rb +++ b/lib/jekyll/page.rb @@ -16,6 +16,15 @@ module Jekyll url ] + # A set of extensions that are considered HTML or HTML-like so we + # should not alter them, this includes .xhtml through XHTM5. + + HTML_EXTENSIONS = %W( + .html + .xhtml + .htm + ) + # Initialize a new Page. # # site - The Site object. @@ -135,8 +144,8 @@ module Jekyll # Returns the destination file path String. def destination(dest) path = site.in_dest_dir(dest, URL.unescape_path(url)) - path = File.join(path, "index.html") if url.end_with?("/") - path << output_ext unless path.end_with?(output_ext) + path = File.join(path, "index") if url.end_with?("/") + path << output_ext unless path.end_with?(output_ext) path end @@ -147,7 +156,7 @@ module Jekyll # Returns the Boolean of whether this Page is HTML or not. def html? - output_ext == '.html' + HTML_EXTENSIONS.include?(output_ext) end # Returns the Boolean of whether this Page is an index file or not. diff --git a/test/test_page.rb b/test/test_page.rb index 1e4d3da6..625812aa 100644 --- a/test/test_page.rb +++ b/test/test_page.rb @@ -261,6 +261,26 @@ class TestPage < JekyllUnitTest assert File.exist?(File.join(dest_dir, 'contacts', 'index.html')) end + should "support .htm extension and respects that" do + page = setup_page('contacts.htm') + page.site.permalink_style = :pretty + do_render(page) + page.write(dest_dir) + + assert File.directory?(dest_dir) + assert File.exist?(File.join(dest_dir, 'contacts', 'index.htm')) + end + + should "support .xhtml extension and respects that" do + page = setup_page('contacts.xhtml') + page.site.permalink_style = :pretty + do_render(page) + page.write(dest_dir) + + assert File.directory?(dest_dir) + assert File.exist?(File.join(dest_dir, 'contacts', 'index.xhtml')) + end + should "write properly with extension different from html" do page = setup_page("sitemap.xml") page.site.permalink_style = :pretty