Gemini: Fix calendar pages

This commit is contained in:
JP Hastings-Spital 2024-04-30 10:58:22 +01:00
parent 26e57ca402
commit 9afb94536e
12 changed files with 87 additions and 48 deletions

View file

@ -197,10 +197,11 @@ date = ["date", "publishDate", "lastmod", ":git"]
[outputs]
home = ["html", "rss", "gemini"]
page = ["html", "gemini"]
rss = ["rss"]
section = ["html", "rss", "gemini"]
taxonomy = ["html", "rss", "gemini"]
term = ["html", "rss", "gemini"]
page = ["html", "gemini"]
[minify]
[minify.tdewolff]

View file

@ -3,6 +3,7 @@ title: Calendar
emoji: 🗓️
outputs:
- html
- gemini
- calendar
- rss
summary: Some events I'm thinking of going to — get in touch if you'd like to join me!

View file

@ -2,15 +2,15 @@
# Postscript
{{- $type := .Type -}}
{{- $paginateType := (partial "article-type.txt" (default "page" $type)) | pluralize -}}
{{- $paginateType := (partial "article-type.txt" (default "page" $type)) -}}
{{- with .NextInSection }}
=> {{ .RelPermalink }} Next post: {{ partial "page-title.txt" . }}{{ end }}
=> {{ .RelPermalink }} Next {{ $paginateType }}: {{ partial "page-title.txt" . }}{{ end }}
{{- with .PrevInSection }}
=> {{ .RelPermalink }} Previous post: {{ partial "page-title.txt" . }}{{ end }}
=> {{ .RelPermalink }} Previous {{ $paginateType }}: {{ partial "page-title.txt" . }}{{ end }}
{{ if eq .Kind "section" }}{{ with .Paginator.Next }}
=> {{ .URL }} Next page of {{ $paginateType }}{{ end }}
=> {{ .URL }} Next page of {{ $paginateType | pluralize }}{{ end }}
{{- with .Paginator.Prev }}
=> {{ .URL }} Previous page of {{ $paginateType }}{{ end }}{{ end }}
=> {{ .URL }} Previous page of {{ $paginateType | pluralize }}{{ end }}{{ end }}
=> https://www.byjp.me{{ replace .RelPermalink "index.gmi" "" }} View this page on the WWW
{{ $dateType := "published" -}}
@ -26,6 +26,8 @@ This {{ partial "article-type.txt" (default "page" $type) }} was {{ $dateType }}
{{- 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 -}}.
=> /tags/ 🔗 List of all hashtags
{{- end }}
You may also want to visit:

18
layouts/calendar/list.gmi Normal file
View file

@ -0,0 +1,18 @@
{{- define "main" -}}
# {{ with .Params.emoji }}{{.}} {{end}}{{ title (replace .Title "-" " ") }}
{{- with .Page.RenderShortcodes }}
{{- partial "markdown.gmi" . -}}{{ end }}
{{ range $bundledEvents := (partial "events.obj" .Data.Pages) -}}
## {{ (index $bundledEvents 0).Date.Format "Jan 2006" }}
{{ range $bundledEvents -}}
{{- $hour := .Date.Format "15" -}}
{{- $duration := .Duration.Hours -}}
{{- $span := "eve" }}
{{- if and (gt $hour 9) (lt $hour 17) }}{{ $span = "day" }}{{ end -}}
{{- if ge $duration 24 }}{{ $span = "multi-day" }}{{ end -}}
=> {{ .Page.RelPermalink }} {{ with .Page.Params.emoji }}{{ . }} {{ end }}{{.Page.Title}} ({{ .Date.Format "Jan 2"}}, {{ $span }})
{{ end -}}
{{- end -}}
{{- end -}}

View file

@ -14,16 +14,7 @@
<div class="content" data-pagefind-body data-pagefind-filter="type:{{.Type | title}}">{{ .Content }}</div>
{{ end }}
{{ $events := dict }}
{{ range $page := .Data.Pages }}
{{ range $page.Params.timings }}
{{ $event := dict "Title" $page.Title "Page" $page.Page "Date" (time.AsTime .starts) "Duration" (partial "iso8601.duration" .duration) }}
{{ if $event.Date.Before time.Now }}{{ continue }}{{ end }}
{{ $bundle := $event.Date.Format "2006-01" }}
{{ $events = merge $events (dict $bundle (sort ((index $events $bundle) | append $event) "Date" "asc")) }}
{{ break }}{{/* Only show the first on the list */}}
{{ end }}
{{ end }}
{{ $events := partial "events.obj" .Data.Pages }}
{{ range $bundledEvents := $events }}
<div class="posts-group">

