flounder

A simple gemini site builder
Log | Files | Refs | README | LICENSE

commit a507b689d5339bd010f078c24ec8ea0a3e6ec58e
parent f39fba2d03282d8217ee76b53fe46c100acec304
Author: alex wennerberg <alex@alexwennerberg.com>
Date:   Mon, 28 Dec 2020 09:25:13 -0800

Add feed builder

Diffstat:
Mgemfeed.go | 24++++++++++++++++++++++--
Mgo.mod | 1+
Mgo.sum | 2++
3 files changed, 25 insertions(+), 2 deletions(-)

diff --git a/gemfeed.go b/gemfeed.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" @@ -15,6 +17,8 @@ import ( "time" ) +const gemlogFolder = "gemlog" + type Gemfeed struct { Title string Creator string @@ -22,6 +26,23 @@ type Gemfeed struct { 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 @@ func urlFromPath(fullPath string) url.URL { // 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) diff --git a/go.mod b/go.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 diff --git a/go.sum b/go.sum @@ -45,6 +45,8 @@ github.com/google/go-cmp v0.3.1/go.mod h1:8QqcDgzrUqlUb/G2PQTWiueGozuR1884gddMyw 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=