Page references wip

This commit is contained in:
Tienson Qin
2020-04-23 22:56:59 +08:00
parent 43301b609c
commit bd6be45543
6 changed files with 70 additions and 27 deletions

View File

@@ -1,5 +1,7 @@
(ns frontend.format.org.block
(:require [frontend.util :as util]))
(:require [frontend.util :as util]
[clojure.walk :as walk]
[clojure.string :as string]))
(defn heading-block?
[block]
@@ -7,6 +9,12 @@
(vector? block)
(= "Heading" (first block))))
(defn target-block?
[block]
(and
(vector? block)
(contains? #{"Target" "Radio_Target"} (first block))))
(defn task-block?
[block]
(and
@@ -51,6 +59,17 @@
:tag/name tag})
tags))
(defn with-refs
[{:keys [title children] :as heading}]
(let [ref-pages (atom [])]
(walk/postwalk
(fn [form]
(when (target-block? form)
(swap! ref-pages conj (string/lower-case (last form))))
form)
(concat title children))
(assoc heading :ref-pages (vec @ref-pages))))
;; TODO create a dummy heading if no headings exists
(defn extract-headings
[blocks last-pos]
@@ -74,6 +93,7 @@
:timestamps timestamps)
(assoc-in [:meta :end-pos] last-pos)
(update :tags ->tags))
heading (with-refs heading)
last-pos' (get-in heading [:meta :pos])]
(recur (conj headings heading) [] (rest blocks) {} last-pos'))