From 7a4d3bf832e236d93878cc4e4626e486128b967e Mon Sep 17 00:00:00 2001 From: JP Hastings-Spital Date: Mon, 29 Apr 2024 17:38:46 +0100 Subject: [PATCH] Gemini: List pages & references to --- config.toml | 1 + content/memex/_index.md | 2 +- layouts/_default/list.gmi | 24 +++++++++++ layouts/_default/single.gmi | 68 +++++++++--------------------- layouts/partials/article-type.txt | 7 +++ layouts/partials/image.gmi | 14 ++++++ layouts/partials/markdown.gmi | 41 ++++++++++++++++++ layouts/partials/post-type.txt | 2 +- layouts/partials/reference-to.gmi | 32 ++++++++++++++ layouts/partials/reference-to.html | 12 +----- layouts/shortcodes/figure.gmi | 19 +++------ layouts/shortcodes/friend.gmi | 6 +++ layouts/shortcodes/imgorvid.gmi | 2 + layouts/shortcodes/linkrot.gmi | 1 + 14 files changed, 157 insertions(+), 74 deletions(-) create mode 100644 layouts/_default/list.gmi create mode 100644 layouts/partials/article-type.txt create mode 100644 layouts/partials/image.gmi create mode 100644 layouts/partials/markdown.gmi create mode 100644 layouts/partials/reference-to.gmi create mode 100644 layouts/shortcodes/friend.gmi create mode 100644 layouts/shortcodes/imgorvid.gmi create mode 100644 layouts/shortcodes/linkrot.gmi diff --git a/config.toml b/config.toml index 3a46e11b..ce2082b9 100644 --- a/config.toml +++ b/config.toml @@ -197,6 +197,7 @@ date = ["date", "publishDate", "lastmod", ":git"] [outputs] home = ["html", "rss", "gemini"] + section = ["html", "rss", "gemini"] page = ["html", "gemini"] [minify] diff --git a/content/memex/_index.md b/content/memex/_index.md index 942e2383..fae214b6 100644 --- a/content/memex/_index.md +++ b/content/memex/_index.md @@ -6,7 +6,7 @@ summary: My memory-expander; a space for me to keep links and thoughts that are Taking a cue from personal sites around the web, this memex keeps unformed ideas, links and references around for me to find and use later. -> Memex, a portmanteau of memory and expansion, is a hypothetical electromechanical device for interacting with documents, described in Vannevar Bush's 1945 article "As We May Think". Bush envisioned the memex as a device which individuals could use as "an enlarged intimate supplement to their memory" and "mechanized so that it may be consulted with exceeding speed and flexibility". +> Memex, a portmanteau of MEMory and EXpansion, is a hypothetical electromechanical device for interacting with documents, described in Vannevar Bush's 1945 article "As We May Think". Bush envisioned the memex as a device which individuals could use as "an enlarged intimate supplement to their memory" and "mechanized so that it may be consulted with exceeding speed and flexibility". > > — Adapted from [Memex](https://en.wikipedia.org/wiki/Memex) on the Wikipedia. diff --git a/layouts/_default/list.gmi b/layouts/_default/list.gmi new file mode 100644 index 00000000..74d13d2b --- /dev/null +++ b/layouts/_default/list.gmi @@ -0,0 +1,24 @@ +# {{ with .Params.emoji }}{{.}} {{end}}{{ title (replace .Title "-" " ") }} + +{{- with .Page.RenderShortcodes }} +{{- partial "markdown.gmi" . -}}{{ end -}} + +{{- $paginator := .Paginate .Pages -}} + +{{- range $paginator.Pages.GroupByDate "2006" }} +## {{ .Key }} +{{ range .Pages -}} + => {{ .RelPermalink }} {{ with .Params.emoji }}{{ . }} {{ end }}{{ partial "page-title.txt" . }} +{{ end -}} +{{- end }} + +# Postscript +{{ with .Paginator.Next }} +=> {{ .URL }} Next page{{ end }} +{{- with .Paginator.Prev }} +=> {{ .URL }} Previous page{{ end }} + +=> / 🏡 Home +{{ range .Site.Menus.main -}} + => {{ .URL | relURL }} {{ .Name }} +{{ end -}} \ No newline at end of file diff --git a/layouts/_default/single.gmi b/layouts/_default/single.gmi index 540ea02b..ce85e36c 100644 --- a/layouts/_default/single.gmi +++ b/layouts/_default/single.gmi @@ -1,65 +1,35 @@ -# {{ .Title }} +# {{ .Title | default (partial "page-title.txt" .) }} -{{ $sections := split (replaceRE `^\s*` "\n" .Page.RenderShortcodes) "\n#" -}} +{{ partial "reference-to.gmi" . -}} -{{- $first := true -}} -{{- range $sections -}} - {{- $content := . -}} - {{- if not $first -}} - {{- $content = printf "\n#%s" $content -}} - {{- end -}} - {{- $first = false -}} - - {{/* Swap out unsupported list types */}} - {{- $content := $content | replaceRE `\n- (.+?)` "\n* $1" -}} - {{- $content := $content | replaceRE `\n(\d+). (.+?)` "\n* $2" -}} - {{/* Remove footnote references */}} - {{- $content := $content | replaceRE `\[\^(.+?)\]:?` "" -}} - {{/* Swap out forced newlines */}} - {{- $content := $content | replaceRE `
` "\n" -}} - {{- $content := $content | replaceRE `\\\n` "\n" -}} - {{/* Links */}} - {{- $content := $content | replaceRE `(.+?)` "[$2]($1)" -}} - {{- $content := $content | replaceRE `\sgemini://(\S*)` " [gemini://$1](gemini://$1)" -}} - {{/* Horizontal rules */}} - {{- $content := $content | replaceRE "\n+---\n+" "\n\n" -}} - {{/* Images */}} - {{- $content := $content | replaceRE `\n\n!\[.*]\((.+?)\)` "\n\n=> $1 An untitled image" -}} - - {{- $refs := findRE `\[.+?\]\([^#].+?\)` $content -}} - {{- $content := $content | replaceRE `\[(.+?)\]\((.+?)\)` "$1" -}} - - {{- $content | safeHTML -}} - - {{- if gt (len $refs) 0 -}} - {{- "\n" -}} - {{- range $refs -}} - {{- $parts := split . "](" -}} - {{- $link := substr (index $parts 1) 0 (sub (len (index $parts 1)) 1) -}} - {{- $title := substr (index $parts 0) 1 | strings.FirstUpper -}} - => {{ printf "%s %s\n" $link $title -}} - {{- end -}} - {{- end -}} +{{- with .Params.media }}{{ range . -}} +{{- partial "image.gmi" (dict "src" .url) -}} {{- end }} +{{ end -}} + +{{- partial "markdown.gmi" .Page.RenderShortcodes -}} +# Postscript + +=> https://www.byjp.me{{ replace .RelPermalink "index.gmi" "" }} View this page on the WWW +{{- with .NextInSection }} +=> {{ .RelPermalink }} Next post: {{ partial "page-title.txt" . }}{{ end }} +{{- with .PrevInSection }} +=> {{ .RelPermalink }} Previous post: {{ partial "page-title.txt" . }}{{ end }} -# What's next {{ $dateType := "published" -}} {{- $date := .Date -}} {{- if not .Date -}} {{- $date = .Lastmod -}} - {{- $dateType := "updated" -}} -{{- end }} -This post was {{ $dateType }} by JP on **{{ $date.Format (.Site.Params.dateFormat | default "2 January 2006") }}** + {{- $dateType := "last updated" -}} +{{- end -}} +This post was {{ $dateType }} by {{ .Params.author | default "JP" }} on **{{ $date.Format (.Site.Params.dateFormat | default "2 January 2006") }}** {{- if not .Params.geminiAware }}, originally in markdown and _without_ Gemini in mind, so things might look a little odd!{{else}}.{{ end }} -{{ with .Params.tags -}} +{{- with .Params.tags }} + I've not quite figured out if hashtags are useful in a Gemini context, but this post was tagged with{{ range (. | sort) }} #{{ . }}{{ end -}}. {{- end }} -=> https://www.byjp.me{{ replace (replace .RelPermalink "/gemini" "" 1) "index.gmi" "" }} View this page on the WWW -{{ with .NextInSection }}=> {{ .RelPermalink }} Next post: {{ .Title }}{{ end }} -{{ with .PrevInSection }}=> {{ .RelPermalink }} Next post: {{ .Title }}{{ end }} - You may also want to visit: => / 🏡 Home diff --git a/layouts/partials/article-type.txt b/layouts/partials/article-type.txt new file mode 100644 index 00000000..d7a95749 --- /dev/null +++ b/layouts/partials/article-type.txt @@ -0,0 +1,7 @@ +{{- if collections.In (slice "cite" "entry") . -}} + {{- "article" -}} +{{- else if eq . "calendar" -}} + {{- "calendar event" -}} +{{- else -}} + {{- . | singularize -}} +{{- end -}} diff --git a/layouts/partials/image.gmi b/layouts/partials/image.gmi new file mode 100644 index 00000000..c417ad09 --- /dev/null +++ b/layouts/partials/image.gmi @@ -0,0 +1,14 @@ +{{- $src := path.Join (path.Dir .Page.RelPermalink) .src -}} +{{- $title := "An untitled image" -}} +{{- if hasSuffix $src ".mp4" }}{{ $title = "An untitled video" }}{{ end -}} +{{- $caption := .caption -}} +{{- $captionChunks := split $caption "." -}} +{{- $shortCap := index $captionChunks 0 }} +{{- if and (lt (len $shortCap) 64) (gt (len $shortCap) 0) -}} + {{- $title = $shortCap -}} + {{- $caption = delimit (after 1 $captionChunks) "." -}} +{{- end -}} +{{- with .title }}{{if gt (len .) 0 }}{{ $title = . }}{{ end }}{{ end -}} +{{ "\n=>" }} {{ $src }} {{ $title }} +{{- with $caption }}{{ if ne $title . }} +> {{ . }}{{ end }}{{ end -}} diff --git a/layouts/partials/markdown.gmi b/layouts/partials/markdown.gmi new file mode 100644 index 00000000..342c8b45 --- /dev/null +++ b/layouts/partials/markdown.gmi @@ -0,0 +1,41 @@ +{{ $sections := split (replaceRE `^\s*` "\n" .) "\n#" -}} +{{- $first := true -}} +{{- range $sections -}} + {{- $content := . -}} + {{- if not $first -}} + {{- $content = printf "\n#%s" $content -}} + {{- end -}} + {{- $first = false -}} + + {{/* Swap out unsupported list types */}} + {{- $content := $content | replaceRE `\n- (.+?)` "\n* $1" -}} + {{- $content := $content | replaceRE `\n(\d+). (.+?)` "\n* $2" -}} + {{/* Remove footnote references */}} + {{- $content := $content | replaceRE `\[\^(.+?)\]:?` "" -}} + {{/* Swap out forced newlines */}} + {{- $content := $content | replaceRE `
` "\n" -}} + {{- $content := $content | replaceRE `\\\n` "\n" -}} + {{/* Links */}} + {{- $content := $content | replaceRE `(.+?)` "[$2]($1)" -}} + {{- $content := $content | replaceRE `\sgemini://(\S*)` " [gemini://$1](gemini://$1)" -}} + {{/* Horizontal rules */}} + {{- $content := $content | replaceRE "\n+---\n+" "\n\n" -}} + {{/* Images */}} + {{- $content := $content | replaceRE `\n\n!\[.*]\((.+?)\)` "\n\n=> $1 An untitled image" -}} + + {{- $refs := findRE `\[.+?\]\([^#].+?\)` $content -}} + {{- $content := $content | replaceRE `\[(.+?)\]\((.+?)\)` "$1⁺" -}} + + {{- $content | safeHTML -}} + + {{- if gt (len $refs) 0 -}} + {{- "\n" -}} + {{- range $refs -}} + {{- $parts := split . "](" -}} + {{- $title := substr (index $parts 0) 1 | strings.FirstUpper -}} + {{- $link := substr (index $parts 1) 0 (sub (len (index $parts 1)) 1) -}} + {{- if hasPrefix $link "/twitter/#" }}{{ continue }}{{ end -}} + => {{ printf "%s %s\n" $link $title -}} + {{- end -}} + {{- end -}} +{{- end }} \ No newline at end of file diff --git a/layouts/partials/post-type.txt b/layouts/partials/post-type.txt index 044688da..55ed3cf4 100644 --- a/layouts/partials/post-type.txt +++ b/layouts/partials/post-type.txt @@ -15,7 +15,7 @@ {{- end -}} {{- if $reference.type -}} - {{- $targetType := partial "partials/article-type.html" (default "article" $reference.type) -}} + {{- $targetType := partial "article-type.txt" (default "article" $reference.type) -}} {{- (printf "%s %s" $targetType $typeStr) | strings.FirstUpper -}} {{- else -}} {{- $typeStr | strings.FirstUpper -}} diff --git a/layouts/partials/reference-to.gmi b/layouts/partials/reference-to.gmi new file mode 100644 index 00000000..3de7d07f --- /dev/null +++ b/layouts/partials/reference-to.gmi @@ -0,0 +1,32 @@ +{{- $references := .Params.references -}} +{{- $url := "" -}} +{{- $phrase := "" -}} +{{- $hasReference := true -}} + +{{- if .Params.bookmarkOf -}} + {{- $url = .Params.bookmarkOf -}} +{{- else if .Params.inReplyTo -}} + {{- $url = .Params.inReplyTo -}} +{{- else if .Params.repostOf -}} + {{- $url = .Params.repostOf -}} +{{- else -}} + {{- $hasReference = false -}} +{{- end }} + +{{- if $hasReference -}} +{{- $hostname := (($url | urls.Parse).Hostname) -}} +{{- $reference := partial "reference.obj" (dict "url" $url "references" $references) -}} + +{{- if and (not $reference.name) (strings.HasPrefix $url "/") -}} + {{- $other := site.GetPage $url -}} + {{- if and $other $other.Page -}} + {{- $reference = dict "name" (partial "page-title.txt" $other.Page) "type" $other.Page.Type "internal" true -}} + {{- end -}} +{{- end }} +=> {{ $url }} {{ "Original " -}} +{{- with $reference.name -}} + {{ partial "article-type.txt" (default "article" $reference.type) }}: {{ . -}} +{{- else -}} + {{- printf "an article from %s" $hostname -}} +{{- end -}} +{{- end -}} diff --git a/layouts/partials/reference-to.html b/layouts/partials/reference-to.html index 3aeddc1f..30d12cdb 100644 --- a/layouts/partials/reference-to.html +++ b/layouts/partials/reference-to.html @@ -2,16 +2,6 @@ {{- $references := .references -}} {{- $mf2 := .mf2 -}} -{{- define "partials/article-type.html" -}} - {{- if collections.In (slice "cite" "entry") . -}} - {{- "article" -}} - {{- else if eq . "calendar" -}} - {{- "calendar event" -}} - {{- else -}} - {{- . | singularize -}} - {{- end -}} -{{- end -}} - {{- $hostname := (($url | urls.Parse).Hostname) -}} {{- $reference := partial "reference.obj" . -}} @@ -23,7 +13,7 @@ {{- end -}} {{ partial "svg.html" (dict "name" .svg) }} {{ .phrase }}{{" "}} {{- with $reference.name -}} - {{- if $reference.internal -}}my{{else}}the{{end}} {{ partial "partials/article-type.html" (default "article" $reference.type) }} {{ partial "rich-link.html" (dict "Class" (printf "%s h-cite" $mf2) "url" $url "Text" . "references" $references) }}. + {{- if $reference.internal -}}my{{else}}the{{end}} {{ partial "article-type.txt" (default "article" $reference.type) }} {{ partial "rich-link.html" (dict "Class" (printf "%s h-cite" $mf2) "url" $url "Text" . "references" $references) }}. {{- else -}} {{- $text := printf "an article from %s" $hostname -}} {{- partial "rich-link.html" (dict "Class" $mf2 "url" $url "Text" $text "references" $references) }} diff --git a/layouts/shortcodes/figure.gmi b/layouts/shortcodes/figure.gmi index 0092319c..d7d85774 100644 --- a/layouts/shortcodes/figure.gmi +++ b/layouts/shortcodes/figure.gmi @@ -1,12 +1,7 @@ -{{- $src := path.Join (path.Dir .Page.RelPermalink) (.Get "src") -}} -{{- $title := "An untitled image" -}} -{{- $caption := (.Get "caption") -}} -{{- $captionChunks := split $caption "." -}} -{{- if lt (len (index $captionChunks 0)) 64 -}} - {{- $title = index $captionChunks 0 -}} - {{- $caption = delimit (after 1 $captionChunks) "." -}} -{{- end -}} -{{- $title := (.Get "title") | default $title -}} -=> {{ $src }} {{ $title }} -{{- with $caption }}{{ if ne $title . }} -> {{ . }}{{ end }}{{ end -}} +{{- $args := dict + "src" (.Get "src") + "caption" (.Get "caption") + "title" (.Get "title") + "alt" (.Get "alt") +-}} +{{- partial "image.gmi" $args -}} \ No newline at end of file diff --git a/layouts/shortcodes/friend.gmi b/layouts/shortcodes/friend.gmi new file mode 100644 index 00000000..2ace3044 --- /dev/null +++ b/layouts/shortcodes/friend.gmi @@ -0,0 +1,6 @@ +{{ $parts := strings.Split (.Get 0) "." -}} +{{- with index site.Data.friends (index $parts 0) -}} + {{.name}} +{{- else -}} + {{ . }} +{{- end }} \ No newline at end of file diff --git a/layouts/shortcodes/imgorvid.gmi b/layouts/shortcodes/imgorvid.gmi new file mode 100644 index 00000000..d18f3c39 --- /dev/null +++ b/layouts/shortcodes/imgorvid.gmi @@ -0,0 +1,2 @@ +{{- $args := dict "src" (.Get "src") -}} +{{- partial "image.gmi" $args -}} diff --git a/layouts/shortcodes/linkrot.gmi b/layouts/shortcodes/linkrot.gmi new file mode 100644 index 00000000..0b0d3438 --- /dev/null +++ b/layouts/shortcodes/linkrot.gmi @@ -0,0 +1 @@ +~~{{ .Get 0 }}~~ \ No newline at end of file