diff --git a/example-config.yaml b/example-config.yaml index 361a91b..a615d7e 100644 --- a/example-config.yaml +++ b/example-config.yaml @@ -14,7 +14,7 @@ cache: blogs: main: path: / - lang: en + lang: en_US title: My blog description: This is my blog sections: diff --git a/go.mod b/go.mod index 1d5f305..4617e72 100644 --- a/go.mod +++ b/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 diff --git a/go.sum b/go.sum index ad40864..e335ee3 100644 --- a/go.sum +++ b/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= diff --git a/render.go b/render.go index 417450a..9483950 100644 --- a/render.go +++ b/render.go @@ -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) { diff --git a/templates/photosummary.gohtml b/templates/photosummary.gohtml index 34d33a5..7c2f81a 100644 --- a/templates/photosummary.gohtml +++ b/templates/photosummary.gohtml @@ -1,7 +1,7 @@ {{ define "photosummary" }}
{{ with p .Data "title" }}

{{ . }}

{{ end }} - {{ with .Data.Published }}

{{ dateformat . "02. Jan 2006" }}

{{ end }} + {{ if .Data.Published }}

{{ longDate .Data.Published .Blog.Lang }}

{{ end }} {{ range $i, $photo := ( ps .Data .Blog.Photos.Parameter ) }} {{ md ( printf "![](%s)" $photo ) }} {{ end }} diff --git a/templates/post.gohtml b/templates/post.gohtml index 637dd6b..a8ff606 100644 --- a/templates/post.gohtml +++ b/templates/post.gohtml @@ -7,9 +7,9 @@
{{ with title .Data }}

{{ . }}

{{ end }} {{ if .Data.Published }} -

{{ string .Blog.Lang "publishedon" }} {{ dateformat .Data.Published "02. Jan 2006" }}

{{ end }} +

{{ string .Blog.Lang "publishedon" }} {{ longDate .Data.Published .Blog.Lang }}

{{ end }} {{ if .Data.Updated }} -

{{ string .Blog.Lang "updatedon" }} {{ dateformat .Data.Updated "02. Jan 2006" }}

{{ end }} +

{{ string .Blog.Lang "updatedon" }} {{ longDate .Data.Updated .Blog.Lang }}

{{ end }} {{ with .Data.Content }}
{{ md . }}
{{ end }} diff --git a/templates/strings/de.yaml b/templates/strings/de_DE.yaml similarity index 100% rename from templates/strings/de.yaml rename to templates/strings/de_DE.yaml diff --git a/templates/summary.gohtml b/templates/summary.gohtml index c80fd10..89b8ba0 100644 --- a/templates/summary.gohtml +++ b/templates/summary.gohtml @@ -1,7 +1,7 @@ {{ define "summary" }}
{{ with p .Data "title" }}

{{ . }}

{{ end }} - {{ with .Data.Published }}

{{ dateformat . "02. Jan 2006" }}

{{ end }} + {{ if .Data.Published }}

{{ longDate .Data.Published .Blog.Lang }}

{{ end }}

{{ summary .Data }}

{{ string .Blog.Lang "view" }}