clerk

Jeremy 2025-01-16T16:57:08.521689Z

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

Liam Duffy 2025-01-16T19:35:13.406139Z

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.)

mkvlr 2025-01-16T19:48:27.778859Z

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.

mkvlr 2025-01-16T19:50:10.221299Z

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)

Liam Duffy 2025-01-16T19:55:16.374089Z

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?

mkvlr 2025-01-16T20:15:27.283759Z

@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
mkvlr 2025-01-16T20:15:54.439499Z

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

✅ 1
mkvlr 2025-01-16T20:16:13.417089Z

let me know if this works