build gemini variants
[xangelo.ca.git] / layouts / _default / single.gmi
1 # {{ .Title }}{{ $scratch := newScratch }}
2 {{ $content := .RawContent -}}
3 {{ $content := $content | replaceRE `#### ` "### " -}}
4 {{ $content := $content | replaceRE `\n- (.+?)` "\n* $1" -}}
5 {{ $content := $content | replaceRE `\n(\d+). (.+?)` "\n* $2" -}}
6 {{ $content := $content | replaceRE `\[\^(.+?)\]:?` "" -}}
7 {{ $content := $content | replaceRE `<br/??>` "\n" -}}
8 {{ $content := $content | replaceRE `<a .*href="(.+?)".*>(.+?)</a>` "[$2]($1)" -}}
9 {{ $content := $content | replaceRE `\sgemini://(\S*)` " [gemini://$1](gemini://$1)" -}}
10 {{ $content := $content | replaceRE `{{< youtube (.+?) >}}` "=> https://www.youtube.com/watch?v=$1 YouTube Video link to $1" -}}
11 {{ $content := $content | replaceRE `{{< vimeo (.+?) >}}` "=> https://vimeo.com/$1 Vimeo Video link to $1" -}}
12 {{ $content := $content | replaceRE "([^`])<.*?>([^`])" "$1$2" -}}
13 {{ $content := $content | replaceRE `\n\n!\[.*\]\((.+?) \"(.+?)\"\)` "\n\n=> $1 Image: $2" -}}
14 {{ $content := $content | replaceRE `\n\n!\[.*]\((.+?)\)` "\n\n=> $1 Embedded Image: $1" -}}
15 {{ $links := findRE `\n=> ` $content }}{{ $scratch.Set "ref" (add (len $links) 1) }}
16 {{ $refs := findRE `\[.+?\]\(.+?\)` $content }}
17 {{ $scratch.Set "content" $content }}{{ 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]" -}}
18
19 {{ if .Next }}=> {{ replace .Next.Permalink "xangelo.ca/gemini" "gemini.xangelo.ca" 1}} ← Newer: {{ .Next.Title }}{{ end }}
20 {{ if .Prev -}}=> {{ replace .Prev.Permalink "xangelo.ca/gemini" "gemini.xangelo.ca" 1}} → Older: {{ .Prev.Title }}{{- end }}
21 {{ $content | safeHTML }}
22
23 ---
24 ## References
25 {{ $scratch.Set "ref" (add (len $links) 1) }}{{ range $refs }}{{ $ref := $scratch.Get "ref" }}{{ $url := (printf "%s #%d" . $ref) }}
26 => {{ $url | replaceRE `\[(.+?)\]\((.+?)\) #(\d+)` "$2 [$3] $1 ($2)" -}}
27 {{ $scratch.Set "ref" (add $ref 1) }}{{ end}}
28 {{ $related := first 3 (where (where .Site.RegularPages.ByDate.Reverse ".Params.tags" "intersect" .Params.tags) "Permalink" "!=" .Permalink) }}
29 {{ if $related }}
30 ## Related articles
31 {{ range $related }}
32 => {{ replace .RelPermalink "xangelo.ca/gemini" "gemini.xangelo.ca" 1}} {{ .Title }}: {{ .Params.Subtitle }}{{ end }}{{ end }}
33 ---