~danilax86: 1 Migrate from gorilla/feeds 4 files changed, 53 insertions(+), 75 deletions(-)
Copy & paste the following snippet into your terminal to import this patchset into git:
curl -s https://lists.sr.ht/~bouncepaw/betula/patches/49710/mbox | git am -3Learn more about email & git
From: Danila Gorelko <danila@danilax86.space> Fixes: https://todo.sr.ht/~bouncepaw/betula/112 --- feeds/feed.go | 68 ++++++++++++++++++++++++------------------------- go.mod | 11 +++----- go.sum | 24 ++++++----------- web/handlers.go | 25 ++++++------------ 4 files changed, 53 insertions(+), 75 deletions(-) diff --git a/feeds/feed.go b/feeds/feed.go index 1074104..fd6abc2 100644 --- a/feeds/feed.go +++ b/feeds/feed.go @@ -7,12 +7,14 @@ import ( "git.sr.ht/~bouncepaw/betula/myco" "git.sr.ht/~bouncepaw/betula/settings" "git.sr.ht/~bouncepaw/betula/types" - "github.com/gorilla/feeds" + "humungus.tedunangst.com/r/webs/rss" "log" "strings" "time" ) +const rssTimeFormat = time.RFC822 + func fiveLastDays(now time.Time) (days []time.Time, dayStamps []string, dayPosts [][]types.Bookmark) { days = make([]time.Time, 5) dayStamps = make([]string, 5) @@ -29,20 +31,18 @@ func fiveLastDays(now time.Time) (days []time.Time, dayStamps []string, dayPosts return days, dayStamps, dayPosts } -func Posts() *feeds.Feed { - author := &feeds.Author{ - Name: settings.AdminUsername(), - } +func Posts() *rss.Feed { + author := settings.AdminUsername() + now := time.Now().AddDate(0, 0, 1) _, _, dayPosts := fiveLastDays(now) - feed := &feeds.Feed{ + feed := rss.Feed{ Title: fmt.Sprintf("%s posts", settings.SiteName()), - Link: &feeds.Link{Href: settings.SiteURL()}, + Link: settings.SiteURL(), Description: fmt.Sprintf("All public posts are sent to this feed."), - Author: author, - Created: now, - Items: []*feeds.Item{}, + PubDate: now.Format(rssTimeFormat), + Items: []*rss.Item{}, } for _, posts := range dayPosts { @@ -54,55 +54,53 @@ func Posts() *feeds.Feed { continue } - var entry = &feeds.Item{ - Title: post.Title, - Link: &feeds.Link{ - Href: post.URL, + var entry = &rss.Item{ + Title: post.Title, + Link: post.URL, + Author: author, + Description: rss.CData{ + descriptionForOnePost(post), }, - Author: author, - Description: descriptionForOnePost(post), - Created: creationTime, + PubDate: creationTime.Format(rssTimeFormat), } feed.Items = append(feed.Items, entry) } } - return feed + return &feed } -func Digest() *feeds.Feed { - author := &feeds.Author{ - Name: settings.AdminUsername(), - } +func Digest() *rss.Feed { + author := settings.AdminUsername() + now := time.Now() days, dayStamps, dayPosts := fiveLastDays(now) - feed := &feeds.Feed{ + feed := rss.Feed{ Title: fmt.Sprintf("%s daily digest", settings.SiteName()), - Link: &feeds.Link{Href: settings.SiteURL()}, + Link: settings.SiteURL(), Description: fmt.Sprintf("Every day, a list of all links posted that day is sent."), - Author: author, - Created: now, - Items: []*feeds.Item{}, + PubDate: now.Format(rssTimeFormat), + Items: []*rss.Item{}, } for i, posts := range dayPosts { if posts == nil { continue } - var entry = &feeds.Item{ - Title: fmt.Sprintf("%s %s", settings.SiteName(), dayStamps[i]), - Link: &feeds.Link{ - Href: fmt.Sprintf("%s/day/%s", settings.SiteURL(), dayStamps[i]), + var entry = &rss.Item{ + Title: fmt.Sprintf("%s %s", settings.SiteName(), dayStamps[i]), + Link: fmt.Sprintf("%s/day/%s", settings.SiteURL(), dayStamps[i]), + Author: author, + Description: rss.CData{ + descriptionFromPosts(posts, dayStamps[i]), }, - Author: author, - Description: descriptionFromPosts(posts, dayStamps[i]), - Created: days[i], + PubDate: days[i].Format(rssTimeFormat), } feed.Items = append(feed.Items, entry) } - return feed + return &feed } const descriptionTemplate = ` diff --git a/go.mod b/go.mod index 9c210fd..f7437ce 100644 --- a/go.mod +++ b/go.mod @@ -4,13 +4,10 @@ go 1.19 require ( git.sr.ht/~bouncepaw/mycomarkup/v5 v5.6.0 - github.com/gorilla/feeds v1.1.1 github.com/mattn/go-sqlite3 v1.14.16 - golang.org/x/crypto v0.5.0 - golang.org/x/net v0.5.0 + golang.org/x/crypto v0.12.0 + golang.org/x/net v0.14.0 + humungus.tedunangst.com/r/webs v0.7.10 ) -require ( - github.com/kr/pretty v0.3.1 // indirect - golang.org/x/text v0.6.0 // indirect -) +require golang.org/x/text v0.12.0 // indirect diff --git a/go.sum b/go.sum index eaf4f4e..6094005 100644 --- a/go.sum +++ b/go.sum @@ -1,20 +1,12 @@ git.sr.ht/~bouncepaw/mycomarkup/v5 v5.6.0 h1:zAZwMF+6x8U/nunpqPRVYoDiqVUMBHI04PG8GsDrFOk= git.sr.ht/~bouncepaw/mycomarkup/v5 v5.6.0/go.mod h1:TCzFBqW11En4EjLfcQtJu8C/Ro7FIFR8vZ+nM9f6Q28= -github.com/creack/pty v1.1.9/go.mod h1:oKZEueFk5CKHvIhNR5MUki03XCEU+Q6VDXinZuGJ33E= -github.com/gorilla/feeds v1.1.1 h1:HwKXxqzcRNg9to+BbvJog4+f3s/xzvtZXICcQGutYfY= -github.com/gorilla/feeds v1.1.1/go.mod h1:Nk0jZrvPFZX1OBe5NPiddPw7CfwF6Q9eqzaBbaightA= -github.com/kr/pretty v0.3.1 h1:flRD4NNwYAUpkphVc1HcthR4KEIFJ65n8Mw5qdRn3LE= -github.com/kr/pretty v0.3.1/go.mod h1:hoEshYVHaxMs3cyo3Yncou5ZscifuDolrwPKZanG3xk= -github.com/kr/text v0.2.0 h1:5Nx0Ya0ZqY2ygV366QzturHI13Jq95ApcVaJBhpS+AY= -github.com/kr/text v0.2.0/go.mod h1:eLer722TekiGuMkidMxC/pM04lWEeraHUUmBw8l2grE= github.com/mattn/go-sqlite3 v1.14.16 h1:yOQRA0RpS5PFz/oikGwBEqvAWhWg5ufRz4ETLjwpU1Y= github.com/mattn/go-sqlite3 v1.14.16/go.mod h1:2eHXhiwb8IkHr+BDWZGa96P6+rkvnG63S2DGjv9HUNg= -github.com/pkg/diff v0.0.0-20210226163009-20ebb0f2a09e/go.mod h1:pJLUxLENpZxwdsKMEsNbx1VGcRFpLqf3715MtcvvzbA= -github.com/rogpeppe/go-internal v1.9.0 h1:73kH8U+JUqXU8lRuOHeVHaa/SZPifC7BkcraZVejAe8= -github.com/rogpeppe/go-internal v1.9.0/go.mod h1:WtVeX8xhTBvf0smdhujwtBcq4Qrzq/fJaraNFVN+nFs= -golang.org/x/crypto v0.5.0 h1:U/0M97KRkSFvyD/3FSmdP5W5swImpNgle/EHFhOsQPE= -golang.org/x/crypto v0.5.0/go.mod h1:NK/OQwhpMQP3MwtdjgLlYHnH9ebylxKWv3e0fK+mkQU= -golang.org/x/net v0.5.0 h1:GyT4nK/YDHSqa1c4753ouYCDajOYKTja9Xb/OHtgvSw= -golang.org/x/net v0.5.0/go.mod h1:DivGGAXEgPSlEBzxGzZI+ZLohi+xUj054jfeKui00ws= -golang.org/x/text v0.6.0 h1:3XmdazWV+ubf7QgHSTWeykHOci5oeekaGJBLkrkaw4k= -golang.org/x/text v0.6.0/go.mod h1:mrYo+phRRbMaCq/xk9113O4dZlRixOauAjOtrjsXDZ8= +golang.org/x/crypto v0.12.0 h1:tFM/ta59kqch6LlvYnPa0yx5a83cL2nHflFhYKvv9Yk= +golang.org/x/crypto v0.12.0/go.mod h1:NF0Gs7EO5K4qLn+Ylc+fih8BSTeIjAP05siRnAh98yw= +golang.org/x/net v0.14.0 h1:BONx9s002vGdD9umnlX1Po8vOZmrgH34qlHcD1MfK14= +golang.org/x/net v0.14.0/go.mod h1:PpSgVXXLK0OxS0F31C1/tv6XNguvCrnXIDrFMspZIUI= +golang.org/x/text v0.12.0 h1:k+n5B8goJNdU7hSvEtMUz3d1Q6D/XW4COJSJR6fN0mc= +golang.org/x/text v0.12.0/go.mod h1:TvPlkZtksWOMsz7fbANvkp4WM8x/WCo/om8BMLbz+aE= +humungus.tedunangst.com/r/webs v0.7.10 h1:DPEsA7DU1P1uOBWYrhJWjqDtll6SGJkWQtJ/2N6P8DI= +humungus.tedunangst.com/r/webs v0.7.10/go.mod h1:ylhqHSPI0Oi7b4nsnx5mSO7AjLXN7wFpEHayLfN/ugk= diff --git a/web/handlers.go b/web/handlers.go index cbf3c0c..bc85e98 100644 --- a/web/handlers.go +++ b/web/handlers.go @@ -13,6 +13,7 @@ import ( "git.sr.ht/~bouncepaw/betula/readpage" "git.sr.ht/~bouncepaw/betula/stricks" "html/template" + "humungus.tedunangst.com/r/webs/rss" "io" "log" "net/http" @@ -852,30 +853,20 @@ func getText(w http.ResponseWriter, rq *http.Request) { _, _ = io.WriteString(w, post.Description) } -func getPostsRss(w http.ResponseWriter, _ *http.Request) { - feed := feeds.Posts() - rss, err := feed.ToRss() +func writeFeed(fd *rss.Feed, w http.ResponseWriter) { + err := fd.Write(w) if err != nil { w.WriteHeader(http.StatusInternalServerError) _, _ = io.WriteString(w, err.Error()) - return } - w.WriteHeader(http.StatusOK) - w.Header().Set("Content-Type", "application/rss+xml") - _, _ = io.WriteString(w, rss) +} + +func getPostsRss(w http.ResponseWriter, _ *http.Request) { + writeFeed(feeds.Posts(), w) } func getDigestRss(w http.ResponseWriter, _ *http.Request) { - feed := feeds.Digest() - rss, err := feed.ToRss() - if err != nil { - w.WriteHeader(http.StatusInternalServerError) - _, _ = io.WriteString(w, err.Error()) // Ain't that failing on my watch. - return - } - w.WriteHeader(http.StatusOK) - w.Header().Set("Content-Type", "application/rss+xml") - _, _ = io.WriteString(w, rss) + writeFeed(feeds.Digest(), w) } var dayStampRegex = regexp.MustCompile("^[0-9]{4}-[0-9]{2}-[0-9]{2}$") -- 2.38.5
Took the closest look at the timestamp. It is different from what it was before, but turns out to be fully standards-compilant! Applying the patch, thank you!
builds.sr.ht <builds@sr.ht>betula/patches/.build.yml: SUCCESS in 45s [Migrate from gorilla/feeds][0] v3 from [~danilax86][1] [0]: https://lists.sr.ht/~bouncepaw/betula/patches/49710 [1]: mailto:danila@danilax86.space ✓ #1154183 SUCCESS betula/patches/.build.yml https://builds.sr.ht/~bouncepaw/job/1154183