mirror of
https://github.com/journeyman-cc/smeagol.git
synced 2026-04-12 18:05:06 +00:00
#45: OK, it doesn't work, but it's close.
Still getting fragment index instead of fragment text.
This commit is contained in:
parent
2f22b733c1
commit
40ab296d1a
5 changed files with 88 additions and 37 deletions
|
|
@ -32,11 +32,29 @@
|
||||||
:default-locale "en-GB" ;; default language used for messages
|
:default-locale "en-GB" ;; default language used for messages
|
||||||
:formatters ;; formatters for processing markdown
|
:formatters ;; formatters for processing markdown
|
||||||
;; extensions.
|
;; extensions.
|
||||||
{:vega {:formatter "smeagol.extensions.vega/process-vega" }
|
{:vega {:formatter "smeagol.extensions.vega/process-vega"
|
||||||
:vis {:formatter "smeagol.extensions.vega/process-vega" }
|
:scripts {:core {:remote "https://cdnjs.cloudflare.com/ajax/libs/vega/5.9.1/vega.min.js"}
|
||||||
:mermaid {:formatter "smeagol.extensions.mermaid/process-mermaid" }
|
:lite {:remote "https://cdnjs.cloudflare.com/ajax/libs/vega-lite/4.1.1/vega-lite.min.js"}
|
||||||
:backticks {:formatter "smeagol.formatting/process-backticks" }
|
:embed {:remote "https://cdnjs.cloudflare.com/ajax/libs/vega-embed/6.2.2/vega-embed.min.js"}
|
||||||
:pswp {:formatter "smeagol.extensions.photoswipe/process-photoswipe" }
|
:styles {}}}
|
||||||
|
:vis {:formatter "smeagol.extensions.vega/process-vega"
|
||||||
|
:scripts {:core {:remote "https://cdnjs.cloudflare.com/ajax/libs/vega/5.9.1/vega.min.js"}
|
||||||
|
:lite {:remote "https://cdnjs.cloudflare.com/ajax/libs/vega-lite/4.1.1/vega-lite.min.js"}
|
||||||
|
:embed {:remote "https://cdnjs.cloudflare.com/ajax/libs/vega-embed/6.2.2/vega-embed.min.js"}
|
||||||
|
:styles {}}}
|
||||||
|
:mermaid {:formatter "smeagol.extensions.mermaid/process-mermaid"
|
||||||
|
:scripts {:core {:local "vendor/mermaid/dist/mermaid.js"}}
|
||||||
|
:styles {}}
|
||||||
|
:backticks {:formatter "smeagol.formatting/process-backticks"
|
||||||
|
:scripts {}
|
||||||
|
:styles {}}
|
||||||
|
:pswp {:formatter "smeagol.extensions.photoswipe/process-photoswipe"
|
||||||
|
:scripts {:core {:local "/vendor/node_modules/photoswipe/dist/photoswipe.min.js"
|
||||||
|
:remote "https://cdnjs.cloudflare.com/ajax/libs/photoswipe/4.1.3/photoswipe.min.js"}
|
||||||
|
:ui {:local "/vendor/node_modules/photoswipe/dist/photoswipe-ui-default.min.js"
|
||||||
|
:remote "https://cdnjs.cloudflare.com/ajax/libs/photoswipe/4.1.3/photoswipe-ui-default.min.js"}}
|
||||||
|
:styles {:core {:local "/vendor/node_modules/photoswipe/dist/photoswipe.css"
|
||||||
|
:remote "/vendor/node_modules/photoswipe/dist/default-skin/default-skin.css"}}}
|
||||||
}
|
}
|
||||||
:log-level :info ;; the minimum logging level; one of
|
:log-level :info ;; the minimum logging level; one of
|
||||||
;; :trace :debug :info :warn :error :fatal
|
;; :trace :debug :info :warn :error :fatal
|
||||||
|
|
|
||||||
|
|
@ -1,20 +1,12 @@
|
||||||
{% extends "templates/base.html" %}
|
{% extends "templates/base.html" %}
|
||||||
|
|
||||||
{% block extra-headers %}
|
{% block extra-headers %}
|
||||||
<!-- ifequal js-from ":cloudflare" -->
|
{% for script in scripts %}
|
||||||
<script src="https://cdnjs.cloudflare.com/ajax/libs/photoswipe/4.1.3/photoswipe-ui-default.min.js"></script>
|
<script src="{{script}}"></script>
|
||||||
<script src="https://cdnjs.cloudflare.com/ajax/libs/photoswipe/4.1.3/photoswipe.min.js"></script>
|
{% endfor %}
|
||||||
{% style "/vendor/node_modules/photoswipe/dist/photoswipe.css" %}
|
{% for style in styles %}
|
||||||
{% style "/vendor/node_modules/photoswipe/dist/default-skin/default-skin.css" %}
|
<link href="{{style}}" rel="stylesheet" type="text/css" />
|
||||||
<script src="https://cdnjs.cloudflare.com/ajax/libs/mermaid/8.4.6/mermaid.min.js"></script>
|
{% endfor %}
|
||||||
<script src="https://cdnjs.cloudflare.com/ajax/libs/vega/5.9.1/vega.min.js"></script>
|
|
||||||
<script src="https://cdnjs.cloudflare.com/ajax/libs/vega-lite/4.1.1/vega-lite.min.js"></script>
|
|
||||||
<script src="https://cdnjs.cloudflare.com/ajax/libs/vega-embed/6.2.2/vega-embed.min.js"></script>
|
|
||||||
<!-- else -->
|
|
||||||
<!-- TODO: currently `lein npm install` fails to build packages on all platforms, and
|
|
||||||
fails SILENTLY. Consequently setting js-from to local is not advised. Investigting. -->
|
|
||||||
<!-- script "vendor/mermaid/dist/mermaid.js" %} -->
|
|
||||||
<!-- endifequal -->
|
|
||||||
{% endblock %}
|
{% endblock %}
|
||||||
|
|
||||||
{% block content %}
|
{% block content %}
|
||||||
|
|
|
||||||
|
|
@ -182,7 +182,7 @@
|
||||||
fragment
|
fragment
|
||||||
first-token
|
first-token
|
||||||
formatter)]
|
formatter)]
|
||||||
(assoc result :extensions (cons kw (:extensions result))))
|
(assoc-in result [:extensions kw] (-> config :formatters kw)))
|
||||||
true
|
true
|
||||||
;; Otherwise process the current fragment as markdown and recurse on
|
;; Otherwise process the current fragment as markdown and recurse on
|
||||||
;; down the list
|
;; down the list
|
||||||
|
|
@ -194,7 +194,12 @@
|
||||||
"Given a map of the form produced by `process-text`, return a string of HTML text
|
"Given a map of the form produced by `process-text`, return a string of HTML text
|
||||||
with the inclusions (if any) reintegrated."
|
with the inclusions (if any) reintegrated."
|
||||||
([processed-text]
|
([processed-text]
|
||||||
(reintegrate-inclusions (:inclusions processed-text) (:text processed-text)))
|
(assoc
|
||||||
|
processed-text
|
||||||
|
:content
|
||||||
|
(reintegrate-inclusions
|
||||||
|
(:inclusions processed-text)
|
||||||
|
(:text processed-text))))
|
||||||
([inclusions text]
|
([inclusions text]
|
||||||
(let [ks (keys inclusions)]
|
(let [ks (keys inclusions)]
|
||||||
(if (empty? (keys inclusions))
|
(if (empty? (keys inclusions))
|
||||||
|
|
@ -213,7 +218,10 @@
|
||||||
|
|
||||||
|
|
||||||
(defn md->html
|
(defn md->html
|
||||||
"Take this markdown source, and return HTML."
|
"Take this `md-src` markdown source, and return a map in which:
|
||||||
|
1. the key `:content` is bound to the equivalent HTML source;
|
||||||
|
2. the key `:extensions`. is bound to details of the extensions
|
||||||
|
used."
|
||||||
[md-src]
|
[md-src]
|
||||||
(reintegrate-inclusions (process-text md-src)))
|
(reintegrate-inclusions (process-text md-src)))
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -25,6 +25,7 @@
|
||||||
[smeagol.uploads :as ul]
|
[smeagol.uploads :as ul]
|
||||||
[taoensso.timbre :as log]
|
[taoensso.timbre :as log]
|
||||||
[com.stuartsierra.component :as component]
|
[com.stuartsierra.component :as component]
|
||||||
|
[smeagol.configuration :refer [config]]
|
||||||
[smeagol.include.resolve-local-file :as resolve]
|
[smeagol.include.resolve-local-file :as resolve]
|
||||||
[smeagol.include :as include]))
|
[smeagol.include :as include]))
|
||||||
|
|
||||||
|
|
@ -123,6 +124,34 @@
|
||||||
(include/new-includer)
|
(include/new-includer)
|
||||||
[:resolver]))))
|
[:resolver]))))
|
||||||
|
|
||||||
|
(defn preferred-source
|
||||||
|
"Here, `component` is expected to be a map with two keys, `:local` and
|
||||||
|
`:remote`. If the value of `:extensions-from` in `config.edn` is remote
|
||||||
|
AND the value of `:remote` is not nil, then the value of `:remote` will
|
||||||
|
be returned. Otherwise, if the value of `:local` is nil and the value of
|
||||||
|
`:remote` is non-nil, the value of `:remote` will be returned. By default,
|
||||||
|
the value of `:local` will be returned."
|
||||||
|
[component]
|
||||||
|
(let [l (:local component) ;; TODO: look at the trick in Selmer to get relative URL
|
||||||
|
r (:remote component)]
|
||||||
|
(cond
|
||||||
|
(= (:extensions-from config) :remote) (if (empty? r) l r)
|
||||||
|
(empty? l) r
|
||||||
|
:else l)))
|
||||||
|
|
||||||
|
(defn collect-preferred
|
||||||
|
"From extensions referenced in this `processed-text`, extract the preferred
|
||||||
|
URLs for this keyword `k`, expected to be either `:scripts` or `:styles`."
|
||||||
|
[processed-text k]
|
||||||
|
(set
|
||||||
|
(remove
|
||||||
|
nil?
|
||||||
|
(map
|
||||||
|
preferred-source
|
||||||
|
(apply
|
||||||
|
concat
|
||||||
|
(map vals (map k (vals (:extensions processed-text)))))))))
|
||||||
|
|
||||||
(defn wiki-page
|
(defn wiki-page
|
||||||
"Render the markdown page specified in this `request`, if any. If none found, redirect to edit-page"
|
"Render the markdown page specified in this `request`, if any. If none found, redirect to edit-page"
|
||||||
[request]
|
[request]
|
||||||
|
|
@ -134,19 +163,23 @@
|
||||||
file-name (str page ".md")
|
file-name (str page ".md")
|
||||||
file-path (cjio/file util/content-dir file-name)
|
file-path (cjio/file util/content-dir file-name)
|
||||||
exists? (.exists (clojure.java.io/as-file file-path))]
|
exists? (.exists (clojure.java.io/as-file file-path))]
|
||||||
(cond exists?
|
(if exists?
|
||||||
(do
|
(do
|
||||||
(log/info (format "Showing page '%s' from file '%s'" page file-path))
|
(log/info (format "Showing page '%s' from file '%s'" page file-path))
|
||||||
(layout/render "wiki.html"
|
(let [processed-text (md->html
|
||||||
(merge (util/standard-params request)
|
(include/expand-include-md
|
||||||
{:title page
|
(:includer md-include-system)
|
||||||
:page page
|
(slurp file-path)))]
|
||||||
:content (md->html
|
(layout/render "wiki.html"
|
||||||
(include/expand-include-md
|
(merge (util/standard-params request)
|
||||||
(:includer md-include-system)
|
processed-text
|
||||||
(slurp file-path)))
|
{:title page
|
||||||
:editable true})))
|
:scripts (collect-preferred processed-text :scripts)
|
||||||
true (response/redirect (str "/edit?page=" page))))))
|
:styles (collect-preferred processed-text :styles)
|
||||||
|
:page page
|
||||||
|
:editable true}))))
|
||||||
|
;else
|
||||||
|
(response/redirect (str "/edit?page=" page))))))
|
||||||
|
|
||||||
|
|
||||||
(defn history-page
|
(defn history-page
|
||||||
|
|
|
||||||
|
|
@ -56,8 +56,8 @@
|
||||||
{:user user
|
{:user user
|
||||||
:admin (auth/get-admin user)
|
:admin (auth/get-admin user)
|
||||||
:js-from (:js-from config)
|
:js-from (:js-from config)
|
||||||
:side-bar (md->html (slurp (cjio/file content-dir "_side-bar.md")))
|
:side-bar (:content (md->html (slurp (cjio/file content-dir "_side-bar.md"))))
|
||||||
:header (md->html (slurp (cjio/file content-dir "_header.md")))
|
:header (:content (md->html (slurp (cjio/file content-dir "_header.md"))))
|
||||||
:version (System/getProperty "smeagol.version")}))
|
:version (System/getProperty "smeagol.version")}))
|
||||||
|
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue