Skip to content

Commit

Permalink
Ignore Emacs lock files from visualization
Browse files Browse the repository at this point in the history
  • Loading branch information
ikappaki committed Dec 4, 2021
1 parent 9161fdf commit 7e62605
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 5 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -12,3 +12,4 @@ clerk.iml
public/girouette.css
public/images/
yarn.lock
*~
10 changes: 8 additions & 2 deletions deps.edn
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,14 @@

:build {:deps {io.github.clojure/tools.build {:git/tag "v0.6.1" :git/sha "515b334"}
io.github.slipset/deps-deploy {:git/sha "b4359c5d67ca002d9ed0c4b41b710d7e5a82e3bf"}
io.github.nextjournal/cas {:git/url "git@github.com:nextjournal/cas"
io.github.nextjournal/cas {:git/url "https://github.com/nextjournal/cas"
:git/sha "5e8079b720e347b9466db9c2282ce79a125a011c"}
rewrite-clj/rewrite-clj {:mvn/version "1.0.699-alpha"}
babashka/fs {:mvn/version "0.0.5"}}
:ns-default build}}}
:ns-default build}

:test {:extra-paths ["test"]
:extra-deps {io.github.cognitect-labs/test-runner
{:git/tag "v0.5.0" :git/sha "b3fd0d2"}}
:main-opts ["-m" "cognitect.test-runner"]
:exec-fn cognitect.test-runner.api/test}}}
16 changes: 13 additions & 3 deletions src/nextjournal/clerk.clj
Original file line number Diff line number Diff line change
Expand Up @@ -175,11 +175,21 @@
(webserver/show-error! e)
(throw e))))

(defn supported-file?
"Returns whether PATH points to a file that can be visualized."
[path]

;; Notes
;;
;; 1. file names starting with .# are most likely Emacs lock files
;; and should be ignored.
(->> path io/file .getName
(re-matches #"(?!\.#).+\.(md|clj|cljc)$")
some?))

(defn file-event [{:keys [type path]}]
(when (and (contains? #{:modify :create} type)
(or (str/ends-with? path ".md")
(str/ends-with? path ".clj")
(str/ends-with? path ".cljc")))
(supported-file? path))
(binding [*ns* (find-ns 'user)]
(let [rel-path (str/replace (str path) (str (fs/canonicalize ".") fs/file-separator) "")
show-file? (or (not @!show-filter-fn)
Expand Down
10 changes: 10 additions & 0 deletions test/nextjournal/clerk_test.clj
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
(ns nextjournal.clerk-test
(:require [nextjournal.clerk :as c]
[clojure.test :as t]))

(t/deftest supported-filenames
(t/is (= true (c/supported-file? "xyz/name.md")))
(t/is (= true (c/supported-file? "xyz/name.clj")))
(t/is (= true (c/supported-file? "xyz/name.cljc")))
(t/is (= false (c/supported-file? "xyz/.#name.cljc")))
)

0 comments on commit 7e62605

Please sign in to comment.