Can't create shortcode for badge from Sheilds.io

Hello! I’ve wrote the following shortcode:

{{ $hint := .Get "hint" }}
{{ $leftColor := "58158f" }}
{{ $rightColor := "000000" }}
{{ $logoColor := "e9e0ff" }}

{{ with .Get "leftColor" }}
    {{ $leftColor = . }}
{{ end }}
{{ with .Get "rightColor" }}
    {{ $rightColor = . }}
{{ end }}
{{ with .Get "logoColor" }}
    {{ $logoColor = . }}
{{ end }}

{{ $params := "" }}
{{ with .Get "logoName" }}
    {{ $params = printf "&logo=%s&logoColor=%s" . $logoColor }}
{{ end }}

<img src='https://img.shields.io/badge/{{ $hint }}-{{ $rightColor }}?labelColor={{ $leftColor }}{{ $params }}' alt="{{ $hint }}"></a>

When I use it as {{< badge hint="Docs-open" leftColor=purple rightColor=red >}} everything works as expected:
image

But when I add logoColor=black logoName=github params my badge breaks:

image

No logo is displayed and leftColor is left. But when I write manually <img src='https://img.shields.io/badge/Docs-open-red?labelColor=purple&amp;logo=github&amp;logoColor=black' alt="{{ Docs-open }}"></a> everything works:
image

I don’t understand how to fix it. :thinking:

  1. Change
{{ $params = printf "&amp;logo=%s&amp;logoColor=%s" . $logoColor }}

to

{{ $params = printf "&logo=%s&logoColor=%s" . $logoColor }}
  1. Change
{{ $params }}

to

{{ $params | safeURL }}

Output

<img src='https://img.shields.io/badge/Docs-open-red?labelColor=purple&amp;logo=github&amp;logoColor=black' alt="Docs-open">

instead of

<img src='https://img.shields.io/badge/Docs-open-red?labelColor=purple%26amp%3blogo%3dgithub%26amp%3blogoColor%3dblack' alt="Docs-open">
1 Like

This topic was automatically closed 2 days after the last reply. New replies are no longer allowed.