Moved observation layout and programatically build pages from API

This commit is contained in:
Brandon Rozek 2025-06-10 21:49:29 -04:00
parent 213ffb459d
commit 2217748994
No known key found for this signature in database
GPG key ID: DFB0E78F805F4567
4 changed files with 106 additions and 1 deletions

View file

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

View file

@ -0,0 +1,39 @@
{{ define "main"}}
{{ partial "header.html" . }}
<main>
<style>main { text-align: left; }</style>
{{ $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 }}
<div style="text-align: center; margin-bottom: 2rem;" class='bloglist-teaser block-center'>
Hello! This page contains {{ $postCount | lang.FormatNumber 0 }} observations,
{{ len $tags }} of which are <strong><a href="https://www.inaturalist.org/posts/39072-research-grade">research grade</a></strong>.
</div>
{{ 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 }}
</main>
{{ end }}

View file

@ -0,0 +1,39 @@
{{ define "main"}}
{{ .Scratch.Set "customTitleHeaderSet" true }}
{{ .Scratch.Set "customTitleHeader" "Observations" }}
{{ .Scratch.Set "customTitleHeaderLink" "/observations/" }}
{{ partial "header.html" . }}
<main>
{{ with .Params }}
<article class="h-entry">
{{ $name := "" }}
{{ if (ne .taxon.common_name "") }}
{{ $name = .taxon.common_name }}
{{ else }}
{{ $name = .taxon.name }}
{{ end }}
{{ $obsURL := .url }}
<h1 class='title p-name'>{{ title $name }}</h1>
{{ if (eq .quality_grade "research")}}
<span>Research Grade </span><i class="fa fa-solid fa-clipboard-check"></i></i>
<br/>
{{ end }}
<p class="date">Observed on <time class="dt-published" datetime='{{ .date }}'>{{ dateFormat "January 2, 2006 15:04" (time .date) }}</time></p>
<p>Location: {{ .place_guess }}</p>
<span>Also on: <a class="u-syndication" href="{{ .syndication }}">iNaturalist</a></span>
<div class="e-content">
{{ if gt (len .photos) 0 }}
{{ range .photos}}
{{ $medium_url := replace .url "square" "medium"}}
{{ $original_url := replace .url "square" "original"}}
<a href="{{ $original_url }}"><img src="{{ $medium_url }}" alt="Photo of {{ .species_guess }}"/></a>
{{ end }}
{{ end }}
</div>
<a class="u-url" style="display: none">{{ .Permalink }}</a>
</article>
{{ end }}
</main>
{{ end }}

@ -1 +1 @@
Subproject commit bcbfa17bb4acdde1e439d8a51a565eabe62a78dd
Subproject commit 831dd9e10ae48fd4a6736b2dd0dfd854b28a37df