all repos — flounder @ 1429d073ba5d02bc8b20b3b9cea99a76956de427

A small site builder for the Gemini protocol

Add all feeds links
alex wennerberg alex@alexwennerberg.com
Sun, 27 Dec 2020 12:57:15 -0800
commit

1429d073ba5d02bc8b20b3b9cea99a76956de427

parent

a748ebeb6a8fdb2e3c36307af3144e5bd815b1a3

3 files changed, 14 insertions(+), 7 deletions(-)

jump to
M gemfeed.gogemfeed.go

@@ -30,10 +30,11 @@ Feed *Gemfeed

} // TODO definitely cache this function -- it reads EVERY gemini file on flounder. -func getAllGemfeedEntries() ([]*FeedEntry, error) { +func getAllGemfeedEntries() ([]*FeedEntry, []*Gemfeed, error) { maxUserItems := 25 - maxItems := 100 + maxItems := 50 var feedEntries []*FeedEntry + var feeds []*Gemfeed err := filepath.Walk(c.FilesDirectory, func(thepath string, info os.FileInfo, err error) error { if isGemini(info.Name()) { f, err := os.Open(thepath)

@@ -51,20 +52,21 @@ feed.Title = "(Untitled Feed)"

} feed.Url = &baseUrl feedEntries = append(feedEntries, feed.Entries...) + feeds = append(feeds, feed) } } return nil }) if err != nil { - return nil, err + return nil, nil, err } else { sort.Slice(feedEntries, func(i, j int) bool { return feedEntries[i].Date.After(feedEntries[j].Date) }) if len(feedEntries) > maxItems { - return feedEntries[:maxItems], nil + return feedEntries[:maxItems], feeds, nil } - return feedEntries, nil + return feedEntries, feeds, nil } }
M http.gohttp.go

@@ -80,7 +80,7 @@ }

func feedHandler(w http.ResponseWriter, r *http.Request) { user := newGetAuthUser(r) - feedEntries, err := getAllGemfeedEntries() + feedEntries, feeds, err := getAllGemfeedEntries() if err != nil { panic(err) }

@@ -88,8 +88,9 @@ data := struct {

Host string PageTitle string FeedEntries []*FeedEntry + Feeds []*Gemfeed AuthUser AuthUser - }{c.Host, c.SiteTitle, feedEntries, user} + }{c.Host, c.SiteTitle, feedEntries, feeds, user} err = t.ExecuteTemplate(w, "feed.html", data) if err != nil { panic(err)
M templates/feed.htmltemplates/feed.html

@@ -12,4 +12,8 @@ {{.DateString}} <a href="//{{.Feed.Creator}}.{{$domain}}">{{.Feed.Creator}}</a>

{{ if .Feed.Title }}<em><a href="{{.Feed.Url}}" class='person-link'>{{.Feed.Title}}</a></em>{{end}} <a href="{{.Url}}">{{.Title}}</a> </p> {{end}} +<h2>All Feeds:</h2> +{{ range .Feeds}} +<a href="{{.Url}}" class='person-link'>{{.Url}}</a> +{{ end}} {{template "footer" .}}