zola icon indicating copy to clipboard operation
zola copied to clipboard

Add defalte filters

Open bemyak opened this issue 3 years ago • 11 comments

Add deflate filters as discussed on the forum

Sanity check:

  • [X] Have you checked to ensure there aren't other open Pull Requests for the same update/change?

Code changes

(Delete or ignore this section for documentation changes)

  • [X] Are you doing the PR on the next branch?

If the change is a new feature or adding to/changing an existing one:

  • [X] Have you created/updated the relevant documentation page(s)?

bemyak avatar Sep 15 '21 22:09 bemyak

I can see the need for decompressing but compressing?

Keats avatar Oct 02 '21 09:10 Keats

Compressing is needed so that a diagram code (PlantUML, Diag, etc) could be compressed and sent to Kroki or to the PlantUML public server (see the compression section in docs). This is my primary use case for this actually :slightly_smiling_face:

bemyak avatar Oct 02 '21 09:10 bemyak

Does that mean that you re-do the request on every file change in zola serve?

Keats avatar Oct 02 '21 17:10 Keats

Yes, right now I'm using the load_data function exactly as described in the Zola docs. This change will allow me to construct a GET request instead of POST, so it'll be the user's browser that makes requests.

bemyak avatar Oct 02 '21 18:10 bemyak

An example use of this filter is like this: in .md file:

{% plantuml(comment="simple diagram") %}
participant Zola
participant Kroki
Zola -> Kroki: POST /plantuml/svg\nContent-type: text/plain\n<diagram_data>
activate Zola
Kroki -> Zola: SVG image
deactivate Zola
Zola -> Zola: embed SVG into HTML
{% end %}

Then in templates/shortcodes/plantuml.html

<figure class="image">
    <img src="https://kroki.io/plantuml/svg/{{body | deflate_compress}}"/>
</figure>

Which will render into

<figure class="image">
    <img src="https://kroki.io/plantuml/svg/eNpVzsEKwjAMBuB7nyIvMHYfsosHBRWFDQ8ykLiGEWzTUuPQt9daBD3-Px9_EjEpjxxRFE7BoYk_xSaFKxuTe6jaEhs47Lse6uje4u5dfZunQZZBlEQrfUZqQOmhGbAMsrCMU0J_tqjYGhyVZ1Qqxz6LeTqnBrrjCtjjRMbSP_y-UBz5C9miRQOs-932BfL4RXE="/>
</figure>

bemyak avatar Oct 02 '21 18:10 bemyak

@Keats , so what do you think about this? Any chances to get it merged until the next release?

bemyak avatar Oct 23 '21 15:10 bemyak

I think I need to see some more people wanting that feature before merging it.

Keats avatar Oct 26 '21 11:10 Keats

What would be the best way to make people aware of such proposals in order to get feedback?

Rust's proposals are mentioned in the "This Week In Rust" newsletter. Maybe for Zola it will make sense to mention such things in changelogs to reach wider audience? I don't think a lot of people check PRs here or the forum.

bemyak avatar Oct 26 '21 12:10 bemyak

Yeah the forum is not checked as often. Maybe create an issue on the repo, people do check those before creating a new one usually. You can point to the PR and the forum.

Keats avatar Oct 26 '21 17:10 Keats

This feature looks interresting to me. Where does the macro in line {% plantuml(comment="simple diagram") %} come from?

It would be nice to adjust the image format (svg/png) and maybe the plantuml-server-url, sending the data to. In case the default will be inaccessible or if the data might be secret.

Maybe https://github.com/migmedia/planturl can be usefull.

migmedia avatar Nov 24 '22 09:11 migmedia

Where does the macro in line {% plantuml(comment="simple diagram") %} come from?

It's a shortcode templates/shortcodes/plantuml.html

{% set postdata = load_data(
	url="https://kroki.io/plantuml/svg",
	format="plain", method="POST",
	content_type="text/plain",
	body=body,
	required=true,
	)
%}
<figure class="image">
	{{ postdata | safe }}
	<figcaption class="comment">
		{% if comment %}
		<em>{{ comment | markdown | safe }}</em>
		{% endif %}
		<em>Open as <a href="https://kroki.io/plantuml/png/{{body | deflate_compress}}">image</a></em>
	</figcaption>
</figure>

You can easily adjust the format and server URL. This PR adds the possibility to put diagrams in URLs like the one in Open as above.

bemyak avatar Nov 24 '22 09:11 bemyak