浏览代码

Merge branch 'master' into feat/electron

Tienson Qin 4 年之前
父节点
当前提交
ea66b25a5a

+ 17 - 2
README.md

@@ -15,7 +15,8 @@ Use it to organize your todo list, to write your journals, or to record your uni
 
 
 ## Why Logseq?
 ## Why Logseq?
 
 
-[Logseq](https://logseq.com) is a freedom-respecting (and open-source too) platform for knowledge sharing and management. It focuses on privacy, longevity, and user control.
+[Logseq](https://logseq.com) is a platform for knowledge sharing and management. It focuses on privacy, longevity, and user control.
+Notice: the backend code will not be open-sourced for security reasons and other potential risks. 
 
 
 The server will never store or analyze your private notes. Your data are plain text files and we currently support both Markdown and Emacs Org mode (more to be added soon).
 The server will never store or analyze your private notes. Your data are plain text files and we currently support both Markdown and Emacs Org mode (more to be added soon).
 
 
@@ -88,6 +89,20 @@ Open <http://localhost:3001>.
 yarn release
 yarn release
 ```
 ```
 
 
+### 5. Run tests
+
+Run ClojureScript tests
+```bash
+yarn
+yarn cljs:test
+node static/tests.js
+```
+
+Run Clojure tests. (Note: `.cljc` files may be tested both by ClojureScript, and Clojure.)
+```bash
+clj -Mtest-clj
+```
+
 ## Alternative: Docker based development environment
 ## Alternative: Docker based development environment
 
 
 ### 1. Fetch sources
 ### 1. Fetch sources
@@ -119,4 +134,4 @@ yarn watch
 
 
 ## Thanks
 ## Thanks
 
 
-[![JetBrains](docs/assets/jetbrains.svg)](https://www.jetbrains.com/?from=logseq)
+[![JetBrains](docs/assets/jetbrains.svg)](https://www.jetbrains.com/?from=logseq)

+ 12 - 5
deps.edn

@@ -1,6 +1,7 @@
 {:paths ["src/main"]
 {:paths ["src/main"]
  :deps
  :deps
  {org.clojure/clojure         {:mvn/version "1.10.0"}
  {org.clojure/clojure         {:mvn/version "1.10.0"}
+  cheshire/cheshire {:mvn/version "5.10.0"}
   rum/rum                     {:mvn/version "0.12.3"}
   rum/rum                     {:mvn/version "0.12.3"}
   ;; rum                         {:local/root "/home/tienson/codes/source/clj/rum"}
   ;; rum                         {:local/root "/home/tienson/codes/source/clj/rum"}
   ;; persistent-sorted-set       {:mvn/version "0.1.2"}
   ;; persistent-sorted-set       {:mvn/version "0.1.2"}
@@ -40,12 +41,18 @@
                   :main-opts ["-m" "shadow.cljs.devtools.cli"]}
                   :main-opts ["-m" "shadow.cljs.devtools.cli"]}
            :test
            :test
            {:extra-paths ["src/test/"]
            {:extra-paths ["src/test/"]
-            :extra-deps  {org.clojure/clojurescript {:mvn/version "1.10.764"}
+            :extra-deps  {
+                          org.clojure/clojurescript {:mvn/version "1.10.764"}
                           org.clojure/test.check {:mvn/version "RELEASE"}}
                           org.clojure/test.check {:mvn/version "RELEASE"}}
             :main-opts   ["-m" "shadow.cljs.devtools.cli"]}
             :main-opts   ["-m" "shadow.cljs.devtools.cli"]}
-           :runner
-           {:extra-deps
-            {com.cognitect/test-runner
+
+           :test-clj
+           {:extra-paths ["src/test/"]
+            :extra-deps
+            {
+             com.cognitect/test-runner
              {:git/url "https://github.com/cognitect-labs/test-runner",
              {:git/url "https://github.com/cognitect-labs/test-runner",
               :sha "76568540e7f40268ad2b646110f237a60295fa3c"}},
               :sha "76568540e7f40268ad2b646110f237a60295fa3c"}},
-            :main-opts ["-m" "cognitect.test-runner" "-d" "test"]}}}
+            :main-opts ["-m" "cognitect.test-runner" "-d" "src/test"]}}}
+
+

+ 17 - 21
src/main/frontend/components/block.cljs

@@ -762,27 +762,23 @@
 
 
         (= name "youtube")
         (= name "youtube")
         (let [url (first arguments)]
         (let [url (first arguments)]
-          (when-let [youtube-id (cond
-                                  (string/starts-with? url "https://youtu.be/")
-                                  (string/replace url "https://youtu.be/" "")
-
-                                  (string? url)
-                                  url
-
-                                  :else
-                                  nil)]
-            (when-not (string/blank? youtube-id)
-              (let [width (min (- (util/get-width) 96)
-                               560)
-                    height (int (* width (/ 315 560)))]
-                [:iframe
-                 {:allow-full-screen "allowfullscreen"
-                  :allow
-                  "accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture"
-                  :frame-border "0"
-                  :src (str "https://www.youtube.com/embed/" youtube-id)
-                  :height height
-                  :width width}]))))
+          (let [YouTube-regex #"^((?:https?:)?//)?((?:www|m).)?((?:youtube.com|youtu.be))(/(?:[\w-]+\?v=|embed/|v/)?)([\w-]+)(\S+)?$"]
+            (when-let [youtube-id (cond
+                                    (== 11 (count url)) url
+                                    :else
+                                    (nth (re-find YouTube-regex url) 5))]
+              (when-not (string/blank? youtube-id)
+                (let [width (min (- (util/get-width) 96)
+                                 560)
+                      height (int (* width (/ 315 560)))]
+                  [:iframe
+                   {:allow-full-screen "allowfullscreen"
+                    :allow
+                    "accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture"
+                    :frame-border "0"
+                    :src (str "https://www.youtube.com/embed/" youtube-id)
+                    :height height
+                    :width width}])))))
 
 
         (= name "embed")
         (= name "embed")
         (let [a (first arguments)]
         (let [a (first arguments)]

+ 1 - 1
src/main/frontend/components/page.cljs

@@ -434,7 +434,7 @@
            {:width (if (and (> width 1280) sidebar-open?)
            {:width (if (and (> width 1280) sidebar-open?)
                      (- width 24 600)
                      (- width 24 600)
                      (- width 24))
                      (- width 24))
-            :height (- height 120)
+            :height height
             :ref (fn [v] (reset! graph-ref v))
             :ref (fn [v] (reset! graph-ref v))
             :ref-atom graph-ref}))
             :ref-atom graph-ref}))
          [:div.ls-center.mt-20
          [:div.ls-center.mt-20

+ 3 - 0
src/main/frontend/components/right_sidebar.cljs

@@ -209,6 +209,9 @@
 (rum/defcs sidebar < rum/reactive
 (rum/defcs sidebar < rum/reactive
   [state]
   [state]
   (let [blocks (state/sub :sidebar/blocks)
   (let [blocks (state/sub :sidebar/blocks)
+        blocks (if (empty? blocks)
+                 [[(state/get-current-repo) "contents" :contents nil]]
+                 blocks)
         sidebar-open? (state/sub :ui/sidebar-open?)
         sidebar-open? (state/sub :ui/sidebar-open?)
         repo (state/sub :git/current-repo)
         repo (state/sub :git/current-repo)
         match (state/sub :route-match)
         match (state/sub :route-match)

+ 2 - 1
src/main/frontend/components/sidebar.cljs

@@ -320,7 +320,8 @@
           :close-fn    close-fn
           :close-fn    close-fn
           :route-match route-match})
           :route-match route-match})
         [:div.#app-container.cp__sidebar-layout
         [:div.#app-container.cp__sidebar-layout
-         {:class (if sidebar-open? "is-right-sidebar-open")}
+         {:class (if sidebar-open? "is-right-sidebar-open")
+          :style {:padding-bottom (if global-graph-pages? 0 30)}}
          (header/header {:open-fn        open-fn
          (header/header {:open-fn        open-fn
                          :white?         white?
                          :white?         white?
                          :current-repo   current-repo
                          :current-repo   current-repo

+ 0 - 1
src/main/frontend/components/sidebar.css

@@ -56,7 +56,6 @@
   display: flex;
   display: flex;
   flex-direction: column;
   flex-direction: column;
   min-height: 100vh;
   min-height: 100vh;
-  padding-bottom: 30px;
 }
 }
 
 
 .cp__sidebar-main-layout {
 .cp__sidebar-main-layout {

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

@@ -25,6 +25,7 @@
     "http://localhost:3000/api/v1/"
     "http://localhost:3000/api/v1/"
     (str website "/api/v1/")))
     (str website "/api/v1/")))
 
 
+;; change if you want to use your own domain instead of default asset.logseq.com
 (def asset-domain (util/format "https://asset.%s.com"
 (def asset-domain (util/format "https://asset.%s.com"
                                app-name))
                                app-name))
 
 

+ 0 - 0
src/main/frontend/external.cljs → src/main/frontend/external.cljc


+ 2 - 2
src/main/frontend/external/protocol.cljs → src/main/frontend/external/protocol.cljc

@@ -2,9 +2,9 @@
 
 
 (defprotocol External
 (defprotocol External
   (toMarkdownFiles [this content config]
   (toMarkdownFiles [this content config]
-    "Should return a map of markdown's file name to contents.")
+    "Should return a map of markdown's file name to contents."))
 
 
   ;; Long-term goal:
   ;; Long-term goal:
   ;; (toMldocAst [this content])
   ;; (toMldocAst [this content])
   ;; (fromMldocAst [this ast])
   ;; (fromMldocAst [this ast])
-  )
+

+ 9 - 4
src/main/frontend/external/roam.cljs → src/main/frontend/external/roam.cljc

@@ -1,6 +1,7 @@
 (ns frontend.external.roam
 (ns frontend.external.roam
-  (:require [frontend.external.protocol :as protocol]
-            [cljs-bean.core :as bean]
+  (:require #?(:cljs [cljs-bean.core :as bean]
+               :clj [cheshire.core :as json])
+            [frontend.external.protocol :as protocol]
             [medley.core :as medley]
             [medley.core :as medley]
             [clojure.walk :as walk]
             [clojure.walk :as walk]
             [clojure.string :as string]
             [clojure.string :as string]
@@ -119,11 +120,15 @@
                    (apply str))))
                    (apply str))))
      files)))
      files)))
 
 
