diff options
author | spaghettiwews <spaghettiwews@outlook.com> | 2020-02-29 20:13:56 +0300 |
---|---|---|
committer | spaghettiwews <spaghettiwews@outlook.com> | 2020-02-29 20:13:56 +0300 |
commit | a079f206181fd6d3690145620a5201f78d865f9f (patch) | |
tree | e972444979c1d2ca517d9bea465422ebdb835982 | |
parent | c53d7e6ee553009fa214e5eeeef4fc76bf486c3c (diff) |
switch timestamps to relative agetimestamp-to-age
-rw-r--r-- | layouts/_default/list.html | 2 | ||||
-rw-r--r-- | layouts/index.html | 2 | ||||
-rw-r--r-- | layouts/items/list.html | 2 | ||||
-rw-r--r-- | layouts/partials/age.html | 25 |
4 files changed, 28 insertions, 3 deletions
diff --git a/layouts/_default/list.html b/layouts/_default/list.html index b60e76c..2fe5fab 100644 --- a/layouts/_default/list.html +++ b/layouts/_default/list.html @@ -6,7 +6,7 @@ <li class="item"> <p class="item__urls"><a href="{{ .Params.ItemUrl }}">{{ .Title }}</a> <span class="item__siteurl">(<a href='/sites/{{ replace $site.Host "www." "" }}'>{{ replace $site.Host "www." "" }}</a>)</span></p> <p class="item__meta"> - <span>{{ .PublishDate }}</span> + {{ partial "age.html" . }} {{ range .Params.tags }} <a class="item__tag" href='/tags/{{- replace . " " "-" -}}'>{{- . -}}</a> {{- end }} diff --git a/layouts/index.html b/layouts/index.html index 67d0d96..44a489e 100644 --- a/layouts/index.html +++ b/layouts/index.html @@ -6,7 +6,7 @@ <li class="item"> <p class="item__urls"><a href="{{ .Params.ItemUrl }}">{{ .Title }}</a> <span class="item__siteurl">(<a href="/sites/{{ replace $site.Host "www." "" }}">{{ replace $site.Host "www." "" }}</a>)</span></p> <p class="item__meta"> - <span>{{ .PublishDate }}</span> + {{ partial "age.html" . }} {{ range .Params.tags }} <a class="item__tag" href="/tags/{{- replace . " " "-" -}}">{{- . -}}</a> {{- end }} diff --git a/layouts/items/list.html b/layouts/items/list.html index 04200e2..d8836b2 100644 --- a/layouts/items/list.html +++ b/layouts/items/list.html @@ -6,7 +6,7 @@ <li class="item"> <p class="item__urls"><a href="{{ .Params.ItemUrl }}">{{ .Title }}</a> <span class="item__siteurl">(<a href="/sites/{{ replace $site.Host "www." "" }}">{{ replace $site.Host "www." "" }}</a>)</span></p> <p class="item__meta"> - <span>{{ .PublishDate }}</span> + {{ partial "age.html" . }} {{ range .Params.tags }} <a class="item__tag" href="/tags/{{- replace . " " "-" -}}">{{- . -}}</a> {{- end }} diff --git a/layouts/partials/age.html b/layouts/partials/age.html new file mode 100644 index 0000000..2674491 --- /dev/null +++ b/layouts/partials/age.html @@ -0,0 +1,25 @@ +<!-- https://kodify.net/hugo/date-time/relative-age-hugo/ --> +{{ $ageDays := div (sub now.Unix .PublishDate.Unix) 86400 }} +{{ $ageMonths := div (sub now.Unix .PublishDate.Unix) 2592000 }} + +<!-- Posted today --> +{{ if eq $ageDays 0 }} + + <span>Posted today</span> + +<!-- Posted in the last 31 days --> +{{ else if lt $ageDays 31 }} + + <span>Posted {{ $ageDays }} + {{ cond (eq $ageDays 1) "day" "days"}} + ago</span> + +<!-- Posted month(s) ago --> +{{ else }} + + <span>Posted {{ $ageMonths }} + {{ cond (eq $ageMonths 1) "month" "months" }} + ago</span> + +{{ end }} +<!-- https://kodify.net/hugo/date-time/relative-age-hugo/ -->
\ No newline at end of file |