all repos — flounder @ e1a6fee5a7a780ce52c136430e98bd954f22f2a2

A small site builder for the Gemini protocol

Present atom feeds
alex wennerberg alex@alexwennerberg.com
Mon, 28 Dec 2020 09:51:06 -0800
commit

e1a6fee5a7a780ce52c136430e98bd954f22f2a2

parent

a507b689d5339bd010f078c24ec8ea0a3e6ec58e

3 files changed, 24 insertions(+), 6 deletions(-)

jump to
M gemfeed.gogemfeed.go

@@ -26,7 +26,7 @@ Url *url.URL

Entries []FeedEntry } -func (gf *Gemfeed) toGorillafeed() *feeds.Feed { +func (gf *Gemfeed) toAtomFeed() string { feed := feeds.Feed{ Title: gf.Title, Author: &feeds.Author{Name: gf.Creator},

@@ -40,7 +40,8 @@ Link: &feeds.Link{Href: fe.Url.String()}, // Rel=alternate?

Created: fe.Date, // Updated not created? }) } - return &feed + res, _ := feed.ToAtom() + return res } type FeedEntry struct {
M gemini.gogemini.go

@@ -88,12 +88,21 @@ w.WriteStatus(gmi.StatusNotFound)

return } log.Println("Request for gemini file", fileName, "for user", userName) - + fullPath := path.Join(c.FilesDirectory, userName, fileName) if fileName == "/gemlog" { // temp hack - _, err := os.Stat(path.Join(c.FilesDirectory, userName, fileName, "index.gmi")) + _, err := os.Stat(path.Join(fullPath, "index.gmi")) if err != nil { w.SetMediaType("text/gemini") io.Copy(w, strings.NewReader(generateGemfeedPage(userName))) + return + } + } else if fileName == "/gemlog/atom.xml" { + _, err := os.Stat(fullPath) + if err != nil { + w.SetMediaType("application/atom+xml") + feed := generateFeedFromUser(userName) + atomString := feed.toAtomFeed() + io.Copy(w, strings.NewReader(atomString)) return } }
M http.gohttp.go

@@ -530,7 +530,7 @@ userName := filepath.Clean(strings.Split(r.Host, ".")[0]) // Clean probably unnecessary

p := filepath.Clean(r.URL.Path) var isDir bool fullPath := path.Join(c.FilesDirectory, userName, p) // TODO rename filepath - stat, _ := os.Stat(fullPath) + stat, err := os.Stat(fullPath) if stat != nil { isDir = stat.IsDir() }

@@ -546,9 +546,17 @@ if r.URL.Path == "/style.css" {

http.ServeFile(w, r, path.Join(c.TemplatesDirectory, "static/style.css")) return } + if r.URL.Path == "/gemlog/atom.xml" && os.IsNotExist(err) { + w.Header().Set("Content-Type", "application/atom+xml") + // TODO set always somehow + feed := generateFeedFromUser(userName) + atomString := feed.toAtomFeed() + io.Copy(w, strings.NewReader(atomString)) + return + } var geminiContent string - _, err := os.Stat(path.Join(fullPath, "index.gmi")) + _, err = os.Stat(path.Join(fullPath, "index.gmi")) if p == "/" || isDir { if os.IsNotExist(err) { if p == "/gemlog" {