Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add defalte filters #1622

Open
wants to merge 1 commit into
base: next
Choose a base branch
from
Open

Add defalte filters #1622

wants to merge 1 commit into from

Conversation

bemyak
Copy link
Contributor

@bemyak bemyak commented Sep 15, 2021

Add deflate filters as discussed on the forum

Sanity check:

  • 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)

  • Are you doing the PR on the next branch?

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

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

@Keats
Copy link
Collaborator

Keats commented Oct 2, 2021

I can see the need for decompressing but compressing?

@bemyak
Copy link
Contributor Author

bemyak commented Oct 2, 2021

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 🙂

@Keats
Copy link
Collaborator

Keats commented Oct 2, 2021

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

@bemyak
Copy link
Contributor Author

bemyak commented Oct 2, 2021

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
Copy link
Contributor Author

bemyak commented Oct 2, 2021

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
Copy link
Contributor Author

bemyak commented Oct 23, 2021

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

@Keats
Copy link
Collaborator

Keats commented Oct 26, 2021

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

@bemyak
Copy link
Contributor Author

bemyak commented Oct 26, 2021

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.

@Keats
Copy link
Collaborator

Keats commented Oct 26, 2021

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.

@migmedia
Copy link

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.

@bemyak
Copy link
Contributor Author

bemyak commented Nov 24, 2022

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants