terminal-labs / lektor-jinja-content

Render Lektor content fields with Jinja2.
Other
11 stars 5 forks source link

Add some granularity #2

Open nixjdm opened 6 years ago

nixjdm commented 6 years ago

I want to add the ability to read a config file that can specify a whitelist and blacklist for types and pages that should / should not be Jinja-ified.

clsource commented 6 years ago

Maybe it could be added a special type

string+jinja markdown+jinja html+jinja

So only models with those fieldtypes will render jinja and then pass to the string, markdown or html field.

Just some ideas 👍

nixjdm commented 6 years ago

I like that even better! That provides for even more granularity, unless the config were more complex. That also is pretty straight forward to use. Good idea!

xlotlu commented 5 years ago

@nixjdm instead of hardcoding and writing custom logic for every field combination, maybe the field type could be a callable :) i.e.

[model]

[fields.stuff]
type = jinjaify(markdown)

Of course, that would require changes in lektor core. :) @clsource's suggestion above fits in this model just as well, although I'd change the syntax to markdown|jinja.

nixjdm commented 5 years ago

I like that too!

I'm also now thinking that this might be able to combine with an implementation of https://github.com/lektor/lektor/issues/625 or similar, so that someone could even toggle at a page level whether something is jinjaified. I image if there are many pages with the same model that allows jinjafication, but it's defaulted to off, it could be re-enabled at a page level to give the user jinja when they want it but keep things as speedy as possible.

xlotlu commented 5 years ago

I don't get how that's related. But I think you're overengineering.. simply because it makes things slow?

I just had another idea re: overenginering: you could ship with a set of complementary tags: {% jinjify %} and {% nojinjify %}, or simply a filter.

But shouldn't the fact that you can set it per field speed things up considerably? Also, why is jinja so slow when there's nothing to render? It should bail out real quick.

nixjdm commented 5 years ago

Ha, it probably is over engineering. There's a lot of options with this, many of which are not mutually exclusive. KISS and all that.

Filters are another good way to narrow this down.

Limiting it per field will surely help a lot, but last time I tried to get a feel for it the speed hit did seem noticeable, and I know some people have large projects. It still takes a little time for jinja to do a basic parse of plain text, which can add up. I didn't spend a lot of effort timing it all though, or at least I didn't record it. It's certainly better than what's currently available.