aboutsummaryrefslogtreecommitdiff
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
commitf9d5f9d7cb1fa2bf22e33f570ea4a70be0924d7b7cf01e2b5c8e84f4500195ed (patch)
treec6179b619d5f1813745e9be574f2528cbb476e1ba44f616ccc3dda02112e72d6
parent516da51f7fb57eb64190dc2bde321da99719a79a833e6b60445bf92b6edccdb1 (diff)
Implement Gemini template for inline web links
-rw-r--r--TODO1
-rw-r--r--archetypes/default.md3
-rw-r--r--layouts/_default/single.gmi30
3 files changed, 32 insertions, 2 deletions
diff --git a/TODO b/TODO
index 0718033..36a833d 100644
--- a/TODO
+++ b/TODO
@@ -1,5 +1,4 @@
- fix spacing
- add tag support
- fix "layouts/_default/single.gmi" changing preformatted text
-- add support for inline elements for HTML
- test internationalization
diff --git a/archetypes/default.md b/archetypes/default.md
index 174e99f..0951f88 100644
--- a/archetypes/default.md
+++ b/archetypes/default.md
@@ -2,5 +2,8 @@
title: "{{ replace .Name "-" " " | title }}"
draft: true
pageinfo: false
+makerefs: false
+_build:
+ list: never
---
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 }}