-
-
Notifications
You must be signed in to change notification settings - Fork 1.8k
/
config.cljs
321 lines (269 loc) · 9.3 KB
/
config.cljs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
(ns frontend.config
(:require [clojure.set :as set]
[clojure.string :as string]
[frontend.state :as state]
[frontend.util :as util]))
(goog-define DEV-RELEASE false)
(defonce dev-release? DEV-RELEASE)
(defonce dev? ^boolean (or dev-release? goog.DEBUG))
(goog-define PUBLISHING false)
(defonce publishing? PUBLISHING)
;; :TODO: How to do this?
;; (defonce desktop? ^boolean goog.DESKTOP)
(def app-name "logseq")
(def website
(if dev?
"http://localhost:3000"
(util/format "https://%s.com" app-name)))
(def api
(if dev?
"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))
(defn asset-uri
[path]
(if (util/file-protocol?)
(string/replace path "/static/" "./")
(if dev? path
(str asset-domain path))))
(goog-define GITHUB_APP_NAME "logseq-test")
(def github-app-name (if dev? GITHUB_APP_NAME "logseq"))
(defn git-pull-secs
[]
(or 60 (get-in @state/state [:config :git-pull-secs])))
(defn git-push-secs
[]
(or 10 (get-in @state/state [:config :git-push-secs])))
(defn git-repo-status-secs
[]
(or 10 (get-in @state/state [:config :git-push-secs])))
(defn text-formats
[]
(let [config-formats (some->> (get-in @state/state [:config :text-formats])
(map :keyword)
(set))]
(set/union
config-formats
#{:json :org :md :yml :dat :asciidoc :rst :txt :markdown :adoc :html :js :ts :edn :clj :ml :rb :ex :erl :java :php :c :css
:excalidraw})))
(def markup-formats
#{:org :md :markdown :asciidoc :rst})
(defn img-formats
[]
(let [config-formats (some->> (get-in @state/state [:config :image-formats])
(map :keyword)
(set))]
(set/union
config-formats
#{:gif :svg :jpeg :ico :png :jpg :bmp})))
(def html-render-formats
#{:adoc :asciidoc})
(defn supported-formats
[]
(set/union (text-formats)
(img-formats)))
;; TODO: rename
(defonce mldoc-support-formats
#{:org :markdown :md})
(defn mldoc-support?
[format]
(contains? mldoc-support-formats (keyword format)))
(def mobile?
(when-not util/node-test?
(re-find #"Mobi" js/navigator.userAgent)))
;; TODO: protocol design for future formats support
(defn get-block-pattern
[format]
(let [format (or format (state/get-preferred-format))
format (keyword format)]
(case format
:org
"*"
:markdown
"#"
"")))
(defn get-hr
[format]
(let [format (or format (keyword (state/get-preferred-format)))]
(case format
:org
"-----"
:markdown
"---"
"")))
(defn get-bold
[format]
(let [format (or format (keyword (state/get-preferred-format)))]
(case format
:org
"*"
:markdown
"**"
"")))
(defn get-italic
[format]
(let [format (or format (keyword (state/get-preferred-format)))]
(case format
:org
"/"
:markdown
"_"
"")))
(defn get-underline
[format]
(let [format (or format (keyword (state/get-preferred-format)))]
(case format
:org
"/"
:markdown
"__"
"")))
(defn get-strike-through
[format]
(let [format (or format (keyword (state/get-preferred-format)))]
(case format
:org
"+"
:markdown
"~~"
"")))
(defn get-highlight
[format]
"^^")
(defn get-code
[format]
(let [format (or format (keyword (state/get-preferred-format)))]
(case format
:org
"~"
:markdown
"`"
"")))
(defn get-subscript
[format]
"_")
(defn get-superscript
[format]
"^")
(defn get-empty-link-and-forward-pos
[format]
(case format
:org
["[[][]]" 2]
:markdown
["[]()" 1]
["" 0]))
(defn with-default-link
[format link]
(case format
:org
[(util/format "[[%s][]]" link)
(+ 4 (count link))]
:markdown
[(util/format "[](%s)" link)
1]
["" 0]))
(defn with-default-label
[format label]
(case format
:org
[(util/format "[[][%s]]" label)
2]
:markdown
[(util/format "[%s]()" label)
(+ 3 (count label))]
["" 0]))
(defn properties-wrapper
[format]
(case format
:markdown
"---\n\n---"
""))
(defn properties-wrapper-pattern
[format]
(case format
:markdown
"---\n%s\n---"
"%s"))
(defn get-file-extension
[format]
(case (keyword format)
:markdown
"md"
(name format)))
(defn get-file-format
[extension]
(case (keyword extension)
:markdown
:markdown
:md
:markdown
(keyword extension)))
(defn default-empty-block
([format]
(default-empty-block format 2))
([format n]
(let [block-pattern (get-block-pattern format)]
(apply str (repeat n block-pattern)))))
(defn with-code-wrapper
[format mode code]
(let [mode (if-not (string/blank? mode)
(str mode " ")
"")]
(case format
:markdown
(util/format "```%s\n%s\n```" mode code)
:org
(util/format "#+BEGIN_SRC%s\n%s\n#+END_SRC" mode code)
code)))
(defonce default-journals-directory "journals")
(defonce default-pages-directory "pages")
(defonce default-draw-directory "draws")
(defn get-pages-directory
[]
(or (state/get-pages-directory) default-pages-directory))
(defn draw?
[path]
(util/starts-with? path default-draw-directory))
(defonce local-repo "local")
(defonce local-assets-dir "assets")
(def config-file "config.edn")
(def custom-css-file "custom.css")
(def metadata-file "metadata.edn")
(def config-default-content
"
{:journal-basis \"daily\" \n\n :project {\n ;; Selected public notes can be published to https://logseq.com/your-project-or-your-username.\n :name \"\"\n :alias \"\"\n ;; your twitter handle\n :twitter \"\"\n ;; description supports both hiccup and html\n :description \"\"}\n\n ;; Currently, we support either \"Markdown\" or \"Org\".\n ;; This can overwrite your global preference so that\n ;; maybe your personal preferred format is Org but you'd\n ;; need to use Markdown for some projects.\n ;; :preferred-format \"\"\n\n ;; Git settings\n :git-pull-secs 60\n :git-push-secs 10\n :git-auto-push true\n\n ;; The app will ignore those directories or files.\n ;; E.g. \"/archived\" \"/test.md\"\n :hidden []\n\n ;; When creating the new journal page, the app will use your template content here.\n ;; Example for Markdown users: \"## [[Work]]\\n###\\n## [[Family]]\\n###\\n\n ;; Example for Org mode users: \"** [[Work]]\\n***\\n** [[Family]]\\n***\\n\n :default-templates\n {:journals \"\"}\n\n ;; The app will show those queries in today's journal page,\n ;; the \"NOW\" query asks the tasks which need to be finished \"now\",\n ;; the \"NEXT\" query asks the future tasks.\n :default-queries\n {:journals\n [{:title \"🔨 NOW\"\n :query [:find (pull ?h [*])\n :in $ ?start ?today\n :where\n [?h :block/marker ?marker]\n [?h :block/page ?p]\n [?p :page/journal? true]\n [?p :page/journal-day ?d]\n [(>= ?d ?start)]\n [(<= ?d ?today)]\n [(contains? #{\"NOW\" \"DOING\"} ?marker)]]\n :inputs [:14d :today]\n :result-transform (fn [result]\n (sort-by (fn [h]\n (get h :block/priority \"Z\")) result))\n :collapsed? false}\n {:title \"📅 NEXT\"\n :query [:find (pull ?h [*])\n :in $ ?start ?next\n :where\n [?h :block/marker ?marker]\n [?h :block/ref-pages ?p]\n [?p :page/journal? true]\n [?p :page/journal-day ?d]\n [(> ?d ?start)]\n [(< ?d ?next)]\n [(contains? #{\"NOW\" \"LATER\" \"TODO\"} ?marker)]]\n :inputs [:today :7d-after]\n :collapsed? false}]}\n\n ;; Add your own commands to speedup.\n ;; E.g. [[\"js\" \"Javascript\"]]\n :commands\n []\n\n ;; Macros replace texts and will make you more productive.\n ;; For example:\n ;; Add this to the macros below:\n ;; {\"poem\" \"Rose is $1, violet's $2. Life's ordered: Org assists you.\"}\n ;; input \"{{{poem(red,blue)}}}\"\n ;; becomes\n ;; Rose is red, violet's blue. Life's ordered: Org assists you.\n :macros {}}\n")
(def markers
#{"now" "later" "todo" "doing" "done" "wait" "waiting"
"canceled" "cancelled" "started" "in-progress"})
(defonce idb-db-prefix "logseq-db/")
(defonce local-db-prefix "logseq_local_")
(defonce local-handle "handle")
(defonce local-handle-prefix (str local-handle "/" local-db-prefix))
(defn local-db?
[s]
(string/starts-with? s local-db-prefix))
(defn local-asset?
[s]
(or (string/starts-with? s (str "/" local-assets-dir))
(string/starts-with? s (str "../" local-assets-dir))))
(defn get-local-dir
[s]
(string/replace s local-db-prefix ""))
(defn get-local-repo
[dir]
(str local-db-prefix dir))
(defn get-repo-dir
[repo-url]
(if (and (util/electron?) (local-db? repo-url))
(get-local-dir repo-url)
(str "/"
(->> (take-last 2 (string/split repo-url #"/"))
(string/join "_")))))
(defn get-repo-path
[repo-url path]
(if (and (util/electron?) (local-db? repo-url))
path
(str (get-repo-dir repo-url) "/" path)))