fix: named heading route for file and db graphs

pull/11311/head
Gabriel Horner 2024-05-08 16:32:10 -04:00
parent 00e153e866
commit d3c276ac50
1 changed files with 10 additions and 13 deletions

View File

@ -158,23 +158,19 @@ independent of format as format specific heading characters are stripped"
(defn get-block-by-page-name-and-block-route-name (defn get-block-by-page-name-and-block-route-name
"Returns first block for given page name and block's route name. Block's route "Returns first block for given page name and block's route name. Block's route
name must match the content of a page's block header" name must match the content of a page's block header"
[repo page-name route-name] [repo page-uuid-str route-name]
(let [db (conn/get-db repo)] (let [db (conn/get-db repo)]
(if (config/db-based-graph? repo) (if (config/db-based-graph? repo)
(->> (d/q '[:find (pull ?b [:block/uuid]) (->> (d/q '[:find (pull ?b [:block/uuid])
:in $ ?page-name ?route-name ?content-matches :in $ ?page-uuid ?route-name ?content-matches %
:where :where
[?page :block/name ?page-name] [?page :block/uuid ?page-uuid]
[?b :block/page ?page] [?b :block/page ?page]
[?b :block/properties ?prop] (has-property ?b :logseq.property/heading)
[?prop-b :block/name "heading"]
[?prop-b :block/type "property"]
[?prop-b :block/uuid ?prop-uuid]
[(get ?prop ?prop-uuid) _]
[?b :block/content ?content] [?b :block/content ?content]
[(?content-matches ?content ?route-name ?b)]] [(?content-matches ?content ?route-name ?b)]]
db db
page-name (uuid page-uuid-str)
route-name route-name
(fn content-matches? [block-content external-content block-id] (fn content-matches? [block-content external-content block-id]
(let [block (db-utils/entity repo block-id) (let [block (db-utils/entity repo block-id)
@ -183,20 +179,21 @@ independent of format as format specific heading characters are stripped"
(db-content/special-id-ref->page-ref ref-tags) (db-content/special-id-ref->page-ref ref-tags)
(db-content/special-id-ref->page ref-tags) (db-content/special-id-ref->page ref-tags)
heading-content->route-name) heading-content->route-name)
(string/lower-case external-content))))) (string/lower-case external-content))))
(rules/extract-rules rules/db-query-dsl-rules [:has-property]))
ffirst) ffirst)
(->> (d/q '[:find (pull ?b [:block/uuid]) (->> (d/q '[:find (pull ?b [:block/uuid])
:in $ ?page-name ?route-name ?content-matches :in $ ?page-uuid ?route-name ?content-matches
:where :where
[?page :block/name ?page-name] [?page :block/uuid ?page-uuid]
[?b :block/page ?page] [?b :block/page ?page]
[?b :block/properties ?prop] [?b :block/properties ?prop]
[(get ?prop :heading) _] [(get ?prop :heading) _]
[?b :block/content ?content] [?b :block/content ?content]
[(?content-matches ?content ?route-name)]] [(?content-matches ?content ?route-name)]]
db db
page-name (uuid page-uuid-str)
route-name route-name
(fn content-matches? [block-content external-content] (fn content-matches? [block-content external-content]
(= (heading-content->route-name block-content) (= (heading-content->route-name block-content)