From 8927a3c672a6e7a40519626b7df31d7dace800a9 Mon Sep 17 00:00:00 2001
From: Alex Shpak <alex-shpak@users.noreply.github.com>
Date: Fri, 10 Apr 2020 20:24:36 +0200
Subject: #162, Add docs/date partial, for date customization

---
 layouts/partials/docs/date.html      | 6 ++++++
 layouts/partials/docs/footer.html    | 2 +-
 layouts/partials/docs/post-meta.html | 5 ++---
 3 files changed, 9 insertions(+), 4 deletions(-)
 create mode 100644 layouts/partials/docs/date.html

(limited to 'layouts/partials')

diff --git a/layouts/partials/docs/date.html b/layouts/partials/docs/date.html
new file mode 100644
index 0000000..73d69a3
--- /dev/null
+++ b/layouts/partials/docs/date.html
@@ -0,0 +1,6 @@
+<!--
+  Returns formatted date.
+  Usage: partial "docs/date" (dict "Date" .Date "Format" .Site.Params.BookDateFormat)
+-->
+{{- $format := default "January 2, 2006" .Format -}}
+{{- return (.Date.Format $format) -}}
diff --git a/layouts/partials/docs/footer.html b/layouts/partials/docs/footer.html
index f9ca80d..303d2bf 100644
--- a/layouts/partials/docs/footer.html
+++ b/layouts/partials/docs/footer.html
@@ -5,7 +5,7 @@
 
 {{ if and .GitInfo .Site.Params.BookRepo }}
   <div>
-    {{ $date := .GitInfo.AuthorDate.Local.Format (default "January 2, 2006" .Site.Params.BookDateFormat) }}
+    {{- $date := partial "docs/date" (dict "Date" .GitInfo.AuthorDate.Local "Format" .Site.Params.BookDateFormat) -}}
     <a class="flex align-center" href="{{ .Site.Params.BookRepo }}/commit/{{ .GitInfo.Hash }}" title='{{ i18n "Last modified by" }} {{ .GitInfo.AuthorName }} | {{ $date }}' target="_blank" rel="noopener">
       <img src="{{ "svg/calendar.svg" | relURL }}" class="book-icon" alt="Calendar" />
       <span>{{ $date }}</span>
diff --git a/layouts/partials/docs/post-meta.html b/layouts/partials/docs/post-meta.html
index 70adb0b..c56a528 100644
--- a/layouts/partials/docs/post-meta.html
+++ b/layouts/partials/docs/post-meta.html
@@ -1,13 +1,12 @@
-{{ $dateFormat := (default "January 2, 2006" .Site.Params.BookDateFormat) }}
 {{ with .Date}}
-  <h5>{{ .Format $dateFormat }}</h5>
+  <h5>{{ partial "docs/date" (dict "Date" . "Format" $.Site.Params.BookDateFormat) }}</h5>
 {{ end }}
 
 {{ range $taxonomy, $_ := .Site.Taxonomies }}
   {{ with $terms := $.GetTerms $taxonomy }}
   <div>
     {{ range $n, $term := $terms }}{{ if $n }}, {{ end }}
-        <a href="{{ $term.RelPermalink }}">{{ $term.Title }}</a>
+      <a href="{{ $term.RelPermalink }}">{{ $term.Title }}</a>
     {{- end }}
   </div>
   {{ end }}
-- 
cgit v1.2.3