all repos — flounder @ dc25dfe97957a301e6122d32ad4e6cbf45de2ecc

A small site builder for the Gemini protocol

Fix URLs in auto gen gemfeeds
alex wennerberg alex@alexwennerberg.com
Sun, 27 Dec 2020 20:23:16 -0800
commit

dc25dfe97957a301e6122d32ad4e6cbf45de2ecc

parent

3fea9763a7096b2cfd756691e68cd017a0c72c12

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

jump to
M gemfeed.gogemfeed.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 @@ Feed *Gemfeed

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 @@ }

break } entry.File = getLocalPath(thepath) + u := urlFromPath(thepath) + entry.Url = &u feedEntries = append(feedEntries, entry) } return nil

@@ -95,11 +106,11 @@ }

// 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 @@ } else {

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 @@ feed.Title = "(Untitled Feed)"

} feed.Url = &baseUrl feedEntries = append(feedEntries, feed.Entries...) - feeds = append(feeds, feed) + feeds = append(feeds, *feed) } } return nil

@@ -189,7 +201,7 @@ fe := FeedEntry{title, parsedUrl, date, matches[2], &gf, ""}

if fe.Title == "" { fe.Title = "(Untitled)" } - gf.Entries = append(gf.Entries, &fe) + gf.Entries = append(gf.Entries, fe) } } }
M http.gohttp.go

@@ -87,8 +87,8 @@ }

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)
M templates/feed.htmltemplates/feed.html

@@ -8,8 +8,7 @@ For more information on how to format your site to show up here, see <a href="https://admin.flounder.online/gemfeed.gmi">this documentation</a>

<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>