summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorNicholas Johnson <nick@nicholasjohnson.ch>2023-01-21 00:00:00 +0000
committerNicholas Johnson <nick@nicholasjohnson.ch>2023-01-21 00:00:00 +0000
commit48dd0fb26f7c667c7a7edeead15dfab0750623220a699ce16889ce911a440dc1 (patch)
tree3a87dcf03457fdd1bd533e7d86b9eff9bb66f2e7ec703b738297125435c4c1c0
parent112abca730d7585e548fedf58162e098eb4304b357ca3f0c47fed4f5d7cb960e (diff)
downloadhugo-theme-journal-098a594e7904bc62964bb5f930df17dff65cd39c57b3027f889bbe20bfd52ee1.tar.gz
hugo-theme-journal-098a594e7904bc62964bb5f930df17dff65cd39c57b3027f889bbe20bfd52ee1.zip
Simplify Gemini single page template link parsingv0.1.1
-rw-r--r--layouts/_default/single.gmi28
1 files changed, 10 insertions, 18 deletions
diff --git a/layouts/_default/single.gmi b/layouts/_default/single.gmi
index 7c110ee..ba22d30 100644
--- a/layouts/_default/single.gmi
+++ b/layouts/_default/single.gmi
@@ -8,24 +8,17 @@
{{ end -}}
# {{ .Name | safeHTML }}
{{ $content := .RawContent }}
-{{- $content = $content | replaceRE `\n####{0,3}` "\n###" }}
-{{- $scratch := newScratch }}
-{{- $scratch.Set "ref" 1 }}
{{- $refs := findRE `\[.+?\]\(.+?\)` $content }}
-{{- $scratch.Set "content" $content }}
{{- if (.Page.Params.makerefs | default true) }}
-{{- range $refs }}
- {{- $ref := $scratch.Get "ref" }}
- {{- $contentInLoop := $scratch.Get "content" }}
- {{- $url := (printf "%s #%d" . $ref) }}
- {{- $contentInLoop := replace $contentInLoop . $url }}
- {{- $scratch.Set "content" $contentInLoop }}
- {{- $scratch.Set "ref" (add $ref 1) }}
+{{- range $ref_index, $ref_val := $refs }}
+ {{- $ref_num := add $ref_index 1 }}
+ {{- $ref_text := $ref_val | replaceRE `\[(.+?)\]\((.+?)\)` "$1" }}
+ {{- $content = replace $content $ref_val (print $ref_text "[" $ref_num "]") 1 }}
{{- end }}
-{{- $content = $scratch.Get "content" | replaceRE `\[(.+?)\]\((.+?)\) #(\d+)` "$1[$3]" }}
{{- else }}
{{- $content = $content | replaceRE `\n\[(.+?)\]\((.+?)\)` (print "\n=> $2 " $emoji "$1") }}
{{- end }}
+{{- $content = $content | replaceRE `\n####{0,3}` "\n###" }}
{{- $content = $content | replaceRE `\*{3}(.+?)\*{3}|\*{2}(.+?)\*{2}|\*{1}(.+?)\*{1}` "$1$2$3$4$5$6" }}
{{- $content = $content | replaceRE `\n- ` "\n* " }}
{{- $content = $content | emojify }}
@@ -33,12 +26,11 @@
{{- if and (.Page.Params.makerefs | default true) $refs }}
## Links
-{{- $scratch.Set "ref" 1 }}
-{{- range $refs }}
- {{- $ref := $scratch.Get "ref" }}
- {{- $url := (printf "%s #%d" . $ref) }}
-{{ $url | replaceRE `\[(.+?)\]\((.+?)\) #(\d+)` (print "=> $2 " $emoji "$3: $1") | safeHTML }}
- {{- $scratch.Set "ref" (add $ref 1) }}
+{{- range $ref_index, $ref_val := $refs }}
+ {{- $ref_num := add $ref_index 1 }}
+ {{- $ref_text := $ref_val | replaceRE `\[(.+?)\]\((.+?)\)` "$1" }}
+ {{- $ref_link := $ref_val | replaceRE `\[(.+?)\]\((.+?)\)` "$2" }}
+{{ print "=> " $ref_link " " $emoji $ref_num ": " $ref_text | safeHTML }}
{{- end }}
{{- end }}
{{- end }}