Merge pull request #82 from madstap/master

Depend on enlive instead of tagsoup (to be able to upgrade to clojure 1.9.0)
This commit is contained in:
Carmen La 2017-01-15 23:32:15 -05:00 committed by GitHub
commit abf45945d0
3 changed files with 21 additions and 20 deletions

View file

@ -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]])

View file

@ -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 "<!--more-->")]
(if (pos? index)
(let [s (subs content 0 index)]
(->> ((tagsoup/parse-string s) 2)
(drop 2)
hiccup/html)))))
"Returns the content until the <!--more--> special comment,
closing any unclosed tags. Returns nil if there's no such comment."
[content]
(when-let [index (s/index-of content "<!--more-->")]
(->> (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)
(update post :content
#(or (content-until-more-marker %)
(->> (enlive/html-snippet %)
(take blocks-per-preview)
hiccup/html))}))
enlive/emit*
(apply str)))))
(defn create-previews
"Returns a sequence of vectors, each containing a set of post previews"

View file

@ -22,7 +22,8 @@
and more content.
</div>
</div>")
"<div id=\"post\"><div class=\"post-content\">
"<div id=\"post\">
<div class=\"post-content\">
this post has more marker
</div></div>")))