+(defn json->edn
+  [raw-string]
+  #?(:cljs (-> raw-string js/JSON.parse bean/->clj)
+     :clj (-> raw-string json/parse-string clojure.walk/keywordize-keys)))
+
 (defrecord Roam []
 (defrecord Roam []
   protocol/External
   protocol/External
   (toMarkdownFiles [this content _config]
   (toMarkdownFiles [this content _config]
-    (let [data (bean/->clj (js/JSON.parse content))]
-      (->files data))))
+    (-> content json->edn ->files)))
 
 
 (comment
 (comment
   (defonce test-roam-json (frontend.db/get-file "same.json"))
   (defonce test-roam-json (frontend.db/get-file "same.json"))

+ 36 - 0
src/test/frontend/external/roam_test.cljc

@@ -0,0 +1,36 @@
+(ns frontend.external.roam-test
+  (:require #?(:clj  [clojure.test :refer :all]
+               :cljs [cljs.test :refer [is deftest]])
+            [frontend.external.roam :as roam]
+            [frontend.external :refer [to-markdown-files]]))
+
+(def minimal-json "
+[
+ {
+  \"create-email\": \"[email protected]\",
+  \"create-time\": 1610708403162,
+  \"title\": \"Export JSON\",
+  \"children\": [
+                  {
+                    \"string\": \"Hello, world!\",
+                    \"create-email\": \"[email protected]\",
+                    \"create-time\": 1610708405787,
+                    \"uid\": \"7c5um7hSz\",
+                    \"edit-time\": 1610708415484,
+                    \"edit-email\": \"[email protected]\"}
+                ],
+  \"edit-time\": 1610708403169,
+  \"edit-email\": \"[email protected]\"}]
+")
+
+(deftest json->edn-test
+  (is (= [1 {:foo 42, :bar "baz"} 3] (roam/json->edn "[1, {\"foo\": 42, \"bar\": \"baz\"}, 3]"))))
+
+(deftest roam-import-test
+  (let [got (to-markdown-files :roam minimal-json {})
+        md (first got)]
+    (is (= 1 (count got)))
+    (is (= "Export JSON" (:title md)))
+    (is (:created-at md))
+    (is (:last-modified-at md))
+    (is (= "---\ntitle: Export JSON\n---\n\n## Hello, world!\n" (:text md)))))