mirror of https://github.com/jlelse/GoBlog
Language based date format on posts
This commit is contained in:
parent
83253f03c4
commit
f2dc532334
|
@ -14,7 +14,7 @@ cache:
|
|||
blogs:
|
||||
main:
|
||||
path: /
|
||||
lang: en
|
||||
lang: en_US
|
||||
title: My blog
|
||||
description: This is my blog
|
||||
sections:
|
||||
|
|
1
go.mod
1
go.mod
|
@ -8,6 +8,7 @@ require (
|
|||
github.com/araddon/dateparse v0.0.0-20201001162425-8aadafed4dc4
|
||||
github.com/caddyserver/certmagic v0.12.0
|
||||
github.com/go-chi/chi v4.1.2+incompatible
|
||||
github.com/goodsign/monday v1.0.1-0.20201007115131-c065b60ec611
|
||||
github.com/gopherjs/gopherjs v0.0.0-20200217142428-fce0ec30dd00 // indirect
|
||||
github.com/gorilla/feeds v1.1.1
|
||||
github.com/jeremywohl/flatten v1.0.1
|
||||
|
|
2
go.sum
2
go.sum
|
@ -84,6 +84,8 @@ github.com/golang/mock v1.3.1/go.mod h1:sBzyDLLjw3U8JLTeZvSv8jJB+tU5PVekmnlKIyFU
|
|||
github.com/golang/protobuf v1.2.0/go.mod h1:6lQm79b+lXiMfvg/cZm0SGofjICqVBUtrP5yJMmIC1U=
|
||||
github.com/golang/protobuf v1.3.1/go.mod h1:6lQm79b+lXiMfvg/cZm0SGofjICqVBUtrP5yJMmIC1U=
|
||||
github.com/golang/protobuf v1.3.2/go.mod h1:6lQm79b+lXiMfvg/cZm0SGofjICqVBUtrP5yJMmIC1U=
|
||||
github.com/goodsign/monday v1.0.1-0.20201007115131-c065b60ec611 h1:uZeRJDvu+pkGLY0AGGQzJr7FRsagVd5+Sf7d7mRRx54=
|
||||
github.com/goodsign/monday v1.0.1-0.20201007115131-c065b60ec611/go.mod h1:r4T4breXpoFwspQNM+u2sLxJb2zyTaxVGqUfTBjWOu8=
|
||||
github.com/google/btree v0.0.0-20180813153112-4030bb1f1f0c/go.mod h1:lNA+9X1NB3Zf8V7Ke586lFgjr2dZNuvo3lPJSGZ5JPQ=
|
||||
github.com/google/btree v1.0.0/go.mod h1:lNA+9X1NB3Zf8V7Ke586lFgjr2dZNuvo3lPJSGZ5JPQ=
|
||||
github.com/google/go-cmp v0.2.0/go.mod h1:oXzfMopK8JAjlY9xF4vHSVASa0yLyX7SntLO5aqRK0M=
|
||||
|
|
|
@ -12,6 +12,7 @@ import (
|
|||
"time"
|
||||
|
||||
"github.com/araddon/dateparse"
|
||||
"github.com/goodsign/monday"
|
||||
)
|
||||
|
||||
const templatesDir = "templates"
|
||||
|
@ -65,6 +66,14 @@ func initRendering() error {
|
|||
}
|
||||
return d.Format(format)
|
||||
},
|
||||
"longDate": func(date string, localeString string) string {
|
||||
d, err := dateparse.ParseIn(date, time.Local)
|
||||
if err != nil {
|
||||
return ""
|
||||
}
|
||||
ml := monday.Locale(localeString)
|
||||
return monday.Format(d, monday.LongFormatsByLocale[ml], ml)
|
||||
},
|
||||
"asset": assetFile,
|
||||
"string": getTemplateStringVariant,
|
||||
"include": func(templateName string, blog *configBlog, data interface{}) (template.HTML, error) {
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
{{ define "photosummary" }}
|
||||
<article>
|
||||
{{ with p .Data "title" }}<h2>{{ . }}</h2>{{ end }}
|
||||
{{ with .Data.Published }}<p>{{ dateformat . "02. Jan 2006" }}</p>{{ end }}
|
||||
{{ if .Data.Published }}<p>{{ longDate .Data.Published .Blog.Lang }}</p>{{ end }}
|
||||
{{ range $i, $photo := ( ps .Data .Blog.Photos.Parameter ) }}
|
||||
{{ md ( printf "![](%s)" $photo ) }}
|
||||
{{ end }}
|
||||
|
|
|
@ -7,9 +7,9 @@
|
|||
<article>
|
||||
{{ with title .Data }}<h1 class=p-name>{{ . }}</h1>{{ end }}
|
||||
{{ if .Data.Published }}
|
||||
<p>{{ string .Blog.Lang "publishedon" }} {{ dateformat .Data.Published "02. Jan 2006" }}</p>{{ end }}
|
||||
<p>{{ string .Blog.Lang "publishedon" }} {{ longDate .Data.Published .Blog.Lang }}</p>{{ end }}
|
||||
{{ if .Data.Updated }}
|
||||
<p>{{ string .Blog.Lang "updatedon" }} {{ dateformat .Data.Updated "02. Jan 2006" }}</p>{{ end }}
|
||||
<p>{{ string .Blog.Lang "updatedon" }} {{ longDate .Data.Updated .Blog.Lang }}</p>{{ end }}
|
||||
{{ with .Data.Content }}
|
||||
<div class=e-content>{{ md . }}</div>
|
||||
{{ end }}
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
{{ define "summary" }}
|
||||
<article>
|
||||
{{ with p .Data "title" }}<h2>{{ . }}</h2>{{ end }}
|
||||
{{ with .Data.Published }}<p>{{ dateformat . "02. Jan 2006" }}</p>{{ end }}
|
||||
{{ if .Data.Published }}<p>{{ longDate .Data.Published .Blog.Lang }}</p>{{ end }}
|
||||
<p>{{ summary .Data }}</p>
|
||||
<a href="{{ .Data.Path }}">{{ string .Blog.Lang "view" }}</a>
|
||||
</article>
|
||||
|
|
Loading…
Reference in New Issue