/
config.cljs
405 lines (338 loc) · 9.7 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
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
(ns frontend.config
(:require [clojure.set :as set]
[clojure.string :as string]
[frontend.state :as state]
[frontend.util :as util]
[shadow.resource :as rc]
[frontend.mobile.util :as mobile-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)
(reset! state/publishing? publishing?)
(def test? false)
;; prod env
;; (goog-define FILE-SYNC-PROD? true)
;; (goog-define LOGIN-URL
;; "https://logseq.auth.us-east-1.amazoncognito.com/login?client_id=7ns5v1pu8nrbs04rvdg67u4a7c&response_type=code&scope=email+openid+phone&redirect_uri=logseq%3A%2F%2Fauth-callback")
;; (goog-define API-DOMAIN "api-prod.logseq.com")
;; dev env
(goog-define FILE-SYNC-PROD? false)
(goog-define LOGIN-URL
"https://logseq-test.auth.us-east-2.amazoncognito.com/login?client_id=4fi79en9aurclkb92e25hmu9ts&response_type=code&scope=email+openid+phone&redirect_uri=logseq%3A%2F%2Fauth-callback")
(goog-define API-DOMAIN "api.logseq.com")
(goog-define WS-URL "wss://og96xf1si7.execute-api.us-east-2.amazonaws.com/production?graphuuid=%s")
;; :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/")))
(def asset-domain (util/format "https://asset.%s.com"
app-name))
;; TODO: Remove this, switch to lazy loader
(defn asset-uri
[path]
(cond
publishing?
path
(util/file-protocol?)
(string/replace path "/static/" "./")
:else
(if dev? path
(str asset-domain path))))
(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 :adoc :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 :webp})))
(def audio-formats #{:mp3 :ogg :mpeg :wav :m4a :flac :wma :aac})
(def media-formats (set/union (img-formats) audio-formats))
(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?
(util/safe-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
"*"
"-")))
(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]
(case format
:org
"^^"
:markdown
"=="
""))
(defn get-code
[format]
(let [format (or format (keyword (state/get-preferred-format)))]
(case format
:org
"~"
:markdown
"`"
"")))
(defn get-empty-link-and-forward-pos
[format]
(case format
:org
["[[][]]" 2]
:markdown
["[]()" 1]
["" 0]))
(defn link-format
[format label link]
(if label
(case format
:org
(util/format "[[%s][%s]]" link label)
:markdown
(util/format "[%s](%s)" label link))
link))
(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-label-link
[format label link]
(case format
:org
[(util/format "[[%s][%s]]" link label)
(+ 4 (count link) (count label))]
:markdown
[(util/format "[%s](%s)" label link)
(+ 4 (count link) (count label))]
["" 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-pattern
[format]
(case format
:markdown
"---\n%s\n---"
"%s"))
(defn get-file-extension
[format]
(case (keyword format)
:markdown
"md"
(name format)))
(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 get-journals-directory
[]
(or (state/get-journals-directory) default-journals-directory))
(defn draw?
[path]
(util/starts-with? path default-draw-directory))
(defonce local-repo "local")
(defn demo-graph?
([]
(demo-graph? (state/get-current-repo)))
([graph]
(= graph local-repo)))
(defonce local-assets-dir "assets")
(defonce recycle-dir ".recycle")
(def config-file "config.edn")
(def custom-css-file "custom.css")
(def custom-js-file "custom.js")
(def pages-metadata-file "pages-metadata.edn")
(def config-default-content (rc/inline "config.edn"))
(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]
(and (string? s)
(string/starts-with? s local-db-prefix)))
(defn local-asset?
[s]
(util/safe-re-find (re-pattern (str "^[./]*" local-assets-dir)) s))
(defn get-local-asset-absolute-path
[s]
(str "/" (string/replace s #"^[./]*" "")))
(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]
(cond
(and (util/electron?) (local-db? repo-url))
(get-local-dir repo-url)
(and (mobile-util/native-platform?) (local-db? repo-url))
(let [dir (get-local-dir repo-url)]
(if (string/starts-with? dir "file:")
dir
(str "file:///" (string/replace dir #"^/+" ""))))
:else
(str "/"
(->> (take-last 2 (string/split repo-url #"/"))
(string/join "_")))))
(defn get-repo-path
[repo-url path]
(if (and (or (util/electron?) (mobile-util/native-platform?))
(local-db? repo-url))
path
(util/node-path.join (get-repo-dir repo-url) path)))
(defn get-file-path
"Normalization happens here"
[repo-url relative-path]
(when (and repo-url relative-path)
(let [path (cond
(and (util/electron?) (local-db? repo-url))
(let [dir (get-repo-dir repo-url)]
(if (string/starts-with? relative-path dir)
relative-path
(str dir "/"
(string/replace relative-path #"^/" ""))))
(and (mobile-util/native-ios?) (local-db? repo-url))
(let [dir (get-repo-dir repo-url)]
(js/decodeURI (str dir relative-path)))
(and (mobile-util/native-android?) (local-db? repo-url))
(let [dir (get-repo-dir repo-url)
dir (if (or (string/starts-with? dir "file:")
(string/starts-with? dir "content:"))
dir
(str "file:///" (string/replace dir #"^/+" "")))]
(str (string/replace dir #"/+$" "") "/" relative-path))
(= "/" (first relative-path))
(subs relative-path 1)
:else
relative-path)]
(util/path-normalize path))))
(defn get-config-path
([]
(get-config-path (state/get-current-repo)))
([repo]
(when repo
(get-file-path repo (str app-name "/" config-file)))))
(defn get-pages-metadata-path
([]
(get-pages-metadata-path (state/get-current-repo)))
([repo]
(when repo
(get-file-path repo (str app-name "/" pages-metadata-file)))))
(defn get-custom-css-path
([]
(get-custom-css-path (state/get-current-repo)))
([repo]
(when repo
(get-file-path repo
(str app-name "/" custom-css-file)))))
(defn get-custom-js-path
([]
(get-custom-js-path (state/get-current-repo)))
([repo]
(when repo
(get-file-path repo
(str app-name "/" custom-js-file)))))
(defn get-block-hidden-properties
[]
(get-in @state/state [:config (state/get-current-repo) :block-hidden-properties]))