Move Work to partial, recurse

This commit is contained in:
Madison Rye Progress
2026-03-12 20:47:06 -07:00
parent 8227fc77e7
commit 457b2454c4
5 changed files with 43 additions and 113 deletions

View File

@ -4,4 +4,4 @@ layout: single
aliases: [stories] aliases: [stories]
--- ---
{{< works >}} {{< works corpus="works" collections="collections" creators="creators" >}}

View File

@ -0,0 +1,36 @@
{{- $work := .work }}
{{- $works := .works }}
{{- $creators := .creators }}
{{- /* This is really ugly, but alas, it is precisely what we need. */ -}}
<dt><a href="{{ $work.url }}">{{ $work.title }}</a> <span class="author">by
{{ range $k, $author := $work.authors }}
{{- if index $creators $author }}<a href="{{ index $creators $author }}" target="_blank">{{ $author | markdownify }}</a>{{ else }}{{ $author | markdownify }}{{ end }}
{{- if ne (add $k 1) ($work.authors | len) }}, {{ end }}
{{- end }}
{{- range $contributor := $work.contributors }},
{{ if index $creators $contributor }}<a href="{{ index $creators $contributor }}" target="_blank">{{ $contributor | markdownify }}</a>{{ else }}{{ $contributor | markdownify }}{{ end }}
<small>(contributor)</small>
{{- end }}
</span></dt>
<dd>
{{ $work.description | markdownify }}
<ul class="meta">
{{- if $work.type }}<li><em>Type:</em> {{ $work.type }}</li>{{- end }}
<li><em>Characters and dates:</em>
{{- range $k, $v := $work.years }}
{{ index $work.characters $k }} — {{ $v }}
{{- if ne (add $k 1) ($work.years | len) }}, {{- end }}
{{- end }}</li>
{{- if $work.cw }}<li><em>CWs:</em> {{ $work.cw }}</li>{{- end }}
{{- if $work.spoilers }}<li><em>Spoilers:</em> {{ $work.spoilers | markdownify }}</li>{{- end }}
</ul>
{{- $subworks := where $works "parent" "eq" $work.title }}
{{- if gt (len $subworks) 0 }}
<h3>Associated works</h3>
<dl>
{{- range $subwork := where $works "parent" "eq" $work.title }}
{{ partial "work.html" (dict "work" $subwork "works" $works "creators" $creators) }}
{{- end }}
</dl>
{{- end }}
</dd>

View File

