|
|
@@ -12,7 +12,10 @@
|
|
|
[frontend.format.block :as block]
|
|
|
[frontend.format :as format]
|
|
|
[cljs-time.core :as t]
|
|
|
- [cljs-time.coerce :as tc]))
|
|
|
+ [cljs-time.coerce :as tc]
|
|
|
+ [medley.core :as medley]
|
|
|
+ [clojure.walk :as walk]
|
|
|
+ [frontend.state :as state]))
|
|
|
|
|
|
(defn- extract-page-list
|
|
|
[content]
|
|
|
@@ -52,12 +55,34 @@
|
|
|
content
|
|
|
(remove-indentation-spaces content (:block/level block)))))))
|
|
|
|
|
|
+(defn get-page-name
|
|
|
+ [file ast]
|
|
|
+ ;; headline
|
|
|
+ (let [ast (map first ast)]
|
|
|
+ (if (string/includes? file "pages/contents.")
|
|
|
+ "Contents"
|
|
|
+ (let [first-block (last (first (filter block/heading-block? ast)))
|
|
|
+ property-name (when (and (contains? #{"Properties" "Property_Drawer"} (ffirst ast))
|
|
|
+ (not (string/blank? (:title (last (first ast))))))
|
|
|
+ (:title (last (first ast))))
|
|
|
+ first-block-name (let [title (last (first (:title first-block)))]
|
|
|
+ (and first-block
|
|
|
+ (string? title)
|
|
|
+ title))
|
|
|
+ file-name (when-let [file-name (last (string/split file #"/"))]
|
|
|
+ (-> (first (util/split-last "." file-name))
|
|
|
+ (string/replace "." "/")))]
|
|
|
+ (or property-name
|
|
|
+ (if (= (state/page-name-order) "heading")
|
|
|
+ (or first-block-name file-name)
|
|
|
+ (or file-name first-block-name)))))))
|
|
|
+
|
|
|
;; TODO: performance improvement
|
|
|
(defn- extract-pages-and-blocks
|
|
|
[repo-url format ast properties file content utf8-content journal?]
|
|
|
(try
|
|
|
(let [now (tc/to-long (t/now))
|
|
|
- page (db/get-page-name file ast)
|
|
|
+ page (get-page-name file ast)
|
|
|
[page page-name journal-day] (block/convert-page-if-journal page)
|
|
|
blocks (->> (block/extract-blocks ast content false format)
|
|
|
(block/with-parent-and-left [:block/name (string/lower-case page)]))
|
|
|
@@ -154,12 +179,17 @@
|
|
|
format (format/get-format file)
|
|
|
ast (mldoc/->edn content
|
|
|
(mldoc/default-config format))
|
|
|
- first-block (first ast)
|
|
|
- properties (let [properties (and (seq first-block)
|
|
|
- (= "Properties" (ffirst first-block))
|
|
|
- (last (first first-block)))]
|
|
|
- (if (and properties (seq properties))
|
|
|
- properties))]
|
|
|
+ first-block (ffirst ast)
|
|
|
+ properties (let [properties (and (text/properties-block? first-block)
|
|
|
+ (->> (last first-block)
|
|
|
+ (into {})
|
|
|
+ (walk/keywordize-keys)))]
|
|
|
+ (when (and properties (seq properties))
|
|
|
+ (if (:filters properties)
|
|
|
+ (update properties :filters
|
|
|
+ (fn [v]
|
|
|
+ (string/replace (or v "") "\\" "")))
|
|
|
+ properties)))]
|
|
|
(extract-pages-and-blocks
|
|
|
repo-url
|
|
|
format ast properties
|