From 26e57ca40250a407e86d6d523ac2f67f60acb611 Mon Sep 17 00:00:00 2001 From: JP Hastings-Spital Date: Tue, 30 Apr 2024 09:40:43 +0100 Subject: [PATCH] Fix taxonomy pages --- .gitignore | 3 ++- Taskfile.yml | 10 +++++----- config.toml | 2 ++ layouts/_default/list.gmi | 3 ++- layouts/_default/taxonomy.gmi | 10 ++++++++++ layouts/partials/image.gmi | 7 ++++--- layouts/partials/markdown.gmi | 16 +++++++++++----- todo.md | 6 ++++++ 8 files changed, 42 insertions(+), 15 deletions(-) create mode 100644 layouts/_default/taxonomy.gmi diff --git a/.gitignore b/.gitignore index 61101fc1..27225a9e 100644 --- a/.gitignore +++ b/.gitignore @@ -3,4 +3,5 @@ /.hugo_build.lock /.lycheecache .env -*.der +# Ignore Agate gemini server's files +/.certificates diff --git a/Taskfile.yml b/Taskfile.yml index 431af089..09471b72 100644 --- a/Taskfile.yml +++ b/Taskfile.yml @@ -3,7 +3,7 @@ version: '3' vars: - domain: https://www.byjp.me + domain: www.byjp.me puma_dev_tld: .test env: @@ -26,15 +26,15 @@ tasks: port: 1313 cmds: - | - [ -d "$HOME/.puma-dev/" ] && (echo {{ .port }} > $HOME/.puma-dev/www.byjp.me) || echo "Puma dev not installed, https://{{ .domain }}{{ .puma_dev_tld }} will not work" - - hugo server -p {{ .port }} --minify --printUnusedTemplates -D --baseURL "{{ .domain }}{{ .puma_dev_tld }}" --appendPort=false + [ -d "$HOME/.puma-dev/" ] && (echo {{ .port }} > $HOME/.puma-dev/{{ .domain }}) || echo "Puma dev not installed, https://{{ .domain }}{{ .puma_dev_tld }} will not work" + - hugo server -p {{ .port }} --minify --printUnusedTemplates -D --baseURL "https://{{ .domain }}{{ .puma_dev_tld }}" --appendPort=false build: desc: Builds the production-ready site in ./public/ vars: cache: /tmp/hugo/cache cmds: - - hugo --cacheDir {{ .cache }} --gc --minify --baseURL "{{ .domain }}" + - hugo --cacheDir {{ .cache }} --gc --minify --baseURL "https://{{ .domain }}" - pagefind import: @@ -48,4 +48,4 @@ tasks: desc: Builds the site & starts a gemini server (on the default port) for it. deps: [ build ] cmds: - - agate --content public --lang en-GB --hostname localhost --central-conf + - agate --content public --lang en-GB --hostname "{{ .domain }}{{ .puma_dev_tld }}" --central-conf diff --git a/config.toml b/config.toml index ce2082b9..0c90997b 100644 --- a/config.toml +++ b/config.toml @@ -198,6 +198,8 @@ date = ["date", "publishDate", "lastmod", ":git"] [outputs] home = ["html", "rss", "gemini"] section = ["html", "rss", "gemini"] + taxonomy = ["html", "rss", "gemini"] + term = ["html", "rss", "gemini"] page = ["html", "gemini"] [minify] diff --git a/layouts/_default/list.gmi b/layouts/_default/list.gmi index 144321f9..6329f7bf 100644 --- a/layouts/_default/list.gmi +++ b/layouts/_default/list.gmi @@ -6,7 +6,8 @@ {{- $paginator := .Paginate .Pages -}} -{{- range $paginator.Pages.GroupByDate "2006" }} +{{- $paginatorGroup := $paginator.Pages.GroupByDate "2006" -}} +{{- range $paginatorGroup }} ## {{ .Key }} {{ range .Pages -}} => {{ .RelPermalink }} {{ with .Params.emoji }}{{ . }} {{ end }}{{ partial "page-title.txt" . }} diff --git a/layouts/_default/taxonomy.gmi b/layouts/_default/taxonomy.gmi new file mode 100644 index 00000000..1689c495 --- /dev/null +++ b/layouts/_default/taxonomy.gmi @@ -0,0 +1,10 @@ +{{- define "main" -}} +# {{ with .Params.emoji }}{{.}} {{end}}{{ title (replace .Title "-" " ") }} + +{{- with .Page.RenderShortcodes }} +{{- partial "markdown.gmi" . -}}{{ end }} + +{{ range .Pages.ByTitle -}} + => {{ .RelPermalink }} {{ with .Params.emoji }}{{ . }} {{ end }}{{ partial "page-title.txt" . }} +{{ end -}} +{{- end -}} diff --git a/layouts/partials/image.gmi b/layouts/partials/image.gmi index c417ad09..cf5fb97b 100644 --- a/layouts/partials/image.gmi +++ b/layouts/partials/image.gmi @@ -1,6 +1,7 @@ {{- $src := path.Join (path.Dir .Page.RelPermalink) .src -}} -{{- $title := "An untitled image" -}} -{{- if hasSuffix $src ".mp4" }}{{ $title = "An untitled video" }}{{ end -}} +{{- $emoji := "🖼️" -}} +{{- $title := "Linked image" -}} +{{- if hasSuffix $src ".mp4" }}{{ $title = "Linked video" }}{{- $emoji = "📼" -}}{{ end -}} {{- $caption := .caption -}} {{- $captionChunks := split $caption "." -}} {{- $shortCap := index $captionChunks 0 }} @@ -9,6 +10,6 @@ {{- $caption = delimit (after 1 $captionChunks) "." -}} {{- end -}} {{- with .title }}{{if gt (len .) 0 }}{{ $title = . }}{{ end }}{{ end -}} -{{ "\n=>" }} {{ $src }} {{ $title }} +{{ "\n=>" }} {{ $src }} {{ $emoji }} {{ $title }} {{- with $caption }}{{ if ne $title . }} > {{ . }}{{ end }}{{ end -}} diff --git a/layouts/partials/markdown.gmi b/layouts/partials/markdown.gmi index 0973a5ba..d020eb68 100644 --- a/layouts/partials/markdown.gmi +++ b/layouts/partials/markdown.gmi @@ -15,19 +15,24 @@ {{/* 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" -}} + {{- $content := $content | replaceRE `\n\n!\[.*]\((.+?)\)` "\n\n=> $1 Linked image" -}} + {{/* Links */}} + {{- $content := $content | replaceRE `(.+?)` "[$2]($1)" -}} + {{- $content := $content | replaceRE `\sgemini://(\S*)` " [gemini://$1](gemini://$1)" -}} + {{- $refs := findRE `\[.+?\]\([^#].+?\)` $content -}} + {{/* Remove lines that are only hashtags */}} + {{- $content := $content | replaceRE `\n(\[.+?\]\(/tags/.*\) *)+\n` "" -}} + {{/* Give hashtags a hash */}} + {{- $content := $content | replaceRE `\[(.+?)\]\(/tags/.*\)` "#$1" -}} + {{/* Give other links a subscript indicator */}} {{- $content := $content | replaceRE `\[(.+?)\]\((.+?)\)` "$1⁺" -}} {{- $content | safeHTML -}} - {{- if gt (len $refs) 0 -}} {{- "\n" -}} {{- range $refs -}} @@ -35,6 +40,7 @@ {{- $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 -}} + {{- if hasPrefix $link "/tags/" }}{{ $title = printf "🔗 #%s" $title }}{{ end -}} => {{ printf "%s %s\n" $link $title -}} {{- end -}} {{- end -}} diff --git a/todo.md b/todo.md index ad34fa4d..e568620d 100644 --- a/todo.md +++ b/todo.md @@ -19,6 +19,12 @@ Things I might work on within my personal blog's software. - [ ] Add links to memex from §refs - [ ] Switch Memex to single file (easier to post to) - [ ] Remove http://gowal.la & https://4sq.com links and/or posts that are useless without them +- [ ] Gemini?! + - [x] Tags pages + - [ ] Calendar page + - [ ] Include link, location, date on event page + - [ ] Handle `
` in posts (example: ChefGPT) + - [ ] Actually serve it up ### Working