Fix marker page

pull/645/head
Tienson Qin 2020-06-25 16:54:54 +08:00
parent 1a10624a67
commit d4c0c2ea8d
1 changed files with 88 additions and 93 deletions

View File

@ -74,112 +74,107 @@
(let [repo (or repo (state/get-current-repo)) (let [repo (or repo (state/get-current-repo))
encoded-page-name (get-page-name state) encoded-page-name (get-page-name state)
page-name (string/lower-case (util/url-decode encoded-page-name)) page-name (string/lower-case (util/url-decode encoded-page-name))
marker-page? (db/marker-page? page-name)
format (db/get-page-format page-name) format (db/get-page-format page-name)
journal? (db/journal-page? page-name) journal? (db/journal-page? page-name)
heading? (util/uuid-string? page-name) heading? (util/uuid-string? page-name)
heading-id (and heading? (uuid page-name)) heading-id (and heading? (uuid page-name))
sidebar? (:sidebar? option) sidebar? (:sidebar? option)
raw-page-headings (get-headings repo page-name journal? heading?) raw-page-headings (get-headings repo page-name journal? heading?)]
page (if heading? (cond
(->> (:db/id (:heading/page (db/entity repo [:heading/uuid heading-id]))) marker-page?
(db/entity repo)) [:div
(db/entity repo [:page/name page-name])) [:h1.title
page-name (:page/name page) (string/upper-case page-name)]
file (:page/file page)] [:div.ml-2
(when page-name (reference/references page-name false true)]]
(cond
(db/marker-page? page-name)
[:div
[:h1.title
(string/upper-case page-name)]
[:div.ml-2
(reference/references page-name false true)]]
;; (and sidebar? file (empty? raw-page-headings)) :else
;; (do (let [page (if heading?
;; (state/sidebar-remove-block! (:sidebar/idx option)) (->> (:db/id (:heading/page (db/entity repo [:heading/uuid heading-id])))
;; [:div.text-sm "Empty"]) (db/entity repo))
(db/entity repo [:page/name page-name]))
page-name (:page/name page)
file (:page/file page)
file-path (and (:db/id file) (:file/path (db/entity repo (:db/id file))))
starred? (contains? (set
(some->> (state/sub [:config repo :starred])
(map string/lower-case)))
page-name)
today? (and
journal?
(= page-name (string/lower-case (date/journal-name))))]
[:div.flex-1.page
(when-not sidebar?
[:div.flex.flex-row.justify-between.items-center {:key "page-title"}
[:div.flex.flex-row
[:a {:on-click (fn [e]
(util/stop e)
(when (gobj/get e "shiftKey")
(when-let [page (db/pull repo '[*] [:page/name page-name])]
(state/sidebar-add-block!
repo
(:db/id page)
:page
{:page page}))
(handler/show-right-sidebar)))}
[:h1.title
(util/capitalize-all page-name)]]
:else [:a.ml-1.text-gray-500.hover:text-gray-700
(let [file-path (and (:db/id file) (:file/path (db/entity repo (:db/id file)))) {:class (if starred? "text-gray-800")
starred? (contains? (set :on-click (fn []
(some->> (state/sub [:config repo :starred]) ;; TODO: save to config file
(map string/lower-case))) (handler/star-page! page-name starred?))}
page-name) (if starred?
today? (and (svg/star-solid "stroke-current")
journal? (svg/star-outline "stroke-current h-5 w-5"))]]
(= page-name (string/lower-case (date/journal-name))))]
[:div.flex-1.page
(when-not sidebar?
[:div.flex.flex-row.justify-between.items-center {:key "page-title"}
[:div.flex.flex-row
[:a {:on-click (fn [e]
(util/stop e)
(when (gobj/get e "shiftKey")
(when-let [page (db/pull repo '[*] [:page/name page-name])]
(state/sidebar-add-block!
repo
(:db/id page)
:page
{:page page}))
(handler/show-right-sidebar)))}
[:h1.title
(util/capitalize-all page-name)]]
[:a.ml-1.text-gray-500.hover:text-gray-700 [:a {:title "Presentation mode(Reveal.js)"
{:class (if starred? "text-gray-800") :on-click (fn []
:on-click (fn [] (state/sidebar-add-block!
;; TODO: save to config file repo
(handler/star-page! page-name starred?))} (:db/id page)
(if starred? :page-presentation
(svg/star-solid "stroke-current") {:page page
(svg/star-outline "stroke-current h-5 w-5"))]] :journal? journal?})
(handler/show-right-sidebar))}
svg/reveal-js]])
[:a {:title "Presentation mode(Reveal.js)" (when (and file-path (not sidebar?) (not journal?))
:on-click (fn [] [:div.text-sm.ml-1.mb-2 {:key "page-file"}
(state/sidebar-add-block! "File: "
repo [:a.bg-base-2.p-1.ml-1 {:style {:border-radius 4}
(:db/id page) :href (str "/file/" (util/url-encode file-path))}
:page-presentation file-path]])
{:page page
:journal? journal?})
(handler/show-right-sidebar))}
svg/reveal-js]])
(when (and file-path (not sidebar?) (not journal?)) (when (and repo (not journal?) (not heading?))
[:div.text-sm.ml-1.mb-2 {:key "page-file"} (let [alias (some->> (db/get-page-alias repo page-name)
"File: " (remove util/file-page?))]
[:a.bg-base-2.p-1.ml-1 {:style {:border-radius 4} (when (seq alias)
:href (str "/file/" (util/url-encode file-path))} [:div.alias.ml-1.mb-1.content {:key "page-alias"}
file-path]]) [:span.font-bold.mr-1 "Page aliases: "]
(for [item alias]
[:a {:href (str "/page/" (util/url-encode item))}
[:span.mr-1 (util/capitalize-all item)]])])))
(when (and repo (not journal?) (not heading?)) ;; headings
(let [alias (some->> (db/get-page-alias repo page-name) (rum/with-key
(remove util/file-page?))] (page-headings-cp repo page raw-page-headings file-path page-name encoded-page-name sidebar? journal? heading? format)
(when (seq alias) "page-headings")
[:div.alias.ml-1.mb-1.content {:key "page-alias"}
[:span.font-bold.mr-1 "Page aliases: "]
(for [item alias]
[:a {:href (str "/page/" (util/url-encode item))}
[:span.mr-1 (util/capitalize-all item)]])])))
;; headings (when (and today? (not sidebar?))
(rum/with-key (let [queries (state/sub [:config repo :default-queries :journals])]
(page-headings-cp repo page raw-page-headings file-path page-name encoded-page-name sidebar? journal? heading? format) (when (seq queries)
"page-headings") [:div#today-queries {:keys "page-today-queries"}
(for [{:keys [title query]} queries]
[:div {:key (str "query-" title)}
(hiccup/custom-query {:start-level 2} {:query-title title}
query)])])))
(when (and today? (not sidebar?)) ;; referenced headings
(let [queries (state/sub [:config repo :default-queries :journals])] [:div {:key "page-references"}
(when (seq queries) (reference/references page-name false false)]]))))
[:div#today-queries {:keys "page-today-queries"}
(for [{:keys [title query]} queries]
[:div {:key (str "query-" title)}
(hiccup/custom-query {:start-level 2} {:query-title title}
query)])])))
;; referenced headings
[:div {:key "page-references"}
(reference/references page-name false false)]])))))
(rum/defc all-pages < rum/reactive (rum/defc all-pages < rum/reactive
[] []