diff options
| -rw-r--r-- | CHANGELOG.md | 1 | ||||
| -rw-r--r-- | exampleSite/config.toml | 2 | ||||
| -rw-r--r-- | layouts/404.html | 6 | ||||
| -rw-r--r-- | layouts/index.html | 19 | ||||
| -rw-r--r-- | layouts/partials/mini-toc.html | 26 | ||||
| -rw-r--r-- | layouts/partials/post-toc-summary.html | 7 |
6 files changed, 45 insertions, 16 deletions
diff --git a/CHANGELOG.md b/CHANGELOG.md index 6f7ab6a..eff67d1 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -13,6 +13,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 - Do not show "Latest Publications" section at the homepage if there are no publications - Add fallback if main sections are not configured - Reformat default 404 page +- Rework the "Latest Publications" section, add post date ## v0.1.0 - 2022-05-27 diff --git a/exampleSite/config.toml b/exampleSite/config.toml index ad0aa32..3421458 100644 --- a/exampleSite/config.toml +++ b/exampleSite/config.toml @@ -142,12 +142,14 @@ disableKinds = ['RSS'] postMeta = ['date'] # Posts date format, for example: 2006-01-02 dateformat = 'January 02, 2006' + dateFormatToc = '2006.01.02' dateFormatFeed = '2006-01-02T15:04:05Z07:00' dateFormatRFC822Z = '02 Jan 2006 15:04:05 UT' # Show "Read more" button in list if true readmore = true # RSS/Atom feed size feedSize = 25 + recentPostsSize = 5 [params.contact] # Forms Backend URL, used in contacts form diff --git a/layouts/404.html b/layouts/404.html index dfe2090..5584276 100644 --- a/layouts/404.html +++ b/layouts/404.html @@ -15,3 +15,9 @@ <a href="{{ "/" | relURL }}">Head back home to try finding it again</a>. </p> </section> + +<hr> + +{{- partial "mini-toc" . -}} + +{{ end }} diff --git a/layouts/index.html b/layouts/index.html index 7dde6eb..d3091c7 100644 --- a/layouts/index.html +++ b/layouts/index.html @@ -1,26 +1,13 @@ {{ define "main" }} -{{- $mainSections := site.Params.mainSections | default (slice "post") }} + {{- with .Content }} <div class="introduction"> {{ . }} </div> - {{- $section := where site.RegularPages "Section" "in" $mainSections }} - {{- $section_count := len $section }} - {{- if ge $section_count 1 }} <hr> - <div class="toc"> - {{/* TODO: Translate me */}} - <h2>Latest Publications</h2> - <ul class="texts"> - {{ range first 10 $section }} - <li class="text-title"> - <a href="{{ .Permalink }}">{{ .Title }}</a> - </li> - {{ end }} - </ul> - </div> - {{ end }} + {{- partial "mini-toc" . -}} {{- else }} + {{- $mainSections := site.Params.mainSections | default (slice "post") }} {{ $paginator := .Paginate (where site.RegularPages "Section" "in" $mainSections) }} <div class="articles"> {{ with .Title }}<h1 class="page-title">{{ . }}</h1>{{ end }} diff --git a/layouts/partials/mini-toc.html b/layouts/partials/mini-toc.html new file mode 100644 index 0000000..4d4d742 --- /dev/null +++ b/layouts/partials/mini-toc.html @@ -0,0 +1,26 @@ +{{/* Define a section to pull recent posts from. + This will default to the section with the most number of pages. */}} +{{ $mainSections := site.Params.mainSections | default (slice "post") }} + +{{/* Create a variable with that section to use in multiple places. */}} +{{ $section := where site.RegularPages "Section" "in" $mainSections }} + +{{/* Check to see if the section is defined for ranging through it */}} +{{ $sectionCount := len $section }} + +{{ if ge $sectionCount 1 }} + {{ $mxPosts := site.Params.recentPostsSize | default 5 }} + + <div class="toc" role="navigation"> + {{/* TODO: Translate me */}} + <h2>Latest Publications</h2> + <ul class="texts"> + {{/* Range through the first $mxPosts items of the $section */}} + {{ range (first $mxPosts $section) }} + <li class="text-title"> + {{ partial "post-toc-summary" . }} + </li> + {{ end }} + </ul> + </div> +{{ end }} diff --git a/layouts/partials/post-toc-summary.html b/layouts/partials/post-toc-summary.html new file mode 100644 index 0000000..d9a70c7 --- /dev/null +++ b/layouts/partials/post-toc-summary.html @@ -0,0 +1,7 @@ +<span class="post-meta"> + <time datetime="{{ .Date.Format "2006-01-02T15:04:05Z07:00" }}"> + {{- .Date.Format (site.Params.dateFormatToc | default "2006.01.02") }} + </time> +</span> + +<a href="{{ .Permalink }}">{{ .Title }} </a> |
