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.53k stars 945 forks source link

Alternative Content Views (Summary, List, ..., like in Hugo) #2541

Closed jbirnick closed 3 months ago

jbirnick commented 3 months ago

In Hugo there is this concept of content views.

The idea is basically that in order to have e.g. a list of all blog posts, one defines once and forever, globally, different "views" of a post. The default is of course the whole page. But then you can e.g. provide a "preview" or "summary" view, which is maybe just a <div> with the cover image of the post and the title of the post. Then to generate e.g. a list of all blog posts, one utilizes this view by including it in the appropriate "for" loop.

The advantage is, that when one previews the posts on different parts of the web page, the style of this preview is defined at a single location in the project. For example, one can image that the "blog" section shows all blog posts, and also the home page shows e.g. the three latest posts. And one wishes to preview them in the exact same style. Then one has boilerplate code if one implements the preview HTML twice.

Now that I think about it... maybe it's even possible to imitate the same behavior in Zola as well. Is it? If so, what do you think would be the cleanest way to do that?

Keats commented 3 months ago

You can use Tera macros for that: https://keats.github.io/tera/docs/#macros

welpo commented 3 months ago

On my theme I loop over posts to show their date, permalink, tags, and summary or description (link to the macro). This allows me to list posts on a front page, for example.

Hope that helps~

jbirnick commented 3 months ago

Thanks!