@ -1,128 +1,22 @@
{{- with hugo.Data.works }} {{- $works := index hugo.Data (.Get "corpus") }}
{{- $works := . }} {{- $collections := index hugo.Data (.Get "collections") }}
{{- $creators := index hugo.Data (.Get "creators") }}
<section class="works"> <section class="works">
<dl> <dl>
{{- range $work := sort (where (where $works "collection" nil) "parent" nil) "title" "asc" }} {{- range $work := sort (where (where $works "collection" nil) "parent" nil) "title" "asc" }}
<dt><a href="{{ $work.url }}">{{ $work.title }}</a> <span class="author">by {{ partial "work.html" (dict "work" $work "works" $works "creators" $creators) }}
{{ range $k, $author := $work.authors }}
{{- if index hugo.Data.creators $author }}<a href="{{ index hugo.Data.creators $author }}" target="_blank">{{ $author | markdownify }}</a>{{ else }}{{ $author | markdownify }}{{ end }}
{{- if ne (add $k 1) ($work.authors | len) }}, {{ end }}
{{- end }}
{{- range $contributor := $work.contributors }},
{{ if index hugo.Data.creators $contributor }}<a href="{{ index hugo.Data.creators $contributor }}" target="_blank">{{ $contributor | markdownify }}</a>{{ else }}{{ $contributor | markdownify }}{{ end }}
<small>(contributor)</small>
{{- end }}
</span></dt>
<dd>
{{ $work.description | markdownify }}
<ul class="meta">
<li><em>Type:</em> {{ $work.type }}</li>
<li><em>Characters and dates:</em>
{{- range $k, $v := $work.years }}
{{ index $work.characters $k }} — {{ $v }}
{{- if ne (add $k 1) ($work.years | len) }}, {{- end }}
{{- end }}</li>
{{- if $work.cw }}<li><em>CWs:</em> {{ $work.cw }}</li>{{- end }}
{{- if $work.spoilers }}<li><em>Spoilers:</em> {{ $work.spoilers | markdownify }}</li>{{- end }}
</ul>
{{- $subworks := where $works "parent" "eq" $work.title }}
{{- if gt (len $subworks) 0 }}
<h3>Associated works</h3>
<dl>
{{- range $subwork := where $works "parent" "eq" $work.title }}
<dt><a href="{{ $subwork.url }}">{{ $subwork.title }}</a> <span class="author">by
{{ range $k, $author := $subwork.authors }}
{{- if index hugo.Data.creators $author }}<a href="{{ index hugo.Data.creators $author }}" target="_blank">{{ $author | markdownify }}</a>{{ else }}{{ $author | markdownify }}{{ end }}
{{- if ne (add $k 1) ($work.authors | len) }}, {{ end }}
{{- end }}
{{- range $contributor := $subwork.contributors }},
{{ if index hugo.Data.creators $contributor }}<a href="{{ index hugo.Data.creators $contributor }}" target="_blank">{{ $contributor | markdownify }}</a>{{ else }}{{ $contributor | markdownify }}{{ end }}
<small>(contributor)</small>
{{- end }}
</span></dt>
<dd>
{{ $subwork.description | markdownify }}
<ul class="meta">
<li><em>Type:</em> {{ $subwork.type }}</li>
<li><em>Characters and dates:</em> <ul>
{{- range $k, $v := $subwork.years }}
<li>{{ index $subwork.characters $k }} — {{ $v }}</li>
{{- end }}
</ul></li>
{{- if $subwork.cw }}<li><em>CWs:</em> {{ $subwork.cw }}</li>{{- end }}
{{- if $subwork.spoilers }}<li><em>Spoilers:</em> {{ $subwork.spoilers | markdownify }}</li>{{- end }}
</ul>
</dd>
{{- end }}
</dl>
{{- end }}
</dd>
{{- end }} {{- end }}
</dl> </dl>
{{- range $collection := hugo.Data.collections }} {{- range $collection := $collections }}
<h2>{{ $collection.title }}</h2> <h2>{{ $collection.title }}</h2>
<dl> <dl>
{{- range $work := where $works "collection" $collection.id }} {{- range $work := where $works "collection" $collection.id }}
<dt><a href="{{ $work.url }}">{{ $work.title }}</a> <span class="author">by {{ partial "work.html" (dict "work" $work "works" $works "creators" $creators) }}
{{ range $k, $author := $work.authors }}
{{- if index hugo.Data.creators $author }}<a href="{{ index hugo.Data.creators $author }}" target="_blank">{{ $author | markdownify }}</a>{{ else }}{{ $author | markdownify }}{{ end }}
{{- if ne (add $k 1) ($work.authors | len) }}, {{ end }}
{{- end }}
{{- range $contributor := $work.contributors }},
{{ if index hugo.Data.creators $contributor }}<a href="{{ index hugo.Data.creators $contributor }}" target="_blank">{{ $contributor | markdownify }}</a>{{ else }}{{ $contributor | markdownify }}{{ end }}
<small>(contributor)</small>
{{- end }}
</span></dt>
<dd>
{{ $work.description | markdownify }}
<ul class="meta">
<li><em>Type:</em> {{ $work.type }}</li>
<li><em>Characters and dates:</em>
{{- range $k, $v := $work.years }}
{{ index $work.characters $k }} — {{ $v }}
{{- if ne (add $k 1) ($work.years | len) }}, {{- end }}
{{- end }}</li>
{{- if $work.cw }}<li><em>CWs:</em> {{ $work.cw }}</li>{{- end }}
{{- if $work.spoilers }}<li><em>Spoilers:</em> {{ $work.spoilers | markdownify }}</li>{{- end }}
</ul>
{{- $subworks := where $works "parent" "eq" $work.title }}
{{- if gt (len $subworks) 0 }}
<h3>Associated works</h3>
<dl>
{{- range $subwork := where $works "parent" "eq" $work.title }}
<dt><a href="{{ $subwork.url }}">{{ $subwork.title }}</a> <span class="author">by
{{ range $k, $author := $subwork.authors }}
{{- if index hugo.Data.creators $author }}<a href="{{ index hugo.Data.creators $author }}" target="_blank">{{ $author | markdownify }}</a>{{ else }}{{ $author | markdownify }}{{ end }}
{{- if ne (add $k 1) ($work.authors | len) }}, {{ end }}
{{- end }}
{{- range $contributor := $subwork.contributors }},
{{ if index hugo.Data.creators $contributor }}<a href="{{ index hugo.Data.creators $contributor }}" target="_blank">{{ $contributor | markdownify }}</a>{{ else }}{{ $contributor | markdownify }}{{ end }}
<small>(contributor)</small>
{{- end }}
</span></dt>
<dd>
{{ $subwork.description | markdownify }}
<ul class="meta">
<li><em>Type:</em> {{ $subwork.type }}</li>
<li><em>Characters and dates:</em> <ul>
{{- range $k, $v := $subwork.years }}
<li>{{ index $subwork.characters $k }} — {{ $v }}</li>
{{- end }}
</ul></li>
{{- if $subwork.cw }}<li><em>CWs:</em> {{ $subwork.cw }}</li>{{- end }}
{{- if $subwork.spoilers }}<li><em>Spoilers:</em> {{ $subwork.spoilers | markdownify }}</li>{{- end }}
</ul>
</dd>
{{- end }}
</dl>
{{- end }}
</dd>
{{- end }} {{- end }}
</dl> </dl>
{{- end }} {{- end }}
</section> </section>
{{- end }}