all repos — flounder @ a507b689d5339bd010f078c24ec8ea0a3e6ec58e

A small site builder for the Gemini protocol

Add feed builder
alex wennerberg alex@alexwennerberg.com
Mon, 28 Dec 2020 09:25:13 -0800
commit

a507b689d5339bd010f078c24ec8ea0a3e6ec58e

parent

f39fba2d03282d8217ee76b53fe46c100acec304

3 files changed, 25 insertions(+), 2 deletions(-)

jump to
M gemfeed.gogemfeed.go

@@ -1,9 +1,11 @@

-// Parses Gemfeed according to the companion spec: gemini://gemini.circumlunar.space/docs/companion/subscription.gmi +// Parses Gemfeed according to the companion spec: +// gemini://gemini.circumlunar.space/docs/companion/subscription.gmi package main import ( "bufio" "fmt" + "github.com/gorilla/feeds" "io" "net/url" "os"

@@ -14,6 +16,8 @@ "sort"

"strings" "time" ) + +const gemlogFolder = "gemlog" type Gemfeed struct { Title string

@@ -22,6 +26,23 @@ Url *url.URL

Entries []FeedEntry } +func (gf *Gemfeed) toGorillafeed() *feeds.Feed { + feed := feeds.Feed{ + Title: gf.Title, + Author: &feeds.Author{Name: gf.Creator}, + Link: &feeds.Link{Href: gf.Url.String()}, + } + feed.Items = []*feeds.Item{} + for _, fe := range gf.Entries { + feed.Items = append(feed.Items, &feeds.Item{ + Title: fe.Title, + Link: &feeds.Link{Href: fe.Url.String()}, // Rel=alternate? + Created: fe.Date, // Updated not created? + }) + } + return &feed +} + type FeedEntry struct { Title string Url *url.URL

@@ -42,7 +63,6 @@

// Non-standard extension // Requires yyyy-mm-dd formatted files func generateFeedFromUser(user string) *Gemfeed { - gemlogFolder := "gemlog" // TODO make configurable gemlogFolderPath := path.Join(c.FilesDirectory, user, gemlogFolder) // NOTE: assumes sanitized input u := urlFromPath(gemlogFolderPath)
M go.modgo.mod

@@ -6,6 +6,7 @@ require (

git.sr.ht/~adnano/go-gemini v0.1.8 github.com/BurntSushi/toml v0.3.1 github.com/emersion/go-webdav v0.3.0 + github.com/gorilla/feeds v1.1.1 github.com/gorilla/handlers v1.5.1 github.com/gorilla/sessions v1.2.1 github.com/mattn/go-sqlite3 v1.14.4
M go.sumgo.sum

@@ -45,6 +45,8 @@ github.com/google/go-cmp v0.3.1/go.mod h1:8QqcDgzrUqlUb/G2PQTWiueGozuR1884gddMywk6iLU=

github.com/google/go-cmp v0.4.0/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE= github.com/google/go-cmp v0.5.2/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE= github.com/google/gofuzz v1.0.0/go.mod h1:dBl0BpW6vV/+mYPU4Po3pmUjxk6FQPldtuIdl/M65Eg= +github.com/gorilla/feeds v1.1.1 h1:HwKXxqzcRNg9to+BbvJog4+f3s/xzvtZXICcQGutYfY= +github.com/gorilla/feeds v1.1.1/go.mod h1:Nk0jZrvPFZX1OBe5NPiddPw7CfwF6Q9eqzaBbaightA= github.com/gorilla/handlers v1.5.1 h1:9lRY6j8DEeeBT10CvO9hGW0gmky0BprnvDI5vfhUHH4= github.com/gorilla/handlers v1.5.1/go.mod h1:t8XrUpc4KVXb7HGyJ4/cEnwQiaxrX/hz1Zv/4g96P1Q= github.com/gorilla/securecookie v1.1.1 h1:miw7JPhV+b/lAHSXz4qd/nN9jRiAFV5FwjeKyCS8BvQ=