View file

@ -0,0 +1,13 @@
{{- define "main" -}}
# {{ with .Params.emoji }}{{.}} {{end}}{{ .Title | default (partial "page-title.txt" .) }}
{{ $event := partial "event.obj" .Params.timings -}}
{{ .Summary | htmlUnescape }}
{{- $starts := time.AsTime $event.timing.starts }}
I{{ if $event.isPast }} was{{ else }}'m{{ end }} planning on going to this event on {{ partial "year-relative-date.txt" $starts }}, from {{ $starts.Format "15:04 (MST)" }}.
{{ with .Params.location }}
=> {{ partial "geolink.url" . }} Location: {{ .name }}{{ end -}}
{{- with .Params.link }}
=> {{ . }} More info on: {{ strings.TrimPrefix "www." (urls.Parse .).Hostname }}{{ end }}
{{ partial "markdown.gmi" .Page.RenderShortcodes -}}
{{- end -}}

View file

@ -2,20 +2,7 @@
<main class="post h-event">
{{ partial "memex-header.html" . }}
{{ $timings := slice -}}
{{ range .Params.timings -}}
{{ if (time.AsTime .starts).After time.Now -}}
{{ $timings = $timings | append . -}}
{{ end -}}
{{ end -}}
{{ $timing := dict }}
{{ $isPast := true }}
{{ if gt (len $timings) 0 }}
{{ $timing = index $timings 0 }}
{{ $isPast = false }}
{{ else }}
{{ $timing = index .Params.timings 0 }}
{{ end }}
{{ $event := partial "event.obj" .Params.timings }}
<article>
<hgroup class="post-title">
@ -40,9 +27,9 @@
{{ end }}
<div class="post-content p-description" data-pagefind-body data-pagefind-filter="type:{{.Type | title}}">
{{ if not $isPast }}
{{ if not $event.isPast }}
<p class="next-visit">
{{ partial "svg.html" (dict "name" "calendar") }} I'm planning on going to this event on {{ partial "year-relative-date.html" (slice (time.AsTime $timing.starts) "dt-start") }}.
{{ partial "svg.html" (dict "name" "calendar") }} I'm planning on going to this event on {{ partial "year-relative-date.html" (slice (time.AsTime $event.timing.starts) "dt-start") }}.
See the bottom of the post for more information.
</p>
{{ end }}
@ -62,7 +49,7 @@
<path d="M21 10c0 7-9 13-9 13s-9-6-9-13a9 9 0 0 1 18 0z"></path>
<circle cx="12" cy="10" r="3"></circle>
</svg>
At <a href="{{ partial "geolink.html" . }}" class="p-location h-geo" target="_blank"><span class="p-name">{{ .name }}</span><span class="hidden" aria-hidden> (<span class="p-latitude">{{ .latitude }}</span>, <span class="p-longitude">{{ .longitude }}</span>)</span></a>
At <a href="{{ partial "geolink.url" . }}" class="p-location h-geo" target="_blank"><span class="p-name">{{ .name }}</span><span class="hidden" aria-hidden> (<span class="p-latitude">{{ .latitude }}</span>, <span class="p-longitude">{{ .longitude }}</span>)</span></a>
</p>{{ end }}
<p>
@ -72,29 +59,29 @@
<line x1="8" y1="2" x2="8" y2="6"></line>
<line x1="3" y1="10" x2="21" y2="10"></line>
</svg>
On {{ partial "year-relative-date.html" (slice (time.AsTime $timing.starts) "dt-start") }}
{{ with sub (len $timings) 1 }}{{ if gt . 0 }} (and {{ . }} other{{ if gt . 1}}s{{end}}){{ end }}{{ end }}
On {{ partial "year-relative-date.html" (slice (time.AsTime $event.timing.starts) "dt-start") }}
{{ with sub (len $event.timings) 1 }}{{ if gt . 0 }} (and {{ . }} other{{ if gt . 1}}s{{end}}){{ end }}{{ end }}
</p>
<p>
<svg xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="feather feather-clock">
<circle cx="12" cy="12" r="10"></circle>
<polyline points="12 6 12 12 16 14"></polyline>
</svg>
{{ $starts := time.AsTime $timing.starts }}
{{ $durationStr := ((strings.Substr $timing.duration 1) | strings.ToLower) }}
{{ $duration := partial "iso8601.duration" $timing.duration }}
{{ $starts := time.AsTime $event.timing.starts }}
{{ $durationStr := ((strings.Substr $event.timing.duration 1) | strings.ToLower) }}
{{ $duration := partial "iso8601.duration" $event.timing.duration }}
From {{ $starts.Format "15:04" }} until {{ $starts.Add $duration | dateFormat "15:04 (MST)" }} (<span class="dt-duration">{{ replace $durationStr "t" "" }}</span>)
</p>
{{ if $timing.attending }}
{{ if $event.timing.attending }}
<p class="attending">
{{ partial "svg.html" (dict "name" "attending") }}
{{ if eq $timing.attending true }}{{ partial "friend.html" "jp.no-emoji" }} is going
{{ else if eq (len $timing.attending) 1 }}
{{ partial "friend.html" (printf "%s.no-emoji" (index $timing.attending 0)) }} is going
{{ if eq $event.timing.attending true }}{{ partial "friend.html" "jp.no-emoji" }} is going
{{ else if eq (len $event.timing.attending) 1 }}
{{ partial "friend.html" (printf "%s.no-emoji" (index $event.timing.attending 0)) }} is going
{{ else }}
{{ $count := len $timing.attending}}
{{ range $i, $attendee := $timing.attending }}
{{ $count := len $event.timing.attending}}
{{ range $i, $attendee := $event.timing.attending }}
{{ partial "friend.html" (printf "%s.no-emoji" $attendee) -}}
{{- if eq $i (sub $count 2) }}{{ if gt $count 2 }},{{ end }} and {{ else if lt $i (sub $count 1) }}, {{ end }}
{{ end }} are going

