Merge pull request #137 from logseq/reitit-generated-links

Use `rfe/href` to create links
pull/645/head
Tienson Qin 2020-09-29 09:29:22 +08:00 committed by GitHub
commit e099500f55
10 changed files with 48 additions and 39 deletions

View File

@ -3,7 +3,8 @@
[frontend.handler.editor :as editor]
[frontend.util :as util]
[clojure.string :as string]
[frontend.text :as text]))
[frontend.text :as text]
[reitit.frontend.easy :as rfe]))
(defn block-parents
([repo block-id format]
@ -18,7 +19,7 @@
(let [parents-atom (atom parents)
component [:div.block-parents.flex-row.flex
(when show-page?
[:a {:href (str "/page/" (util/encode-str page-name))}
[:a {:href (rfe/href :page {:name (util/encode-str page-name)})}
(or (:page/original-name page)
(:page/name page))])
@ -34,7 +35,7 @@
(apply str))]
(when (and (not (string/blank? title))
(not= (string/lower-case page-name) (string/lower-case title)))
[:a {:href (str "/page/" uuid)}
[:a {:href (rfe/href :page {:name uuid})}
title])))
parents (remove nil? parents)]
(reset! parents-atom parents)

View File

@ -30,7 +30,8 @@
[frontend.state :as state]
[frontend.search :as search]
[frontend.components.widgets :as widgets]
[promesa.core :as p]))
[promesa.core :as p]
[reitit.frontend.easy :as rfe]))
(defn loaded? []
js/window.Excalidraw)
@ -427,7 +428,7 @@
:initial-data (or elements #js [])}))
[:div.absolute.top-4.left-4.hidden.md:block
[:div.flex.flex-row.items-center
[:a.mr-3.opacity-70.hover:opacity-100 {:href "/"
[:a.mr-3.opacity-70.hover:opacity-100 {:href (rfe/href :home)
:title "Back to logseq"}
(svg/logo false)]
(files)

View File

@ -22,7 +22,8 @@
[frontend.date :as date]
[cljs-time.coerce :as tc]
[cljs-time.core :as t]
[frontend.context.i18n :as i18n]))
[frontend.context.i18n :as i18n]
[reitit.frontend.easy :as rfe]))
(defn- get-path
[state]
@ -51,8 +52,8 @@
[:tr {:key file-id}
[:td
(let [href (if (config/draw? file)
(str "/draw?file=" (string/replace file (str config/default-draw-directory "/") ""))
(str "/file/" file-id))]
(rfe/href :draw nil {:file (string/replace file (str config/default-draw-directory "/") "")})
(rfe/href :file {:path file-id}))]
[:a.text-gray-700 {:href href}
file])]
[:td [:span.text-gray-500.text-sm
@ -96,7 +97,7 @@
(when page
[:div.text-sm.mb-4.ml-1 "Page: "
[:a.bg-base-2.p-1.ml-1 {:style {:border-radius 4}
:href (str "/page/" (util/url-encode page))
:href (rfe/href :page {:name (util/url-encode page)})
:on-click (fn [e]
(util/stop e)
(when (gobj/get e "shiftKey")

View File

@ -39,7 +39,8 @@
[frontend.format.mldoc :as mldoc]
[frontend.text :as text]
[frontend.utf8 :as utf8]
[frontend.date :as date]))
[frontend.date :as date]
[reitit.frontend.easy :as rfe]))
;; local state
(defonce *block-children
@ -240,7 +241,7 @@
page (string/lower-case page-name)
href (if html-export?
(util/encode-str page)
(str "/page/" (util/encode-str page)))]
(rfe/href :page {:name (util/encode-str page)}))]
[:a.page-ref
{:href href
:on-click (fn [e]
@ -274,7 +275,7 @@
[:span.text-gray-500 "[["])
(if (string/ends-with? s ".excalidraw")
[:a.page-ref
{:href (str "/draw?file=" (string/replace s (str config/default-draw-directory "/") ""))
{:href (rfe/href :draw nil {:file (string/replace s (str config/default-draw-directory "/") "")})
:on-click (fn [e] (util/stop e))}
[:span
(svg/excalidraw-logo)
@ -348,7 +349,7 @@
(->elem :sub (map-inline config l))
["Tag" s]
(if (and s (util/tag-valid? s))
[:a.tag.mr-1 {:href (str "/page/" s)
[:a.tag.mr-1 {:href (rfe/href :page {:name s})
:on-click (fn [e]
(util/stop e)
(let [repo (state/get-current-repo)
@ -404,7 +405,7 @@
(if block
[:span
[:span.text-gray-500 "(("]
[:a {:href (str "/page/" id)
[:a {:href (rfe/href :page {:name id})
:on-click (fn [e]
(util/stop e)
(when (gobj/get e "shiftKey")
@ -674,7 +675,7 @@
:else
[:span ""])]
[:a (if (not dummy?)
{:href (str "/page/" uuid)
{:href (rfe/href :page {:name uuid})
:on-click (fn [e]
(util/stop e)
(when (gobj/get e "shiftKey")
@ -812,7 +813,7 @@
:on-click (fn [] (editor-handler/set-priority block p))}])]
[:a.opacity-50.hover:opacity-100
{:class "priority"
:href (str "/page/" priority)
:href (rfe/href :page {:name priority})
:style {:margin-right 3.5}}
(util/format "[#%s]" (str priority))])))
@ -826,7 +827,7 @@
(mapv (fn [{:keys [db/id tag/name]}]
(if (util/tag-valid? name)
[:a.tag.mx-1 {:key (str "tag-" id)
:href (str "/page/" name)}
:href (rfe/href :page {:name name})}
(str "#" name)]
[:span.warning.mx-1 {:title "Invalid tag, tags only accept alphanumeric characters, \"-\", \"_\", \"@\" and \"%\"."}
(str "#" name)]))
@ -1411,7 +1412,7 @@
(string/replace "[" "")
(string/replace "]" "")
(string/replace "#" ""))]
[:a.tag.mr-1 {:href (str "/page/" tag)}
[:a.tag.mr-1 {:href (rfe/href :page {:name tag})}
tag]))
(property-value format v)))
(property-value format v))])))]

View File

@ -36,7 +36,8 @@
[cljs-time.coerce :as tc]
[cljs-time.core :as t]
[cljs.pprint :as pprint]
[frontend.context.i18n :as i18n]))
[frontend.context.i18n :as i18n]
[reitit.frontend.easy :as rfe]))
(defn- get-page-name
[state]
@ -446,7 +447,7 @@
(:db/id page)
:page
{:page page}))))
:href (str "/page/" encoded-page)}
:href (rfe/href :page {:name encoded-page})}
page]]
[:td [:span.text-gray-500.text-sm
(if (zero? modified-at)

View File

@ -8,7 +8,8 @@
[frontend.handler.repo :as repo-handler]
[frontend.handler.route :as route-handler]
[frontend.handler.export :as export-handler]
[frontend.util :as util]))
[frontend.util :as util]
[reitit.frontend.easy :as rfe]))
(rum/defc add-repo
[]
@ -26,7 +27,7 @@
[:div.flex.my-4 {:key "add-button"}
(ui/button
"Add another repo"
:href "/repo/add")]
:href (rfe/href :repo-add))]
(for [{:keys [id url] :as repo} repos]
[:div.flex.justify-between.mb-1 {:key id}

View File

@ -21,7 +21,8 @@
[cljs-bean.core :as bean]
[goog.object :as gobj]
[frontend.graph :as graph]
[frontend.context.i18n :as i18n]))
[frontend.context.i18n :as i18n]
[reitit.frontend.easy :as rfe]))
(rum/defc block-cp < rum/reactive
[repo idx block]
@ -59,7 +60,7 @@
(if (seq pages)
(for [page pages]
[:a.mb-1 {:key (str "recent-page-" page)
:href (str "/page/" page)}
:href (rfe/href :page {:name page})}
page]))]))
(rum/defcs foldable-list <
@ -76,7 +77,7 @@
svg/arrow-right-v2))]
[:a.ml-2 {:key (str "contents-" page)
:href (str "/page/" page)}
:href (rfe/href :page {:name page})}
(util/capitalize-all page)]]
(when (seq l)
[:div.contents-list.ml-4 {:class (if @fold? "hidden" "initial")}
@ -133,7 +134,7 @@
:page
(let [page-name (get-in block-data [:page :page/name])]
[[:a {:href (str "/page/" (util/url-encode page-name))}
[[:a {:href (rfe/href :page {:name (util/url-encode page-name)})}
(util/capitalize-all page-name)]
[:div.ml-2
(page-cp repo page-name)]])

View File

@ -28,7 +28,8 @@
[dommy.core :as d]
[clojure.string :as string]
[goog.object :as gobj]
[frontend.context.i18n :as i18n]))
[frontend.context.i18n :as i18n]
[reitit.frontend.easy :as rfe]))
(defn nav-item
[title href svg-d active? close-modal-fn]
@ -333,33 +334,33 @@
(->>
[(when current-repo
{:title (t :graph)
:options {:href "/graph"}
:options {:href (rfe/href :graph)}
:icon svg/graph-sm})
(when logged?
{:title (t :all-repos)
:options {:href "/repos"}
:options {:href (rfe/href :repos)}
:icon svg/repos-sm})
{:title (t :excalidraw-title)
:options {:href "/draw"}
:options {:href (rfe/href :draw)}
:icon (svg/excalidraw-logo)}
(when current-repo
{:title (t :all-pages)
:options {:href "/all-pages"}
:options {:href (rfe/href :all-pages)}
:icon svg/pages-sm})
(when current-repo
{:title (t :all-files)
:options {:href "/all-files"}
:options {:href (rfe/href :all-files)}
:icon svg/folder-sm})
(when (and default-home current-repo)
{:title (t :all-journals)
:options {:href "/all-journals"}
:options {:href (rfe/href :all-journals)}
:icon svg/calendar-sm})
{:title (t :settings)
:options {:href "/settings"}
:options {:href (rfe/href :settings)}
:icon svg/settings-sm}
(when current-repo
{:title (t :import)
:options {:href "/import"}
:options {:href (rfe/href :import)}
:icon svg/import-sm})
{:title [:div.flex-row.flex.justify-between.items-center
[:span (t :join-community)]]

View File

@ -17,7 +17,8 @@
[frontend.components.svg :as svg]
[frontend.components.commit :as commit]
[clojure.set :as set]
[frontend.context.i18n :as i18n]))
[frontend.context.i18n :as i18n]
[reitit.frontend.easy :as rfe]))
(rum/defcs choose-preferred-format
[]
@ -73,7 +74,7 @@
(for [file changed-files]
[:li {:key (str "sync-" file)}
[:div.flex.flex-row.justify-between.align-items
[:a {:href (str "/file/" (util/encode-str file))}
[:a {:href (rfe/href :file {:path (util/encode-str file)})}
file]
[:a.ml-4.text-sm.mt-1
{:on-click (fn [e]

View File

@ -19,8 +19,8 @@
(defn start []
(when-let [node (.getElementById js/document "root")]
(rum/mount (page/current-page) node)
(set-router!)))
(set-router!)
(rum/mount (page/current-page) node)))
(defn ^:export init []
;; init is called ONCE when the page loads