mirror of
https://git.sr.ht/~seirdy/seirdy.one
synced 2024-11-27 22:12:10 +00:00
3c00cfd4e8
More concise than using <a> every time i need to add an attr to a link
23 lines
814 B
HTML
23 lines
814 B
HTML
{{/* Split .Title into two parts, title and attributes. */}}
|
|
{{- $parts := split . "{" -}}
|
|
{{- $parts = apply $parts "trim" "." " " -}}
|
|
{{- $parts = apply $parts "trim" "." "}" -}}
|
|
|
|
{{/* Extract title into a string. */}}
|
|
{{- $title := index $parts 0 -}}
|
|
|
|
{{/* Extract attributes into a dictionary. */}}
|
|
{{- $temp := index $parts 1 -}}
|
|
{{- $temp = split $temp "'" -}}
|
|
{{- $temp = first (sub (len $temp) 1) $temp -}}
|
|
{{- $temp = apply $temp "replace" "." "=" "" -}}
|
|
{{- $temp = apply $temp "trim" "." " " -}}
|
|
{{- $attributes := dict -}}
|
|
{{- if $temp -}}
|
|
{{- range (seq 0 2 (sub (len $temp) 1)) -}}
|
|
{{- $attributes = merge $attributes (dict (index $temp . ) (index $temp (add 1 .))) -}}
|
|
{{- end -}}
|
|
{{- end -}}
|
|
|
|
{{- $parsedTitle := dict "title" $title "attributes" $attributes -}}
|
|
{{- return $parsedTitle -}}
|