Move a bunch of shortcodes and partials back from the platters theme

This commit is contained in:
Eryn Wells 2024-10-08 08:45:44 -07:00
parent 20d53e0df2
commit 3102dc1e56
29 changed files with 1 additions and 1 deletions

View file

@ -0,0 +1,6 @@
{{ $nethack_data := $.Site.Data.nethack.logfile }}
{{ $logfile := slice }}
{{ range $nethack_data }}
{{ $logfile = $logfile | append .logfile }}
{{ end }}
{{ return $logfile }}

View file

@ -0,0 +1,48 @@
{{- $cause := .death.cause -}}
{{- $didAscend := eq $cause "ascended" -}}
{{- $level := (cond (gt .dungeon.level.n 0) (.dungeon.level.descriptive | lower) .dungeon.level.descriptive) -}}
<div>{{- if $didAscend -}}✨{{- else -}}🪦{{- end -}}</div>
<h4 class="date">{{ time.Format "January 2, 2006" .end_date }}</h4>
<div class="character-descriptor">{{ .character.abbreviated }}</div>
<p>
{{- $name := .character.name -}}
{{- $descriptiveAlignment := .character.alignment.descriptive | lower -}}
{{- $descriptiveRace := .character.race.descriptive | lower -}}
{{- $descriptiveRole := .character.role.descriptive -}}
{{- if $didAscend -}}
{{ $name }}, a {{ $descriptiveAlignment }} {{ $descriptiveRace }} {{ $descriptiveRole }}, ascended.
{{- else -}}
{{ $name }}, a {{ $descriptiveAlignment }} {{ $descriptiveRace }} {{ $descriptiveRole }}, died
{{ if gt .death.count 1 -}}for the last time{{- end }} in
<span class="nobreak">{{ .dungeon.name }}</span>
on <span class="nobreak">{{ $level }}</span>.
She was {{ .death.cause }}.
{{- end -}}
</p>
<table class="stats">
<tr>
{{- $startDate := time.Format "January, 02 2006" .start_date -}}
{{- $startDatetime := time.Format "2006-01-02" .start_date -}}
<td class="began">Began <time class="nobreak" datetime="{{ $startDatetime }}">{{ $startDate }}</time></td>
<td class="score">{{ .score | lang.FormatNumber 0 }} points</td>
{{/*
When I first wrote the importer script, I read about the log file
format on the Nethackwiki. It labeled a field as "maximum level",
which I interpreted as maximum character level. Turns out it's
actually maximum *dungeon* level. The script has been updated, but I
won't be able to update all the imported logfiles.
https://nethackwiki.com/wiki/Logfile
*/}}
{{ with .dungeon.max_level }}
<td class="level">{{ .descriptive }}</td>
{{ else }}
{{ with .character.max_level }}<td class="level">Level {{ . }}</td>{{ end }}
{{ end }}
<td class="hp">
{{- $hp := float .character.hp.n -}}
{{- $hpMax := .character.hp.max -}}
{{- if gt $hp 0 }}{{ $hp }} / {{ $hpMax }}{{ else }}{{ $hp }}{{ end }} hp
</td>
</tr>
</table>

View file

