1 Show titles from posts on page

This commit is contained in:
Peter Stuifzand 2019-12-22 10:52:43 +01:00
parent 2c5e249787
commit 32bbd6a954
5 changed files with 88 additions and 0 deletions

1
.gitignore vendored Normal file
View File

@ -0,0 +1 @@
/weekly

10
go.mod Normal file
View File

@ -0,0 +1,10 @@
module p83.nl/go/weekly
go 1.12
require (
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
willnorris.com/go/microformats v1.0.0
)

11
go.sum Normal file
View File

@ -0,0 +1,11 @@
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=
golang.org/x/net v0.0.0-20191209160850-c0dbc17a3553 h1:efeOvDhwQ29Dj3SdAV/MJf8oukgn+8D8WgaCaRMchF8=
golang.org/x/net v0.0.0-20191209160850-c0dbc17a3553/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s=
golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
p83.nl/go/ekster v0.0.0-20191119211024-4511657daa0b h1:MzIItcq83xZn1apSjCNovs55CZE/R/7GUnlOeIJ9HRI=
p83.nl/go/ekster v0.0.0-20191119211024-4511657daa0b/go.mod h1:NDCrcUlnixnkQ4u36jm3Hhvq0WcayEjg8SpAsFdQWLE=
willnorris.com/go/microformats v1.0.0 h1:II6uDIJBPp6RpJQqRWm+6IN9lI00mN/jQAC5OHuF4HA=
willnorris.com/go/microformats v1.0.0/go.mod h1:AXRtimOA0J5fDmM2sxlka4G6PNLWC4bCNJcZjLvFdDw=

43
main.go Normal file
View File

@ -0,0 +1,43 @@
package main
import (
"html/template"
"log"
"net/http"
"net/url"
"os"
"willnorris.com/go/microformats"
"p83.nl/go/ekster/pkg/jf2"
)
func main() {
u, err := url.Parse(os.Args[1])
if err != nil {
log.Fatal(err)
}
resp, err := http.Get(u.String())
if err != nil {
log.Fatal(err)
}
defer resp.Body.Close()
if resp.StatusCode != 200 {
log.Fatalf("Status is not 200, but %d", resp.StatusCode)
}
md := microformats.Parse(resp.Body, u)
items := jf2.SimplifyMicroformatDataItems(md)
t, err := template.ParseFiles("templates/weekly.html")
if err != nil {
log.Fatal(err)
}
err = t.Execute(os.Stdout, items)
if err != nil {
log.Fatal(err)
}
}

23
templates/weekly.html Normal file
View File

@ -0,0 +1,23 @@
<html lang="en">
<head>
<title>Weekly summaries</title>
</head>
<body>
<div class="h-feed">
<h1 class="p-name">Weekly</h1>
{{ range . }}
<div class="h-entry">
<h2 class="p-name">{{ .Name }}</h2>
{{ if .Content }}
{{ if .Content.HTML }}
<div class="e-content">{{ .Content.HTML }}</div>
{{ else }}
<div class="p-content">{{ .Content.Text }}</div>
{{ end }}
{{ end }}
</div>
{{ end }}
</div>
</body>
</html>