Prettify html option

There already exists an option to minify the generated HTML. But what I’d like to have instead is a prettified HTML, i.e. one passed through a pretty printer. The reason is that through the templating, the generated HTML can look pretty weird in terms of whitespace and indentation.

And while I’ll likely serve the minified HTML in production, when writing and debugging my page I regularly have to look at the source code, for which a pretty rendering would be appreciated.

This could be resolved with the whitespace control Tera

This is good to know and I’ll definitely make use of it, however this cannot account for things like indentation.

In the meanwhile, using a plugin in your editor can get you part of the way to what you want.

I’m not clear as to what kind of plugin would help here. This is not about prettifying my templates (which I have no problem doing by hand), but the rendered HTML

I see what you’re saying now, my mistake. If I understand you correctly, yes, Zola will copy whatever prettifying is in your template, unless minify is set, however, no, there’s no way to control the prettification for non-templated html, such as what is produced from piping your content to safe. I think that’s it right?

In that case, you’re right, my suggestion will not help. The only thing I can think of until a feature like this is added is to add an extra step to your build, serve, or deploy process. For zola build that’s pretty straightforward, as you would just pipe the output of your build to a tool to prettify. For zola serve, in the case of development, it’s more complicated, but you can have a local static server upstream that does the prettification, which proxies requests to the zola server and then prettifies the responses.

I do this for example when I’m working on Zola projects that integrate with Cloudflare page functions, which is obviously not functionality that Zola has natively, and it works fine. In that case I use Cloudflare’s wrangler CLI tool, but the same concept could be done with one of your choice. Hope that helps.

1 Like

I see, thank you. My initial feature suggestion was to implement an option similar to minify-html. However now I’m thinking of something more general.

I think that requiring an entire forwarding html server just for this is a bit overkill, and also that any solution should work the same for both zola build and zola serve.

So how about some functionality to pipe all output files through an external command? This would be a powerful solution for many other use cases, with the added benefit that one can use a beautifier of choice without dragging more dependencies into Zola itself.

So how about some functionality to pipe all output files through an external command?

I’m not a Zola maintainer, so I’m not in a position to comment on your feature request. However in regards to proxying being ‘overkill’, that’s certainly something to think about, because it’s essentially another way of saying the benefit is not worth the trouble.

For build and serve, they work differently. If you look at the output of build vs serve you’ll see that serve doesn’t store any the html in the output directory, which is why I suggested a proxy. I don’t think there’s any way around this.

At the end of the day, no SSG is going to provide every feature for everyone. They all have to make tradeoffs at some point.

And also remove or prettify markdown such as headings that appear in the top of the summary of the section.

Currently using

section.html

{{ page.content | striptags | truncate(length=300) | safe }}

page.md

+++
title = "A blog entry"
date = 2023-01-16
weight = 3

+++
# Headline. <-- I dont want this in the summary

Bacon ipsum ixna on the igpay ...