flounder

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

commit dc25dfe97957a301e6122d32ad4e6cbf45de2ecc
parent 3fea9763a7096b2cfd756691e68cd017a0c72c12
Author: alex wennerberg <alex@alexwennerberg.com>
Date:   Sun, 27 Dec 2020 20:23:16 -0800

Fix URLs in auto gen gemfeeds

Diffstat:
Mgemfeed.go | 30+++++++++++++++++++++---------
Mhttp.go | 4++--
Mtemplates/feed.html | 3+--
3 files changed, 24 insertions(+), 13 deletions(-)

diff --git a/gemfeed.go b/gemfeed.go @@ -19,7 +19,7 @@ type Gemfeed struct { Title string Creator string Url *url.URL - Entries []*FeedEntry + Entries []FeedEntry } type FeedEntry struct { @@ -31,16 +31,25 @@ type FeedEntry struct { File string // TODO refactor } +func urlFromPath(fullPath string) url.URL { + creator := getCreator(fullPath) + baseUrl := url.URL{} + baseUrl.Host = creator + "." + c.Host + baseUrl.Path = getLocalPath(fullPath) + return baseUrl +} + // Non-standard extension // Requires yyyy-mm-dd formatted files func generateFeedFromUser(user string) []FeedEntry { gemlogFolder := "gemlog" // TODO make configurable gemlogFolderPath := path.Join(c.FilesDirectory, user, gemlogFolder) // NOTE: assumes sanitized input + u := urlFromPath(gemlogFolderPath) feed := Gemfeed{ Title: user + "'s Gemfeed", Creator: user, - // URL? etc? + Url: &u, } var feedEntries []FeedEntry err := filepath.Walk(gemlogFolderPath, func(thepath string, info os.FileInfo, err error) error { @@ -80,6 +89,8 @@ func generateFeedFromUser(user string) []FeedEntry { break } entry.File = getLocalPath(thepath) + u := urlFromPath(thepath) + entry.Url = &u feedEntries = append(feedEntries, entry) } return nil @@ -95,11 +106,11 @@ func generateFeedFromUser(user string) []FeedEntry { // TODO definitely cache this function // TODO include generateFeedFromFolder for "gemfeed" folders -func getAllGemfeedEntries() ([]*FeedEntry, []*Gemfeed, error) { +func getAllGemfeedEntries() ([]FeedEntry, []Gemfeed, error) { maxUserItems := 25 maxItems := 50 - var feedEntries []*FeedEntry - var feeds []*Gemfeed + var feedEntries []FeedEntry + var feeds []Gemfeed users, err := getActiveUserNames() if err != nil { return nil, nil, err @@ -107,9 +118,10 @@ func getAllGemfeedEntries() ([]*FeedEntry, []*Gemfeed, error) { for _, user := range users { fe := generateFeedFromUser(user) if len(fe) > 0 { - feeds = append(feeds, fe[0].Feed) + feeds = append(feeds, *fe[0].Feed) for _, e := range fe { - feedEntries = append(feedEntries, &e) + fmt.Println(e) + feedEntries = append(feedEntries, e) } } } @@ -132,7 +144,7 @@ func getAllGemfeedEntries() ([]*FeedEntry, []*Gemfeed, error) { } feed.Url = &baseUrl feedEntries = append(feedEntries, feed.Entries...) - feeds = append(feeds, feed) + feeds = append(feeds, *feed) } } return nil @@ -189,7 +201,7 @@ func ParseGemfeed(text io.Reader, baseUrl url.URL, limit int) (*Gemfeed, error) if fe.Title == "" { fe.Title = "(Untitled)" } - gf.Entries = append(gf.Entries, &fe) + gf.Entries = append(gf.Entries, fe) } } } diff --git a/http.go b/http.go @@ -87,8 +87,8 @@ func feedHandler(w http.ResponseWriter, r *http.Request) { data := struct { Host string PageTitle string - FeedEntries []*FeedEntry - Feeds []*Gemfeed + FeedEntries []FeedEntry + Feeds []Gemfeed AuthUser AuthUser }{c.Host, c.SiteTitle, feedEntries, feeds, user} err = t.ExecuteTemplate(w, "feed.html", data) diff --git a/templates/feed.html b/templates/feed.html @@ -8,8 +8,7 @@ For more information on how to format your site to show up here, see <a href="ht <h2>Feed:</h2> {{ range .FeedEntries}} <p> -{{.DateString}} <a href="//{{.Feed.Creator}}.{{$domain}}">{{.Feed.Creator}}</a> -{{ if .Feed.Title }}<em><a href="{{.Feed.Url}}">{{.Feed.Title}}</a></em>{{end}} <a href="{{.Url}}">{{.Title}}</a> +{{.DateString}} {{ if .Feed.Title }}<em><a href="{{.Feed.Url}}">{{.Feed.Title}}</a></em>{{end}} <a href="{{.Url}}">{{.Title}}</a> </p> {{end}} <h2>All Feeds:</h2>