flounder

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

commit e1a6fee5a7a780ce52c136430e98bd954f22f2a2
parent a507b689d5339bd010f078c24ec8ea0a3e6ec58e
Author: alex wennerberg <alex@alexwennerberg.com>
Date:   Mon, 28 Dec 2020 09:51:06 -0800

Present atom feeds

Diffstat:
Mgemfeed.go | 5+++--
Mgemini.go | 13+++++++++++--
Mhttp.go | 12++++++++++--
3 files changed, 24 insertions(+), 6 deletions(-)

diff --git a/gemfeed.go b/gemfeed.go @@ -26,7 +26,7 @@ type Gemfeed struct { 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 @@ func (gf *Gemfeed) toGorillafeed() *feeds.Feed { Created: fe.Date, // Updated not created? }) } - return &feed + res, _ := feed.ToAtom() + return res } type FeedEntry struct { diff --git a/gemini.go b/gemini.go @@ -88,14 +88,23 @@ func gmiPage(w *gmi.ResponseWriter, r *gmi.Request) { 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 + } } gmi.ServeFile(w, gmi.Dir(path.Join(c.FilesDirectory, userName)), fileName) diff --git a/http.go b/http.go @@ -530,7 +530,7 @@ func userFile(w http.ResponseWriter, r *http.Request) { 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 @@ func userFile(w http.ResponseWriter, r *http.Request) { 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" {