View file

@ -0,0 +1,15 @@
{{- $timings := slice -}}
{{- range . -}}
{{- if (time.AsTime .starts).After time.Now -}}
{{- $timings = $timings | append . -}}
{{- end -}}
{{- end -}}
{{- $timing := dict -}}
{{- $isPast := true -}}
{{- if gt (len $timings) 0 -}}
{{- $timing = index $timings 0 -}}
{{- $isPast = false -}}
{{- else -}}
{{- $timing = index . 0 -}}
{{- end -}}
{{- return (dict "timings" $timings "timing" $timing "isPast" $isPast) -}}

View file

@ -0,0 +1,11 @@
{{- $events := dict -}}
{{- range $page := . -}}
{{- range $page.Params.timings -}}
{{- $event := dict "Title" $page.Title "Page" $page.Page "Date" (time.AsTime .starts) "Duration" (partial "iso8601.duration" .duration) -}}
{{- if $event.Date.Before time.Now }}{{ continue }}{{ end -}}
{{- $bundle := $event.Date.Format "2006-01" -}}
{{- $events = merge $events (dict $bundle (sort ((index $events $bundle) | append $event) "Date" "asc")) -}}
{{- break -}}{{/* Only show the first on the list */}}
{{- end -}}
{{- end -}}
{{- return $events -}}

View file

@ -1,9 +1,9 @@
{{- $url := .url -}}
{{- $title := .Title -}}
{{- $isExternal := strings.HasPrefix $url "http" -}}
{{- $text := .Text -}}
{{- $text := .Text | default $url -}}
{{/* It pains me that Hugo doesn't have a urls.IsValid method, and has no error catching to allow me to try urls.Parse and catch failures */}}
{{- if gt (len (strings.FindRE `^https?:\/\/[A-z0-9_-]*?[:]?[A-z0-9_-]*?[@]?[A-z0-9]+([\-\.]{1}[a-z0-9]+)*\.[a-z]{2,5}(:[0-9]{1,5})?(\/.*)?$` .Text)) 0 -}}
{{- if gt (len (strings.FindRE `^https?:\/\/[A-z0-9_-]*?[:]?[A-z0-9_-]*?[@]?[A-z0-9]+([\-\.]{1}[a-z0-9]+)*\.[a-z]{2,5}(:[0-9]{1,5})?(\/.*)?$` $text)) 0 -}}
{{- $url := urls.Parse $text -}}
{{- $text = strings.TrimPrefix "www." $url.Hostname -}}
{{- if lt (len $url.Path) 16 -}}

View file

@ -21,8 +21,8 @@ Things I might work on within my personal blog's software.
- [ ] 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
- [x] Calendar page
- [x] Include link, location, date on event page
- [ ] Handle `<details>` in posts (example: ChefGPT)
- [ ] Actually serve it up