Merge pull request #17 from dl1ely/master

Fix overly eager replacement of file extensions in uris, fixes #16
This commit is contained in:
Carmen La 2015-01-28 19:16:37 -05:00
commit 91effffe82

View file

@ -23,6 +23,11 @@
(if-let [root (k config)] (if-let [root (k config)]
(str "/" root "/") "/")) (str "/" root "/") "/"))
(defn re-pattern-from-ext
"Creates a properly quoted regex pattern for the given file extension"
[ext]
(re-pattern (str (s/replace ext "." "\\.") "$")))
(defn find-md-assets (defn find-md-assets
"Returns a list of files ending with .md under templates" "Returns a list of files ending with .md under templates"
[ignored-files] [ignored-files]
@ -47,12 +52,12 @@
(defn post-uri (defn post-uri
"Creates a post uri from the post file name" "Creates a post uri from the post file name"
[file-name {:keys [blog-prefix post-root]} mu] [file-name {:keys [blog-prefix post-root]} mu]
(str blog-prefix post-root (s/replace file-name (re-pattern (m/ext mu)) ".html"))) (str blog-prefix post-root (s/replace file-name (re-pattern-from-ext (m/ext mu)) ".html")))
(defn page-uri (defn page-uri
"Creates a page uri from the page file name" "Creates a page uri from the page file name"
[page-name {:keys [blog-prefix page-root]} mu] [page-name {:keys [blog-prefix page-root]} mu]
(str blog-prefix page-root (s/replace page-name (re-pattern (m/ext mu)) ".html"))) (str blog-prefix page-root (s/replace page-name (re-pattern-from-ext (m/ext mu)) ".html")))
(defn read-page-meta (defn read-page-meta
"Returns the clojure map from the top of a markdown page/post" "Returns the clojure map from the top of a markdown page/post"
@ -68,7 +73,7 @@
[page config markup] [page config markup]
(with-open [rdr (java.io.PushbackReader. (reader page))] (with-open [rdr (java.io.PushbackReader. (reader page))]
(let [page-name (.getName page) (let [page-name (.getName page)
file-name (s/replace page-name (re-pattern (m/ext markup)) ".html") file-name (s/replace page-name (re-pattern-from-ext (m/ext markup)) ".html")
page-meta (read-page-meta page-name rdr) page-meta (read-page-meta page-name rdr)
content ((m/render-fn markup) rdr config)] content ((m/render-fn markup) rdr config)]
{:file-name file-name {:file-name file-name