Просмотр исходного кода

enhance: publishing

also, hide built-in pages in "All Pages"
Tienson Qin 4 лет назад
Родитель
Сommit
4e09dc2d52

+ 3 - 4
src/main/frontend/components/export.cljs

@@ -14,9 +14,6 @@
        [:h1.title "Export"]
 
        [:ul.mr-1
-        [:li.mb-4
-         [:a.font-medium {:on-click #(export/convert-repo-markdown-v2! current-repo)}
-          (t :convert-markdown)]]
         (when (util/electron?)
           [:li.mb-4
            [:a.font-medium {:on-click #(export/export-repo-as-html! current-repo)}
@@ -36,7 +33,9 @@
         [:li.mb-4
          [:a.font-medium {:on-click #(export/export-repo-as-roam-json! current-repo)}
           (t :export-roam-json)]]
-        ]
+        [:li.mb-4
+         [:a.font-medium {:on-click #(export/convert-repo-markdown-v2! current-repo)}
+          (t :convert-markdown)]]]
        [:a#download-as-edn.hidden]
        [:a#download-as-edn-v2.hidden]
        [:a#download-as-json-v2.hidden]

+ 4 - 3
src/main/frontend/components/header.cljs

@@ -110,9 +110,10 @@
           :options {:href (rfe/href :all-journals)}
           :icon svg/calendar-sm})
 
-       {:title (t :settings)
-        :options {:on-click state/open-settings!}
-        :icon svg/settings-sm}
+       (when-not (state/publishing-enable-editing?)
+         {:title (t :settings)
+          :options {:on-click state/open-settings!}
+          :icon svg/settings-sm})
 
        (when developer-mode?
          {:title (t :plugins)

+ 10 - 0
src/main/frontend/components/settings.cljs

@@ -334,6 +334,14 @@
                           (when (= "Enter" (util/ekey e))
                             (update-home-page e)))}]]]])])
 
+(defn enable-all-pages-public-row [t enable-all-pages-public?]
+  (toggle "all pages public"
+          (t :settings-page/enable-all-pages-public)
+          enable-all-pages-public?
+          (fn []
+            (let [value (not enable-all-pages-public?)]
+              (config-handler/set-config! :publishing/all-pages-public? value)))))
+
 (defn encryption-row [t enable-encryption?]
   (toggle "enable_encryption"
           (t :settings-page/enable-encryption)
@@ -417,6 +425,7 @@
         current-repo (state/get-current-repo)
         enable-journals? (state/enable-journals? current-repo)
         enable-encryption? (state/enable-encryption? current-repo)
+        enable-all-pages-public? (state/all-pages-public?)
         instrument-disabled? (state/sub :instrument/disabled?)
         logical-outdenting? (state/logical-outdenting?)
         enable-tooltip? (state/enable-tooltip?)
@@ -453,6 +462,7 @@
         (tooltip-row t enable-tooltip?)
         (timetracking-row t enable-timetracking?)
         (journal-row t enable-journals?)
+        (enable-all-pages-public-row t enable-all-pages-public?)
         (encryption-row t enable-encryption?)
         (keyboard-shortcuts-row t)
         (auto-push-row t current-repo enable-git-auto-push?)]

+ 2 - 0
src/main/frontend/config.cljs

@@ -12,6 +12,8 @@
 (goog-define PUBLISHING false)
 (defonce publishing? PUBLISHING)
 
+(reset! state/publishing? publishing?)
+
 (def test? false)
 
 ;; :TODO: How to do this?

+ 2 - 1
src/main/frontend/db.cljs

@@ -63,7 +63,8 @@
 
  [frontend.db.query-react
   react-query custom-query-result-transform]
- )
+
+ [frontend.db.default built-in-pages-names built-in-pages])
 
 ;; persisting DBs between page reloads
 (defn persist! [repo]

+ 31 - 1
src/main/frontend/db/model.cljs

@@ -1119,6 +1119,31 @@
        db)
       (db-utils/seq-flatten)))
 
