Merge pull request #87 from madstap/master
Add nohighlight to klipsified code blocks.
This commit is contained in:
commit
dea3725759
2 changed files with 27 additions and 6 deletions
|
@ -471,21 +471,26 @@
|
|||
(catch Exception _
|
||||
(throw (IllegalArgumentException. "Failed to parse config.edn")))))
|
||||
|
||||
(defn klipsify
|
||||
"Add the klipse html under the :klipse key and adds nohighlight
|
||||
classes to any code blocks that are to be klipsified. Expects
|
||||
configuration to be under :klipse, if there's none it does nothing."
|
||||
[{:keys [klipse content] :as post-or-page}]
|
||||
(-> post-or-page
|
||||
(update :klipse klipse/emit content)
|
||||
(update :content klipse/tag-nohighlight (:settings klipse))))
|
||||
|
||||
(defn compile-assets
|
||||
"Generates all the html and copies over resources specified in the config"
|
||||
[]
|
||||
(println (green "compiling assets..."))
|
||||
(let [{:keys [^String site-url blog-prefix rss-name recent-posts sass-dest keep-files ignored-files previews? author-root-uri theme]
|
||||
:as config} (read-config)
|
||||
posts (map (fn [{:keys [klipse content] :as post}]
|
||||
(assoc post :klipse (klipse/emit klipse content)))
|
||||
(add-prev-next (read-posts config)))
|
||||
posts (map klipsify (add-prev-next (read-posts config)))
|
||||
posts-by-tag (group-by-tags posts)
|
||||
posts (tag-posts posts config)
|
||||
latest-posts (->> posts (take recent-posts) vec)
|
||||
pages (map (fn [{:keys [klipse content] :as page}]
|
||||
(assoc page :klipse (klipse/emit klipse content)))
|
||||
(read-pages config))
|
||||
pages (map klipsify (read-pages config))
|
||||
home-page (->> pages
|
||||
(filter #(boolean (:home? %)))
|
||||
(first))
|
||||
|
|
|
@ -51,6 +51,22 @@
|
|||
;;;;;;;;;;;;
|
||||
;; klipse
|
||||
|
||||
(defn eval-classes
|
||||
"Takes the :settings map and returns all values that are css class selectors."
|
||||
[settings]
|
||||
(filter #(str/starts-with? % ".") (vals settings)))
|
||||
|
||||
(defn tag-nohighlight
|
||||
"Takes html as a string and a coll of class-selectors and adds
|
||||
nohighlight to all code blocks that includes one of them."
|
||||
[html settings]
|
||||
(letfn [(tag [h clas]
|
||||
(enlive/sniptest h
|
||||
[(keyword (str "code" clas))]
|
||||
(fn [x]
|
||||
(update-in x [:attrs :class] #(str % " nohighlight")))))]
|
||||
(reduce tag html (eval-classes settings))))
|
||||
|
||||
(def defaults
|
||||
{:js-src
|
||||
{:min "https://storage.googleapis.com/app.klipse.tech/plugin_prod/js/klipse_plugin.min.js"
|
||||
|
|
Loading…
Reference in a new issue