Skip to content

Commit

Permalink
Use layout identifiers for dates
Browse files Browse the repository at this point in the history
- Adds new Hugo feature
  (https://gohugo.io/functions/dateformat/#datetime-formatting-layouts)
enabling date localization in defaults
  • Loading branch information
victoriadrake committed Feb 14, 2022
1 parent 052a699 commit fade059
Show file tree
Hide file tree
Showing 7 changed files with 137 additions and 122 deletions.
37 changes: 19 additions & 18 deletions layouts/_default/list.html
Original file line number Diff line number Diff line change
@@ -1,21 +1,22 @@
{{ define "main" }}
<div class="container markdown top-pad">
{{ .Content }}
</div>
<div class="container">
<ul>
{{ range .Pages.ByPublishDate.Reverse }}
{{ if .Date }}
<li>
<a href="{{ .Permalink }}">{{ .Date.Format (.Site.Params.dateFormat | default "Jan 02, 2006") }} | {{ .Title | markdownify }}</a>
</li>
{{ else }}
<li>
<a href="{{ .Permalink }}">{{ .Title | markdownify }}</a>
</li>
{{ end }}
{{ end }}
</ul>
</div>
<div class="container markdown top-pad">
{{ .Content }}
</div>
<div class="container">
<ul>
{{ range .Pages.ByPublishDate.Reverse }}
{{ if .Date }}
<li>
<a href="{{ .Permalink }}">{{ .Date.Format (.Site.Params.dateFormat | default ":date_medium") }} |
{{ .Title | markdownify }}</a>
</li>
{{ else }}
<li>
<a href="{{ .Permalink }}">{{ .Title | markdownify }}</a>
</li>
{{ end }}
{{ end }}
</ul>
</div>
</body>
{{ end }}
33 changes: 17 additions & 16 deletions layouts/_default/taxonomy.html
Original file line number Diff line number Diff line change
@@ -1,21 +1,22 @@
{{ define "title" }}
<h1 class="bold-title is-1">{{ .Data.Singular | humanize }}: {{ lower .Title | markdownify }}</h1>
<h1 class="bold-title is-1">{{ .Data.Singular | humanize }}: {{ lower .Title | markdownify }}</h1>
{{ end }}

{{ define "main" }}
<div class="container">
<ul>
{{ range .Pages.ByPublishDate.Reverse }}
{{ if .Date }}
<li>
<a href="{{ .Permalink }}">{{ .Date.Format (.Site.Params.dateFormat | default "Jan 02, 2006") }} | {{ .Title | markdownify }}</a>
</li>
{{ else }}
<li>
<a href="{{ .Permalink }}">{{ .Title | markdownify }}</a>
</li>
{{ end }}
{{ end }}
</ul>
</div>
<div class="container">
<ul>
{{ range .Pages.ByPublishDate.Reverse }}
{{ if .Date }}
<li>
<a href="{{ .Permalink }}">{{ .Date.Format (.Site.Params.dateFormat | default ":date_medium") }} |
{{ .Title | markdownify }}</a>
</li>
{{ else }}
<li>
<a href="{{ .Permalink }}">{{ .Title | markdownify }}</a>
</li>
{{ end }}
{{ end }}
</ul>
</div>
{{ end }}
55 changes: 28 additions & 27 deletions layouts/blog/list.html
Original file line number Diff line number Diff line change
@@ -1,31 +1,32 @@
{{ define "main" }}
<div class="container markdown top-pad">
{{ .Content }}
</div>
<div class="container">
{{ if .Site.Params.home.showLatest | default true }}
<h2 class="title is-2 top-pad">{{ i18n "index_blog_latestPosts" . }}</h2>
{{ range first 1 .Pages.ByPublishDate.Reverse }}
<div class="summary">{{ if .Params.date }}{{ .Date.Format (.Site.Params.dateFormat | default "Jan 02, 2006") }}{{ end }}
<h3 class="title is-3 strong-post-title">
<a href="{{ .Permalink }}">
{{ .Title | markdownify }}
</a>
</h3>
<div class="markdown">
{{ .Summary }}
{{ if .Truncated }}
<a href="{{ .Permalink }}">{{ i18n "index_blog_readMore" . }}</a>
{{ end }}
</div>
</div>
<div class="container markdown top-pad">
{{ .Content }}
</div>
<div class="container">
{{ if .Site.Params.home.showLatest | default true }}
<h2 class="title is-2 top-pad">{{ i18n "index_blog_latestPosts" . }}</h2>
{{ range first 1 .Pages.ByPublishDate.Reverse }}
<div class="summary">
{{ if .Params.date }}{{ .Date.Format (.Site.Params.dateFormat | default ":date_medium") }}{{ end }}
<h3 class="title is-3 strong-post-title">
<a href="{{ .Permalink }}">
{{ .Title | markdownify }}
</a>
</h3>
<div class="markdown">
{{ .Summary }}
{{ if .Truncated }}
<a href="{{ .Permalink }}">{{ i18n "index_blog_readMore" . }}</a>
{{ end }}
{{ end }}
<h2 class="title is-2 top-pad">{{ i18n "index_blog_allPosts" . }}</h2>
{{if .Site.Params.home.allPostsArchiveFormat}}
{{ partialCached "blog/archive.html" .}}
{{else}}
{{ partialCached "blog/li.html" . }}
{{end}}
</div>
</div>
{{ end }}
{{ end }}
<h2 class="title is-2 top-pad">{{ i18n "index_blog_allPosts" . }}</h2>
{{if .Site.Params.home.allPostsArchiveFormat}}
{{ partialCached "blog/archive.html" .}}
{{else}}
{{ partialCached "blog/li.html" . }}
{{end}}
</div>
{{ end }}
39 changes: 22 additions & 17 deletions layouts/blog/single.html
Original file line number Diff line number Diff line change
Expand Up @@ -10,46 +10,51 @@ <h2 class="title is-1 top-pad strong-post-title">
<a href="{{ .Permalink }}">{{ .Title | markdownify }}</a>
</h2>
<div class="post-data">
{{ if .Params.date }}{{ .Date.Format (.Site.Params.dateFormat | default "Jan 02, 2006") }}{{ end }}
{{ if .Site.Params.showReadingTime | default true }}
{{ if .Params.date }} | {{ end }}
{{ i18n "blog_readingTime" .ReadingTime }}
{{ if .Params.date }}{{ .Date.Format (.Site.Params.dateFormat | default ":date_medium") }}{{ end }}
{{ if .Site.Params.showReadingTime | default true }}
{{ if .Params.date }} | {{ end }}
{{ i18n "blog_readingTime" .ReadingTime }}
{{ end }}
</div>
{{ if or .Site.Params.share.twitter .Site.Params.share.facebook .Site.Params.share.pinterest }}
<div class="blog-share">
{{ i18n "blog_shareThis" . }}:
{{ if .Site.Params.share.twitter }}
<a class="twitter-share-button" href="https://twitter.com/intent/tweet?text={{ .Title | markdownify }}%20{{ .Permalink }}" onclick="window.open(this.href, 'twitter-share', 'width=550,height=235');return false;">
<a class="twitter-share-button"
href="https://twitter.com/intent/tweet?text={{ .Title | markdownify }}%20{{ .Permalink }}"
onclick="window.open(this.href, 'twitter-share', 'width=550,height=235');return false;">
<i class="fab fa-twitter"></i>
<span class="hidden">Twitter</span>
</a>
{{ end }}
{{ if .Site.Params.share.facebook }}
<a class="icon-facebook" href="https://www.facebook.com/sharer/sharer.php?u={{ .Permalink }}" onclick="window.open(this.href, 'facebook-share','width=580,height=296');return false;">
<a class="icon-facebook" href="https://www.facebook.com/sharer/sharer.php?u={{ .Permalink }}"
onclick="window.open(this.href, 'facebook-share','width=580,height=296');return false;">
<i class="fab fa-facebook-f"></i>
<span class="hidden">Facebook</span>
</a>
{{ end }}
{{ if .Site.Params.share.pinterest }}
<a class="icon-pinterest" href="http://pinterest.com/pin/create/button/?url={{ .Permalink }}{{ if .Params.pinterestMedia }}&amp;media={{ .Site.BaseURL }}{{ .Params.pinterestMedia }}{{ end }}&amp;description={{ .Title | safeHTML}}" onclick="window.open(this.href, 'pinterest-share','width=580,height=296');return false;">
<a class="icon-pinterest"
href="http://pinterest.com/pin/create/button/?url={{ .Permalink }}{{ if .Params.pinterestMedia }}&amp;media={{ .Site.BaseURL }}{{ .Params.pinterestMedia }}{{ end }}&amp;description={{ .Title | safeHTML}}"
onclick="window.open(this.href, 'pinterest-share','width=580,height=296');return false;">
<i class="fab fa-pinterest-p"></i>
<span class="hidden">Pinterest</span>
</a>
{{ end }}
</div>
{{ end }}
{{ range $taxonomy_term, $taxonomy := .Params }}
{{ with $.Site.GetPage $taxonomy_term }}
{{ $len := (len $taxonomy) }}
<p>
{{ $taxonomy_term | title }}:
{{ range $key, $value := $taxonomy }}
<a href="{{ (printf "/%s/" $taxonomy_term) | relLangURL }}{{ . | urlize }}">
{{ $value }}</a>{{ if ne (add $key 1) $len }},{{ end }}
{{ end }}
</p>
{{ end }}
{{ with $.Site.GetPage $taxonomy_term }}
{{ $len := (len $taxonomy) }}
<p>
{{ $taxonomy_term | title }}:
{{ range $key, $value := $taxonomy }}
<a href="{{ (printf " /%s/" $taxonomy_term) | relLangURL }}{{ . | urlize }}">
{{ $value }}</a>{{ if ne (add $key 1) $len }},{{ end }}
{{ end }}
</p>
{{ end }}
{{ end }}
</div>
<!-- Begin blog post content -->
Expand Down
35 changes: 19 additions & 16 deletions layouts/partials/blog/archive.html
Original file line number Diff line number Diff line change
@@ -1,24 +1,27 @@
<section>
{{ $prev := now.Format "2006"}} <!--start from the current year-->
{{ range first 1 .Pages.ByPublishDate.Reverse }}
{{if .Date}} <!--also add the header if there are posts during the current year-->
{{if eq $prev (.Date.Format "2006")}} <h2 class="title is-2 top-pad"> {{ $prev }}</h2> {{end}}
{{ $prev := now.Format "2006"}}
<!--start from the current year-->
{{ range first 1 .Pages.ByPublishDate.Reverse }}
{{if .Date}}
<!--also add the header if there are posts during the current year-->
{{if eq $prev (.Date.Format "2006")}}
<h2 class="title is-2 top-pad"> {{ $prev }}</h2> {{end}}
{{end}}
{{end}}
{{end}}

{{range .Pages.ByPublishDate.Reverse}}
{{range .Pages.ByPublishDate.Reverse}}
{{if .Date}}
{{$curr := .Date.Format "2006"}}
{{if lt $curr $prev }}
<h2 class="title is-2 top-pad">{{ $curr }}</h2>
{{end}}
{{if lt $curr $prev }}
<h2 class="title is-2 top-pad">{{ $curr }}</h2>
{{end}}
<li class="post-item">
{{ if .Params.date }}
<span>{{ .Date.Format (.Site.Params.dateFormat | default "Jan 02, 2006") }}</span> -
{{ end }}
<span><a href="{{ .Permalink }}">{{ .Title | markdownify }}</a></span>
{{ if .Params.date }}
<span>{{ .Date.Format (.Site.Params.dateFormat | default ":date_medium") }}</span> -
{{ end }}
<span><a href="{{ .Permalink }}">{{ .Title | markdownify }}</a></span>
</li>
{{ $prev = $curr}}
{{ $prev = $curr}}
{{end}}
{{end}}
{{end}}
</section>
</section>
7 changes: 4 additions & 3 deletions layouts/partials/blog/li.html
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
{{ range .Pages.ByPublishDate.Reverse }}
<li class="post-item">
<span><a href="{{ .Permalink }}">{{ .Title | markdownify }}</a></span>{{ if .Params.date }} - <span>{{ .Date.Format (.Site.Params.dateFormat | default "Jan 02, 2006") }}</span>{{ end }}
</li>
<li class="post-item">
<span><a href="{{ .Permalink }}">{{ .Title | markdownify }}</a></span>{{ if .Params.date }} -
<span>{{ .Date.Format (.Site.Params.dateFormat | default ":date_medium") }}</span>{{ end }}
</li>
{{ end }}
53 changes: 28 additions & 25 deletions layouts/partials/home/blog.html
Original file line number Diff line number Diff line change
Expand Up @@ -4,40 +4,43 @@
<div class="container">
{{ if .Site.Params.home.showLatest | default true }}
<h2 class="title is-2 has-text-centered">{{ i18n "index_blog_latestPosts" . }}</h2>
{{ range first 1 .Pages.ByPublishDate.Reverse }}
<div class="summary">{{ if .Params.date }}{{ .Date.Format (.Site.Params.dateFormat | default "Jan 02, 2006") }}{{ end }}
<h3 class="title is-3 latest-post-title"><a href="{{ .Permalink }}">{{ .Title | markdownify }}</a></h3>
<div class="markdown">
{{ .Summary }}
{{ if .Truncated }}
<a href="{{ .Permalink }}">{{ i18n "index_blog_readMore" . }}</a>
{{ end }}
</div>
{{ range first 1 .Pages.ByPublishDate.Reverse }}
<div class="summary">
{{ if .Params.date }}{{ .Date.Format (.Site.Params.dateFormat | default ":date_medium") }}{{ end }}
<h3 class="title is-3 latest-post-title"><a href="{{ .Permalink }}">{{ .Title | markdownify }}</a></h3>
<div class="markdown">
{{ .Summary }}
{{ if .Truncated }}
<a href="{{ .Permalink }}">{{ i18n "index_blog_readMore" . }}</a>
{{ end }}
</div>
{{ end }}
</div>
{{ end }}
{{ end }}
</div>
</div>
{{ if .Site.Params.home.showAllPosts }}
<div class="section" id="all-posts">
<div class="container">
<h2 class="title is-2 top-pad">{{ i18n "index_blog_allPosts" . }}</h2>
{{if .Site.Params.home.allPostsArchiveFormat}}
{{ partialCached "blog/archive.html" .}}
{{else}}
{{ partialCached "blog/li.html" . }}
{{ if .Site.Params.home.showAllPosts }}
<div class="section" id="all-posts">
<div class="container">
<h2 class="title is-2 top-pad">{{ i18n "index_blog_allPosts" . }}</h2>
{{if .Site.Params.home.allPostsArchiveFormat}}
{{ partialCached "blog/archive.html" .}}
{{else}}
{{ partialCached "blog/li.html" . }}
{{end}}
</div>
</div>
{{ else }}
<div class="container has-text-centered top-pad">
<a href="{{ .Permalink }}">{{ i18n "index_blog_allPosts" . }}</a>
</div>
{{ end }}
</div>
{{ else }}
<div class="container has-text-centered top-pad">
<a href="{{ .Permalink }}">{{ i18n "index_blog_allPosts" . }}</a>
</div>
{{ end }}

<!-- End Blog container -->
{{ partial "top-icon.html" . }}

<!-- End Blog section -->
<div class="container"><hr></div>
<div class="container">
<hr>
</div>
{{ end }}

0 comments on commit fade059

Please sign in to comment.