From 9c7c935d665a87e6d12fc5fe53171e631b06cc71 Mon Sep 17 00:00:00 2001 From: Aleksander Madland Stapnes Date: Sun, 15 Jan 2017 05:17:48 -0300 Subject: [PATCH 1/2] Style pedantry: Remove trailing whitespace. My emacs did it... --- src/cryogen_core/compiler.clj | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/cryogen_core/compiler.clj b/src/cryogen_core/compiler.clj index 018b606..e71bf2c 100644 --- a/src/cryogen_core/compiler.clj +++ b/src/cryogen_core/compiler.clj @@ -481,10 +481,10 @@ :latest-posts latest-posts :navbar-pages navbar-pages :sidebar-pages sidebar-pages - :home-page (if (not-empty home-pages) - (first home-pages) + :home-page (if (not-empty home-pages) + (first home-pages) (merge (first latest-posts) - {:layout "home.html"})) + {:layout "home.html"})) :archives-uri (page-uri "archives.html" config) :index-uri (page-uri "index.html" config) :tags-uri (page-uri "tags.html" config) From dbd5caaf1f90075e4b65b982ff5498450a3dcd21 Mon Sep 17 00:00:00 2001 From: Aleksander Madland Stapnes Date: Sun, 15 Jan 2017 05:30:25 -0300 Subject: [PATCH 2/2] Replace tagsoup dependency with enlive Tagsoup depends on an old version of clojure.data.xml, which doesn't compile with clojure 1.9.0-alpha12. Enlive seems more actively maintained and used. --- project.clj | 2 +- src/cryogen_core/compiler.clj | 30 ++++++++++++++--------------- test/cryogen_core/compiler_test.clj | 3 ++- 3 files changed, 18 insertions(+), 17 deletions(-) diff --git a/project.clj b/project.clj index 5fd0ff8..c938571 100644 --- a/project.clj +++ b/project.clj @@ -14,6 +14,6 @@ [selmer "1.10.3"] [pandect "0.6.1"] [hawk "0.2.11"] - [clj-tagsoup "0.3.0" :exclusions [org.clojure/clojure]]] + [enlive "1.1.6"]] :deploy-repositories [["snapshots" :clojars] ["releases" :clojars]]) diff --git a/src/cryogen_core/compiler.clj b/src/cryogen_core/compiler.clj index e71bf2c..1b6d63c 100644 --- a/src/cryogen_core/compiler.clj +++ b/src/cryogen_core/compiler.clj @@ -5,8 +5,7 @@ [clojure.java.io :refer [copy file reader writer]] [clojure.string :as s] [text-decoration.core :refer :all] - [pl.danieljanus.tagsoup :as tagsoup] - [hiccup.core :as hiccup] + [net.cgrand.enlive-html :as enlive] [cryogen-core.toc :refer [generate-toc]] [cryogen-core.sass :as sass] [cryogen-core.markup :as m] @@ -295,23 +294,24 @@ :uri uri}))))) (defn content-until-more-marker - [^String content] - (let [index (.indexOf content "")] - (if (pos? index) - (let [s (subs content 0 index)] - (->> ((tagsoup/parse-string s) 2) - (drop 2) - hiccup/html))))) + "Returns the content until the special comment, + closing any unclosed tags. Returns nil if there's no such comment." + [content] + (when-let [index (s/index-of content "")] + (->> (subs content 0 index) + enlive/html-snippet + enlive/emit* + (apply str)))) (defn create-preview "Creates a single post preview" [blocks-per-preview post] - (merge post - {:content (or (content-until-more-marker (:content post)) - (->> ((tagsoup/parse-string (:content post)) 2) - (drop 2) - (take blocks-per-preview) - hiccup/html))})) + (update post :content + #(or (content-until-more-marker %) + (->> (enlive/html-snippet %) + (take blocks-per-preview) + enlive/emit* + (apply str))))) (defn create-previews "Returns a sequence of vectors, each containing a set of post previews" diff --git a/test/cryogen_core/compiler_test.clj b/test/cryogen_core/compiler_test.clj index 2d76c8d..46a5a55 100644 --- a/test/cryogen_core/compiler_test.clj +++ b/test/cryogen_core/compiler_test.clj @@ -22,7 +22,8 @@ and more content. ") - "
+ "
+
this post has more marker
")))