borkdude / quickblog

Light-weight static blog engine for Clojure and babashka
https://blog.michielborkent.nl/
MIT License
173 stars 29 forks source link

Add `refresh-templates` task #8

Closed jmglov closed 2 years ago

jmglov commented 2 years ago

When the default templates in resources/templates are modified, quickblog users need to manually copy them into their blog's templates directory. We should add a refresh-templates task that does this automatically.

This will require moving the default templates from resources/templates to resources/templates/default so they don't collide with templates/ on the user's resource path.

borkdude commented 2 years ago

quickblog users need to manually copy them into their blog's templates directory.

This is actually done automatically when you delete your templates directory (or at least, it used to work, not sure if it still works after the last couple of PRs)

So a bb clean && rm -r templates should be sufficient. I don't see the need to move templates to resources/templates/default - why?

jmglov commented 2 years ago

Because you may well have custom templates in your blog, and you probably won't want to delete them just to get the latest changes. But yes, deleting templates/ and re-running bb render will still pull all of the default templates on demand. I also think it's unpleasant for the user to have to know that bb clean isn't enough to refresh everything, and I don't think removing templates/ in bb clean is the right thing either.

I'll go ahead an open a PR and you can have a look and see what you think. If you don't feel this is necessary, we can just add a section to the README that explains how to get the new templates. :)

borkdude commented 2 years ago

So, when refresh-templates is run, the users get the new default templates in their templates dir in templates/default or so? And then they can diff to update their own template?

jmglov commented 2 years ago

All templates that exist in resources/templates/default will be copied to templates/, overwriting anything the user has there, but leaving any custom templates they have untouched. I'm adding a section to the README that explains how to use this. PR is almost ready; I'll open it after breakfast.

jmglov commented 2 years ago

The reason that the templates need to be moved is that the user's directory will almost certainly be on the classpath, meaning that io/resource will pick up the file in templates/ before the one in resources/templates/:

(io/resource "templates/base.html")
;; => #object[java.net.URL 0x50c810a5 "file:/home/jmglov/Documents/code/clojure/quickblog/./templates/base.html"]
borkdude commented 2 years ago

Why would the ./templates directory be on the user's classpath?

borkdude commented 2 years ago

If you are worried about classpath conflicts, then I suggest moving the templates to src/quickblog/templates or resources/quickblog/templates instead.

jmglov commented 2 years ago

Dunno, but it is when I run bb nrepl-server 1667 and connect to it from CIDER. I assumed that running bb <task> would have the same behaviour.

On Mon, 18 Jul 2022 at 13:46, Michiel Borkent @.***> wrote:

Why would the ./templates directory be on the user's classpath?

— Reply to this email directly, view it on GitHub https://github.com/borkdude/quickblog/issues/8#issuecomment-1187183395, or unsubscribe https://github.com/notifications/unsubscribe-auth/AABWWRRR2QXLBABC4ZVEJN3VUU7ZPANCNFSM533GSQIA . You are receiving this because you authored the thread.Message ID: @.***>

-- Sent from my iPhone. Please excuse the brevity and potential typos.

jmglov commented 2 years ago

Yeah, that makes sense to me. Will do!

On Mon, 18 Jul 2022 at 13:47, Michiel Borkent @.***> wrote:

If you are worried about classpath conflicts, then I suggest moving the templates to src/quickblob/templates or resources/quickblog/templates instead.

— Reply to this email directly, view it on GitHub https://github.com/borkdude/quickblog/issues/8#issuecomment-1187186514, or unsubscribe https://github.com/notifications/unsubscribe-auth/AABWWRVCZGKRMFUJFX44ON3VUU76ZANCNFSM533GSQIA . You are receiving this because you authored the thread.Message ID: @.***>

-- Sent from my iPhone. Please excuse the brevity and potential typos.

borkdude commented 2 years ago

Right, this happens when you have ["."] in your bb.edn.

jmglov commented 2 years ago

Makes sense. I assume it’s not so uncommon to do that, so I’ll go with your suggestion of resources/quickblog/templates.

On Mon, 18 Jul 2022 at 15:21, Michiel Borkent @.***> wrote:

Right, this happens when you have ["."] in your bb.edn.

— Reply to this email directly, view it on GitHub https://github.com/borkdude/quickblog/issues/8#issuecomment-1187410814, or unsubscribe https://github.com/notifications/unsubscribe-auth/AABWWRXFJA25XDFC4E3PMGLVUVK35ANCNFSM533GSQIA . You are receiving this because you authored the thread.Message ID: @.***>

-- Sent from my iPhone. Please excuse the brevity and potential typos.

borkdude commented 2 years ago

Sounds good!

jmglov commented 2 years ago

@borkdude This one can be closed as well.