Compare commits

...

2 commits

Author SHA1 Message Date
4fc7d8bc35 gemini: generate taxonomy pages 2024-03-03 15:00:03 -06:00
8034385a97 gemini: display links below paragraphs 2024-03-03 14:44:08 -06:00
3 changed files with 52 additions and 43 deletions

View file

@ -19,7 +19,7 @@ enableInlineShortcodes = true
home = ['html', 'rss', 'gemini'] home = ['html', 'rss', 'gemini']
section = ['html'] section = ['html']
taxonomy = ['html'] taxonomy = ['html']
term = ['html', 'rss'] term = ['html', 'rss', 'gemini']
page = ['html', 'rss', 'gemini'] page = ['html', 'rss', 'gemini']
# rename rss output from index.xml to feed.xml # rename rss output from index.xml to feed.xml

10
layouts/_default/list.gmi Normal file
View file

@ -0,0 +1,10 @@
=> / 💻 [runtimeterror $]
# {{ .Title }}
{{- range .Pages }}
=> {{ .RelPermalink }} {{ .Date.Format "2006-01-02" }} {{ .Title }}
{{- end }}
---
=> / Home
=> https://runtimeterror.dev{{ replace (replace .RelPermalink "/gemini" "" 1) "index.gmi" "" }} This article on the big web

View file

