flounder

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

commit ae612edb4c91f05f4cc2e44a1bd8546092214e90
parent c22ee7e5f475466e3b1350eec310ee1bf57b2834
Author: alex wennerberg <alex@alexwennerberg.com>
Date:   Sun, 31 Oct 2021 01:23:40 -0700

Add RSS feeeed for file updates

kinda wonky
only on http atm

Diffstat:
Mhttp.go | 39++++++++++++++++++++++++++++++++++++---
1 file changed, 36 insertions(+), 3 deletions(-)

diff --git a/http.go b/http.go @@ -17,6 +17,7 @@ import ( "time" gmi "git.sr.ht/~adnano/go-gemini" + feeds "git.sr.ht/~aw/gorilla-feeds" "github.com/gorilla/handlers" "github.com/gorilla/sessions" _ "github.com/mattn/go-sqlite3" @@ -89,18 +90,50 @@ func rootHandler(w http.ResponseWriter, r *http.Request) { func updatesHandler(w http.ResponseWriter, r *http.Request) { // user authUser := getAuthUser(r) - username := filepath.Clean(r.URL.Path[len("/updates/"):]) + var username string + if strings.HasSuffix(r.URL.Path, "atom.xml") { + username = filepath.Clean(r.URL.Path[len("/updates/") : len(r.URL.Path)-len("atom.xml")]) + w.Header().Set("Content-Type", "application/atom+xml") + // build atom feed + files, err := getUpdatedFiles(authUser.IsAdmin, username) + if err != nil { + serverError(w, err) + return + } + baseURL := "//" + username + "." + c.Host + feed := feeds.Feed{ + Title: username + "'s updated files", + Author: &feeds.Author{Name: username}, + Link: &feeds.Link{Href: baseURL}, + } + feed.Items = []*feeds.Item{} + for _, file := range files { + feed.Items = append(feed.Items, &feeds.Item{ + Title: file.Name, + Link: &feeds.Link{Href: baseURL + "/" + file.Name}, + Created: file.UpdatedTime, // actually updated. kinda funky + }) + } + res, err := feed.ToAtom() + if err != nil { + serverError(w, err) + return + } + io.Copy(w, strings.NewReader(res)) + return + } else { + username = filepath.Clean(r.URL.Path[len("/updates/"):]) + } files, err := getUpdatedFiles(authUser.IsAdmin, username) if err != nil { serverError(w, err) return } data := struct { - Config Config AuthUser AuthUser User string Files []*File - }{c, authUser, username, files} + }{authUser, username, files} err = t.ExecuteTemplate(w, "updates.html", data) if err != nil { serverError(w, err)