fix: filters

close #1783
pull/1845/head
Tienson Qin 2021-05-12 20:10:03 +08:00
parent 8efa39d65e
commit b991599244
9 changed files with 63 additions and 100 deletions

View File

@ -81,7 +81,8 @@
filtered-ref-blocks (block-handler/filter-blocks repo ref-blocks filters true)
n-ref (count filtered-ref-blocks)]
(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.content
(when (seq scheduled-or-deadlines)

View File

@ -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-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-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-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

View File

@ -172,7 +172,8 @@
:where
[?file :file/path ?path]
[(?pred $ ?path)]
[?block :block/file ?file]]
[?block :block/file ?file]
[(missing? $ ?block :block/name)]]
(conn/get-conn repo-url) pred)
db-utils/seq-flatten)))
@ -182,7 +183,8 @@
:in $ ?path
:where
[?file :file/path ?path]
[?block :block/file ?file]]
[?block :block/file ?file]
[(missing? $ ?block :block/name)]]
(conn/get-conn repo-url) path)
db-utils/seq-flatten))
@ -701,28 +703,6 @@
(vector? 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
[page-name]
(when page-name

View File

@ -41,7 +41,8 @@
(when (and (not (util/starts-with? page "http:"))
(not (util/starts-with? page "https:"))
(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)))
(and
@ -144,13 +145,6 @@
(vector? block)
(= "Timestamp" (first block))))
(defn properties-block?
[block]
(and
(vector? block)
(contains? #{"Property_Drawer" "Properties"}
(first block))))
(defn definition-list-block?
[block]
(and
@ -299,7 +293,7 @@
refs)
(remove string/blank?))
refs (->> (distinct (concat refs children-pages))
(remove nil?))
(remove nil?))
refs (map (fn [ref] (page-name->map ref with-id?)) refs)]
(assoc block :refs refs))))
@ -434,7 +428,7 @@
(drop-while #(= ["Break_Line"] %)))]
(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)]
(recur headings block-body (rest blocks) timestamps properties last-pos last-level children))
@ -497,7 +491,8 @@
(when (seq block-body)
(reset! pre-block-body (reverse block-body)))
(when (seq properties)
(reset! pre-block-properties (:properties properties)))
(let [properties (:properties properties)]
(reset! pre-block-properties properties)))
(-> (reverse headings)
safe-blocks))))]
(let [first-block (first blocks)

View File

@ -212,16 +212,3 @@
(defn plain->text
[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)))

View File

@ -1,44 +1,4 @@
(ns frontend.format.mldoc-test
(:require [frontend.format.mldoc :refer [parse-properties]]
(:require [frontend.format.mldoc]
[clojure.string :as string]
[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))))))

View File

@ -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

View File

@ -433,3 +433,10 @@
(defn image-link?
[img-formats s]
(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))))

View File

@ -1133,7 +1133,10 @@
;; fs
(defn get-file-ext
[file]
(last (string/split file #"\.")))
(and
(string? file)
(string/includes? file ".")
(last (string/split file #"\."))))
(defn get-dir-and-basename
[path]