diff --git a/themes/v2/layouts/_default/single.gmi b/themes/v2/layouts/_default/single.gmi index d921af0..9df0fac 100644 --- a/themes/v2/layouts/_default/single.gmi +++ b/themes/v2/layouts/_default/single.gmi @@ -1,20 +1,2 @@ # {{ .Title }} -{{ $content := .RawContent -}} -{{ $content = $content | replaceRE `\n+` "" -}} -{{ $content = $content | replaceRE `\[([^\]]+)\]\[(\d+)\]` "$1[$2]" -}} -{{ $content = $content | replaceRE `(?m)^\[(\d+)\]: (.*)$` "=> $2 [$1] $2" -}} -{{ $content = $content | replaceRE `=> (/.+\.pdf)` "=> https://davideisinger.com$1"}} -{{ $content = $content | replaceRE `(?m)\n\n >` "\n\n>" -}} -{{ $content = $content | replaceRE `(?m)\n\n ([A-Z])` " $1" -}} -{{ $audioRE := `` }} -{{ range findRE $audioRE $content -}} -{{ $url := . | replaceRE $audioRE "$1" | replaceRE ` ` "%20" -}} -{{ $title := . | replaceRE $audioRE "$2" -}} -{{ $content = replace $content . (printf "=> %s %s" $url $title) -}} -{{ end -}} -{{ range findRE `{{<(dither|thumbnail) [^/]+/>}}` $content -}} -{{ $rendered := $.Page.RenderString . -}} -{{ $url := $rendered | replaceRE `(?s).*src="([^"]+)".*` "=> $1" -}} -{{ $content = replace $content . $url -}} -{{ end -}} -{{ $content | safeHTML }} +{{ partial "gemtext.gmi" (dict "content" .RawContent "page" $.Page) }} diff --git a/themes/v2/layouts/index.gmi b/themes/v2/layouts/index.gmi index 8d5e3bc..e9d548b 100644 --- a/themes/v2/layouts/index.gmi +++ b/themes/v2/layouts/index.gmi @@ -1,6 +1,6 @@ # David Eisinger -{{ .RawContent }} +{{ partial "gemtext.gmi" (dict "content" .RawContent "page" $.Page) }} {{ range (where .Site.RegularPages "Type" "in" "journal") -}} => {{ .RelPermalink | replaceRE `index.gmi` "" }} {{ .Title }} {{ end -}} diff --git a/themes/v2/layouts/partials/gemtext.gmi b/themes/v2/layouts/partials/gemtext.gmi new file mode 100644 index 0000000..a8650a7 --- /dev/null +++ b/themes/v2/layouts/partials/gemtext.gmi @@ -0,0 +1,21 @@ +{{ $content := .content -}} +{{ $page := .page -}} +{{ $content = $content | replaceRE `\n+` "" -}} +{{ $content = $content | replaceRE `\[([^\]]+)\]\[(\d+)\]` "$1[$2]" -}} +{{ $content = $content | replaceRE `(?m)^\[(\d+)\]: (.*)$` "=> $2 [$1] $2" -}} +{{ $content = $content | replaceRE `=> (/.+\.pdf)` "=> https://davideisinger.com$1" -}} +{{ $content = $content | replaceRE `(?m) >` ">" -}} +{{ $content = $content | replaceRE `(?m)^ \*` "* ⇢" -}} +{{ $content = $content | replaceRE `(?m)^[\*-]{3}$` "✱ ✱ ✱" -}} +{{ $audioRE := `` -}} +{{ range findRE $audioRE $content -}} +{{ $url := . | replaceRE $audioRE "$1" | replaceRE ` ` "%20" -}} +{{ $title := . | replaceRE $audioRE "$2" -}} +{{ $content = replace $content . (printf "=> %s %s" $url $title) -}} +{{ end -}} +{{ range findRE `{{<(dither|thumbnail) [^/]+/>}}` $content -}} +{{ $rendered := $page.RenderString . -}} +{{ $url := $rendered | replaceRE `(?s).*src="([^"]+)".*` "=> $1" -}} +{{ $content = replace $content . $url -}} +{{ end -}} +{{ $content | safeHTML -}}