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.69k stars 953 forks source link

Long shortcodes / How to best insert images from markdown #2476

Open druskus20 opened 6 months ago

druskus20 commented 6 months ago

Documentation issue

Summary

What's the best way to insert images from markdown. I would like to be able to specify: width, height. alt text, and op.

This is suggested on the docs:

{% set resized = resize_image(format="jpg", path=page.colocated_path ~ img_name, width=width, op="fit_width") %}
<img alt="{{ alt }}" src="{{ resized.url | safe }}" />

However, to the best of my knowledge this does not allow for default parameters and it becomes verbose. Creating different shortcodes for combinations of these parameters become cumbersome.

For example, we could create:

But this does not scale well 4 shortcodes is already a bit too much.

xpe commented 4 months ago

@druskus20 Have you tried using the default filter? See https://keats.github.io/tera/docs/#default

I would like to read more {{ "" | default (value="Louise Michel") }}!