From e31c69f24de8e52ef8972b8b8ef2293dc6d81c19 Mon Sep 17 00:00:00 2001
From: "Patrick M. Niedzielski" <patrick@pniedzielski.net>
Date: Fri, 27 Jan 2017 21:14:43 +0000
Subject: [PATCH] Support permalinks with no extension or slash

Jekyll supports extensionless permalinks with no trailing slash [1],
as in the following:

  /year/month/slug

For such a permalink, Jekyll generates a file `/year/month/slug.html`
and assumes the web server will play nicely and serve this file when
it receives a request for `/year/month/slug`.

This patch adds support for such permalinks for files Pandoc-generated
files in other formats, with the generated URLs having a form
mirroring the generated HTML files:

  /year/month/slug.format

[1]: https://jekyllrb.com/docs/permalinks/#extensionless-permalinks
---
 lib/jekyll-pandoc-multiple-formats/pandoc_file.rb | 8 ++++++++
 1 file changed, 8 insertions(+)

diff --git a/lib/jekyll-pandoc-multiple-formats/pandoc_file.rb b/lib/jekyll-pandoc-multiple-formats/pandoc_file.rb
index 7afa130..ef02ac7 100644
--- a/lib/jekyll-pandoc-multiple-formats/pandoc_file.rb
+++ b/lib/jekyll-pandoc-multiple-formats/pandoc_file.rb
@@ -67,6 +67,14 @@ module Jekyll
         path << @format
       end
 
+      # if permalink ends with trailing .html or trailing slash, path now ends with proper suffix
+      # for other cases (permalink with no trailing extension or slash), append format
+      # (ie /year/month/slug permalink --> /year/month/slug.pdf)
+      if not path.end_with? ".#{@format}"
+        path << '.'
+        path << @format
+      end
+
       path
     end
 
-- 
GitLab