@ -0,0 +1,66 @@
<div class="photo-params">
<div class="container">
<table>
{{ if and .Tags.Make .Tags.Model }}
<thead>
<td class="make-model" colspan=4>
{{- $make := .Tags.Make -}}
{{- $model := .Tags.Model -}}
{{- if in $model $make -}}
{{ .Tags.Model }}
{{- else -}}
{{ .Tags.Make }} {{ .Tags.Model }}
{{- end -}}
</td>
</thead>
{{ end }}
{{ with .Tags.LensModel }}
<tr>
<td colspan=4 class="lens">{{ . }}</td>
</tr>
{{ end }}
<tr>
{{- $hasLocation := and .Lat .Long -}}
{{ if $hasLocation -}}
<td colspan=2 class="location">
{{ $lat := float .Lat }}{{ $latDir := cond (eq $lat 0) "" (cond (gt $lat 0) "N" "S") }}
<data class="latitude" value="{{ $lat }}">{{ .Lat | lang.FormatNumber (cond (ne $lat 0) 3 0) }}º{{ $latDir }}</data>,
{{ $long := float .Long }}{{ $longDir := cond (eq $long 0) "" (cond (gt $long 0) "E" "W") }}
<data class="longitude" value="{{ $long }}">{{ .Long | lang.FormatNumber (cond (ne $long 0) 3 0) }}º{{ $longDir }}</data>
</td>
{{- end -}}
{{ if and .Tags.PixelXDimension .Tags.PixelYDimension -}}
<td colspan={{ if $hasLocation }}2{{ else }}4{{ end }} class="size">
{{- $widthpx := .Tags.PixelXDimension -}}
{{- $heightpx := .Tags.PixelYDimension -}}
{{- if and (gt $widthpx 0) (gt $heightpx 0) -}}
{{- $megapixels := div (mul $widthpx $heightpx) 1e6 -}}
<data class="megapixels nobreak" value="{{ $megapixels }}">{{ $megapixels | lang.FormatNumber 0 }} MP</data>
<span class="nobreak"><data class="width">{{ $widthpx }}</data> × <data class="height">{{ $heightpx }}</data></span>
{{- end -}}
</td>
{{ end }}
</tr>
{{ if or .Tags.ISOSpeedRatings .Tags.FocalLengthIn35mmFilm .Tags.FNumber .Tags.ExposureTime }}
<tr class="exposure-attributes">
<td class="iso">{{ with .Tags.ISOSpeedRatings }}ISO {{ . }}{{ end }}</td>
<td class="focal-length">
{{- $focalLength := .Tags.FocalLengthIn35mmFilm | default .Tags.FocalLength -}}
{{- with $focalLength -}}{{ . }} mm{{- end -}}
</td>
<td class="f-number">{{ with .Tags.FNumber }}{{ printf "ƒ%0.1f" . }}{{ end }}</td>
<td class="exposure-time">
{{- with $exposureTime := .Tags.ExposureTime -}}
{{- if in $exposureTime "/" -}}
{{ . }} s
{{- else -}}
1/{{ printf "%.0f" (div 1.0 (float $exposureTime)) }} s
{{- end -}}
{{- end -}}
</td>
</tr>
{{ end }}
</table>
</div>
</div>

View file

@ -0,0 +1,9 @@
{{ $thumbnailResourcesNames := slice "thumbnail" "Thumbnail" "thumbnail.jpg" "Thumbnail.jpg" }}
{{ with index .Params "thumbnail" }}
{{ $thumbnailResourcesNames = $thumbnailResourcesNames | append . }}
{{ end }}
{{ $imageResources := .Resources.ByType "image" }}
{{ $photos := where $imageResources "Name" "not in" $thumbnailResourcesNames }}
{{ return $photos }}

View file

@ -0,0 +1,50 @@
{{/*
Renders a photo thumbnail. If neither a target height or target width are
given, and the image is already in the correct orientation, no image
processing is performed.
Arguments
---------
"Page" : A reference to the current Page
"Height" : The target height of the image
"Width" : The target width of the image
Returns
-------
The processed thumbnail image resource
*/}}
{{- $thumbnailResource := .Page.Resources.GetMatch
(index .Page.Params "thumbnail" | default "[tT]humbnail*")
| default (index (.Page.Resources.ByType "image") 0) -}}
{{- if not $thumbnailResource -}}
{{- errorf "No thumbnail available for %s" .Page.Permalink }}
{{- end -}}
{{ $orientation := partial "image-utilities/orientation-angle.html" $thumbnailResource }}
{{ $targetWidth := 0 }}
{{ with .Width }}
{{ $targetWidth = . }}
{{ else }}
{{ $targetWidth = $thumbnailResource.Width }}
{{ end }}
{{ $targetHeight := 0 }}
{{ with .Height }}
{{ $targetHeight = . }}
{{ else }}
{{ $targetHeight = $thumbnailResource.Height }}
{{ end }}
{{ $thumbnail := false }}
{{ if not (and (eq $orientation 0)
(eq $targetWidth $thumbnailResource.Width)
(eq $targetHeight $thumbnailResource.Height)) }}
{{ $thumbnail = $thumbnailResource.Fit (printf "%dx%d r%d" $targetWidth $targetHeight (sub 360 $orientation)) }}
{{ else }}
{{ $thumbnail = $thumbnailResource }}
{{ end }}
{{ return $thumbnail }}