@ -1,18 +1,20 @@
{{- $scratch := newScratch -}}{{- $scratch.Set "ref" 1 -}}
=> / 💻 [runtimeterror $] => / 💻 [runtimeterror $]
# {{ .Title }}{{ $scratch := newScratch }} {{ if .Params.Date }}
{{- if .Params.Date }}
{{- $postDate := .Date.Format "2006-01-02" }} {{- $postDate := .Date.Format "2006-01-02" }}
{{- $updateDate := .Lastmod.Format "2006-01-02" }} {{- $updateDate := .Lastmod.Format "2006-01-02" }}
{{ $postDate }}{{ if ne $postDate $updateDate }} ~ {{ $updateDate }}{{ end }} {{- $postDate }}{{ if ne $postDate $updateDate }} ~ {{ $updateDate }}{{ end }}
{{- end }} {{- end }}
{{/* The bulk of this regex magic is derived from https://brainbaking.com/post/2021/04/using-hugo-to-launch-a-gemini-capsule/ */}} # {{ .Title }}
{{ $content := .RawContent -}} {{/* The bulk of this regex magic was inspired by https://brainbaking.com/post/2021/04/using-hugo-to-launch-a-gemini-capsule/ */}}
{{ range $content := split .RawContent "\n\n" }}
{{- $blockRef := $scratch.Get "ref" -}}
{{- $content := $content | replaceRE `#{4,} ` "### " -}}{{/* reduce headings to a max of 3 levels */}} {{- $content := $content | replaceRE `#{4,} ` "### " -}}{{/* reduce headings to a max of 3 levels */}}
{{- $content := $content | replaceRE `(?m:^- (.+?)$)` "\n* $1" -}}{{/* convert unordered lists */}} {{- $content := $content | replaceRE `(?m:^- (.+?)$)` "\n* $1" -}}{{/* convert unordered lists */}}
{{- $content := $content | replaceRE `(?m:^(?:\d+). (.+?)$)` "* $1" -}}{{/* convert ordered lists */}} {{- $content := $content | replaceRE `(?m:^(?:\d+). (.+?)$)` "* $1" -}}{{/* convert ordered lists */}}
{{- $content := $content | replaceRE `\n\[\^(.+?)\]:\s.*` "" -}}{{/* remove footnote definitions */}} {{- $content := $content | replaceRE `\n?\[\^(.+?)\]:\s*.*` "" -}}{{/* remove footnote definitions */}}
{{- $content := $content | replaceRE `\[\^(.+?)\]` "" -}}{{/* remove footnote anchors */}} {{- $content := $content | replaceRE `\[\^(.+?)\]` "" -}}{{/* remove footnote anchors */}}
{{- $content := $content | replaceRE `((?m:^(?:\|.*\|)+\n)+)` "```\n$1\n```\n" -}}{{/* convert markdown tables to plaintext ascii */}} {{- $content := $content | replaceRE `((?m:^(?:\|.*\|)+\n?)+)` "```\n$1\n```\n" -}}{{/* render markdown tables as plaintext ascii */}}
{{- $content := $content | replaceRE "(?m:^`([^`]*)`$)" "```\n$1\n```\n" -}}{{/* convert single-line inline code to blocks */}} {{- $content := $content | replaceRE "(?m:^`([^`]*)`$)" "```\n$1\n```\n" -}}{{/* convert single-line inline code to blocks */}}
{{- $content := $content | replaceRE `\{\{%\snotice.*%\}\}` "<-- note -->" -}}{{/* convert hugo notices */}} {{- $content := $content | replaceRE `\{\{%\snotice.*%\}\}` "<-- note -->" -}}{{/* convert hugo notices */}}
{{- $content := $content | replaceRE `\{\{%\s/notice.*%\}\}` "<-- /note -->" -}} {{- $content := $content | replaceRE `\{\{%\s/notice.*%\}\}` "<-- /note -->" -}}
@ -21,11 +23,9 @@
{{- $content := $content | replaceRE `(?m:^\[!\[(.*)\]\(.*\)\]\((.*)\)$)` "=> $2 $1" -}}{{/* remove images from uptime links */}} {{- $content := $content | replaceRE `(?m:^\[!\[(.*)\]\(.*\)\]\((.*)\)$)` "=> $2 $1" -}}{{/* remove images from uptime links */}}
{{- $content := $content | replaceRE `(?m:^\s*(?:(?:\*|\-)\s+)?\[(.*)\]\((.*)\)$)` "=> $2 $1" -}}{{/* convert links already on own line */}} {{- $content := $content | replaceRE `(?m:^\s*(?:(?:\*|\-)\s+)?\[(.*)\]\((.*)\)$)` "=> $2 $1" -}}{{/* convert links already on own line */}}
{{- $content := $content | replaceRE `(?m:^!\[(.*)\]\((.+?)\)$)` "=> $2 Image: $1" -}}{{/* convert embedded images */}} {{- $content := $content | replaceRE `(?m:^!\[(.*)\]\((.+?)\)$)` "=> $2 Image: $1" -}}{{/* convert embedded images */}}
{{- $content := $content | replaceRE `\n{3,}` "\n\n" -}}{{/* try to ensure we don't get more than two newlines in a row */}} {{- $links := findRE `\[.+?\]\(.+?\)` $content -}}
{{- $scratch.Set "ref" 1 -}}
{{- $refs := findRE `\[.+?\]\(.+?\)` $content -}}{{/* find remaining inline links */}}
{{- $scratch.Set "content" $content -}} {{- $scratch.Set "content" $content -}}
{{- range $refs -}} {{- range $links -}}
{{- $ref := $scratch.Get "ref" -}} {{- $ref := $scratch.Get "ref" -}}
{{- $contentInLoop := $scratch.Get "content" -}} {{- $contentInLoop := $scratch.Get "content" -}}
{{- $url := (printf "%s #%d" . $ref) -}} {{- $url := (printf "%s #%d" . $ref) -}}
@ -33,20 +33,19 @@
{{- $scratch.Set "content" $contentInLoop -}} {{- $scratch.Set "content" $contentInLoop -}}
{{- $scratch.Set "ref" (add $ref 1) -}} {{- $scratch.Set "ref" (add $ref 1) -}}
{{- end -}} {{- end -}}
{{- $content := $scratch.Get "content" | replaceRE `\[(.+?)\]\((.+?)\) #(\d+)` "$1 [$3]" -}}{{/* replace inline links with footnote */}} {{- $content := $scratch.Get "content" | replaceRE `\[(.+?)\]\((.+?)\) #(\d+)` "$1 [$3]" }}
{{- $content | safeHTML }} {{- $content | safeHTML }}
{{- range $links -}}
{{- $ref := $scratch.Get "ref" -}}
{{- $url := (printf "%s #%d" . $blockRef) }}
=> {{ $url | replaceRE `\[(.+?)\]\((.+?)\) #(\d+)` "$2 [$3] $1" }}
{{- $blockRef = add $blockRef 1 -}}
{{ end }}
{{ end }}
--- ---
{{ $subject := printf "Re: %s" .Title -}} {{ $subject := printf "Re: %s" .Title -}}
=> mailto:blog@runtimeterror.dev?subject={{ urlquery $subject | replaceRE `\+` "%20" }} 📧 Reply via email => mailto:blog@runtimeterror.dev?subject={{ urlquery $subject | replaceRE `\+` "%20" }} 📧 Reply via email
## Bibliography
{{ $scratch.Set "ref" 1 -}}
{{ range $refs -}}
{{- $ref := $scratch.Get "ref" -}}
{{- $url := (printf "%s #%d" . $ref) -}}
=> {{ $url | replaceRE `\[(.+?)\]\((.+?)\) #(\d+)` "$2 [$3] $1" }}{{/* render links in biblio footer */}}
{{- $scratch.Set "ref" (add $ref 1) }}
{{ end -}}
{{ $related := first 3 (where (where .Site.RegularPages.ByDate.Reverse ".Params.tags" "intersect" .Params.tags) "Permalink" "!=" .Permalink) }} {{ $related := first 3 (where (where .Site.RegularPages.ByDate.Reverse ".Params.tags" "intersect" .Params.tags) "Permalink" "!=" .Permalink) }}
{{ if $related }} {{ if $related }}
## Related articles ## Related articles