mirror of https://github.com/theNewDynamic/gohugo-theme-ananke.git

Patrick Kollitsch
yesterday ae0c6ae00a249f9c3cc819edbfb899fe309d406e
feat: add since shortcode for release badges

Migrate the `since` shortcode from the documentation site into the theme
so every Ananke site can use it. It renders a small badge linking to the
release a feature was introduced in.

The version is resolved from the first positional argument, a named
`version` argument, or the page's `since` front matter. The release link
is built from a configurable printf format string
(`params.ananke.shortcodes.since.url`) and the label uses a new
translatable `since` i18n string.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
2 files modified
1 files added
33 ■■■■■ changed files
config/_default/params.toml 5 ●●●●● patch | view | raw | blame | history
i18n/en.toml 3 ●●●●● patch | view | raw | blame | history
layouts/_shortcodes/since.html 25 ●●●●● patch | view | raw | blame | history
config/_default/params.toml
@@ -4,6 +4,11 @@
[ananke.home]
content_alignment = "center" # options: left, center, right
[ananke.shortcodes.since]
# printf format string for the `since` shortcode's release link.
# %s is replaced with the version. Point this at your own project's releases.
url = "https://github.com/gohugo-ananke/ananke/releases/tag/v%s"
[ananke.social]
icon_path = "ananke/socials/%s.svg"
i18n/en.toml
@@ -34,6 +34,9 @@
[send]
other = "Send"
[since]
other = "since"
[taxonomyPageList]
other = "Below you will find pages that utilize the taxonomy term “{{ .Title }}”"
layouts/_shortcodes/since.html
New file
@@ -0,0 +1,25 @@
{{- /*
  since shortcode
  Renders a small badge linking to the release where a feature was introduced.
  The version is taken from, in order of precedence:
    - the first positional argument:  since "2.17.0"
    - the named "version" argument:   since version="2.17.0"
    - the page's "since" front matter: since = "2.17.0"
  The link target is built from the printf format string in
  params.ananke.shortcodes.since.url, which receives the version as its only
  argument (default: the Ananke releases page).
*/ -}}
{{- $version := or (.Get 0) (.Get "version") .Page.Params.since -}}
{{- with $version -}}
  {{- $urlFormat := site.Params.ananke.shortcodes.since.url | default "https://github.com/gohugo-ananke/ananke/releases/tag/v%s" -}}
  {{- $url := printf $urlFormat . -}}
  <a class="f6 link dim br2 ba bw1 ph3 pv2 mb2 dib navy"
    href="{{ $url }}" target="_blank" rel="noopener">
    {{ T "since" }} {{ . }}
  </a>
{{- else -}}
  {{- warnf "[ananke] the 'since' shortcode in %q needs a version argument or a 'since' front matter value" .Page.File.Path -}}
{{- end -}}