aboutsummaryrefslogtreecommitdiff
path: root/layouts/_default
diff options
context:
space:
mode:
Diffstat (limited to 'layouts/_default')
-rw-r--r--layouts/_default/single.gmi30
1 files changed, 29 insertions, 1 deletions
diff --git a/layouts/_default/single.gmi b/layouts/_default/single.gmi
index 63f23ac..6cb5005 100644
--- a/layouts/_default/single.gmi
+++ b/layouts/_default/single.gmi
@@ -9,8 +9,36 @@
# {{ .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) }}
+{{- end }}
+{{- $content := $scratch.Get "content" | replaceRE `\[(.+?)\]\((.+?)\) #(\d+)` "$1[$3]" }}
+{{- else }}
{{- $content = $content | replaceRE `\n\[(.+?)\]\((.+?)\)` (print "\n=> $2 " $emoji "$1") }}
+{{- end }}
{{- $content = $content | replaceRE `\*{3}(.+?)\*{3}|\*{2}(.+?)\*{2}|\*{1}(.+?)\*{1}` "$1$2$3$4$5$6" }}
{{- $content = $content | replaceRE `\n- ` "\n* " }}
{{- $content = $content | emojify }}
-{{- $content | safeHTML }}{{ end }}
+{{- $content | safeHTML }}
+{{- if (.Page.Params.makerefs | default true) }}
+
+## 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) }}
+{{- end }}
+{{- end }}
+{{- end }}