From 16aa6e5bf7f1178c464692e6e8f8520bd5bbf75c Mon Sep 17 00:00:00 2001 From: Trevor Hartman Date: Thu, 27 Dec 2018 21:52:41 -0700 Subject: [PATCH] Update behaviour of clean-urls? feature (#113) - Files no longer generated as `/foo-bar/index.html`, generated as just `foo-bar.html` instead - With `clean-urls?` on, all page links will have trailing `.html` stripped --- project.clj | 2 +- src/cryogen_core/compiler.clj | 9 ++++++--- 2 files changed, 7 insertions(+), 4 deletions(-) diff --git a/project.clj b/project.clj index a4360b7..9e219ba 100644 --- a/project.clj +++ b/project.clj @@ -1,4 +1,4 @@ -(defproject cryogen-core "0.1.64" +(defproject cryogen-core "0.1.65-SNAPSHOT" :description "Cryogen's compiler" :url "https://github.com/cryogen-project/cryogen-core" :license {:name "Eclipse Public License" diff --git a/src/cryogen_core/compiler.clj b/src/cryogen_core/compiler.clj index 65b5319..4b9b595 100644 --- a/src/cryogen_core/compiler.clj +++ b/src/cryogen_core/compiler.clj @@ -65,13 +65,14 @@ (let [fmt (java.text.SimpleDateFormat. date-fmt)] (.parse fmt (.substring file-name 0 10)))) + (defn page-uri "Creates a URI from file name. `uri-type` is any of the uri types specified in config, e.g., `:post-root-uri`." ([file-name params] (page-uri file-name nil params)) ([file-name uri-type {:keys [blog-prefix clean-urls?] :as params}] (let [page-uri (get params uri-type) - uri-end (if clean-urls? (string/replace file-name #"(index)?\.html" "/") file-name)] + uri-end (if clean-urls? (string/replace file-name #"(index)?\.html" "") file-name)] (cryogen-io/path "/" blog-prefix page-uri uri-end)))) (defn read-page-meta @@ -227,10 +228,12 @@ (map (partial sort-by :page-index) [navbar-pages sidebar-pages]))) (defn write-html - "When `clean-urls?` is set, appends `/index.html` before spit; otherwise just spits." + "When `clean-urls?` is set, appends `.html` before spit; otherwise just spits." [file-uri {:keys [clean-urls?]} data] (if clean-urls? - (cryogen-io/create-file-recursive (cryogen-io/path file-uri "index.html") data) + (cryogen-io/create-file + (if (= "/" file-uri) "index.html" (str file-uri ".html")) + data) (cryogen-io/create-file file-uri data))) (defn- print-debug-info [data]