mirror of https://github.com/logseq/logseq
parent
8efa39d65e
commit
b991599244
|
@ -81,7 +81,8 @@
|
||||||
filtered-ref-blocks (block-handler/filter-blocks repo ref-blocks filters true)
|
filtered-ref-blocks (block-handler/filter-blocks repo ref-blocks filters true)
|
||||||
n-ref (count filtered-ref-blocks)]
|
n-ref (count filtered-ref-blocks)]
|
||||||
(when (or (> n-ref 0)
|
(when (or (> n-ref 0)
|
||||||
(seq scheduled-or-deadlines))
|
(seq scheduled-or-deadlines)
|
||||||
|
(seq filter-state))
|
||||||
[:div.references.mt-6.flex-1.flex-row
|
[:div.references.mt-6.flex-1.flex-row
|
||||||
[:div.content
|
[:div.content
|
||||||
(when (seq scheduled-or-deadlines)
|
(when (seq scheduled-or-deadlines)
|
||||||
|
|
|
@ -45,7 +45,7 @@
|
||||||
get-file-blocks get-file-contents get-file-last-modified-at get-file-no-sub get-file-page get-file-page-id file-exists?
|
get-file-blocks get-file-contents get-file-last-modified-at get-file-no-sub get-file-page get-file-page-id file-exists?
|
||||||
get-file-pages get-files get-files-blocks get-files-full get-files-that-referenced-page get-journals-length
|
get-file-pages get-files get-files-blocks get-files-full get-files-that-referenced-page get-journals-length
|
||||||
get-latest-journals get-marker-blocks get-matched-blocks get-page get-page-alias get-page-alias-names get-page-blocks get-page-linked-refs-refed-pages
|
get-latest-journals get-marker-blocks get-matched-blocks get-page get-page-alias get-page-alias-names get-page-blocks get-page-linked-refs-refed-pages
|
||||||
get-page-blocks-count get-page-blocks-no-cache get-page-file get-page-format get-page-name get-page-properties
|
get-page-blocks-count get-page-blocks-no-cache get-page-file get-page-format get-page-properties
|
||||||
get-page-properties-content get-page-referenced-blocks get-page-referenced-pages get-page-unlinked-references get-page-referenced-blocks-no-cache
|
get-page-properties-content get-page-referenced-blocks get-page-referenced-pages get-page-unlinked-references get-page-referenced-blocks-no-cache
|
||||||
get-pages get-pages-relation get-pages-that-mentioned-page get-public-pages get-tag-pages
|
get-pages get-pages-relation get-pages-that-mentioned-page get-public-pages get-tag-pages
|
||||||
journal-page? local-native-fs? mark-repo-as-cloned! page-alias-set page-blocks-transform pull-block
|
journal-page? local-native-fs? mark-repo-as-cloned! page-alias-set page-blocks-transform pull-block
|
||||||
|
|
|
@ -172,7 +172,8 @@
|
||||||
:where
|
:where
|
||||||
[?file :file/path ?path]
|
[?file :file/path ?path]
|
||||||
[(?pred $ ?path)]
|
[(?pred $ ?path)]
|
||||||
[?block :block/file ?file]]
|
[?block :block/file ?file]
|
||||||
|
[(missing? $ ?block :block/name)]]
|
||||||
(conn/get-conn repo-url) pred)
|
(conn/get-conn repo-url) pred)
|
||||||
db-utils/seq-flatten)))
|
db-utils/seq-flatten)))
|
||||||
|
|
||||||
|
@ -182,7 +183,8 @@
|
||||||
:in $ ?path
|
:in $ ?path
|
||||||
:where
|
:where
|
||||||
[?file :file/path ?path]
|
[?file :file/path ?path]
|
||||||
[?block :block/file ?file]]
|
[?block :block/file ?file]
|
||||||
|
[(missing? $ ?block :block/name)]]
|
||||||
(conn/get-conn repo-url) path)
|
(conn/get-conn repo-url) path)
|
||||||
db-utils/seq-flatten))
|
db-utils/seq-flatten))
|
||||||
|
|
||||||
|
@ -701,28 +703,6 @@
|
||||||
(vector? block)
|
(vector? block)
|
||||||
(= "Heading" (first block))))
|
(= "Heading" (first 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 heading-block? ast)))
|
|
||||||
property-name (when (and (= "Properties" (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)))))))
|
|
||||||
|
|
||||||
(defn get-page-original-name
|
(defn get-page-original-name
|
||||||
[page-name]
|
[page-name]
|
||||||
(when page-name
|
(when page-name
|
||||||
|
|
|
@ -41,7 +41,8 @@
|
||||||
(when (and (not (util/starts-with? page "http:"))
|
(when (and (not (util/starts-with? page "http:"))
|
||||||
(not (util/starts-with? page "https:"))
|
(not (util/starts-with? page "https:"))
|
||||||
(not (util/starts-with? page "file:"))
|
(not (util/starts-with? page "file:"))
|
||||||
(or (= ext :excalidraw) (not (contains? (config/supported-formats) ext))))
|
(or (= ext :excalidraw)
|
||||||
|
(not (contains? (config/supported-formats) ext))))
|
||||||
page)))
|
page)))
|
||||||
|
|
||||||
(and
|
(and
|
||||||
|
@ -144,13 +145,6 @@
|
||||||
(vector? block)
|
(vector? block)
|
||||||
(= "Timestamp" (first block))))
|
(= "Timestamp" (first block))))
|
||||||
|
|
||||||
(defn properties-block?
|
|
||||||
[block]
|
|
||||||
(and
|
|
||||||
(vector? block)
|
|
||||||
(contains? #{"Property_Drawer" "Properties"}
|
|
||||||
(first block))))
|
|
||||||
|
|
||||||
(defn definition-list-block?
|
(defn definition-list-block?
|
||||||
[block]
|
[block]
|
||||||
(and
|
(and
|
||||||
|
@ -434,7 +428,7 @@
|
||||||
(drop-while #(= ["Break_Line"] %)))]
|
(drop-while #(= ["Break_Line"] %)))]
|
||||||
(recur headings (conj block-body ["Paragraph" other-body]) (rest blocks) timestamps' properties last-pos last-level children))
|
(recur headings (conj block-body ["Paragraph" other-body]) (rest blocks) timestamps' properties last-pos last-level children))
|
||||||
|
|
||||||
(properties-block? block)
|
(text/properties-block? block)
|
||||||
(let [properties (extract-properties block start_pos end_pos)]
|
(let [properties (extract-properties block start_pos end_pos)]
|
||||||
(recur headings block-body (rest blocks) timestamps properties last-pos last-level children))
|
(recur headings block-body (rest blocks) timestamps properties last-pos last-level children))
|
||||||
|
|
||||||
|
@ -497,7 +491,8 @@
|
||||||
(when (seq block-body)
|
(when (seq block-body)
|
||||||
(reset! pre-block-body (reverse block-body)))
|
(reset! pre-block-body (reverse block-body)))
|
||||||
(when (seq properties)
|
(when (seq properties)
|
||||||
(reset! pre-block-properties (:properties properties)))
|
(let [properties (:properties properties)]
|
||||||
|
(reset! pre-block-properties properties)))
|
||||||
(-> (reverse headings)
|
(-> (reverse headings)
|
||||||
safe-blocks))))]
|
safe-blocks))))]
|
||||||
(let [first-block (first blocks)
|
(let [first-block (first blocks)
|
||||||
|
|
|
@ -212,16 +212,3 @@
|
||||||
(defn plain->text
|
(defn plain->text
|
||||||
[plains]
|
[plains]
|
||||||
(string/join (map last plains)))
|
(string/join (map last plains)))
|
||||||
|
|
||||||
(defn parse-properties
|
|
||||||
[content format]
|
|
||||||
(let [ast (->> (->edn content
|
|
||||||
(default-config format))
|
|
||||||
(map first))
|
|
||||||
properties (collect-page-properties ast)
|
|
||||||
properties (let [properties (and (seq ast)
|
|
||||||
(= "Properties" (ffirst ast))
|
|
||||||
(last (first ast)))]
|
|
||||||
(if (and properties (seq properties))
|
|
||||||
properties))]
|
|
||||||
(into {} properties)))
|
|
||||||
|
|
|
@ -1,44 +1,4 @@
|
||||||
(ns frontend.format.mldoc-test
|
(ns frontend.format.mldoc-test
|
||||||
(:require [frontend.format.mldoc :refer [parse-properties]]
|
(:require [frontend.format.mldoc]
|
||||||
[clojure.string :as string]
|
[clojure.string :as string]
|
||||||
[cljs.test :refer [deftest are is testing]]))
|
[cljs.test :refer [deftest are is testing]]))
|
||||||
|
|
||||||
(deftest test-parse-org-properties
|
|
||||||
[]
|
|
||||||
(testing "just title"
|
|
||||||
(let [content "#+TITLE: some title "
|
|
||||||
props (parse-properties content "org")]
|
|
||||||
(are [x y] (= x y)
|
|
||||||
;; TODO: should we trim in parse-properties?
|
|
||||||
"some title" (string/trim (:title props)))))
|
|
||||||
|
|
||||||
(testing "filetags"
|
|
||||||
(let [content "
|
|
||||||
#+FILETAGS: :tag1:tag_2:@tag:
|
|
||||||
#+ROAM_TAGS: roamtag
|
|
||||||
body"
|
|
||||||
props (parse-properties content "org")]
|
|
||||||
(are [x y] (= x y)
|
|
||||||
(list "@tag" "tag1" "tag_2") (sort (:filetags props))
|
|
||||||
["roamtag"] (:roam_tags props)
|
|
||||||
(list "@tag" "roamtag" "tag1" "tag_2") (sort (:tags props)))))
|
|
||||||
|
|
||||||
(testing "roam tags"
|
|
||||||
(let [content "
|
|
||||||
#+FILETAGS: filetag
|
|
||||||
#+ROAM_TAGS: roam1 roam2
|
|
||||||
body
|
|
||||||
"
|
|
||||||
props (parse-properties content "org")]
|
|
||||||
(are [x y] (= x y)
|
|
||||||
["roam1" "roam2"] (:roam_tags props)
|
|
||||||
(list "filetag" "roam1" "roam2") (sort (:tags props)))))
|
|
||||||
|
|
||||||
(testing "quoted roam tags"
|
|
||||||
(let [content "
|
|
||||||
#+ROAM_TAGS: \"why would\" you use \"spaces\" xxx
|
|
||||||
body
|
|
||||||
"
|
|
||||||
props (parse-properties content "org")]
|
|
||||||
;; TODO maybe need to sort or something
|
|
||||||
(is (= ["why would" "spaces" "you" "use" "xxx"] (:roam_tags props))))))
|
|
||||||
|
|
|
@ -12,7 +12,10 @@
|
||||||
[frontend.format.block :as block]
|
[frontend.format.block :as block]
|
||||||
[frontend.format :as format]
|
[frontend.format :as format]
|
||||||
[cljs-time.core :as t]
|
[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
|
(defn- extract-page-list
|
||||||
[content]
|
[content]
|
||||||
|
@ -52,12 +55,34 @@
|
||||||
content
|
content
|
||||||
(remove-indentation-spaces content (:block/level block)))))))
|
(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
|
;; TODO: performance improvement
|
||||||
(defn- extract-pages-and-blocks
|
(defn- extract-pages-and-blocks
|
||||||
[repo-url format ast properties file content utf8-content journal?]
|
[repo-url format ast properties file content utf8-content journal?]
|
||||||
(try
|
(try
|
||||||
(let [now (tc/to-long (t/now))
|
(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)
|
[page page-name journal-day] (block/convert-page-if-journal page)
|
||||||
blocks (->> (block/extract-blocks ast content false format)
|
blocks (->> (block/extract-blocks ast content false format)
|
||||||
(block/with-parent-and-left [:block/name (string/lower-case page)]))
|
(block/with-parent-and-left [:block/name (string/lower-case page)]))
|
||||||
|
@ -154,12 +179,17 @@
|
||||||
format (format/get-format file)
|
format (format/get-format file)
|
||||||
ast (mldoc/->edn content
|
ast (mldoc/->edn content
|
||||||
(mldoc/default-config format))
|
(mldoc/default-config format))
|
||||||
first-block (first ast)
|
first-block (ffirst ast)
|
||||||
properties (let [properties (and (seq first-block)
|
properties (let [properties (and (text/properties-block? first-block)
|
||||||
(= "Properties" (ffirst first-block))
|
(->> (last first-block)
|
||||||
(last (first first-block)))]
|
(into {})
|
||||||
(if (and properties (seq properties))
|
(walk/keywordize-keys)))]
|
||||||
properties))]
|
(when (and properties (seq properties))
|
||||||
|
(if (:filters properties)
|
||||||
|
(update properties :filters
|
||||||
|
(fn [v]
|
||||||
|
(string/replace (or v "") "\\" "")))
|
||||||
|
properties)))]
|
||||||
(extract-pages-and-blocks
|
(extract-pages-and-blocks
|
||||||
repo-url
|
repo-url
|
||||||
format ast properties
|
format ast properties
|
||||||
|
|
|
@ -433,3 +433,10 @@
|
||||||
(defn image-link?
|
(defn image-link?
|
||||||
[img-formats s]
|
[img-formats s]
|
||||||
(some (fn [fmt] (re-find (re-pattern (str "(?i)\\." fmt "(?:\\?([^#]*))?(?:#(.*))?$")) s)) img-formats))
|
(some (fn [fmt] (re-find (re-pattern (str "(?i)\\." fmt "(?:\\?([^#]*))?(?:#(.*))?$")) s)) img-formats))
|
||||||
|
|
||||||
|
(defn properties-block?
|
||||||
|
[block]
|
||||||
|
(and
|
||||||
|
(vector? block)
|
||||||
|
(contains? #{"Property_Drawer" "Properties"}
|
||||||
|
(first block))))
|
||||||
|
|
|
@ -1133,7 +1133,10 @@
|
||||||
;; fs
|
;; fs
|
||||||
(defn get-file-ext
|
(defn get-file-ext
|
||||||
[file]
|
[file]
|
||||||
(last (string/split file #"\.")))
|
(and
|
||||||
|
(string? file)
|
||||||
|
(string/includes? file ".")
|
||||||
|
(last (string/split file #"\."))))
|
||||||
|
|
||||||
(defn get-dir-and-basename
|
(defn get-dir-and-basename
|
||||||
[path]
|
[path]
|
||||||
|
|
Loading…
Reference in New Issue