mirror of https://github.com/jlelse/GoBlog
Use ParseLocal method
This commit is contained in:
parent
68650a883e
commit
6256b2fdd9
|
@ -7,7 +7,7 @@ WORKDIR /app
|
|||
RUN go build --tags "libsqlite3 linux sqlite_fts5"
|
||||
|
||||
FROM alpine:3.12
|
||||
RUN apk add --no-cache sqlite-dev
|
||||
RUN apk add --no-cache sqlite-dev tzdata
|
||||
COPY templates/ /app/templates/
|
||||
COPY --from=build /app/GoBlog /bin/
|
||||
WORKDIR /app
|
||||
|
|
|
@ -5,7 +5,6 @@ import (
|
|||
"encoding/pem"
|
||||
"net/http"
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
"github.com/araddon/dateparse"
|
||||
)
|
||||
|
@ -104,12 +103,12 @@ func (p *post) toASNote() *asNote {
|
|||
// Dates
|
||||
dateFormat := "2006-01-02T15:04:05-07:00"
|
||||
if p.Published != "" {
|
||||
if t, err := dateparse.ParseIn(p.Published, time.Local); err == nil {
|
||||
if t, err := dateparse.ParseLocal(p.Published); err == nil {
|
||||
as.Published = t.Format(dateFormat)
|
||||
}
|
||||
}
|
||||
if p.Updated != "" {
|
||||
if t, err := dateparse.ParseIn(p.Updated, time.Local); err == nil {
|
||||
if t, err := dateparse.ParseLocal(p.Updated); err == nil {
|
||||
as.Updated = t.Format(dateFormat)
|
||||
}
|
||||
}
|
||||
|
|
4
feeds.go
4
feeds.go
|
@ -43,8 +43,8 @@ func generateFeed(blog string, f feedType, w http.ResponseWriter, r *http.Reques
|
|||
},
|
||||
}
|
||||
for _, p := range posts {
|
||||
created, _ := dateparse.ParseIn(p.Published, time.Local)
|
||||
updated, _ := dateparse.ParseIn(p.Updated, time.Local)
|
||||
created, _ := dateparse.ParseLocal(p.Published)
|
||||
updated, _ := dateparse.ParseLocal(p.Updated)
|
||||
var enc *feeds.Enclosure
|
||||
if p.firstParameter(feedAudioURL) != "" {
|
||||
enc = &feeds.Enclosure{
|
||||
|
|
4
go.mod
4
go.mod
|
@ -58,12 +58,12 @@ require (
|
|||
golang.org/x/crypto v0.0.0-20201208171446-5f87f3452ae9 // indirect
|
||||
golang.org/x/lint v0.0.0-20201208152925-83fdc39ff7b5 // indirect
|
||||
golang.org/x/mod v0.4.0 // indirect
|
||||
golang.org/x/net v0.0.0-20201209123823-ac852fbbde11 // indirect
|
||||
golang.org/x/net v0.0.0-20201216054612-986b41b23924 // indirect
|
||||
golang.org/x/sync v0.0.0-20201207232520-09787c993a3a
|
||||
golang.org/x/sys v0.0.0-20201214210602-f9fddec55a1e // indirect
|
||||
golang.org/x/term v0.0.0-20201210144234-2321bbc49cbf // indirect
|
||||
golang.org/x/text v0.3.4 // indirect
|
||||
golang.org/x/tools v0.0.0-20201211185031-d93e913c1a58 // indirect
|
||||
golang.org/x/tools v0.0.0-20201215192005-fa10ef0b8743 // indirect
|
||||
gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c // indirect
|
||||
gopkg.in/ini.v1 v1.62.0 // indirect
|
||||
gopkg.in/yaml.v2 v2.4.0 // indirect
|
||||
|
|
8
go.sum
8
go.sum
|
@ -420,8 +420,8 @@ golang.org/x/net v0.0.0-20200202094626-16171245cfb2/go.mod h1:z5CRVTTTmAJ677TzLL
|
|||
golang.org/x/net v0.0.0-20200226121028-0de0cce0169b/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s=
|
||||
golang.org/x/net v0.0.0-20200707034311-ab3426394381/go.mod h1:/O7V0waA8r7cgGh81Ro3o1hOxt32SMVPicZroKQ2sZA=
|
||||
golang.org/x/net v0.0.0-20201021035429-f5854403a974/go.mod h1:sp8m0HH+o8qH0wwXwYZr8TS3Oi6o0r6Gce1SSxlDquU=
|
||||
golang.org/x/net v0.0.0-20201209123823-ac852fbbde11 h1:lwlPPsmjDKK0J6eG6xDWd5XPehI0R024zxjDnw3esPA=
|
||||
golang.org/x/net v0.0.0-20201209123823-ac852fbbde11/go.mod h1:m0MpNAwzfU5UDzcl9v0D8zg8gWTRqZa9RBIspLL5mdg=
|
||||
golang.org/x/net v0.0.0-20201216054612-986b41b23924 h1:QsnDpLLOKwHBBDa8nDws4DYNc/ryVW2vCpxCs09d4PY=
|
||||
golang.org/x/net v0.0.0-20201216054612-986b41b23924/go.mod h1:m0MpNAwzfU5UDzcl9v0D8zg8gWTRqZa9RBIspLL5mdg=
|
||||
golang.org/x/oauth2 v0.0.0-20180821212333-d2e6202438be/go.mod h1:N/0e6XlmueqKjAGxoOufVs8QHGRruUQn6yWY3a++T0U=
|
||||
golang.org/x/oauth2 v0.0.0-20190226205417-e64efc72b421/go.mod h1:gOpvHmFTYa4IltrdGE7lF6nIHvwfUNPOp7c8zoXwtLw=
|
||||
golang.org/x/oauth2 v0.0.0-20190604053449-0f29369cfe45/go.mod h1:gOpvHmFTYa4IltrdGE7lF6nIHvwfUNPOp7c8zoXwtLw=
|
||||
|
@ -499,8 +499,8 @@ golang.org/x/tools v0.0.0-20191216052735-49a3e744a425 h1:VvQyQJN0tSuecqgcIxMWnnf
|
|||
golang.org/x/tools v0.0.0-20191216052735-49a3e744a425/go.mod h1:TB2adYChydJhpapKDTa4BR/hXlZSLoq2Wpct/0txZ28=
|
||||
golang.org/x/tools v0.0.0-20200130002326-2f3ba24bd6e7/go.mod h1:TB2adYChydJhpapKDTa4BR/hXlZSLoq2Wpct/0txZ28=
|
||||
golang.org/x/tools v0.0.0-20200609164405-eb789aa7ce50/go.mod h1:EkVYQZoAsY45+roYkvgYkIh4xh/qjgUK9TdY2XT94GE=
|
||||
golang.org/x/tools v0.0.0-20201211185031-d93e913c1a58 h1:1Bs6RVeBFtLZ8Yi1Hk07DiOqzvwLD/4hln4iahvFlag=
|
||||
golang.org/x/tools v0.0.0-20201211185031-d93e913c1a58/go.mod h1:emZCQorbCU4vsT4fOWvOPXz4eW1wZW4PmDk9uLelYpA=
|
||||
golang.org/x/tools v0.0.0-20201215192005-fa10ef0b8743 h1:SLHKXsC4wI4NdEGVGe/yxcTBkF/mPUS7agW3Qt5smVg=
|
||||
golang.org/x/tools v0.0.0-20201215192005-fa10ef0b8743/go.mod h1:emZCQorbCU4vsT4fOWvOPXz4eW1wZW4PmDk9uLelYpA=
|
||||
golang.org/x/xerrors v0.0.0-20190717185122-a985d3407aa7/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
|
||||
golang.org/x/xerrors v0.0.0-20191011141410-1b5146add898/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
|
||||
golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543 h1:E7g+9GITq07hpfrRu66IVDexMakfv52eLZ2CXBWiKr4=
|
||||
|
|
|
@ -21,14 +21,14 @@ func (p *post) checkPost() error {
|
|||
p.Content = strings.TrimSuffix(strings.TrimPrefix(p.Content, "\n"), "\n")
|
||||
// Fix date strings
|
||||
if p.Published != "" {
|
||||
d, err := dateparse.ParseIn(p.Published, time.Local)
|
||||
d, err := dateparse.ParseLocal(p.Published)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
p.Published = d.String()
|
||||
}
|
||||
if p.Updated != "" {
|
||||
d, err := dateparse.ParseIn(p.Updated, time.Local)
|
||||
d, err := dateparse.ParseLocal(p.Updated)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
@ -73,7 +73,7 @@ func (p *post) checkPost() error {
|
|||
random := generateRandomString(5)
|
||||
p.Slug = fmt.Sprintf("%v-%02d-%02d-%v", now.Year(), int(now.Month()), now.Day(), random)
|
||||
}
|
||||
published, _ := dateparse.ParseIn(p.Published, time.Local)
|
||||
published, _ := dateparse.ParseLocal(p.Published)
|
||||
pathTmplString := appConfig.Blogs[p.Blog].Sections[p.Section].PathTemplate
|
||||
if pathTmplString == "" {
|
||||
return errors.New("path template empty")
|
||||
|
|
10
render.go
10
render.go
|
@ -87,14 +87,14 @@ func initRendering() error {
|
|||
},
|
||||
// Others
|
||||
"dateformat": func(date string, format string) string {
|
||||
d, err := dateparse.ParseIn(date, time.Local)
|
||||
d, err := dateparse.ParseLocal(date)
|
||||
if err != nil {
|
||||
return ""
|
||||
}
|
||||
return d.Format(format)
|
||||
},
|
||||
"longdate": func(date string, localeString string) string {
|
||||
d, err := dateparse.ParseIn(date, time.Local)
|
||||
d, err := dateparse.ParseLocal(date)
|
||||
if err != nil {
|
||||
return ""
|
||||
}
|
||||
|
@ -108,18 +108,18 @@ func initRendering() error {
|
|||
return time.Now().String()
|
||||
},
|
||||
"dateadd": func(date string, years, months, days int) string {
|
||||
d, err := dateparse.ParseIn(date, time.Local)
|
||||
d, err := dateparse.ParseLocal(date)
|
||||
if err != nil {
|
||||
return ""
|
||||
}
|
||||
return d.AddDate(years, months, days).String()
|
||||
},
|
||||
"datebefore": func(date string, before string) bool {
|
||||
d, err := dateparse.ParseIn(date, time.Local)
|
||||
d, err := dateparse.ParseLocal(date)
|
||||
if err != nil {
|
||||
return false
|
||||
}
|
||||
b, err := dateparse.ParseIn(before, time.Local)
|
||||
b, err := dateparse.ParseLocal(before)
|
||||
if err != nil {
|
||||
return false
|
||||
}
|
||||
|
|
|
@ -23,10 +23,10 @@ func serveSitemap(w http.ResponseWriter, r *http.Request) {
|
|||
Loc: p.fullURL()}
|
||||
var lastMod time.Time
|
||||
if p.Updated != "" {
|
||||
lastMod, _ = dateparse.ParseIn(p.Updated, time.Local)
|
||||
lastMod, _ = dateparse.ParseLocal(p.Updated)
|
||||
}
|
||||
if p.Published != "" && lastMod.IsZero() {
|
||||
lastMod, _ = dateparse.ParseIn(p.Published, time.Local)
|
||||
lastMod, _ = dateparse.ParseLocal(p.Published)
|
||||
}
|
||||
if !lastMod.IsZero() {
|
||||
item.LastMod = &lastMod
|
||||
|
|
Loading…
Reference in New Issue