Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/gundamew/hugo-bingo.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBing-Sheng Chen <gundamew@gmail.com>2019-08-01 10:26:38 +0300
committerBing-Sheng Chen <gundamew@gmail.com>2019-08-01 10:26:38 +0300
commited05cb19a263f2259d87f1afa169005badfefcf8 (patch)
tree05a72d0d805b6dd0563fad980241f24b33ed8692
parent9341e736fc758699a3f232806817f0dd74a6b2aa (diff)
refactor(date): Refactor date string partial
Now the format of date string is customizable. See also: https://zwbetz.com/make-a-hugo-blog-from-scratch/#date-and-tags-partial
-rw-r--r--README.md7
-rw-r--r--layouts/_default/list.html2
-rw-r--r--layouts/_default/single.html2
-rw-r--r--layouts/_default/time-element.html1
-rw-r--r--layouts/index.html2
-rw-r--r--layouts/partials/date.html2
6 files changed, 12 insertions, 4 deletions
diff --git a/README.md b/README.md
index 7de067c..59f5814 100644
--- a/README.md
+++ b/README.md
@@ -90,6 +90,13 @@ Available social icons:
* `stackoverflow`
* `twitter`
+### Custom date format
+
+```toml
+[params]
+ dateFormat = "2006-01-02"
+```
+
## Built With
* [Highlight.js](https://highlightjs.org/)
diff --git a/layouts/_default/list.html b/layouts/_default/list.html
index a750cae..fc812d1 100644
--- a/layouts/_default/list.html
+++ b/layouts/_default/list.html
@@ -5,7 +5,7 @@
{{ range .Data.Pages }}
<li>
<a href="{{ .Permalink }}">{{ .Title }}</a>
- <p>{{ .Render "time-element" }}</p>
+ <p>{{- partial "date.html" . -}}</p>
</li>
{{ end }}
</ul>
diff --git a/layouts/_default/single.html b/layouts/_default/single.html
index c85ba48..58797cf 100644
--- a/layouts/_default/single.html
+++ b/layouts/_default/single.html
@@ -1,7 +1,7 @@
{{ define "main" }}
<main id="single">
<h1>{{ .Title }}</h1>
- <h2>{{ .Render "time-element" }}</h2>
+ <h2>{{- partial "date.html" . -}}</h2>
<section class="post-content">
{{ .Content }}
</section>
diff --git a/layouts/_default/time-element.html b/layouts/_default/time-element.html
deleted file mode 100644
index 29f092c..0000000
--- a/layouts/_default/time-element.html
+++ /dev/null
@@ -1 +0,0 @@
-<time datetime="{{ .Date.Format "2006-01-02T15:04:05-0700" }}">{{ .Date.Format "2006-01-02" }}</time>
diff --git a/layouts/index.html b/layouts/index.html
index 6f45c08..64c798e 100644
--- a/layouts/index.html
+++ b/layouts/index.html
@@ -22,7 +22,7 @@
<ul>
{{ range first 5 .Data.Pages.ByPublishDate.Reverse }}
<li>
- <span>{{ .Render "time-element" }}</span>
+ <span>{{- partial "date.html" . -}}</span>
<a href="{{ .Permalink }}">{{ .Title }}</a>
</li>
{{ end }}
diff --git a/layouts/partials/date.html b/layouts/partials/date.html
new file mode 100644
index 0000000..a05383b
--- /dev/null
+++ b/layouts/partials/date.html
@@ -0,0 +1,2 @@
+{{ $dateFormat := .Site.Params.dateFormat | default "Jan 2, 2006" }}
+<time datetime="{{ .Date.Format "2006-01-02T15:04:05-0700" }}">{{ .Date.Format $dateFormat }}</time>