getzola / zola

A fast static site generator in a single binary with everything built-in. https://www.getzola.org
https://www.getzola.org
MIT License
13.05k stars 921 forks source link

[Feature Request] Allow customizing markdown input via templating #2294

Open ararunaufc opened 10 months ago

ararunaufc commented 10 months ago

(cross-posted from this discourse thread)

Hi, guys,

I'd like to share an idea with the devs, but also with everyone else, about customization of markdown output. What I want with this post is both to know about its implementation feasibility and about its viability from a usage perspective. I'd be happy to try implementing it myself, but I'd need some mentoring.

My idea is to extend the "default template files" idea (think the default atom.xml or 404.html). The way it would work is we would define a default file for each markdown construct and we would pass the corresponding contents as we do with the other templates. As with the other templates, they could be overridden by the user placing a correspondingly named file in the correct place.

So, for example, we could have unordered-list.html, header.html, emph.html, etc. This way, we would be able to place the classes we wanted and use tera constructs for additional customization.

The issue would be these additional intermediate renderings making the whole process too slow...

I know that by using this the user would be able to completely jeopardize the semantic relation between markdown input and HTML output, but is this really an issue?

I would really love feedback about this. Thanks.

Keats commented 10 months ago

That's not going to happen, it would be much slower than the current approach and you can get somewhere similar with CSS and shortcodes

snicolai commented 10 months ago

I'd love to have this for images. Hugo has this and I'm able to check in multiple resolutions or formats of an image and use this templating mechanism to test for the presence of the extra resolutions and formats and generate the appropriate srcset attribute. Hugo calls this feature render hooks.

Hugo documentation at: https://gohugo.io/templates/render-hooks/

Yes you can use shortcodes for this, but if you switch static site generators, you have to go edit every single file. If the theme is allowed to implement a render hook, then switching themes is easy. If two different themes use different shortcode names, then you have to either do a custom modification to theme to use your existing shortcode name or edit all the markdown to switch to the new theme's shortcode name.

araruna commented 10 months ago

That's not going to happen, it would be much slower than the current approach and [...]

Do you think that even with pre-caching (somehow)? :disappointed:

[...] you can get somewhere similar with CSS and shortcodes

Well, not exactly. I'm using Fomantic-UI (think of it as being like Bootstrap) and I need to add its classes to some of the tags to get the looks I want, but I can't do it with right now, for example, with lists.

At least I didn't figure out how yet...

Keats commented 10 months ago

I've had a look at Hugo render hooks and i can see how that would be useful. If someone can do a PR, we can benchmark to see the impact on rendering speed.

ararunaufc commented 10 months ago

If someone can do a PR, we can benchmark to see the impact on rendering speed.

I could try, but as I said I would need some mentoring... How could I proceed to find a mentor, @Keats?

Thank you.

Keats commented 10 months ago

I would normally help but I won't have time in the foreseeable future. Do you need help with Rust or the Zola codebase?

ararunaufc commented 10 months ago

I would normally help but I won't have time in the foreseeable future.

I completely understand.

Do you need help with Rust or the Zola codebase?

It's with the codebase. I actually know a fair bit of Rust.

mwcz commented 10 months ago

I can help benchmark when the time comes.

ararunaufc commented 10 months ago

I think I need some place where I can ask stuff about the codebase and about the implementation ideas I have. In order not to clutter this current issue (which I think is not about exactly the same thing), I'll open another issue to be used as my "planner".

Keats (not a mention, on purpose), sorry if it starts to annoy you with too many notifications, but I believe there is some way to mute them even when you're the repo owner. I think I can @ mention you if absolutely necessary.

Edit: The issue was created, and is accessible here from the log. It's #2307.