#47: Something well broken here, but I'm on the right path

Fragment indices are being returned instead of fragments, and it does not seem that the extension formatters are being called at all. But... config is definitely improved in the
right direction.
This commit is contained in:
Simon Brooke 2020-02-12 12:35:18 +00:00
parent b191f40d05
commit 0d686a9b63
No known key found for this signature in database
GPG key ID: A7A4F18D1D4DF987
5 changed files with 32 additions and 14 deletions

View file

@ -27,6 +27,7 @@
[org.clojure/core.memoize "0.5.9"]
[org.clojure/data.json "0.2.6"]
[org.clojure/tools.logging "0.4.0"]
[org.clojure/tools.trace "0.7.10"]
[org.slf4j/slf4j-api "1.7.25"]
[org.slf4j/log4j-over-slf4j "1.7.25"]
[org.slf4j/jul-to-slf4j "1.7.25"]

View file

@ -32,11 +32,12 @@
:default-locale "en-GB" ;; default language used for messages
:formatters ;; formatters for processing markdown
;; extensions.
{"vega" smeagol.formatting/process-vega
"vis" smeagol.formatting/process-vega
"mermaid" smeagol.extensions.mermaid/process-mermaid
"backticks" smeagol.formatting/process-backticks
"pswp" smeagol.extensions.photoswipe/process-photoswipe}
{:vega {:formatter "smeagol.extensions.vega/process-vega" }
:vis {:formatter "smeagol.extensions.vega/process-vega" }
:mermaid {:formatter "smeagol.extensions.mermaid/process-mermaid" }
:backticks {:formatter "smeagol.formatting/process-backticks" }
:pswp {:formatter "smeagol.extensions.photoswipe/process-photoswipe" }
}
:log-level :info ;; the minimum logging level; one of
;; :trace :debug :info :warn :error :fatal
:js-from :cdnjs ;; where to load JavaScript libraries

View file

@ -13,7 +13,7 @@ That's all there is to it - a sequence of image links just as you'd write them a
## The Gallery
This page holds another example Photoswipe gallery, this time using a simpler, Markdown-based specification. Processing this specification takes more work than the full syntax used in the other [Example gallery], so the gallery may be slower to load; but it's much easier to configure.
This page holds another example Photoswipe gallery, this time using a simpler, Markdown-based specification. Processing this specification takes more work than the full syntax used in the other [[Example gallery]], so the gallery may be slower to load; but it's much easier to configure.
```pswp
![Frost on a gate, Laurieston](content/uploads/g1.jpg)

View file

@ -174,10 +174,15 @@
;; 1)
(defn process-photoswipe
[^String url-or-pswp-spec ^Integer index]
[^String url-or-pswp-spec ^Integer index]
(log/info "process-photoswipe called with arg1 `"
url-or-pswp-spec "`; arg2 `" index "`.")
(let [data (resource-url-or-data->data url-or-pswp-spec)
spec (cs/trim (:data data))]
(if
(cs/starts-with? spec "![")
(process-simple-photoswipe spec index)
(process-full-photoswipe spec index))))
spec (cs/trim (:data data))
result
(if
(cs/starts-with? spec "![")
(process-simple-photoswipe spec index)
(process-full-photoswipe spec index))]
(log/info "process-photoswipe returning `" result "`.")
))

View file

@ -8,7 +8,8 @@
[markdown.core :as md]
[smeagol.configuration :refer [config]]
[smeagol.extensions.mermaid :refer [process-mermaid]]
[smeagol.extensions.photoswipe :refer [process-photoswipe]]))
[smeagol.extensions.photoswipe :refer [process-photoswipe]]
[taoensso.timbre :as log]))
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;;;
@ -149,7 +150,17 @@
;; I need to put the backticks back in.
remarked (if (odd? index) (str "```" fragment "\n```") fragment)
first-token (get-first-token fragment)
formatter (eval ((:formatters config) first-token))]
formatter (if-not
(empty? first-token)
(try
(let [kw (keyword first-token)]
(read-string (-> config :formatters kw :formatter)))
(catch Exception _
(do
(log/info "No formatter found for extension `" first-token "`")
;; no extension registered - there sometimes won't be,
;; and it doesn't matter
nil))))]
(cond
(empty? fragments)
(assoc result :text