website/layouts/shortcodes/glossary_tooltip.html

27 lines
1.2 KiB
HTML
Raw Normal View History

{{- $id := .Get "term_id" -}}
{{- $text := .Get "text" -}}
{{- partial "docs/glossary-terms.html" $.Page -}}
{{- $glossary_items := $.Page.Scratch.Get "glossary_items" -}}
{{- if not $glossary_items -}}
{{- errorf "[%s] No glossary items found" site.Language.Lang -}}
{{- else -}}
2019-05-08 20:18:36 +00:00
{{- $term_info := $glossary_items.GetMatch (printf "%s.md" $id ) -}}
{{- if not $term_info -}}
{{- errorf "[%s] %q: %q is not a valid glossary term_id, see ./docs/reference/glossary/* for a full list" site.Language.Lang .Page.Path $id -}}
{{- end }}
{{- with $term_info -}}
{{- $text := $text | default $term_info.Title -}}
{{- $glossary_home := "docs/reference/glossary/?all=true" | relLangURL -}}
{{- $external_link := $term_info.Params.full_link | default (printf "%s#term-%s" $glossary_home $id | safeURL ) -}}
{{- $tooltip := $term_info.Params.short_description | markdownify -}}
{{- $tooltip := $tooltip | replaceRE "(?s)<a class='glossary-tooltip'.*?>(.*?)<span class='tooltip-text'>.*</a>" "$1" | plainify -}}
{{- $tooltip := trim $tooltip " \n" -}}
<a class='glossary-tooltip' href='{{ $external_link }}' target='_blank'>
{{- $text -}}
<span class='tooltip-text'>
{{- $tooltip | safeHTML -}}
</span>
</a>
{{- end -}}
{{- end -}}