From 22177489945cfc9f2664e5a1f1a171c249d3502f Mon Sep 17 00:00:00 2001 From: Brandon Rozek Date: Tue, 10 Jun 2025 21:49:29 -0400 Subject: [PATCH] Moved observation layout and programatically build pages from API --- content/observations/_content.gotmpl | 27 +++++++++++++++++++ layouts/observations/list.html | 39 ++++++++++++++++++++++++++++ layouts/observations/single.html | 39 ++++++++++++++++++++++++++++ themes/pulp | 2 +- 4 files changed, 106 insertions(+), 1 deletion(-) create mode 100644 content/observations/_content.gotmpl create mode 100644 layouts/observations/list.html create mode 100644 layouts/observations/single.html diff --git a/content/observations/_content.gotmpl b/content/observations/_content.gotmpl new file mode 100644 index 0000000..940c2cf --- /dev/null +++ b/content/observations/_content.gotmpl @@ -0,0 +1,27 @@ +{{/* Get remote data. */}} +{{ $items := dict }} +{{ $url := "https://api.brandonrozek.com/observations" }} +{{ with try (resources.GetRemote $url ) }} + {{ with .Err }} + {{ errorf "Unable to get remote resource %s: %s" $url . }} + {{ else with .Value }} + {{ $items = . | transform.Unmarshal }} + {{ else }} + {{ errorf "Unable to get remote resource %s" $url }} + {{ end }} +{{ end }} + +{{ range $items.observations }} + {{ $dates := dict "date" (time.AsTime .created_at) }} + {{ $params := . }} + {{ $page := dict + "content" (dict "mediaType" "text/markdown" "value" "") + "dates" $dates + "kind" "page" + "params" $params + "path" .id + "title" "" + "build" (dict "render" "never") + }} + {{ $.AddPage $page }} +{{ end }} \ No newline at end of file diff --git a/layouts/observations/list.html b/layouts/observations/list.html new file mode 100644 index 0000000..b2accaa --- /dev/null +++ b/layouts/observations/list.html @@ -0,0 +1,39 @@ +{{ define "main"}} + {{ partial "header.html" . }} +
+ + {{ $posts := where site.RegularPages "Type" "observations" }} + {{ $postCount := len $posts }} + {{ range last 1 $posts }} + {{ $scratch := newScratch }} + {{ $scratch.Set "researchGradeCount" 0 }} + {{ range .Pages }} + {{ if (eq .quality_grade "research")}} + {{ $scratch.Add "researchGradeCount" 1 }} + {{ end }} + {{ end }} + {{ $tags := .Site.Taxonomies.tags }} +
+ Hello! This page contains {{ $postCount | lang.FormatNumber 0 }} observations, + {{ len $tags }} of which are research grade. +
+ {{ end }} + {{ .Content }} + {{ $listPageDateFormat := .Site.Params.listPageDateFormat | default "January, 2006"}} + {{ range $index, $value := .Pages.GroupByDate $listPageDateFormat }} + {{ range .Pages }} + {{ $dataJ := dict "created_at" .Date + "url" .Params.syndication + "quality_grade" .Params.quality_grade + "place_guess" .Params.place_guess + "photos" .Params.photos + "taxon" .Params.taxon + }} + + {{ .Scratch.Set "obs" $dataJ }} + {{ .Scratch.Set "obs_url" .Permalink }} + {{ partial "external/inat.html" . }} + {{ end }} + {{ end }} +
+{{ end }} diff --git a/layouts/observations/single.html b/layouts/observations/single.html new file mode 100644 index 0000000..315d2c6 --- /dev/null +++ b/layouts/observations/single.html @@ -0,0 +1,39 @@ +{{ define "main"}} +{{ .Scratch.Set "customTitleHeaderSet" true }} +{{ .Scratch.Set "customTitleHeader" "Observations" }} +{{ .Scratch.Set "customTitleHeaderLink" "/observations/" }} +{{ partial "header.html" . }} +
+ {{ with .Params }} + +
+ {{ $name := "" }} + {{ if (ne .taxon.common_name "") }} + {{ $name = .taxon.common_name }} + {{ else }} + {{ $name = .taxon.name }} + {{ end }} + {{ $obsURL := .url }} +

{{ title $name }}

+ {{ if (eq .quality_grade "research")}} + Research Grade +
+ {{ end }} +

Observed on

+

Location: {{ .place_guess }}

+ Also on: iNaturalist + +
+ {{ if gt (len .photos) 0 }} + {{ range .photos}} + {{ $medium_url := replace .url "square" "medium"}} + {{ $original_url := replace .url "square" "original"}} + Photo of {{ .species_guess }} + {{ end }} + {{ end }} +
+ +
+ {{ end }} +
+{{ end }} diff --git a/themes/pulp b/themes/pulp index bcbfa17..831dd9e 160000 --- a/themes/pulp +++ b/themes/pulp @@ -1 +1 @@ -Subproject commit bcbfa17bb4acdde1e439d8a51a565eabe62a78dd +Subproject commit 831dd9e10ae48fd4a6736b2dd0dfd854b28a37df