diff --git a/lib/jekyll-pandoc-multiple-formats.rb b/lib/jekyll-pandoc-multiple-formats.rb
index 05c40573bde62e92b33489477ea3917545748439..acea7e648af1249a6cf3fe119f9ec466eab3133b 100644
--- a/lib/jekyll-pandoc-multiple-formats.rb
+++ b/lib/jekyll-pandoc-multiple-formats.rb
@@ -23,6 +23,8 @@ class PandocGenerator < Generator
         FileUtils.mkdir_p(post_path)
 
         filename = post.url.gsub(/\.html$/, ".#{output}")
+        # Have a filename!
+        filename = "#{post.url.gsub(/\//, "-").gsub(/-$/, "")}.#{output}" if filename =~ /\/$/
 
         filename_with_path = File.join(post_path, filename)