我如何处理 Luminus 中不在 "resources" 中的 html 个文件?

How can I handle html files in Luminus which aren't in "resources"?

我有这个:

(defn about-page []
    (layout/render "about.html" {:title "About"}))

但由于我已将目录 "templates" 从 "resources" 移动到根目录,并且在服务器上我可能会把它放在另一个地方,但它不起作用。我这样做是因为我不想将 html 模板嵌入到输出 jar 中。 那么我怎样才能使代码工作,我怎样才能访问我在 "templates" 中的 html 文件呢?

对于静态图片也是同样的问题,css,js:我现在把它们放在根目录中,所以它们不在 "resources" 中。它们在 "public" 文件夹中。但是,当我将它们称为 "public/css/css1.css" 时,它们没有被发现,也就是说,路径 localhost:3000/public/css/css1.css 不存在。

我怎样才能告诉 Luminus 我的静力学现在在哪里?

模板位置

Selmer's documentation describes how to change the location of the templates:

By default the templates are located relative to the ClassLoader URL. If you'd like to set a custom location for the templates, you can use selmer.parser/set-resource-path! to do that:

(selmer.parser/set-resource-path! "/var/html/templates/")

It's also possible to set the root template path in a location relative to the resource path of the application:

(set-resource-path! (clojure.java.io/resource "META-INF/foo/templates"))

This allows the templates to be refrerenced using include and extends tags without having to specify the full path.

To reset the resource path back to the default simply pass it a nil:

(selmer.parser/set-resource-path! nil)

The application will then look for templates at this location. This can be useful if you're deploying the application as a jar and would like to be able to modify the HTML without having to redeploy it.

因为您希望在更改模板时重新加载模板,您还应该记住 Selmer 缓存了它们:

When rendering files Selmer will cache the compiled template. A recompile will be triggered if the last modified timestamp of the file changes. Note that changes in files referenced by the template will not trigger a recompile. This means that if your template extends or includes other templates you must touch the file that's being rendered for changes to take effect.

Alternatively you can turn caching on and off using (selmer.parser/cache-on!) and (selmer.parser/cache-off!) respectively.

资产位置

静态资源的处理是使用 <app>.middleware 命名空间中的 site-defaults 配置的。您需要配置它的 :static 条目以使用 :files 代替:

(-> site-defaults
  (assoc :static {:files "/var/www/html"}))

并且您需要将文件从 resources/public 目录复制到该位置。