+(defn get-public-false-pages
+  [db]
+  (-> (d/q
+        '[:find ?p
+          :where
+          [?p :block/name]
+          [?p :block/properties ?properties]
+          [(get ?properties :public) ?pub]
+          [(= false ?pub)]]
+        db)
+      (db-utils/seq-flatten)))
+
+(defn get-public-false-block-ids
+  [db]
+  (-> (d/q
+        '[:find ?b
+          :where
+          [?p :block/name]
+          [?p :block/properties ?properties]
+          [(get ?properties :public) ?pub]
+          [(= false ?pub)]
+          [?b :block/page ?p]]
+        db)
+      (db-utils/seq-flatten)))
+
 (defn get-all-templates
   []
   (let [pred (fn [db properties]
@@ -1181,10 +1206,15 @@
 (defn clean-export!
   [db]
   (let [remove? #(contains? #{"me" "recent" "file"} %)
+        non-public-pages (get-public-false-pages db)
+        non-public-datoms (get-public-false-block-ids db)
+        non-public-datom-ids (set (concat non-public-pages non-public-datoms))
         filtered-db (d/filter db
                               (fn [db datom]
                                 (let [ns (namespace (:a datom))]
-                                  (not (remove? ns)))))
+                                  (and (not (remove? ns))
+                                       (not (contains? #{:block/file} (:a datom)))
+                                       (not (contains? non-public-datom-ids (:e datom)))))))
         datoms (d/datoms filtered-db :eavt)
         assets (get-assets datoms)]
     [@(d/conn-from-datoms datoms db-schema/schema) assets]))

+ 1 - 0
src/main/frontend/dicts.cljs

@@ -213,6 +213,7 @@
         :settings-page/enable-timetracking "Enable timetracking"
         :settings-page/enable-tooltip "Enable tooltips"
         :settings-page/enable-journals "Enable journals"
+        :settings-page/enable-all-pages-public "Enable all pages public when publishing"
         :settings-page/enable-encryption "Enable encryption feature"
         :settings-page/customize-shortcuts "Keyboard shortcuts"
         :settings-page/shortcut-settings "Customize shortcuts"

+ 2 - 2
src/main/frontend/handler/editor.cljs

@@ -2956,7 +2956,7 @@
     :else
     ;; expand one level
     (let [blocks-with-level (all-blocks-with-level {})
-          max-level (apply max (map :block/level blocks-with-level))]
+          max-level (or (apply max (map :block/level blocks-with-level)) 99)]
       (loop [level 1]
         (if (> level max-level)
           nil
@@ -2990,7 +2990,7 @@
     ;; collapse by one level from outside
     (let [blocks-with-level
           (all-blocks-with-level {:collapse? true})
-          max-level (apply max (map :block/level blocks-with-level))]
+          max-level (or (apply max (map :block/level blocks-with-level)) 99)]
       (loop [level max-level]
         (if (zero? level)
           nil

+ 3 - 1
src/main/frontend/handler/page.cljs

@@ -454,7 +454,9 @@
   [repo]
   (->> (db/get-modified-pages repo)
        (remove util/file-page?)
-       (remove util/uuid-string?)))
+       (remove util/uuid-string?)
+       (remove (fn [p]
+                 (db/built-in-pages-names (string/upper-case p))))))
 
 (defn get-filters
   [page-name]

+ 11 - 9
src/main/frontend/modules/outliner/file.cljs

@@ -9,7 +9,8 @@
             [frontend.handler.notification :as notification]
             [goog.object :as gobj]
             [frontend.state :as state]
-            [clojure.string :as string]))
+            [clojure.string :as string]
+            [frontend.config :as config]))
 
 (def write-chan (async/chan))
 
@@ -28,14 +29,15 @@
 
 (defn write-files!
   [page-db-ids]
-  (doseq [page-db-id (set page-db-ids)]
-    (try (do-write-file! page-db-id)
-         (catch js/Error e
-           (notification/show!
-            "Write file failed, please copy the changes to other editors in case of losing data."
-            [:div "Error: " (str (gobj/get e "stack"))]
-            :error)
-           (log/error :file/write-file-error {:error e})))))
+  (when-not config/publishing?
+    (doseq [page-db-id (set page-db-ids)]
+      (try (do-write-file! page-db-id)
+           (catch js/Error e
+             (notification/show!
+              "Write file failed, please copy the changes to other editors in case of losing data."
+              [:div "Error: " (str (gobj/get e "stack"))]
+              :error)
+             (log/error :file/write-file-error {:error e}))))))
 
 (defn sync-to-file
   [{page-db-id :db/id}]

+ 3 - 1
src/main/frontend/publishing.cljs

@@ -12,7 +12,8 @@
             [reitit.frontend.easy :as rfe]
             [cljs.reader :as reader]
             [frontend.components.page :as component-page]
-            [frontend.components.editor :as component-editor]))
+            [frontend.components.editor :as component-editor]
+            [frontend.modules.shortcut.core :as shortcut]))
 
 ;; The publishing site should be as thin as possible.
 ;; Both files and git libraries can be removed.
