gohugoio / hugo

The world’s fastest framework for building websites.
https://gohugo.io
Apache License 2.0
75.94k stars 7.54k forks source link

encoding: Add the ZlibCompress function #12867

Closed razonyang closed 1 month ago

razonyang commented 1 month ago

The PR adds zlib compression support to the template, which is useful for generating Kroki diagrams without requiring remote APIs, reducing build time and avoiding network issues.

Template usage:

{{ $diagram := `blockdiag {
  Kroki -> generates -> "Block diagrams";
  Kroki -> is -> "very easy!";

  Kroki [color = "greenyellow"];
  "Block diagrams" [color = "pink"];
  "very easy!" [color = "orange"];
}`
}}
{{- $encoded := encoding.ZlibCompress $diagram | encoding.Base64Encode }}
{{- $encoded = replace $encoded "+" "-" }}
{{- $encoded = replace $encoded "/" "_" }}
{{- $encoded = replace $encoded "=" "" }}
<img src="https://kroki.io/blockdiag/svg/{{ $encoded }}">

If this feature is not going to be accepted, please feel free to close it.

bep commented 1 month ago

See https://github.com/gohugoio/hugo/blob/master/CONTRIBUTING.md#code-contribution

Any non-trivial code change needs to update an open issue. A non-trivial code change without an issue reference with one of the labels bug or enhancement will not be merged.

Create a proposal first.

razonyang commented 1 month ago

Sorry I missed that, issue created #12868.