From d7ff4234f0f311979225bb718a73e5c2aa84f8d6 Mon Sep 17 00:00:00 2001 From: Parker Moore Date: Mon, 25 Jan 2016 14:48:28 -0800 Subject: [PATCH] Renderer#output_ext: honor folders when looking for ext Previously, even if the document permalink was a folder, it would look for an extension on that. For example, if I have: permalink: "/new-version-jekyll-v3.0.0/" the output_ext would be ".0". Now, the output_ext honors the trailing slash and will report based on the converters instead. --- lib/jekyll/renderer.rb | 2 +- .../_with.dots/permalink.with.slash.tho.md | 5 +++ test/test_collections.rb | 2 +- test/test_document.rb | 35 +++++++++++++++++++ 4 files changed, 42 insertions(+), 2 deletions(-) create mode 100644 test/source/_with.dots/permalink.with.slash.tho.md diff --git a/lib/jekyll/renderer.rb b/lib/jekyll/renderer.rb index c7b6042b..09815a60 100644 --- a/lib/jekyll/renderer.rb +++ b/lib/jekyll/renderer.rb @@ -168,7 +168,7 @@ module Jekyll private def permalink_ext - if document.permalink + if document.permalink && !document.permalink.end_with?("/") permalink_ext = File.extname(document.permalink) permalink_ext unless permalink_ext.empty? end diff --git a/test/source/_with.dots/permalink.with.slash.tho.md b/test/source/_with.dots/permalink.with.slash.tho.md new file mode 100644 index 00000000..71b9b2e4 --- /dev/null +++ b/test/source/_with.dots/permalink.with.slash.tho.md @@ -0,0 +1,5 @@ +--- +permalink: /with.dots/permalink.with.slash.tho/ +--- + +I'm a file with dots BUT I have a permalink which ends with a slash. diff --git a/test/test_collections.rb b/test/test_collections.rb index be3a9320..138bed6b 100644 --- a/test/test_collections.rb +++ b/test/test_collections.rb @@ -203,7 +203,7 @@ class TestCollections < JekyllUnitTest end should "contain one document" do - assert_equal 2, @collection.docs.size + assert_equal 3, @collection.docs.size end should "allow dots in the filename" do diff --git a/test/test_document.rb b/test/test_document.rb index 7c6f7bef..1197c4da 100644 --- a/test/test_document.rb +++ b/test/test_document.rb @@ -207,6 +207,10 @@ class TestDocument < JekyllUnitTest should "produce the right destination file" do assert_equal @dest_file, @document.destination(dest_dir) end + + should "honor the output extension of its permalink" do + assert_equal ".html", @document.output_ext + end end context "a document in a collection with pretty permalink style" do @@ -267,6 +271,10 @@ class TestDocument < JekyllUnitTest @dest_file = dest_dir("slides/example-slide-7.php") end + should "be written out properly" do + assert_exist @dest_file + end + should "produce the permalink as the url" do assert_equal "/slides/example-slide-7.php", @document.url end @@ -274,6 +282,10 @@ class TestDocument < JekyllUnitTest should "be written to the proper directory" do assert_equal @dest_file, @document.destination(dest_dir) end + + should "honor the output extension of its permalink" do + assert_equal ".php", @document.output_ext + end end context "documents in a collection with custom title permalinks" do @@ -318,6 +330,29 @@ class TestDocument < JekyllUnitTest end end + context "document with a permalink with dots & a trailing slash" do + setup do + @site = fixture_site({"collections" => { + "with.dots" => { "output" => true } + }}) + @site.process + @document = @site.collections["with.dots"].docs.last + @dest_file = dest_dir("with.dots", "permalink.with.slash.tho", "index.html") + end + + should "yield an HTML document" do + assert_equal @dest_file, @document.destination(dest_dir) + end + + should "be written properly" do + assert_exist @dest_file + end + + should "get the right output_ext" do + assert_equal ".html", @document.output_ext + end + end + context "documents in a collection" do setup do @site = fixture_site({