Skip to content

Instantly share code, notes, and snippets.

@lonelydev
Created January 10, 2024 18:13
Show Gist options
  • Save lonelydev/5ac6bbbe86b6c64e1d2221e2ccd99b08 to your computer and use it in GitHub Desktop.
Save lonelydev/5ac6bbbe86b6c64e1d2221e2ccd99b08 to your computer and use it in GitHub Desktop.
bmc-button partial template
<!-- Based on the shortcode -
https://github.com/isqua/hugo-shortcodes/blob/main/themes/hugo-shortcodes/layouts/shortcodes/bmc-button.html -->
{{ if .Site.Params.ShowBuyMeACoffeeButton }}
<div class="bmc-button-container">
{{- $slug := default .Site.Params.HugoShortcodes.BuyMeACoffee.Slug | default "" -}}
{{- $text := default .Site.Params.HugoShortcodes.BuyMeACoffee.Text | default "Buy me a coffee" -}}
{{- $font := default .Site.Params.HugoShortcodes.BuyMeACoffee.Font | default "Cookie" -}}
{{- $emoji := default .Site.Params.HugoShortcodes.BuyMeACoffee.Emoji | default "" -}}
{{- $button_colour := default .Site.Params.HugoShortcodes.BuyMeACoffee.ButtonColor | default "ffdd00" -}}
{{- $font_colour := default .Site.Params.HugoShortcodes.BuyMeACoffee.FontColor | default "000000" -}}
{{- $coffee_colour := default .Site.Params.HugoShortcodes.BuyMeACoffee.CoffeeColor | default "ffffff" -}}
{{- $outline_colour := default .Site.Params.HugoShortcodes.BuyMeACoffee.CupColor | default "000000" -}}
{{- $url := printf "https://www.buymeacoffee.com/%s" $slug }}
{{- $params := slice "slug" $slug "text" $text "emoji" $emoji "font_family" $font "button_colour" $button_colour "font_colour" $font_colour "outline_colour" $outline_colour "coffee_colour" $coffee_colour -}}
{{- $image := printf "https://img.buymeacoffee.com/button-api/?%s" (querify $params) }}
<a class="hugo-shortcodes-bmc-button" href="{{ $url | safeURL }}">
<img src="{{ $image | safeURL }}" alt="{{ $text }}" />
</a>
</div>
{{ end }}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment