Merge branch 'only-week'

This commit is contained in:
Peter Stuifzand 2019-12-22 11:10:54 +01:00
commit 2e4e7c4d86
4 changed files with 24 additions and 0 deletions

1
go.mod
View File

@ -3,6 +3,7 @@ module p83.nl/go/weekly
go 1.12
require (
github.com/jinzhu/now v1.1.1
github.com/pkg/errors v0.8.1 // indirect
golang.org/x/net v0.0.0-20191209160850-c0dbc17a3553 // indirect
p83.nl/go/ekster v0.0.0-20191119211024-4511657daa0b

2
go.sum
View File

@ -1,3 +1,5 @@
github.com/jinzhu/now v1.1.1 h1:g39TucaRWyV3dwDO++eEc6qf8TVIQ/Da48WmqjZ3i7E=
github.com/jinzhu/now v1.1.1/go.mod h1:d3SSVoowX0Lcu0IBviAWJpolVfI5UJVZZ7cO71lE/z8=
github.com/pkg/errors v0.8.1 h1:iURUrRGxPUNPdy5/HRSm+Yj6okJ6UtLINN0Q9M4+h3I=
github.com/pkg/errors v0.8.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0=
golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w=

19
main.go
View File

@ -6,7 +6,10 @@ import (
"net/http"
"net/url"
"os"
"time"
"github.com/jinzhu/now"
"p83.nl/go/ekster/pkg/microsub"
"willnorris.com/go/microformats"
"p83.nl/go/ekster/pkg/jf2"
@ -31,6 +34,8 @@ func main() {
md := microformats.Parse(resp.Body, u)
items := jf2.SimplifyMicroformatDataItems(md)
items = filterEntriesAfter(items, now.With(time.Now()).Monday())
t, err := template.ParseFiles("templates/weekly.html")
if err != nil {
log.Fatal(err)
@ -41,3 +46,17 @@ func main() {
log.Fatal(err)
}
}
func filterEntriesAfter(items []microsub.Item, from time.Time) []microsub.Item {
var result []microsub.Item
for _, item := range items {
published, err := time.Parse(time.RFC3339, item.Published)
if err != nil {
continue
}
if published.After(from) {
result = append(result, item)
}
}
return result
}

View File

@ -16,6 +16,8 @@
<div class="p-content">{{ .Content.Text }}</div>
{{ end }}
{{ end }}
<time datetime="{{ .Published }}">{{ .Published }}</time>
</div>
{{ end }}
</div>