refactor: split single header and meta components into partials
This commit is contained in:
parent
d0577aec91
commit
e6889cabba
22 changed files with 742 additions and 406 deletions
43
layouts/partials/single/main-header.html
Normal file
43
layouts/partials/single/main-header.html
Normal file
|
@ -0,0 +1,43 @@
|
|||
{{- /*
|
||||
Displays the header information for an item.
|
||||
|
||||
@params pc Page context
|
||||
@params sc Site context
|
||||
*/
|
||||
-}}
|
||||
|
||||
|
||||
<!-- Validation -->
|
||||
|
||||
{{- if ( not ( isset . "sc" ) ) -}}
|
||||
{{- errorf "No site context received" -}}
|
||||
{{- end -}}
|
||||
|
||||
{{- if ( not ( isset . "pc" ) ) -}}
|
||||
{{- errorf "No page context received (%q)" .sc.Page.File.Dir -}}
|
||||
{{- end -}}
|
||||
|
||||
|
||||
<!-- Rendering -->
|
||||
|
||||
<header class="site-content__header">
|
||||
{{ if .pc.Params.series }}
|
||||
{{ partial "single/main-header/series.html" ( dict "series" ( .pc.GetTerms "series" ) ) }}
|
||||
{{ end }}
|
||||
|
||||
{{ partial "single/main-header/item-tile.html" ( dict "pc" .pc "sc" .sc ) }}
|
||||
|
||||
{{ partial "single/main-header/word-count.html" ( dict "wordCount" .pc.FuzzyWordCount ) }}
|
||||
|
||||
{{ partial "single/main-header/dates.html" ( dict "publishDate" .pc.PublishDate "lastmodDate" .pc.Lastmod ) }}
|
||||
|
||||
{{ partial "single/main-header/authors.html" ( dict "authors" .pc.Params.authors "site_author" .sc.Site.Params.Author ) }}
|
||||
|
||||
{{ partial "single/main-header/warnings.html" ( dict "pc" .pc ) }}
|
||||
|
||||
{{ with .pc.Params.notes }}
|
||||
{{ partial "single/main-header/notes.html" ( dict "notes" . "sc" $.sc ) }}
|
||||
{{ end }}
|
||||
|
||||
{{ partial "single/main-header/toc.html" ( dict "toc" .pc.TableOfContents "fileDir" .sc.Page.File.Dir "appendices" .pc.Params.appendices ) }}
|
||||
</header>
|
23
layouts/partials/single/main-header/authors.html
Normal file
23
layouts/partials/single/main-header/authors.html
Normal file
|
@ -0,0 +1,23 @@
|
|||
{{- /*
|
||||
Renders the authors for an item.
|
||||
|
||||
@params authors The item's author(s).
|
||||
@params sc The site context.
|
||||
*/ -}}
|
||||
|
||||
<p style="display: none">Author{{ with .authors }}s{{ end }}:
|
||||
{{- with .authors -}}
|
||||
</p>
|
||||
<ul>
|
||||
{{- range . -}}
|
||||
{{- if ( eq . $.site_author.name ) -}}
|
||||
<li><p><a class="p-author" itemprop="author" rel="author" href="{{ $.sc.Site.Home.Permalink }}">{{ $.sc.Site.Params.Author.name }}</a></p></li>
|
||||
{{- else -}}
|
||||
<li><p class="p-author" itemprop="author">{{- . -}}</p></li>
|
||||
{{- end -}}
|
||||
{{- end -}}
|
||||
</ul>
|
||||
{{- else -}}
|
||||
<a class="p-author" itemprop="author" rel="author" href="{{ $.sc.Site.Home.Permalink }}">{{ $.sc.Site.Params.Author.name }}</a>
|
||||
{{- end -}}
|
||||
</p>
|
58
layouts/partials/single/main-header/dates.html
Normal file
58
layouts/partials/single/main-header/dates.html
Normal file
|
@ -0,0 +1,58 @@
|
|||
{{- /*
|
||||
Displays dates for an item.
|
||||
|
||||
@params publishDate The date an item was published.
|
||||
@params lastmodDate The date an item was last modified.
|
||||
*/
|
||||
-}}
|
||||
|
||||
{{ $publishDate := .publishDate }}
|
||||
{{ $lastmodDate := .lastmodDate }}
|
||||
|
||||
|
||||
<p class="article-header__publish-date">
|
||||
Published:
|
||||
<time
|
||||
class="dt-published"
|
||||
datetime="{{ $publishDate | time.Format "2006-01-02T15:04:05-07:00" }}"
|
||||
itemprop="datePublished"
|
||||
>{{- $publishDate.Format "January 2" -}}<sup
|
||||
>{{- if in (slice 1 21 31) $publishDate.Day -}}
|
||||
st
|
||||
{{- else if in (slice 2 22) $publishDate.Day -}}
|
||||
nd
|
||||
{{- else if in (slice 3 23) $publishDate.Day -}}
|
||||
rd
|
||||
{{- else -}}
|
||||
th
|
||||
{{- end -}} </sup
|
||||
>, 1{{- $publishDate.Format "2006" | lang.FormatNumberCustom 0 }} <abbr
|
||||
style="font-variant: small-caps; font-size: 0.8em;"
|
||||
title="Holocene Era"
|
||||
>HE</abbr
|
||||
></time
|
||||
>
|
||||
</p>
|
||||
|
||||
<p class="article-header__modified-date">
|
||||
Last modified:
|
||||
<time
|
||||
class="dt-updated"
|
||||
datetime="{{ $lastmodDate | time.Format "2006-01-02T15:04:05-07:00" }}"
|
||||
itemprop="dateModified"
|
||||
>{{- $lastmodDate.Format "January 2" -}}<sup>{{- if in (slice 1 21 31) $lastmodDate.Day -}}
|
||||
st
|
||||
{{- else if in (slice 2 22) $lastmodDate.Day -}}
|
||||
nd
|
||||
{{- else if in (slice 3 23) $lastmodDate.Day -}}
|
||||
rd
|
||||
{{- else -}}
|
||||
th
|
||||
{{- end -}}</sup>,
|
||||
1{{- $lastmodDate.Format "2006" | lang.FormatNumberCustom 0 }} <abbr
|
||||
style="font-variant: small-caps; font-size: 0.8em;"
|
||||
title="Holocene Era"
|
||||
>HE</abbr
|
||||
></time
|
||||
>
|
||||
</p>
|
70
layouts/partials/single/main-header/item-tile.html
Normal file
70
layouts/partials/single/main-header/item-tile.html
Normal file
|
@ -0,0 +1,70 @@
|
|||
{{- /*
|
||||
Renders the header tile for an item.
|
||||
|
||||
@params pc The page context.
|
||||
@params sc The site context.
|
||||
*/ -}}
|
||||
|
||||
{{- if ( not ( isset . "sc" ) ) -}}
|
||||
{{- errorf "No site context received" -}}
|
||||
{{- end -}}
|
||||
|
||||
{{- if ( not ( isset . "pc" ) ) -}}
|
||||
{{- errorf "No page context received (%q)" .sc.Page.File.Dir -}}
|
||||
{{- end -}}
|
||||
|
||||
{{ with .pc.Params.featured_image }}
|
||||
<img class="u-photo" style="display: none;" src="
|
||||
{{- with ( $.pc.Resources.GetMatch . ) -}}
|
||||
{{ partialCached "images/get-image.html" ( dict "img" . ) . }}
|
||||
{{- else -}}
|
||||
{{- . -}}
|
||||
{{- end -}}
|
||||
"
|
||||
itemprop="image"
|
||||
{{- with ( $.pc.Resources.GetMatch . ) -}}
|
||||
alt="{{ .Params.alt }}"
|
||||
{{- end -}}
|
||||
/>
|
||||
{{ end }}
|
||||
|
||||
<div class="article-header__featured-image"
|
||||
{{ with .pc.Params.featured_image }}
|
||||
{{ with ( $.pc.Resources.GetMatch . ) }}
|
||||
style="background-image: url({{ partialCached "images/get-image.html" ( dict "img" . ) . }})"
|
||||
{{ else }}
|
||||
style="background-image: url({{ . }})"
|
||||
{{ end }}
|
||||
{{ end -}}
|
||||
>
|
||||
|
||||
<div class="article-header__title-wrapper">
|
||||
<a class="u-url u-uid" style="display: none" href="{{ .pc.Permalink }}"></a>
|
||||
<hgroup class="p-name" itemprop="name">
|
||||
<h2 class="article-header__title{{ if gt ( len ( .pc.Title | plainify ) ) 40 }} article-header__title--long{{ end }}">
|
||||
{{- .pc.Title | safeHTML -}}
|
||||
</h2>
|
||||
{{ with .pc.Params.subtitle }}
|
||||
<p class="article-header__subtitle">{{ . | safeHTML }}</p>
|
||||
{{ end }}
|
||||
</hgroup>
|
||||
</div>
|
||||
|
||||
{{ with ( .pc.Resources.GetMatch .pc.Params.featured_image ) }}
|
||||
<p class="attr">
|
||||
{{- with .Params.attrlink -}}<a href="{{ . }}" target="_blank" rel="noopener">{{- end -}}
|
||||
{{- .Params.attr | safeHTML -}}
|
||||
{{- if .Params.attrlink -}}</a>{{- end -}}
|
||||
{{- if .Params.attrlicence }} (
|
||||
{{- with .Params.attrlicencelink -}}
|
||||
<a href="{{ . }}" target="_blank" rel="noopener">
|
||||
{{- end -}}
|
||||
{{- .Params.attrlicence -}}
|
||||
{{- if .Params.attrlicencelink -}}
|
||||
</a>
|
||||
{{- end -}}
|
||||
)
|
||||
{{- end -}}
|
||||
<p>
|
||||
{{ end }}
|
||||
</div>
|
16
layouts/partials/single/main-header/notes.html
Normal file
16
layouts/partials/single/main-header/notes.html
Normal file
|
@ -0,0 +1,16 @@
|
|||
{{- /*
|
||||
Renders the notes for an item.
|
||||
|
||||
@params note The notes for an item.
|
||||
@params sc Site context.
|
||||
*/
|
||||
-}}
|
||||
|
||||
|
||||
<aside class="article-header__notes">
|
||||
<ul>
|
||||
{{ range .notes }}
|
||||
<li>{{ . | $.sc.RenderString | safeHTML }}</li>
|
||||
{{ end }}
|
||||
</ul>
|
||||
</aside>
|
18
layouts/partials/single/main-header/series.html
Normal file
18
layouts/partials/single/main-header/series.html
Normal file
|
@ -0,0 +1,18 @@
|
|||
{{- /*
|
||||
Renders the series of an item.
|
||||
|
||||
@params series A list of series' for the item.
|
||||
*/
|
||||
-}}
|
||||
|
||||
|
||||
<p class="article-header__series">
|
||||
Part of series:
|
||||
{{ range .series }}
|
||||
<a
|
||||
class="u-url"
|
||||
href="{{ .RelPermalink }}"
|
||||
>{{ .LinkTitle }}</a
|
||||
>
|
||||
{{ end }}
|
||||
</p>
|
34
layouts/partials/single/main-header/toc.html
Normal file
34
layouts/partials/single/main-header/toc.html
Normal file
|
@ -0,0 +1,34 @@
|
|||
{{- /*
|
||||
Renders appendices and corrigenda for an item.
|
||||
|
||||
@params toc The page ToC.
|
||||
@params appendices The item's appendices. Optional.
|
||||
@params fileDir The file folder name.
|
||||
*/
|
||||
-}}
|
||||
|
||||
{{ $empty_toc_html := "<nav id=\"TableOfContents\"></nav>" }}
|
||||
|
||||
{{ if and ( .toc ) ( ne .toc $empty_toc_html ) }}
|
||||
<nav class="article-header__table-of-contents">
|
||||
<h3 class="article-header__subtitle">Table of Contents</h3>
|
||||
{{ .toc }}
|
||||
{{- if fileExists ( path.Join .fileDir "appendices.md" ) -}}
|
||||
<ul class="toc-list--appendices">
|
||||
<li>
|
||||
<a href="#appendices">Appendices</a>
|
||||
<ol>
|
||||
{{ range .appendices }}
|
||||
<li><a href="#{{ . | anchorize }}">{{ . | safeHTML }}</a></li>
|
||||
{{ end }}
|
||||
</ol>
|
||||
</li>
|
||||
</ul>
|
||||
{{- end -}}
|
||||
{{- if fileExists ( path.Join .fileDir "corrigenda.md" ) -}}
|
||||
<ul class="toc-list--corrigenda">
|
||||
<li><a href="#corrigenda">Corrigenda</a></li>
|
||||
</ul>
|
||||
{{- end -}}
|
||||
</nav>
|
||||
{{ end }}
|
33
layouts/partials/single/main-header/warnings.html
Normal file
33
layouts/partials/single/main-header/warnings.html
Normal file
|
@ -0,0 +1,33 @@
|
|||
{{- /*
|
||||
Renders the automatic warnings for an item.
|
||||
|
||||
@params pc The page context.
|
||||
*/
|
||||
-}}
|
||||
|
||||
{{ $post_age_in_years := math.Round ( div ( div ( now.Sub .pc.PublishDate ).Hours 24 ) 365 ) }}
|
||||
|
||||
{{ if ( or .pc.Params.site .pc.Params.controversial ( gt $post_age_in_years 2 ) ) }}
|
||||
<aside class="article-header__warnings">
|
||||
<ul>
|
||||
{{ if ( gt $post_age_in_years 2 ) }}
|
||||
<li>
|
||||
This piece was written <strong>over {{ $post_age_in_years }} years ago</strong>. It may no longer accurately reflect my views now,
|
||||
or may be factually outdated.
|
||||
</li>
|
||||
{{ end }}
|
||||
{{ if .pc.Params.controversial }}
|
||||
<li>
|
||||
This piece has been marked as potentially <strong>controversial</strong>, whether due to the topic addressed, the content of the
|
||||
article, or both. Don't say you weren't warned.
|
||||
</li>
|
||||
{{ end }}
|
||||
{{ if .pc.Params.site }}
|
||||
<li>
|
||||
This piece was originally written for an older version of this site. As such, it may not have transferred over properly and some
|
||||
images and links might be broken.
|
||||
</li>
|
||||
{{ end }}
|
||||
</ul>
|
||||
</aside>
|
||||
{{ end }}
|
9
layouts/partials/single/main-header/word-count.html
Normal file
9
layouts/partials/single/main-header/word-count.html
Normal file
|
@ -0,0 +1,9 @@
|
|||
{{- /*
|
||||
Displays the length of an item.
|
||||
|
||||
@params wordCount The wordcount of an item.
|
||||
*/
|
||||
-}}
|
||||
|
||||
|
||||
<p class="article-header__word-count">~<span itemprop="wordCount">{{ .wordCount | lang.FormatNumberCustom 0 }}</span> words</p>
|
36
layouts/partials/single/post-meta.html
Normal file
36
layouts/partials/single/post-meta.html
Normal file
|
@ -0,0 +1,36 @@
|
|||
{{- /*
|
||||
Displays the meta information for an item.
|
||||
|
||||
@params pc Page context
|
||||
@params sc Site context
|
||||
*/
|
||||
-}}
|
||||
|
||||
|
||||
<footer class="site-content__footer">
|
||||
<h2>Meta</h2>
|
||||
|
||||
{{- with ( .pc.GetTerms "categories" ) -}}
|
||||
{{ partial "single/post-meta/categories.html" ( dict "categories" . ) }}
|
||||
{{- end -}}
|
||||
|
||||
{{- with ( .pc.GetTerms "areas" ) -}}
|
||||
{{ partial "single/post-meta/life-areas.html" ( dict "areas" . ) }}
|
||||
{{- end -}}
|
||||
|
||||
{{- with ( .pc.GetTerms "skills" ) -}}
|
||||
{{ partial "single/post-meta/skills.html" ( dict "pc" $.pc "skills" . "skills_ciisec_levels" $.pc.Params.skills_ciisec_levels ) }}
|
||||
{{- end -}}
|
||||
|
||||
{{- if ( .pc.GetTerms "organisations" ) -}}
|
||||
{{ partial "single/post-meta/organisations.html" ( dict "pc" .pc "sc" .sc ) }}
|
||||
{{- end -}}
|
||||
|
||||
{{- with ( .pc.GetTerms "locations" ) -}}
|
||||
{{ partial "single/post-meta/locations.html" ( dict "locations" . ) }}
|
||||
{{- end -}}
|
||||
|
||||
{{- with ( .pc.GetTerms "tags" ) -}}
|
||||
{{ partial "single/post-meta/tags.html" ( dict "tags" . ) }}
|
||||
{{- end -}}
|
||||
</footer>
|
21
layouts/partials/single/post-meta/categories.html
Normal file
21
layouts/partials/single/post-meta/categories.html
Normal file
|
@ -0,0 +1,21 @@
|
|||
{{- /*
|
||||
Displays the categories for an item.
|
||||
|
||||
@params categories The item's categories.
|
||||
*/
|
||||
-}}
|
||||
|
||||
|
||||
<section
|
||||
id="post-categories"
|
||||
class="article-footer__categories"
|
||||
aria-labelledby="post-categories-title"
|
||||
itemprop="articleSection"
|
||||
>
|
||||
<h3 id="post-categories-title">Categories</h3>
|
||||
<ul>
|
||||
{{- range .categories -}}
|
||||
<li class="p-category"><a href="{{ .RelPermalink }}">{{ .LinkTitle | safeHTML }}</a></li>
|
||||
{{- end -}}
|
||||
</ul>
|
||||
</section>
|
19
layouts/partials/single/post-meta/life-areas.html
Normal file
19
layouts/partials/single/post-meta/life-areas.html
Normal file
|
@ -0,0 +1,19 @@
|
|||
{{- /*
|
||||
Displays the life areas for an item.
|
||||
|
||||
@params areas The item's life areas.
|
||||
*/
|
||||
-}}
|
||||
|
||||
|
||||
<section
|
||||
class="article-footer__links"
|
||||
itemprop="articleSection"
|
||||
>
|
||||
<h3 id="item-areas-title">Areas</h3>
|
||||
<ul>
|
||||
{{- range .areas.ByTitle -}}
|
||||
<li class="p-category"><a href="{{ .RelPermalink }}">{{ .LinkTitle }}</a></li>
|
||||
{{- end -}}
|
||||
</ul>
|
||||
</section>
|
23
layouts/partials/single/post-meta/locations.html
Normal file
23
layouts/partials/single/post-meta/locations.html
Normal file
|
@ -0,0 +1,23 @@
|
|||
{{- /*
|
||||
Displays the locations for an item.
|
||||
|
||||
@params locations The locations or the item.
|
||||
*/
|
||||
-}}
|
||||
|
||||
|
||||
<section
|
||||
id="post-locations"
|
||||
class="article-footer__locations"
|
||||
>
|
||||
<h3>Locations</h3>
|
||||
<div
|
||||
id="map"
|
||||
style="width: 100%; height: 500px; margin: 0; display: block;"
|
||||
></div>
|
||||
<ul style="display: none">
|
||||
{{- range .locations.ByTitle -}}
|
||||
<li class="p-location"><a href="{{ .RelPermalink }}">{{ .LinkTitle | safeHTML }}</a></li>
|
||||
{{- end -}}
|
||||
</ul>
|
||||
</section>
|
31
layouts/partials/single/post-meta/organisations.html
Normal file
31
layouts/partials/single/post-meta/organisations.html
Normal file
|
@ -0,0 +1,31 @@
|
|||
{{- /*
|
||||
Displays the organisations for an item.
|
||||
|
||||
@params pc The page context.
|
||||
@params sc The site context.
|
||||
*/
|
||||
-}}
|
||||
|
||||
|
||||
<section
|
||||
id="post-organisations"
|
||||
class="article-footer__organisations"
|
||||
itemprop="articleSection"
|
||||
>
|
||||
<h3>Organisations</h3>
|
||||
<ul>
|
||||
{{ $all_organisations := partialCached "get_all_organisations.html" .pc }}
|
||||
<!-- TODO: Replace with hierarchy partial -->
|
||||
{{- range ( .pc.GetTerms "organisations" ) -}}
|
||||
{{ $matched_organisations := ( union ( union ( where $all_organisations "Title" ( .Title | plainify ) ) ( where $all_organisations "Params.abbreviation" ( .Title | plainify ) ) ) ( where $all_organisations "Params.fka" ( .Title | plainify ) ) ) }}
|
||||
{{ with $matched_organisations }}
|
||||
{{ range . }}
|
||||
{{ partial "cv/organisation/get-title.html" ( dict "organisation" . "site_redact" $.sc.Site.Params.redact ) .File.Dir }}
|
||||
{{ end }}
|
||||
{{ else }}
|
||||
{{ erroridf "missing-organisation" "Could not find organisation %q (%q)" .Title $.sc.File.Path }}
|
||||
<li>{{ if ( .Params.markup_title ) }}{{ .Params.markup_title | safeHTML }}{{ else }}{{ .Title }}{{ end }}</li>
|
||||
{{ end }}
|
||||
{{- end -}}
|
||||
</ul>
|
||||
</section>
|
30
layouts/partials/single/post-meta/skills.html
Normal file
30
layouts/partials/single/post-meta/skills.html
Normal file
|
@ -0,0 +1,30 @@
|
|||
{{- /*
|
||||
Displays the skills for an item.
|
||||
|
||||
@params pc The page context.
|
||||
@params skills The item's skills
|
||||
@params skills_ciisec_levels The matched CIISec levels for the skills. Optional.
|
||||
*/
|
||||
-}}
|
||||
|
||||
|
||||
<section
|
||||
class="article-footer__links"
|
||||
itemprop="articleSection"
|
||||
>
|
||||
<h3 id="item-skills-title">Skills</h3>
|
||||
<ul>
|
||||
{{- .pc.Scratch.Set "i" 0 -}}
|
||||
{{- range .skills.ByTitle -}}
|
||||
{{- if hasPrefix .LinkTitle "CIISec/" -}}
|
||||
<li class="p-category">
|
||||
<a href="{{ .RelPermalink }}">{{ .LinkTitle }}</a>
|
||||
<span class="level">(level {{ index $.skills_ciisec_levels ( $.pc.Scratch.Get "i" ) }})</span>
|
||||
</li>
|
||||
{{- $.pc.Scratch.Add "i" 1 -}}
|
||||
{{- else -}}
|
||||
<li class="p-category"><a href="{{ .RelPermalink }}">{{ .LinkTitle }}</a></li>
|
||||
{{- end -}}
|
||||
{{- end -}}
|
||||
</ul>
|
||||
</section>
|
19
layouts/partials/single/post-meta/tags.html
Normal file
19
layouts/partials/single/post-meta/tags.html
Normal file
|
@ -0,0 +1,19 @@
|
|||
{{- /*
|
||||
Displays the tags for an item.
|
||||
|
||||
@params tags The tags or the item.
|
||||
*/
|
||||
-}}
|
||||
|
||||
|
||||
<section
|
||||
id="post-tags"
|
||||
class="article-footer__tags"
|
||||
>
|
||||
<h3>Tags</h3>
|
||||
<ul>
|
||||
{{- range .tags.ByTitle -}}
|
||||
<li class="p-category"><a href="{{ .RelPermalink }}">{{ .LinkTitle | safeHTML }}</a></li>
|
||||
{{- end -}}
|
||||
</ul>
|
||||
</section>
|
Loading…
Add table
Add a link
Reference in a new issue