Files
davideisinger.com/themes/v2/layouts/partials/gemtext.gmi
David Eisinger 364f39a761 Refactor
2025-02-16 02:38:31 -05:00

24 lines
1.2 KiB
Gemtext

{{ $content := .content -}}
{{ $page := .page -}}
{{ $content = $content | replaceRE `<!--more-->\n+` "" -}}
{{ $content = $content | replaceRE `\[([^\]]+)\]\[(\d+)\]` "$1[$2]" -}}
{{ $content = $content | replaceRE `(?m)^\[(\d+)\]: (.*)$` "=> $2 [$1] $2" -}}
{{ $content = $content | replaceRE `\[([^\]]+)\]\([^\)]+\)` "$1" -}}
{{ $content = $content | replaceRE `(?m)^ >` ">" -}}
{{ $content = $content | replaceRE `(?m)^ \*` "* ⇢" -}}
{{ $content = $content | replaceRE `(?m)^- ` "* " -}}
{{ $content = $content | replaceRE `(?m)^[\*-]{3}$` "✱ ✱ ✱" -}}
{{ $content = $content | replaceRE `=> (/.+\.pdf)` (printf "=> %s$1" site.BaseURL) -}}
{{ $audioRE := `<audio controls src="(.*/([^"]+))"></audio>` -}}
{{ range findRE $audioRE $content -}}
{{ $url := . | replaceRE $audioRE "$1" | replaceRE ` ` "%20" -}}
{{ $title := . | replaceRE $audioRE "$2" -}}
{{ $content = replace $content . (printf "=> %s %s" $url (substr $title 0 -4)) -}}
{{ end -}}
{{ range findRE `{{<(dither|thumbnail) [^/]+/>}}` $content -}}
{{ $rendered := $page.RenderString . -}}
{{ $url := $rendered | replaceRE `(?s).*src="([^"]+)".*` "=> $1" -}}
{{ $content = replace $content . $url -}}
{{ end -}}
{{ $content | safeHTML -}}