Disable batch optimization for now

pull/645/head
Tienson Qin 2020-08-27 10:48:36 +08:00
parent 238deee9ee
commit 035d443b5e
13 changed files with 47 additions and 39 deletions

View File

@ -110,11 +110,11 @@
parts-2 (string/split path #"/") parts-2 (string/split path #"/")
current-dir (string/join "/" (drop-last 1 parts))] current-dir (string/join "/" (drop-last 1 parts))]
(cond (cond
(string/starts-with? path "/") (util/starts-with? path "/")
path path
(and (not (string/starts-with? path "..")) (and (not (util/starts-with? path ".."))
(not (string/starts-with? path "."))) (not (util/starts-with? path ".")))
(str current-dir "/" path) (str current-dir "/" path)
:else :else
@ -138,7 +138,7 @@
;; TODO: safe encoding asciis ;; TODO: safe encoding asciis
;; TODO: image link to another link ;; TODO: image link to another link
(defn image-link [config url href label] (defn image-link [config url href label]
(let [href (if (string/starts-with? href "http") (let [href (if (util/starts-with? href "http")
href href
(get-file-absolute-path config href))] (get-file-absolute-path config href))]
[:img.rounded-sm.shadow-xl.mb-2.mt-2 [:img.rounded-sm.shadow-xl.mb-2.mt-2
@ -555,7 +555,7 @@
(= name "embed") (= name "embed")
(let [a (first arguments)] (let [a (first arguments)]
(cond (cond
(and (string/starts-with? a "[[") (and (util/starts-with? a "[[")
(string/ends-with? a "]]")) (string/ends-with? a "]]"))
(let [page-name (-> (string/replace a "[[" "") (let [page-name (-> (string/replace a "[[" "")
(string/replace "]]" "") (string/replace "]]" "")
@ -563,7 +563,7 @@
(when-not (string/blank? page-name) (when-not (string/blank? page-name)
(page-embed config page-name))) (page-embed config page-name)))
(and (string/starts-with? a "((") (and (util/starts-with? a "((")
(string/ends-with? a "))")) (string/ends-with? a "))"))
(when-let [s (-> (string/replace a "((" "") (when-let [s (-> (string/replace a "((" "")
(string/replace "))" "") (string/replace "))" "")

View File

@ -192,7 +192,7 @@
"Clone" "Clone"
:on-click :on-click
(fn [] (fn []
(when (string/starts-with? repo-url "https://github.com/") (when (util/starts-with? repo-url "https://github.com/")
(let [repo-url (string/replace repo-url ".git" "")] (let [repo-url (string/replace repo-url ".git" "")]
(repo-handler/clone-and-pull repo-url) (repo-handler/clone-and-pull repo-url)
(route-handler/redirect-to-home!))))) (route-handler/redirect-to-home!)))))

View File

@ -216,7 +216,7 @@
(defn draw? (defn draw?
[path] [path]
(string/starts-with? path default-draw-directory)) (util/starts-with? path default-draw-directory))
(defonce local-repo "local") (defonce local-repo "local")
(def config-file "config.edn") (def config-file "config.edn")

View File

@ -48,7 +48,7 @@
(defn get-repo-path (defn get-repo-path
[url] [url]
(if (string/starts-with? url "http") (if (util/starts-with? url "http")
(->> (take-last 2 (string/split url #"/")) (->> (take-last 2 (string/split url #"/"))
(string/join "/")) (string/join "/"))
url)) url))
@ -610,7 +610,7 @@
[files] [files]
(remove (remove
(fn [file] (fn [file]
(string/starts-with? file "journals/")) (util/starts-with? file "journals/"))
files)) files))
(defn get-pages (defn get-pages
@ -911,7 +911,7 @@
exists? (atom #{}) exists? (atom #{})
lines (doall lines (doall
(mapv (fn [line] (mapv (fn [line]
(let [result (filter #(and (string/starts-with? line (prefix-f %)) (let [result (filter #(and (util/starts-with? line (prefix-f %))
%) %)
directive-keys)] directive-keys)]
(if (seq result) (if (seq result)
@ -1079,7 +1079,7 @@
[file ast] [file ast]
;; headline ;; headline
(let [ast (map first ast)] (let [ast (map first ast)]
(if (string/starts-with? file "pages/contents.") (if (util/starts-with? file "pages/contents.")
"Contents" "Contents"
(let [file-page-name (get-file-page file) (let [file-page-name (get-file-page file)
first-block (last (first (filter block/heading-block? ast))) first-block (last (first (filter block/heading-block? ast)))
@ -1243,7 +1243,7 @@
[repo-url file content utf8-content] [repo-url file content utf8-content]
(if (string/blank? content) (if (string/blank? content)
[] []
(let [journal? (string/starts-with? file "journals/") (let [journal? (util/starts-with? file "journals/")
format (format/get-format file) format (format/get-format file)
ast (mldoc/->edn content ast (mldoc/->edn content
(mldoc/default-config format)) (mldoc/default-config format))

View File

@ -115,10 +115,10 @@
(let [content (string/trim (doall (map-join children)))] (let [content (string/trim (doall (map-join children)))]
(reset! *inside-pre? false) (reset! *inside-pre? false)
(case format (case format
:markdown (if (string/starts-with? content "```") :markdown (if (util/starts-with? content "```")
content content
(str "```\n" content "\n```")) (str "```\n" content "\n```"))
:org (if (string/starts-with? content "#+BEGIN_SRC") :org (if (util/starts-with? content "#+BEGIN_SRC")
content content
(util/format "#+BEGIN_SRC\n%s\n#+END_SRC" content)) (util/format "#+BEGIN_SRC\n%s\n#+END_SRC" content))
nil))) nil)))

View File

@ -33,8 +33,8 @@
(= typ "Search") (= typ "Search")
(not (contains? #{\# \* \/ \( \[} (first (second (:url (second block)))))) (not (contains? #{\# \* \/ \( \[} (first (second (:url (second block))))))
(let [page (second (:url (second block)))] (let [page (second (:url (second block)))]
(when (and (not (string/starts-with? page "http")) (when (and (not (util/starts-with? page "http"))
(not (string/starts-with? page "file")) (not (util/starts-with? page "file"))
(not (string/ends-with? page ".html"))) (not (string/ends-with? page ".html")))
page))) page)))

View File

@ -43,7 +43,7 @@
([dir path] ([dir path]
(create-if-not-exists dir path "")) (create-if-not-exists dir path ""))
([dir path initial-content] ([dir path initial-content]
(let [path (if (string/starts-with? path "/") (let [path (if (util/starts-with? path "/")
path path
(str "/" path))] (str "/" path))]
(util/p-handle (util/p-handle

View File

@ -101,8 +101,8 @@
(let [{:keys [selection-start selection-end format value block edit-id input]} m (let [{:keys [selection-start selection-end format value block edit-id input]} m
empty-selection? (= selection-start selection-end) empty-selection? (= selection-start selection-end)
selection (subs value selection-start selection-end) selection (subs value selection-start selection-end)
selection-link? (and selection (or (string/starts-with? selection "http://") selection-link? (and selection (or (util/starts-with? selection "http://")
(string/starts-with? selection "https://"))) (util/starts-with? selection "https://")))
[content back-pos] (cond [content back-pos] (cond
empty-selection? empty-selection?
(config/get-empty-link-and-back-pos format) (config/get-empty-link-and-back-pos format)
@ -622,15 +622,15 @@
content (state/get-edit-content) content (state/get-edit-content)
new-content (-> new-content (->
(cond (cond
(string/starts-with? content "TODO") (util/starts-with? content "TODO")
(string/replace-first content "TODO" "DOING") (string/replace-first content "TODO" "DOING")
(string/starts-with? content "DOING") (util/starts-with? content "DOING")
(string/replace-first content "DOING" "DONE") (string/replace-first content "DOING" "DONE")
(string/starts-with? content "LATER") (util/starts-with? content "LATER")
(string/replace-first content "LATER" "NOW") (string/replace-first content "LATER" "NOW")
(string/starts-with? content "NOW") (util/starts-with? content "NOW")
(string/replace-first content "NOW" "DONE") (string/replace-first content "NOW" "DONE")
(string/starts-with? content "DONE") (util/starts-with? content "DONE")
(string/replace-first content "DONE" "") (string/replace-first content "DONE" "")
:else :else
(str (if (= :now (state/get-preferred-workflow)) (str (if (= :now (state/get-preferred-workflow))
@ -661,7 +661,7 @@
(when (>= idx 0) (when (>= idx 0)
(let [block (nth blocks idx) (let [block (nth blocks idx)
collapsed? (= "none" (d/style block "display")) collapsed? (= "none" (d/style block "display"))
prefix-match? (string/starts-with? (gobj/get block "id") prefix)] prefix-match? (util/starts-with? (gobj/get block "id") prefix)]
(if (or collapsed? (if (or collapsed?
;; might be embed blocks ;; might be embed blocks
(not prefix-match?)) (not prefix-match?))
@ -678,7 +678,7 @@
(when (>= (count blocks) idx) (when (>= (count blocks) idx)
(when-let [block (util/nth-safe blocks idx)] (when-let [block (util/nth-safe blocks idx)]
(let [collapsed? (= "none" (d/style block "display")) (let [collapsed? (= "none" (d/style block "display"))
prefix-match? (string/starts-with? (gobj/get block "id") prefix)] prefix-match? (util/starts-with? (gobj/get block "id") prefix)]
(if (or collapsed? (if (or collapsed?
;; might be embed blocks ;; might be embed blocks
(not prefix-match?)) (not prefix-match?))
@ -1283,7 +1283,7 @@
(defn append-paste-doc! (defn append-paste-doc!
[format event] [format event]
(let [[html text] (util/get-clipboard-as-html event)] (let [[html text] (util/get-clipboard-as-html event)]
(when-not (string/starts-with? (string/trim text) "http") (when-not (util/starts-with? (string/trim text) "http")
(let [doc-text (html-parser/parse format html)] (let [doc-text (html-parser/parse format html)]
(when-not (string/blank? doc-text) (when-not (string/blank? doc-text)
(util/stop event) (util/stop event)

View File

@ -58,7 +58,7 @@
(some (fn [pattern] (some (fn [pattern]
(or (or
(= path pattern) (= path pattern)
(and (string/starts-with? pattern "/") (and (util/starts-with? pattern "/")
(= (str "/" (first (string/split path #"/"))) (= (str "/" (first (string/split path #"/")))
pattern)))) patterns)) pattern)))) patterns))

View File

@ -17,8 +17,8 @@
(fn [image] (fn [image]
(let [src (get-src image)] (let [src (get-src image)]
(and src (and src
(not (or (string/starts-with? src "http://") (not (or (util/starts-with? src "http://")
(string/starts-with? src "https://")))))) (util/starts-with? src "https://"))))))
images)] images)]
(doseq [img local-images] (doseq [img local-images]
(gobj/set img (gobj/set img

View File

@ -92,7 +92,7 @@
:markdown (str (string/lower-case k) ": ") :markdown (str (string/lower-case k) ": ")
"") "")
exists? (atom false) exists? (atom false)
lines (remove #(string/starts-with? % prefix) lines)] lines (remove #(util/starts-with? % prefix) lines)]
(string/join "\n" lines)) (string/join "\n" lines))
full-content (str new-directives-content "\n\n" (string/trim after-content))] full-content (str new-directives-content "\n\n" (string/trim after-content))]
(file-handler/alter-file (state/get-current-repo) (file-handler/alter-file (state/get-current-repo)

View File

@ -300,11 +300,14 @@
(defn check-changed-files-status (defn check-changed-files-status
[f] [f]
(when (gobj/get js/window.workerThread "getChangedFiles") (when (gobj/get js/window.workerThread "getChangedFiles")
(p/let [files (js/window.workerThread.getChangedFiles (util/get-repo-dir (state/get-current-repo)))] (->
(let [files (bean/->clj files)] (p/let [files (js/window.workerThread.getChangedFiles (util/get-repo-dir (state/get-current-repo)))]
(when (empty? files) (let [files (bean/->clj files)]
;; FIXME: getChangedFiles not return right result (when (empty? files)
(state/reset-changed-files! files)))))) ;; FIXME: getChangedFiles not return right result
(state/reset-changed-files! files))))
(p/catch (fn [error]
(js/console.dir error))))))
(defn push (defn push
([repo-url] ([repo-url]

View File

@ -352,9 +352,14 @@
#{"DETAILS" "SUMMARY"} #{"DETAILS" "SUMMARY"}
(gobj/get node "tagName")))) (gobj/get node "tagName"))))
;; Debug
(defn starts-with?
[s substr]
(string/starts-with? s substr))
(defn journal? (defn journal?
[path] [path]
(string/starts-with? path "journals/")) (starts-with? path "journals/"))
(defn drop-first-line (defn drop-first-line
[s] [s]
@ -693,7 +698,7 @@
(loop [idx (dec index)] (loop [idx (dec index)]
(if (>= idx 0) (if (>= idx 0)
(let [block (nth blocks idx) (let [block (nth blocks idx)
prefix-match? (string/starts-with? (gobj/get block "id") prefix)] prefix-match? (starts-with? (gobj/get block "id") prefix)]
(if (and prefix-match? (if (and prefix-match?
(= level (d/attr block "level"))) (= level (d/attr block "level")))
block block