Gemini: List pages & references to

This commit is contained in:
JP Hastings-Spital 2024-04-29 17:38:46 +01:00
parent ff9b3834e5
commit 7a4d3bf832
14 changed files with 157 additions and 74 deletions

View file

@ -197,6 +197,7 @@ date = ["date", "publishDate", "lastmod", ":git"]
[outputs]
home = ["html", "rss", "gemini"]
section = ["html", "rss", "gemini"]
page = ["html", "gemini"]
[minify]

View file

@ -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 <em>mem</em>ory and <em>ex</em>pansion, 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.

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

@ -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 -}}

View file

@ -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 `<br/??>` "\n" -}}
{{- $content := $content | replaceRE `\\\n` "\n" -}}
{{/* Links */}}
{{- $content := $content | replaceRE `<a .*href="(.+?)".*>(.+?)</a>` "[$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

View file

@ -0,0 +1,7 @@
{{- if collections.In (slice "cite" "entry") . -}}
{{- "article" -}}
{{- else if eq . "calendar" -}}
{{- "calendar event" -}}
{{- else -}}
{{- . | singularize -}}
{{- end -}}

View file

@ -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 -}}

View file

@ -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 `<br/??>` "\n" -}}
{{- $content := $content | replaceRE `\\\n` "\n" -}}
{{/* Links */}}
{{- $content := $content | replaceRE `<a .*href="(.+?)".*>(.+?)</a>` "[$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 }}

View file

@ -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 -}}

View file

@ -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 -}}

View file

@ -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) }}

View file

@ -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 -}}

View file

@ -0,0 +1,6 @@
{{ $parts := strings.Split (.Get 0) "." -}}
{{- with index site.Data.friends (index $parts 0) -}}
<a href="{{.site}}">{{.name}}</a>
{{- else -}}
{{ . }}
{{- end }}

View file

@ -0,0 +1,2 @@
{{- $args := dict "src" (.Get "src") -}}
{{- partial "image.gmi" $args -}}

View file

@ -0,0 +1 @@
~~{{ .Get 0 }}~~