diff --git a/.gitignore b/.gitignore index 7d9456f95..f8b315e20 100644 --- a/.gitignore +++ b/.gitignore @@ -12,3 +12,4 @@ clerk.iml public/girouette.css public/images/ yarn.lock +*~ diff --git a/deps.edn b/deps.edn index f7b366101..c8589de89 100644 --- a/deps.edn +++ b/deps.edn @@ -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}}} diff --git a/src/nextjournal/clerk.clj b/src/nextjournal/clerk.clj index 8ab28d4b5..027697885 100644 --- a/src/nextjournal/clerk.clj +++ b/src/nextjournal/clerk.clj @@ -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) diff --git a/test/nextjournal/clerk_test.clj b/test/nextjournal/clerk_test.clj new file mode 100644 index 000000000..0cb961394 --- /dev/null +++ b/test/nextjournal/clerk_test.clj @@ -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"))) + )