@@ -70,6 +71,7 @@
   (register-components-fns!)
   (restore-from-transit-str!)
   (restore-state!)
+  (shortcut/refresh!)
   (start))
 
 (defn stop []

+ 13 - 2
src/main/frontend/state.cljs

@@ -217,7 +217,9 @@
 
 (defn all-pages-public?
   []
-  (true? (:all-pages-public? (get-config))))
+  (let [value (:publishing/all-pages-public? (get-config))
+        value (if (some? value) value (:all-pages-public? (get-config)))]
+    (true? value)))
 
 (defn enable-grammarly?
   []
@@ -738,11 +740,20 @@
        :container (gobj/get container "id")
        :pos (cursor/pos (gdom/getElement edit-input-id))})))
 
+(defonce publishing? (atom nil))
+
+(defn publishing-enable-editing?
+  []
+  (and @publishing? (:publishing/enable-editing? (get-config))))
+
 (defn set-editing!
   ([edit-input-id content block cursor-range]
    (set-editing! edit-input-id content block cursor-range true))
   ([edit-input-id content block cursor-range move-cursor?]
-   (when (and edit-input-id block)
+   (when (and edit-input-id block
+              (or
+               (publishing-enable-editing?)
+               (not @publishing?)))
      (let [block-element (gdom/getElement (string/replace edit-input-id "edit-block" "ls-block"))
            container (util/get-block-container block-element)
            block (if container

+ 1 - 1
templates/config.edn

@@ -40,7 +40,7 @@
  ;; When :all-pages-public? true, export repo would export all pages within that repo.
  ;; Regardless of whether you've set any page to public or not.
  ;; Example:
- ;; :all-pages-public? true
+ ;; :publishing/all-pages-public? true
 
  ;; Specify default home page and sidebar status for Logseq
  ;; If not specified, Logseq default opens journals page on startup

+ 5 - 2
yarn.lock

@@ -7482,12 +7482,15 @@ react-grid-layout@^0.16.6:
     react-draggable "3.x"
     react-resizable "1.x"
 
[email protected]:
+  version "2.1.0"
+  resolved "https://registry.yarnpkg.com/react-icon-base/-/react-icon-base-2.1.0.tgz#a196e33fdf1e7aaa1fda3aefbb68bdad9e82a79d"
+  integrity sha1-oZbjP98eeqof2jrvu2i9rZ6Cp50=
+
 react-icons@^2.2.7:
   version "2.2.7"
   resolved "https://registry.yarnpkg.com/react-icons/-/react-icons-2.2.7.tgz#d7860826b258557510dac10680abea5ca23cf650"
   integrity sha512-0n4lcGqzJFcIQLoQytLdJCE0DKSA9dkwEZRYoGrIDJZFvIT6Hbajx5mv9geqhqFiNjUgtxg8kPyDfjlhymbGFg==
-  dependencies:
-    react-icon-base "2.1.0"
 
 react-is@^16.3.1, react-is@^16.8.1:
   version "16.13.1"