Skip to content

Commit

Permalink
feat: page content fts breadcrumb support
Browse files Browse the repository at this point in the history
  • Loading branch information
cnrpman authored and tiensonqin committed Nov 25, 2022
1 parent 95d7987 commit cf655b3
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 5 deletions.
4 changes: 3 additions & 1 deletion src/main/frontend/components/block.cljs
Original file line number Diff line number Diff line change
Expand Up @@ -2497,12 +2497,14 @@
(rum/defc breadcrumb-separator [] [:span.mx-2.opacity-50 ""])

(defn breadcrumb
"block-id - uuid of the target block of breadcrumb. page uuid is also acceptable"
[config repo block-id {:keys [show-page? indent? end-separator? level-limit _navigating-block]
:or {show-page? true
level-limit 3}
:as opts}]
(let [parents (db/get-block-parents repo block-id (inc level-limit))
page (db/get-block-page repo block-id)
page (or (db/get-block-page repo block-id) ;; only return for block uuid
(model/query-block-by-uuid block-id)) ;; return page entity when received page uuid
page-name (:block/name page)
page-original-name (:block/original-name page)
show? (or (seq parents) show-page? page-name)
Expand Down
5 changes: 2 additions & 3 deletions src/main/frontend/components/search.cljs
Original file line number Diff line number Diff line change
Expand Up @@ -67,10 +67,9 @@
"Return hiccup of highlighted page content FTS result"
[content q]
(when-not (or (string/blank? content) (string/blank? q))
[:div (loop [content content
[:div (loop [content content ;; why recur? because there might be multiple matches
result []]
(let [_ (prn "content" content "result" result)
[b-cut hl-cut e-cut] (text-util/cut-by content "$pfts_2lqh>$" "$<pfts_2lqh$")
(let [[b-cut hl-cut e-cut] (text-util/cut-by content "$pfts_2lqh>$" "$<pfts_2lqh$")
hiccups-add [(when-not (string/blank? b-cut)
[:span b-cut])
(when-not (string/blank? hl-cut)
Expand Down
4 changes: 3 additions & 1 deletion src/main/frontend/util/text.cljs
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,9 @@

(defn cut-by
"Cut string by specifid wrapping symbols, only match the first occurrence.
value - string to cut"
value - string to cut
before - cutting symbol (before)
end - cutting symbol (end)"
[value before end]
(let [b-pos (string/index-of value before)
b-len (count before)]
Expand Down

0 comments on commit cf655b3

Please sign in to comment.