1
0
Fork 0
mirror of https://git.sr.ht/~seirdy/seirdy.one synced 2024-12-18 23:03:16 +00:00
seirdy.one/layouts/partials/functions/parse-title-attribute.html
Rohan Kumar 3c00cfd4e8
Internal: markdown extension for adding link attrs
More concise than using <a> every time i need to add an attr to a link
2022-02-28 13:41:24 -08:00

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 -}}