From 98e81875d4058cef6d0d7aebe0c12029afeb36d2 Mon Sep 17 00:00:00 2001 From: Jan-Lukas Else Date: Fri, 26 Feb 2021 10:31:38 +0100 Subject: [PATCH] Replace monday library with ISO8601 dates --- config.go | 1 - go.mod | 6 ++--- go.sum | 13 +++++----- posts.go | 39 +++++++++++------------------ render.go | 18 +++---------- templates/summaryandpostmeta.gohtml | 4 +-- utils.go | 8 ++++++ 7 files changed, 36 insertions(+), 53 deletions(-) diff --git a/config.go b/config.go index 6ba07fa..5c772e3 100644 --- a/config.go +++ b/config.go @@ -49,7 +49,6 @@ type configCache struct { type configBlog struct { Path string `mapstructure:"path"` Lang string `mapstructure:"lang"` - TimeLang string `mapstructure:"timelang"` Title string `mapstructure:"title"` Description string `mapstructure:"description"` Pagination int `mapstructure:"pagination"` diff --git a/go.mod b/go.mod index 32f95d7..d4d5306 100644 --- a/go.mod +++ b/go.mod @@ -14,7 +14,6 @@ require ( github.com/go-fed/httpsig v1.1.0 github.com/go-sql-driver/mysql v1.5.0 // indirect github.com/gofrs/flock v0.8.0 // indirect - github.com/goodsign/monday v1.0.1-0.20201007115131-c065b60ec611 github.com/google/go-cmp v0.5.4 // indirect github.com/gopherjs/gopherjs v0.0.0-20210202160940-bed99a852dfe // indirect github.com/gorilla/feeds v1.1.1 @@ -28,12 +27,13 @@ require ( github.com/lestrrat-go/file-rotatelogs v2.4.0+incompatible github.com/lestrrat-go/strftime v1.0.4 // indirect github.com/lib/pq v1.9.0 // indirect + github.com/libdns/libdns v0.2.0 // indirect github.com/lopezator/migrator v0.3.0 github.com/magiconair/properties v1.8.4 // indirect github.com/mattn/go-sqlite3 v1.14.6 github.com/mholt/acmez v0.1.3 // indirect github.com/microcosm-cc/bluemonday v1.0.4 - github.com/miekg/dns v1.1.39 // indirect + github.com/miekg/dns v1.1.40 // indirect github.com/mitchellh/mapstructure v1.4.1 // indirect github.com/pelletier/go-toml v1.8.1 // indirect github.com/smartystreets/assertions v1.2.0 // indirect @@ -55,7 +55,7 @@ require ( golang.org/x/mod v0.4.1 // indirect golang.org/x/net v0.0.0-20210224082022-3d97a244fca7 // indirect golang.org/x/sync v0.0.0-20210220032951-036812b2e83c - golang.org/x/sys v0.0.0-20210223212115-eede4237b368 // indirect + golang.org/x/sys v0.0.0-20210225134936-a50acf3fe073 // indirect golang.org/x/term v0.0.0-20201210144234-2321bbc49cbf // indirect golang.org/x/text v0.3.5 // indirect gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c // indirect diff --git a/go.sum b/go.sum index 6c203a2..7d0cfce 100644 --- a/go.sum +++ b/go.sum @@ -91,8 +91,6 @@ 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= @@ -183,8 +181,9 @@ github.com/lestrrat-go/strftime v1.0.4/go.mod h1:E1nN3pCbtMSu1yjSVeyuRFVm/U0xoR7 github.com/lib/pq v1.0.0/go.mod h1:5WUZQaWbwv1U+lTReE5YruASi9Al49XbQIvNi/34Woo= github.com/lib/pq v1.9.0 h1:L8nSXQQzAYByakOFMTwpjRoHsMJklur4Gi59b6VivR8= github.com/lib/pq v1.9.0/go.mod h1:AlVN5x4E4T544tWzH6hKfbfQvm3HdbOxrmggDNAPY9o= -github.com/libdns/libdns v0.1.0 h1:0ctCOrVJsVzj53mop1angHp/pE3hmAhP7KiHvR0HD04= github.com/libdns/libdns v0.1.0/go.mod h1:yQCXzk1lEZmmCPa857bnk4TsOiqYasqpyOEeSObbb40= +github.com/libdns/libdns v0.2.0 h1:ewg3ByWrdUrxrje8ChPVMBNcotg7H9LQYg+u5De2RzI= +github.com/libdns/libdns v0.2.0/go.mod h1:yQCXzk1lEZmmCPa857bnk4TsOiqYasqpyOEeSObbb40= github.com/lopezator/migrator v0.3.0 h1:VW/rR+J8NYwPdkBxjrFdjwejpgvP59LbmANJxXuNbuk= github.com/lopezator/migrator v0.3.0/go.mod h1:bpVAVPkWSvTw8ya2Pk7E/KiNAyDWNImgivQY79o8/8I= github.com/magiconair/properties v1.8.1/go.mod h1:PppfXfuXeibc/6YijjN8zIbojt8czPbwD3XqdrwzmxQ= @@ -205,8 +204,8 @@ github.com/microcosm-cc/bluemonday v1.0.4 h1:p0L+CTpo/PLFdkoPcJemLXG+fpMD7pYOoDE github.com/microcosm-cc/bluemonday v1.0.4/go.mod h1:8iwZnFn2CDDNZ0r6UXhF4xawGvzaqzCRa1n3/lO3W2w= github.com/miekg/dns v1.0.14/go.mod h1:W1PPwlIAgtquWBMBEV9nkV9Cazfe8ScdGz/Lj7v3Nrg= github.com/miekg/dns v1.1.30/go.mod h1:KNUDUusw/aVsxyTYZM1oqvCicbwhgbNgztCETuNZ7xM= -github.com/miekg/dns v1.1.39 h1:6dRfDGnHiXOMmTZkwWANy7bBXXlKls5Qu+pn+Ue0TLo= -github.com/miekg/dns v1.1.39/go.mod h1:KNUDUusw/aVsxyTYZM1oqvCicbwhgbNgztCETuNZ7xM= +github.com/miekg/dns v1.1.40 h1:pyyPFfGMnciYUk/mXpKkVmeMQjfXqt3FAJ2hy7tPiLA= +github.com/miekg/dns v1.1.40/go.mod h1:KNUDUusw/aVsxyTYZM1oqvCicbwhgbNgztCETuNZ7xM= github.com/mitchellh/cli v1.0.0/go.mod h1:hNIlj7HEI86fIcpObd7a0FcrxTWetlwJDGcceTlRvqc= github.com/mitchellh/go-homedir v1.0.0/go.mod h1:SfyaCUpYCn1Vlf4IUYiD9fPX4A5wJrkLzIz1N1q0pr0= github.com/mitchellh/go-testing-interface v1.0.0/go.mod h1:kRemZodwjscx+RGhAo8eIhFbs2+BFgRtFPeD/KE+zxI= @@ -405,8 +404,8 @@ golang.org/x/sys v0.0.0-20200724161237-0e2f3a69832c/go.mod h1:h1NjWce9XRLGQEsW7w golang.org/x/sys v0.0.0-20200930185726-fdedc70b468f/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20201119102817-f84b799fce68/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20210119212857-b64e53b001e4/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= -golang.org/x/sys v0.0.0-20210223212115-eede4237b368 h1:fDE3p0qf2V1co1vfj3/o87Ps8Hq6QTGNxJ5Xe7xSp80= -golang.org/x/sys v0.0.0-20210223212115-eede4237b368/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= +golang.org/x/sys v0.0.0-20210225134936-a50acf3fe073 h1:8qxJSnu+7dRq6upnbntrmriWByIakBuct5OM/MdQC1M= +golang.org/x/sys v0.0.0-20210225134936-a50acf3fe073/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/term v0.0.0-20201117132131-f5c789dd3221/go.mod h1:Nr5EML6q2oocZ2LXRh80K7BxOlk5/8JxuGnuhpl+muw= golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo= golang.org/x/term v0.0.0-20201210144234-2321bbc49cbf h1:MZ2shdL+ZM/XzY3ZGOnh4Nlpnxz5GSOhOmtHo3iPU6M= diff --git a/posts.go b/posts.go index d61f7ab..5fd24ae 100644 --- a/posts.go +++ b/posts.go @@ -8,10 +8,8 @@ import ( "reflect" "strconv" "strings" - "time" "github.com/go-chi/chi" - "github.com/goodsign/monday" "github.com/vcraescu/go-paginator" ) @@ -152,28 +150,19 @@ func serveSearchResults(blog string, path string) func(w http.ResponseWriter, r } func serveDate(blog string, path string, year, month, day int) func(w http.ResponseWriter, r *http.Request) { - var title string - // Specific - if year != 0 && month == 0 && day == 0 { - title = fmt.Sprintf("%0004d", year) - } else if year != 0 && month != 0 && day == 0 { - ml := monday.Locale(appConfig.Blogs[blog].TimeLang) - date := time.Date(year, time.Month(month), 1, 1, 0, 0, 0, time.Local) - title = monday.Format(date, "January 2006", ml) - } else if year != 0 && month != 0 && day != 0 { - ml := monday.Locale(appConfig.Blogs[blog].TimeLang) - date := time.Date(year, time.Month(month), day, 1, 0, 0, 0, time.Local) - title = monday.Format(date, "January 2, 2006", ml) - } else - // Generic - if year == 0 && month != 0 && day == 0 { - ml := monday.Locale(appConfig.Blogs[blog].TimeLang) - date := time.Date(0, time.Month(month), 1, 1, 0, 0, 0, time.Local) - title = monday.Format(date, "January", ml) - } else if year == 0 && month != 0 && day != 0 { - ml := monday.Locale(appConfig.Blogs[blog].TimeLang) - date := time.Date(0, time.Month(month), day, 1, 0, 0, 0, time.Local) - title = monday.Format(date, "January 2", ml) + var title strings.Builder + if year != 0 { + title.WriteString(fmt.Sprintf("%0004d", year)) + } else { + title.WriteString("XXXX") + } + if month != 0 { + title.WriteString(fmt.Sprintf("-%02d", month)) + } else if day != 0 { + title.WriteString("-XX") + } + if day != 0 { + title.WriteString(fmt.Sprintf("-%02d", day)) } return serveIndex(&indexConfig{ blog: blog, @@ -181,7 +170,7 @@ func serveDate(blog string, path string, year, month, day int) func(w http.Respo year: year, month: month, day: day, - title: title, + title: title.String(), }) } diff --git a/render.go b/render.go index 2449cd4..f1e2ae2 100644 --- a/render.go +++ b/render.go @@ -16,7 +16,6 @@ import ( "time" "github.com/araddon/dateparse" - "github.com/goodsign/monday" ) const ( @@ -93,20 +92,9 @@ func initRendering() error { return p.shortURL() }, // Others - "dateformat": func(date string, format string) string { - d, err := dateparse.ParseLocal(date) - if err != nil { - return "" - } - return d.Local().Format(format) - }, - "longdate": func(date string, localeString string) string { - d, err := dateparse.ParseLocal(date) - if err != nil { - return "" - } - ml := monday.Locale(localeString) - return monday.Format(d.Local(), monday.LongFormatsByLocale[ml], ml) + "dateformat": dateFormat, + "isodate": func(date string) string { + return dateFormat(date, "2006-01-02") }, "unixtodate": func(unix int64) string { return time.Unix(unix, 0).Local().String() diff --git a/templates/summaryandpostmeta.gohtml b/templates/summaryandpostmeta.gohtml index fca6d5c..591f917 100644 --- a/templates/summaryandpostmeta.gohtml +++ b/templates/summaryandpostmeta.gohtml @@ -1,7 +1,7 @@ {{ define "summaryandpostmeta" }} {{ $section := (index .Blog.Sections .Data.Section) }} - {{ if .Data.Published }}
{{ string .Blog.Lang "publishedon" }} {{ if $section }} in {{ $section.Title }}{{ end }}
{{ end }} - {{ if .Data.Updated }}
{{ string .Blog.Lang "updatedon" }}
{{ end }} + {{ if .Data.Published }}
{{ string .Blog.Lang "publishedon" }} {{ if $section }} in {{ $section.Title }}{{ end }}
{{ end }} + {{ if .Data.Updated }}
{{ string .Blog.Lang "updatedon" }}
{{ end }} {{ if p .Data "replylink" }}
{{ string .Blog.Lang "replyto" }}: {{ p .Data "replytitle" | default (p .Data "replylink") }}
{{ end }} diff --git a/utils.go b/utils.go index 140d33c..f3dd4fc 100644 --- a/utils.go +++ b/utils.go @@ -157,3 +157,11 @@ func toLocal(s string) (string, error) { } return d.Local().String(), nil } + +func dateFormat(date string, format string) string { + d, err := dateparse.ParseLocal(date) + if err != nil { + return "" + } + return d.Local().Format(format) +}