borkdude/quickblog

Add `refresh-templates` task

Closed this issue · 13 comments

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.

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?

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

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?

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.

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"]

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

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

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

Sounds good!

@borkdude This one can be closed as well.