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

github.com/spaghettiwews/hugonews.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--layouts/_default/list.html2
-rw-r--r--layouts/index.html2
-rw-r--r--layouts/items/list.html2
-rw-r--r--layouts/partials/age.html25
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