View file

@ -0,0 +1 @@
<abbr {{ with .Get "title" }}title="{{ . }}"{{ end }}>{{ .Inner }}</abbr>

View file

@ -0,0 +1 @@
<span class="anagram" data-replacement="{{ with .Get 1 }}{{ . }}{{ end }}">{{ with .Get 0 }}{{ . }}{{ end }}</span>

View file

@ -0,0 +1,5 @@
{{ $id := .Get "id" }}
{{ $mp3 := (.Page.Resources.GetMatch (.Get "mp3")) }}
<audio {{ with $id }}id="{{ . }}"{{ end }}>
{{ with $mp3 }}<source src="{{ . }}" type="audio/mpeg">{{ end }}
</audio>

View file

@ -0,0 +1,9 @@
<!---->{{ if not (.Get "summary") }}
<!---->{{ errorf "missing param 'summary': %s" .Position }}
<!---->{{ else if not (.Get "content") }}{{ warnf "missing param 'content': %s" .Position }}
<!---->{{ end }}
<details {{ if (eq (.Get `openByDefault`) true) }}open="true" {{ end }}>
<summary markdown="span">{{ .Get "summary" | markdownify }}</summary>
{{ .Get "content" | markdownify }}
</details>

View file

@ -0,0 +1,4 @@
{{- $trimmedInner := trim .Inner "\n " -}}
<figure class="code">
{{ $.Page.RenderString $trimmedInner }}
</figure>

View file

@ -0,0 +1,45 @@
{{- $imgs := slice -}}
{{- $class := .Get "class" -}}
{{- $shouldResize := .Get "shouldResize" | default true -}}
{{- $shouldShowTitle := (.Get "shouldShowTitle") | default true -}}
{{- if .Get "name" -}}
{{- $imgs = $imgs | append (.Page.Resources.GetMatch (.Get "name")) -}}
{{- else if .Get "names" -}}
{{- range (split (.Get "names") ",") -}}
{{- $imgs = $imgs | append ($.Page.Resources.GetMatch .) -}}
{{- end -}}
{{- else -}}
{{ errorf "Missing name or names parameter to figures/image" }}
{{- end -}}
{{- if lt (len $imgs) 0 -}}
{{ errorf "No images found for name(s) parameter" }}
{{- end -}}
<figure {{ with $class }}class="{{ . }}"{{ end }}>
<div class=container>
{{ range $img := $imgs }}
{{- $linkedImg := $img -}}
{{ if not $img }}
{{ errorf "Found nil in images list for %s" $.Page.Permalink }}
{{ end }}
{{- if $shouldResize -}}
{{ $linkedImg = $img.Fit "1280x1280" }}
{{- end -}}
{{- $altText := $img.Params.alt | default $img.Title -}}
<a href="{{ $img.RelPermalink }}">
<img src="{{ $linkedImg.RelPermalink }}"
{{- with $altText }} alt="{{ . }}"{{- end }}
{{- with $img.Title }} title="{{ . }}"{{- end }}>
</a>
{{- end }}
</div>
{{ if and $shouldShowTitle -}}
{{- range $imgs -}}
{{- if gt (len .Title) 0 -}}
<figcaption>{{ .Title }}</figcaption>
{{- end -}}
{{- end -}}
{{- end }}
</figure>

