Skip to content

Commit

Permalink
Update behaviour of clean-urls? feature (#113)
Browse files Browse the repository at this point in the history
- 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
  • Loading branch information
devth authored and lacarmen committed Dec 28, 2018
1 parent 67ef4b2 commit 16aa6e5
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 4 deletions.
2 changes: 1 addition & 1 deletion 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"
Expand Down
9 changes: 6 additions & 3 deletions src/cryogen_core/compiler.clj
Expand Up @@ -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
Expand Down Expand Up @@ -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]
Expand Down

0 comments on commit 16aa6e5

Please sign in to comment.