diff options
author | Alec Warner <antarus@gentoo.org> | 2020-05-27 19:16:17 -0700 |
---|---|---|
committer | Alec Warner <antarus@gentoo.org> | 2020-05-27 19:16:17 -0700 |
commit | e95db8fca023bc310d0853674fd2c0a40d356450 (patch) | |
tree | 54fc060a78f9a54a8628810e7ecd2550a479132f /pkg/app/handler/packages/utils.go | |
parent | Fix broken build. I blame rod pike and smalltalk. (diff) | |
download | soko-e95db8fca023bc310d0853674fd2c0a40d356450.tar.gz soko-e95db8fca023bc310d0853674fd2c0a40d356450.tar.bz2 soko-e95db8fca023bc310d0853674fd2c0a40d356450.zip |
Consolidate the feed code for new Atom module.
Now each module just defines the main feed object and we use one
function to populate the feed entries.
Signed-off-by: Alec Warner <antarus@gentoo.org>
Diffstat (limited to 'pkg/app/handler/packages/utils.go')
-rw-r--r-- | pkg/app/handler/packages/utils.go | 25 |
1 files changed, 25 insertions, 0 deletions
diff --git a/pkg/app/handler/packages/utils.go b/pkg/app/handler/packages/utils.go index d9ce6e1..dfece1a 100644 --- a/pkg/app/handler/packages/utils.go +++ b/pkg/app/handler/packages/utils.go @@ -5,6 +5,8 @@ package packages import ( "crypto/md5" "encoding/hex" + "fmt" + "github.com/gorilla/feeds" "github.com/go-pg/pg" "github.com/go-pg/pg/v9/orm" "html/template" @@ -17,6 +19,7 @@ import ( "sort" "strings" textTemplate "text/template" + "time" ) // getAddedPackages returns a list of recently added @@ -125,6 +128,28 @@ func GetKeywordedVersions(n int) []*models.Version { return keywordedVersions } +// addFeedItems is a helper to add items to a feed; most of the feeds use []*models.Version as the entity. +func addFeedItems(f *feeds.Feed, versions []*models.Version) { + for _, version := range versions { + cpv := fmt.Sprintf("%s-%s", version.Atom, version.Version) + item := &feeds.Item{ + Title: cpv, + Link: &feeds.Link{Href: fmt.Sprintf("https://packages.gentoo.org/package/%s", version.Atom)}, + Description: version.Description, + Author: &feeds.Author{Name: "unknown"}, + Created: time.Now(), + } + if len(version.Commits) > 0 { + lastCommit := version.Commits[0] + item.Author = &feeds.Author{Name: lastCommit.CommitterName} + item.Created = lastCommit.CommitterDate + item.Content = fmt.Sprintf("%s is now available in Gentoo on these architectures: %s. See <a href='https://gitweb.gentoo.org/repo/gentoo.git/commit/?id=%s'>Gitweb</a>", + cpv, version.Keywords, lastCommit.Id) + } + f.Add(item) + } +} + // RenderPackageTemplates renders the given templates using the given data // One pattern can be used to specify templates func renderPackageTemplate(page string, templatepattern string, funcMap template.FuncMap, data interface{}, w http.ResponseWriter) { |