1
0
Fork 0
mirror of https://git.sr.ht/~seirdy/seirdy.one synced 2024-12-25 10:12:10 +00:00
seirdy.one/layouts/partials/functions/parse-title-attribute.html

24 lines
814 B
HTML
Raw Normal View History

{{/* 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 -}}