Open benluelo opened 2 years ago
I think you can use the configuration to do this: https://djc.github.io/askama/configuration.html.
This is the content of my askama.toml
file:
[[escaper]]
path = "::askama::Html"
extensions = ["askama"]
Ah, sorry; it does like we currently always use the mime_guess crate to determine the MIME type from an extension. I suppose we could add configuration that would let you override the MIME type in the configuration for a particular escaper
entry (although it makes that name no longer a great fit). Would you be interested in contributing such a change? You'd want to add a field to the RawEscaper
, thread it into Config::escapers
and then override TemplateInput::mime_type
(and add a test). Should be fairly straightforward.
In https://github.com/djc/askama/blob/082a9c2db9bb128956dd70f146af3e0228e4c433/askama_shared/src/input.rs#L225 we strip off Jinja2 extensions. Maybe we could make this list extensible or add ".askama"?
That also seems like a decent option, but would require the OP to make their extensions .html.askama
, I suppose?
I think extending the escaper is the best bet. I also think it would be a good idea to have a parameter in the template derive, something like #[template(mime_type = "whatever")]
(perhaps only available when used with an integration that supports it?)
As for extending the escaper, what are your thoughts on something like this?
[[alias]]
askama = "html"
Would let you use .askama
as a synonym to .html
.
That would add a bunch of complexity that I'd prefer to avoid.
Understandable. I will start work on a PR later today for the changes mentioned previously!
It should be possible to change the mime type of the templates. I use
.askama
for my templates and.html
for raw html files, and I getcontent-type: application/octet-stream
when usingaskama_axum
. I am using the latest git commit.An example template: