forked from logseq/logseq
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
a878690
commit 8b0067a
Showing
40 changed files
with
2,968 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,5 @@ | ||
#!/bin/sh | ||
cd web | ||
yarn clean && yarn release | ||
cd ../ | ||
aws s3 sync ./resources/static/ s3://logseq-site/static/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
{:paths ["src/main"] | ||
:deps | ||
{org.clojure/clojure {:mvn/version "1.10.0"} | ||
rum {:mvn/version "0.11.4"} | ||
datascript-transit {:mvn/version "0.3.0"} | ||
funcool/promesa {:mvn/version "4.0.2"} | ||
medley {:mvn/version "1.2.0"} | ||
metosin/reitit-frontend {:mvn/version "0.3.10"} | ||
cljs-bean {:mvn/version "1.5.0"}} | ||
|
||
:aliases {:cljs {:extra-paths ["src/dev-cljs/"] | ||
:extra-deps {org.clojure/clojurescript {:mvn/version "1.10.520"} | ||
thheller/shadow-cljs {:mvn/version "RELEASE"} | ||
binaryage/devtools {:mvn/version "0.9.10"} | ||
org.clojure/tools.namespace {:mvn/version "0.2.11"} | ||
cider/cider-nrepl {:mvn/version "0.23.0-SNAPSHOT"}} | ||
:main-opts ["-m" "shadow.cljs.devtools.cli"]} | ||
:test | ||
{:extra-paths ["test"], | ||
:extra-deps {org.clojure/test.check {:mvn/version "RELEASE"}}} | ||
:runner | ||
{: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"]}}} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
{ | ||
"name": "logseq", | ||
"version": "0.0.1", | ||
"private": true, | ||
"devDependencies": { | ||
"shadow-cljs": "2.8.81" | ||
}, | ||
"scripts": { | ||
"watch": "clojure -A:cljs watch app", | ||
"release": "clojure -A:cljs release app", | ||
"debug": "clojure -A:cljs release app --debug", | ||
"report": "clojure -A:cljs run shadow.cljs.build-report app report.html", | ||
"clean": "/usr/bin/rm -rf target; /usr/bin/rm -rf resources/static/js/compiled; /usr/bin/rm -rf resources/static/js/cljs-runtime; /usr/bin/rm resources/static/js/main.js.map; /usr/bin/rm resources/static/js/manifest.edn" | ||
}, | ||
"dependencies": { | ||
"@tailwindcss/ui": "^0.1.3", | ||
"browserfs": "^1.4.3", | ||
"dev": "^0.1.3", | ||
"isomorphic-git": "^1.3.1", | ||
"mldoc_org": "^0.2.6", | ||
"purgecss": "^2.1.0", | ||
"react": "^16.12.0", | ||
"react-dom": "^16.12.0", | ||
"react-textarea-autosize": "^7.1.2", | ||
"react-transition-group": "^4.3.0", | ||
"showdown": "^1.9.1", | ||
"tailwindcss": "^1.2.0" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
(ns shadow.hooks | ||
(:require [clojure.java.shell :refer [sh]] | ||
[clojure.string :as str])) | ||
|
||
;; copied from https://gist.github.com/mhuebert/ba885b5e4f07923e21d1dc4642e2f182 | ||
(defn exec [& cmd] | ||
(let [cmd (str/split (str/join " " (flatten cmd)) #"\s+") | ||
_ (println (str/join " " cmd)) | ||
{:keys [exit out err]} (apply sh cmd)] | ||
(if (zero? exit) | ||
(when-not (str/blank? out) | ||
(println out)) | ||
(println err)))) | ||
|
||
(defn purge-css | ||
{:shadow.build/stage :flush} | ||
[state {:keys [css-source | ||
js-globs | ||
public-dir]}] | ||
(case (:shadow.build/mode state) | ||
:release | ||
(exec "purgecss --css " css-source | ||
(for [content (if (string? js-globs) [js-globs] js-globs)] | ||
(str "--content " content)) | ||
"-o" public-dir) | ||
|
||
:dev | ||
(do | ||
(exec "mkdir -p" public-dir) | ||
(exec "cp" css-source (str public-dir "/" (last (str/split css-source #"/")))))) | ||
state) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
(ns shadow.user | ||
(:require [shadow.cljs.devtools.api :as api])) | ||
|
||
(defn cljs-repl | ||
[] | ||
(api/watch :app) | ||
(api/repl :app)) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
(ns frontend.blob) | ||
|
||
(defn- decode | ||
"Decodes the data portion of a data url from base64" | ||
[[media-type data]] | ||
[media-type (js/atob data)]) | ||
|
||
(defn- uint8 | ||
"Converts a base64 decoded data string to a Uint8Array" | ||
[[media-type data]] | ||
(->> (map #(.charCodeAt %1) data) | ||
js/Uint8Array. | ||
(vector media-type))) | ||
|
||
(defn- make-blob | ||
"Creates a JS Blob object from a media type and a Uint8Array" | ||
[[media-type uint8]] | ||
(js/Blob. (array uint8) (js-obj "type" media-type))) | ||
|
||
(defn blob | ||
"Converts a data-url into a JS Blob. This is useful for uploading | ||
image data from JavaScript." | ||
[data-url] | ||
{:pre [(string? data-url)]} | ||
(-> (re-find #"^data:([^;]+);base64,(.*)$" data-url) | ||
rest | ||
decode | ||
uint8 | ||
make-blob)) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,104 @@ | ||
(ns frontend.components.agenda | ||
(:require [rum.core :as rum] | ||
[frontend.util :as util] | ||
[frontend.handler :as handler] | ||
[frontend.format.org.block :as block] | ||
[frontend.state :as state] | ||
[clojure.string :as string] | ||
[frontend.format.org-mode :as org] | ||
[frontend.components.sidebar :as sidebar] | ||
[frontend.db :as db] | ||
[frontend.ui :as ui])) | ||
|
||
(rum/defc timestamps-cp | ||
[timestamps] | ||
[:ul | ||
(for [[type {:keys [date time]}] timestamps] | ||
(let [{:keys [year month day]} date | ||
{:keys [hour min]} time] | ||
[:li {:key type} | ||
[:span {:style {:margin-right 6}} type] | ||
[:span (if time | ||
(str year "-" month "-" day " " hour ":" min) | ||
(str year "-" month "-" day))]]))]) | ||
|
||
(rum/defc title-cp | ||
[title] | ||
(let [title-json (js/JSON.stringify (clj->js title)) | ||
html (org/inline-list->html title-json)] | ||
(util/raw-html html))) | ||
|
||
(rum/defc children-cp | ||
[children] | ||
(let [children-json (js/JSON.stringify (clj->js children)) | ||
html (org/json->html children-json)] | ||
(util/raw-html html))) | ||
|
||
(rum/defc marker-cp | ||
[marker] | ||
(if marker | ||
[:span {:class (str "marker-" (string/lower-case marker)) | ||
:style {:margin-left 8}} | ||
(if (contains? #{"DOING" "IN-PROGRESS"} marker) | ||
(str " (" marker ")"))])) | ||
|
||
(rum/defc tags-cp | ||
[tags] | ||
[:span | ||
(for [{:keys [tag/name]} tags] | ||
[:span.tag {:key name} | ||
[:span | ||
name]])]) | ||
|
||
(rum/defc agenda | ||
[] | ||
(let [tasks (db/get-agenda)] | ||
(sidebar/sidebar | ||
[:div#agenda | ||
[:h2.mb-3 "Agenda"] | ||
(if (seq tasks) | ||
[:div.ml-1 | ||
(let [tasks (block/sort-tasks tasks)] | ||
(for [{:heading/keys [uuid marker title priority level tags children timestamps meta repo file] :as task} tasks] | ||
[:div.mb-2 | ||
{:key (str "task-" uuid) | ||
:style {:padding-left 8 | ||
:padding-right 8}} | ||
[:div.column | ||
[:div.row {:style {:align-items "center"}} | ||
(case marker | ||
(list "DOING" "IN-PROGRESS" "TODO") | ||
(ui/checkbox {:on-change (fn [_] | ||
;; FIXME: Log timestamp | ||
(handler/check task))}) | ||
|
||
"WAIT" | ||
[:span {:style {:font-weight "bold"}} | ||
"WAIT"] | ||
|
||
"DONE" | ||
(ui/checkbox {:checked true | ||
:on-change (fn [_] | ||
;; FIXME: Log timestamp | ||
(handler/uncheck task) | ||
)}) | ||
|
||
nil) | ||
[:div.row.ml-2 | ||
(if priority | ||
[:span.priority.mr-1 | ||
(str "#[" priority "]")]) | ||
(title-cp title) | ||
(marker-cp marker) | ||
(when (seq tags) | ||
(tags-cp tags))]] | ||
(when (seq timestamps) | ||
(timestamps-cp timestamps)) | ||
|
||
;; FIXME: parse error | ||
;; (when (seq children) | ||
;; (children-cp children)) | ||
|
||
]] | ||
))] | ||
"Empty")]))) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
(ns frontend.components.content | ||
(:require [rum.core :as rum] | ||
[frontend.format :as format] | ||
[frontend.format.org-mode :as org] | ||
[frontend.handler :as handler] | ||
[frontend.util :as util])) | ||
|
||
(defn- highlight! | ||
[] | ||
(doseq [block (-> (js/document.querySelectorAll "pre code") | ||
(array-seq))] | ||
(js/hljs.highlightBlock block))) | ||
|
||
(rum/defc html < | ||
{:did-mount (fn [state] | ||
(highlight!) | ||
(handler/render-local-images!) | ||
state) | ||
:did-update (fn [state] | ||
(highlight!) | ||
state)} | ||
[content format config] | ||
(case format | ||
(list :png :jpg :jpeg) | ||
content | ||
(util/raw-html (format/to-html content format | ||
config)))) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,86 @@ | ||
(ns frontend.components.file | ||
(:require [rum.core :as rum] | ||
[frontend.util :as util] | ||
[frontend.handler :as handler] | ||
[clojure.string :as string] | ||
[frontend.db :as db] | ||
[frontend.components.sidebar :as sidebar] | ||
[frontend.ui :as ui] | ||
[frontend.format :as format] | ||
[frontend.format.org-mode :as org] | ||
[frontend.components.content :as content] | ||
[goog.crypt.base64 :as b64])) | ||
|
||
(defn- get-path | ||
[state] | ||
(let [route-match (first (:rum/args state)) | ||
encoded-path (get-in route-match [:parameters :path :path]) | ||
decoded-path (b64/decodeString encoded-path)] | ||
[encoded-path decoded-path])) | ||
|
||
(rum/defcs file < | ||
[state] | ||
(let [[encoded-path path] (get-path state) | ||
suffix (keyword (string/lower-case (last (string/split path #"\."))))] | ||
(sidebar/sidebar | ||
(cond | ||
(and suffix (contains? #{:md :markdown :org} suffix)) | ||
[:div.content | ||
[:a {:href (str "/file/" encoded-path "/edit")} | ||
"edit"] | ||
(let [content (db/get-file (last (get-path state)))] | ||
(cond | ||
(string/blank? content) | ||
[:span] | ||
|
||
content | ||
(content/html content suffix org/default-config) | ||
|
||
:else | ||
"Loading ..."))] | ||
|
||
;; image type | ||
(and suffix (contains? #{:png :jpg :jpeg} suffix)) | ||
(content/html [:img {:src path}] suffix org/default-config) | ||
|
||
:else | ||
[:div "Format ." (name suffix) " is not supported."])))) | ||
|
||
(defn- count-newlines | ||
[s] | ||
(count (re-seq #"\n" (or s "")))) | ||
|
||
(rum/defcs edit < | ||
(rum/local nil ::content) | ||
(rum/local "" ::commit-message) | ||
{:will-mount (fn [state] | ||
(assoc state ::initial-content (db/get-file (last (get-path state)))))} | ||
[state] | ||
(let [initial-content (get state ::initial-content) | ||
initial-rows (+ 3 (count-newlines initial-content)) | ||
content (get state ::content) | ||
commit-message (get state ::commit-message) | ||
rows (if (nil? @content) initial-rows (+ 3 (count-newlines @content))) | ||
[_encoded-path path] (get-path state)] | ||
(prn {:rows rows}) | ||
(sidebar/sidebar | ||
[:div.content | ||
[:h3.mb-2 (str "Update " path)] | ||
[:textarea | ||
{:rows rows | ||
:default-value initial-content | ||
:on-change #(reset! content (.. % -target -value)) | ||
:auto-focus true}] | ||
[:div.mt-1.mb-1.relative.rounded-md.shadow-sm | ||
[:input.form-input.block.w-full.sm:text-sm.sm:leading-5 | ||
{:placeholder "Commit message" | ||
:on-change (fn [e] | ||
(reset! commit-message (util/evalue e)))}]] | ||
(ui/button "Save" (fn [] | ||
(when (and (not (string/blank? @content)) | ||
(not (= initial-content | ||
@content))) | ||
(let [commit-message (if (string/blank? @commit-message) | ||
(str "Update " path) | ||
@commit-message)] | ||
(handler/alter-file path commit-message @content)))))]))) |
Oops, something went wrong.