clerk 2025-01-16

Hi all, how can I serve an image from local path within render-fn?

is there a way to use (clerk/serve! {:watch-paths ["notebooks" "src"]}) to watch for non-clj/md files? https://github.clerk.garden/nextjournal/book-of-clerk/commit/a343752adb110e80a7cb33e375517eb3597e9db1/#file-watcher seem to only mention watching clj/md files. I'm interested in reloading my notebook when a source file for a dataset changes (`.edn` or .csv etc.)

use the :show-filtern-fn option of clerk/serve! for this > - :show-filter-fn to restrict when to re-evaluate or show a notebook as a result of file system event. Useful for e.g. pinning a notebook. Will be called with the string path of the changed file.

do you’d have a more general watch-path that also watches the edn file and then a show-filter-fn that will be called with the relative path of the string argument and decides if to show the changed file as a result (truthy) or re-show the last file (falsy)

I'm having a bit of trouble understanding. Would you mind helping me out with a more specific example? I've cloned the https://github.com/nextjournal/clerk-demo I have a test.edn file under resources Currently I call (clerk/serve! {:watch-paths ["notebooks" "src" "resources"]}) from my REPL I have a notebooks/test.clj notebook which calls (slurp "resources/test.edn") Is there a way to re-evaluate notebooks/test.clj whenever resources/test.edn changes?

@liamdanielduffy sure, this should do:

(clerk/serve {:watch-paths ["notebooks/test.clj" "resources/test.edn"]
              :show-filter-fn (fn [changed-file-path]
                                (clojure.string/ends-with? ".clj"))})

🙌 1

you will also need to turn off caching on the expression that slurps the file, otherwise clerk would cache it

✅ 1

let me know if this works