View file

@ -0,0 +1,4 @@
{{- $id := .Get "id" -}}
<div class="centered">
<figure class="p5-sketch {{ with .Get "bordered" }}bordered{{ end }}" id="{{ $id }}"></figure>
</div>

View file

@ -0,0 +1,3 @@
{{- $id := .Get "id" -}}
<figure class="railroad-diagram" {{ if $id }}id="{{ $id }}"{{ end }}></figure>
{{ .Inner }}

View file

@ -0,0 +1,12 @@
{{- $pc := .Page.Site.Config.Privacy.YouTube -}}
{{- if not $pc.Disable -}}
{{- $ytHost := cond $pc.PrivacyEnhanced "www.youtube-nocookie.com" "www.youtube.com" -}}
{{- $id := .Get "id" | default (.Get 0) -}}
{{- $class := .Get "class" | default (.Get 1) -}}
{{- $title := .Get "title" | default "YouTube Video" }}
<figure {{ with $class }}class="{{ . }}"{{ end }}>
<div class="youtube">
<iframe src="https://{{ $ytHost }}/embed/{{ $id }}{{ with .Get "autoplay" }}{{ if eq . "true" }}?autoplay=1{{ end }}{{ end }}" allowfullscreen frameborder=0 title="{{ $title }}"></iframe>
</div>
</figure>
{{ end -}}

View file

@ -0,0 +1,3 @@
<div class="grid2">
{{ .Inner }}
</div>

View file

@ -0,0 +1,21 @@
{{ $img := dict }}
{{ with .Get "name" }}
{{ $img = $.Page.Resources.GetMatch . }}
{{ else }}
{{ errorf "No name given to img shortcode" }}
{{ end }}
{{/* Space separated list of classes to apply to the <img> tag */}}
{{ $classes := .Get "class" }}
{{ $altText := .Get "alt" | default $img.Params.alt }}
{{ if not $altText }}
{{ warnf "Image doesn't have alt text: %s" $img.RelPermalink }}
{{ end }}
{{ $resizedImg := $img.Fit "1280x1280" }}
<img src="{{ $resizedImg.RelPermalink }}"
width="{{ $resizedImg.Width }}"
height="{{ $resizedImg.Height }}"
alt="{{ $altText }}"
{{ with $classes }}class="{{ . }}"{{ end }}>

View file

@ -0,0 +1 @@
<span lang="{{ .Get 0 }}">{{ .Inner }}</span>{{- "" -}}

View file

@ -0,0 +1,3 @@
{{- $logfile := partial "nethack/log.html" . -}}
{{- $numberOfAscensions := where $logfile "death.cause" "ascended" | len -}}
{{- $numberOfAscensions | lang.FormatNumber 0 -}}

View file

@ -0,0 +1,10 @@
{{ $nethack_data := $.Site.Data.nethack.logfile }}
{{ $logfile := slice }}
{{ range $nethack_data }}
{{ $logfile = $logfile | append .logfile }}
{{ end }}
<ol class="logfile">
<li>
{{ partial "nethack/logentry.html" (index (sort $logfile "score" "desc") 0) }}
</li>
</ol>

View file

@ -0,0 +1,10 @@
{{- $logfile := partial "nethack/log.html" . -}}
<ol class="logfile">
{{ range sort $logfile "end_date" "desc" }}
{{ if ne .death.cause "quit" }}
<li>
{{ partial "nethack/logentry.html" .}}
</li>
{{ end }}
{{ end }}
</ol>

View file

@ -0,0 +1,2 @@
{{- $numberOfEntries := (partial "nethack/log.html" .) | len -}}
{{- $numberOfEntries | lang.FormatNumber 0 -}}

