Page reference format changed to square brackets

pull/645/head
Tienson Qin 2020-05-01 12:17:41 +08:00
parent 60a8b29cd6
commit 1fbe78f923
3 changed files with 53 additions and 39 deletions

View File

@ -168,32 +168,37 @@
(util/format "\\(%s\\)" s)
["Target" s]
[:span
[:span.text-gray-500 "<<"]
[:a {:href (str "/page/" (util/url-encode s))} s]
[:span.text-gray-500 ">>"]]
[:a {:id s} s]
["Radio_Target" s]
[:a {:href (str "/page/" (util/url-encode s))} (str "<<<" s ">>>")]
[:a {:id s} s]
;; [:a {:href (str "/page/" (util/url-encode s))} (str "<<<" s ">>>")]
["Link" link]
(let [{:keys [url label]} link]
(let [href (string-of-url url)
img-formats (set (map name (config/img-formats)))]
(if (some (fn [fmt] (re-find (re-pattern (str "\\." fmt)) href)) img-formats)
(image-link url href label)
(let [[href label] (match url
["Search" s]
[(str "#" (anchor-link s))
s]
:else
[href
(map-inline label)])]
(match url
["Search" s]
(case (first s)
\#
(->elem :a {:href (str "#" (anchor-link (subs s 1)))} (map-inline label))
;; FIXME: same headline, see more https://orgmode.org/manual/Internal-Links.html
\*
(->elem :a {:href (str "#" (anchor-link (subs s 1)))} (map-inline label))
;; page reference
[:span.page-reference
[:span.text-gray-500 "[["]
[:a {:href (str "/page/" (util/url-encode s))} s]
[:span.text-gray-500 "]]"]])
:else
(let [href (string-of-url url)
img-formats (set (map name (config/img-formats)))]
(if (some (fn [fmt] (re-find (re-pattern (str "\\." fmt)) href)) img-formats)
(image-link url href label)
(->elem
:a
{:href href}
label)))))
(map-inline label))))))
["Verbatim" s]
[:code s]

View File

@ -9,11 +9,14 @@
(vector? block)
(= "Heading" (first block))))
(defn target-block?
(defn page-reference-block?
[block]
(and
(vector? block)
(contains? #{"Target" "Radio_Target"} (first block))))
(= "Link" (first block))
(= "Search" (first (:url (second block))))
(not (contains? #{\# \*} (first (second (:url (second block))))))
))
(defn task-block?
[block]
@ -64,8 +67,9 @@
(let [ref-pages (atom [])]
(walk/postwalk
(fn [form]
(when (target-block? form)
(swap! ref-pages conj (string/capitalize (last form))))
(when (page-reference-block? form)
(let [page (second (:url (second form)))]
(swap! ref-pages conj (string/capitalize page))))
form)
(concat title children))
(assoc heading :ref-pages (vec @ref-pages))))

View File

@ -10,22 +10,27 @@
(rum/defc current-page < rum/reactive
[]
(let [route-match (state/sub :route-match)]
(if route-match
(let [route-name (get-in route-match [:data :name])
no-animate? (contains? #{:repos :repo-add :file}
route-name)]
(when-let [view (:view (:data route-match))]
(sidebar/sidebar
route-match
(if no-animate?
(route-view view route-match)
(ui/transition-group
{:class-name "router-wrapper"}
(ui/css-transition
{:class-names "pageChange"
:key route-name
:timeout {:enter 300
:exit 200}}
(route-view view route-match)))))))
(when-let [route-match (state/sub :route-match)]
(if-let [view (:view (:data route-match))]
(sidebar/sidebar
route-match
(view route-match))
;; FIXME: disable for now
;; (let [route-name (get-in route-match [:data :name])
;; no-animate? (contains? #{:repos :repo-add :file}
;; route-name)]
;; (when-let [view (:view (:data route-match))]
;; (sidebar/sidebar
;; route-match
;; (if no-animate?
;; (route-view view route-match)
;; (ui/transition-group
;; {:class-name "router-wrapper"}
;; (ui/css-transition
;; {:class-names "pageChange"
;; :key route-name
;; :timeout {:enter 300
;; :exit 200}}
;; (route-view view route-match)))))))
[:div "404 Page"])))