Merge branch 'master' into feat/electron

pull/1179/head
Tienson Qin 2021-01-26 15:27:12 +08:00
commit ea66b25a5a
12 changed files with 100 additions and 37 deletions

View File

@ -15,7 +15,8 @@ Use it to organize your todo list, to write your journals, or to record your uni
## 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).
@ -88,6 +89,20 @@ Open <http://localhost:3001>.
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
### 1. Fetch sources
@ -119,4 +134,4 @@ yarn watch
## Thanks
[![JetBrains](docs/assets/jetbrains.svg)](https://www.jetbrains.com/?from=logseq)
[![JetBrains](docs/assets/jetbrains.svg)](https://www.jetbrains.com/?from=logseq)

View File

@ -1,6 +1,7 @@
{:paths ["src/main"]
:deps
{org.clojure/clojure {:mvn/version "1.10.0"}
cheshire/cheshire {:mvn/version "5.10.0"}
rum/rum {:mvn/version "0.12.3"}
;; rum {:local/root "/home/tienson/codes/source/clj/rum"}
;; persistent-sorted-set {:mvn/version "0.1.2"}
@ -40,12 +41,18 @@
:main-opts ["-m" "shadow.cljs.devtools.cli"]}
: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"}}
: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",
:sha "76568540e7f40268ad2b646110f237a60295fa3c"}},
:main-opts ["-m" "cognitect.test-runner" "-d" "test"]}}}
:main-opts ["-m" "cognitect.test-runner" "-d" "src/test"]}}}

View File

@ -762,27 +762,23 @@
(= name "youtube")
(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")
(let [a (first arguments)]

View File

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

View File

@ -209,6 +209,9 @@
(rum/defcs sidebar < rum/reactive
[state]
(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?)
repo (state/sub :git/current-repo)
match (state/sub :route-match)

View File

@ -320,7 +320,8 @@
:close-fn close-fn
:route-match route-match})
[: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
:white? white?
:current-repo current-repo

View File

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

View File

@ -25,6 +25,7 @@
"http://localhost:3000/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"
app-name))

View File

@ -2,9 +2,9 @@
(defprotocol External
(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:
;; (toMldocAst [this content])
;; (fromMldocAst [this ast])
)

View File

@ -1,6 +1,7 @@
(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]
[clojure.walk :as walk]
[clojure.string :as string]
@ -119,11 +120,15 @@
(apply str))))
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 []
protocol/External
(toMarkdownFiles [this content _config]
(let [data (bean/->clj (js/JSON.parse content))]
(->files data))))
(-> content json->edn ->files)))
(comment
(defonce test-roam-json (frontend.db/get-file "same.json"))

View File

@ -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\": \"adam@example.com\",
\"create-time\": 1610708403162,
\"title\": \"Export JSON\",
\"children\": [
{
\"string\": \"Hello, world!\",
\"create-email\": \"adam@example.com\",
\"create-time\": 1610708405787,
\"uid\": \"7c5um7hSz\",
\"edit-time\": 1610708415484,
\"edit-email\": \"adam@example.com\"}
],
\"edit-time\": 1610708403169,
\"edit-email\": \"adam@example.com\"}]
")
(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)))))