View file

@ -0,0 +1,7 @@
{{- $n := .Get 0 -}}
{{- $logfile := partial "nethack/log.html" . -}}
<ol class="logfile topn">
{{ range first $n (sort $logfile "score" "desc") -}}
<li>{{ partial "nethack/logentry.html" . }}</li>
{{- end }}
</ol>

View file

@ -0,0 +1,9 @@
{{- with $photoPage := $.Page.GetPage (printf "photos/%s" (.Get 0)) -}}
{{- $thumbnail := partial "photos/thumbnail.html" (dict "Page" . "Width" 1280 "Height" 1280) -}}
{{- $altText := $thumbnail.Params.alt | default .Title -}}
<a class="to-photo-post" href="{{ .RelPermalink }}" title="{{ .Title }}">
<img src="{{ $thumbnail.RelPermalink }}"{{ with $altText }} alt="{{ . }}"{{ end }}>
</a>
{{- else -}}
{{- errorf "No page matching '%s'" (.Get 0) -}}
{{- end -}}

View file

@ -0,0 +1,3 @@
{{- $subreddit := .Get 0 -}}
<a class="hover-only" href="https://reddit.com/r/{{ $subreddit }}"><code class="nobg">r/{{ $subreddit }}</code></a>
{{- "" -}}

View file

@ -0,0 +1,27 @@
<ul>
{{ $pages := union .Site.RegularPages .Site.Sections }}
{{ if .Page.IsHome }}
{{ $pages = where site.RegularPages "Type" "in" site.Params.mainSections }}
{{ end }}
{{ $paginator := .Page.Paginate $pages }}
{{ range $index, $page := $paginator.Pages }}
<li>
<a href="{{ .Permalink }}">{{ .Title }}</a>
<time datetime="{{ .Date.Format "2006-01-02" }}">{{ .Date | time.Format ":date_medium" }}</time>
{{ if $page.Draft }}
<span class="draft">draft</span>
{{ end }}
</li>
{{ end }}
</ul>
{{ if gt $paginator.TotalPages 1 }}
<nav class="main-nav">
{{ if $paginator.HasPrev }}
<a class="prev" href="{{ $paginator.Prev.URL }}">← {{ i18n "prev_page" }}</a>
{{ end }}
{{ if $paginator.HasNext }}
<a class="next" href="{{ $paginator.Next.URL }}">{{ i18n "next_page" }} →</a>
{{ end }}
</nav>
{{ end }}

View file

@ -0,0 +1,18 @@
<header class="flex-date">
{{ .Inner }}
<span class="date">
{{ if .IsNamedParams }}
{{ with .Get "from" }}
<time datetime="{{ . }} ">{{ . }}</time>
{{ end }}
to
{{ with .Get "to" }}
<time datetime="{{ . }}">{{ . }}</time>
{{ else }}
present
{{ end }}
{{ else }}
{{ .Get 0 }}
{{ end }}
</span>
</header>

View file

@ -0,0 +1,14 @@
<header class="flex-date">
<h3>{{ .Get "company" }}: {{ .Get "team" }}</h3>
<span class="date">
{{ with .Get "from" }}
<time datetime="{{ . }} ">{{ . }}</time>
{{ end }}
{{ with .Get "to" }}
<time datetime="{{ . }}">{{ . }}</time>
{{ else }}
present
{{ end }}
</span>
</header>

View file

@ -0,0 +1 @@
<ruby {{ with .Get 1 }}lang="{{ . }}"{{ end }}><span>{{- .Inner }}</span> <rp>(</rp><rt {{ with .Get 2 }}lang="{{ . }}"{{ end }}>{{- .Get 0 -}}</rt><rp>)</rp></ruby>{{- "" -}}

View file

@ -0,0 +1,3 @@
<section {{ with .Get "class" }}class="{{ . }}"{{ end }}>
{{ .Inner }}
</section>