1
1
mirror of https://github.com/go-gitea/gitea synced 2025-07-22 18:28:37 +00:00

RSS/Atom support for Repos (#19055)

* support for repos
* refactor
* advertise the feeds via meta tags
* allow feed suffix and feed header
* optimize performance
This commit is contained in:
6543
2022-03-13 17:40:47 +01:00
committed by GitHub
parent 780cf76f6e
commit bc0d2c8ada
14 changed files with 188 additions and 110 deletions

View File

@@ -29,7 +29,6 @@ import (
"code.gitea.io/gitea/modules/markup/markdown"
"code.gitea.io/gitea/modules/setting"
"code.gitea.io/gitea/modules/util"
"code.gitea.io/gitea/routers/web/feed"
issue_service "code.gitea.io/gitea/services/issue"
pull_service "code.gitea.io/gitea/services/pull"
@@ -131,7 +130,7 @@ func Dashboard(ctx *context.Context) {
ctx.Data["MirrorCount"] = len(mirrors)
ctx.Data["Mirrors"] = mirrors
ctx.Data["Feeds"] = feed.RetrieveFeeds(ctx, models.GetFeedsOptions{
ctx.Data["Feeds"], err = models.GetFeeds(ctx, models.GetFeedsOptions{
RequestedUser: ctxUser,
RequestedTeam: ctx.Org.Team,
Actor: ctx.User,
@@ -140,8 +139,8 @@ func Dashboard(ctx *context.Context) {
IncludeDeleted: false,
Date: ctx.FormString("date"),
})
if ctx.Written() {
if err != nil {
ctx.ServerError("GetFeeds", err)
return
}

View File

@@ -74,19 +74,7 @@ func Profile(ctx *context.Context) {
uname = strings.TrimSuffix(uname, ".gpg")
}
showFeedType := ""
if strings.HasSuffix(uname, ".rss") {
showFeedType = "rss"
uname = strings.TrimSuffix(uname, ".rss")
} else if strings.Contains(ctx.Req.Header.Get("Accept"), "application/rss+xml") {
showFeedType = "rss"
}
if strings.HasSuffix(uname, ".atom") {
showFeedType = "atom"
uname = strings.TrimSuffix(uname, ".atom")
} else if strings.Contains(ctx.Req.Header.Get("Accept"), "application/atom+xml") {
showFeedType = "atom"
}
isShowFeed, uname, showFeedType := feed.GetFeedType(uname, ctx.Req)
ctxUser := GetUserByName(ctx, uname)
if ctx.Written() {
@@ -95,7 +83,7 @@ func Profile(ctx *context.Context) {
if ctxUser.IsOrganization() {
// Show Org RSS feed
if len(showFeedType) != 0 {
if isShowFeed {
feed.ShowUserFeed(ctx, ctxUser, showFeedType)
return
}
@@ -123,11 +111,14 @@ func Profile(ctx *context.Context) {
}
// Show User RSS feed
if len(showFeedType) != 0 {
if isShowFeed {
feed.ShowUserFeed(ctx, ctxUser, showFeedType)
return
}
// advertise feed via meta tag
ctx.Data["FeedURL"] = ctxUser.HTMLURL()
// Show OpenID URIs
openIDs, err := user_model.GetUserOpenIDs(ctxUser.ID)
if err != nil {
@@ -259,7 +250,7 @@ func Profile(ctx *context.Context) {
total = ctxUser.NumFollowing
case "activity":
ctx.Data["Feeds"] = feed.RetrieveFeeds(ctx, models.GetFeedsOptions{
ctx.Data["Feeds"], err = models.GetFeeds(ctx, models.GetFeedsOptions{
RequestedUser: ctxUser,
Actor: ctx.User,
IncludePrivate: showPrivate,
@@ -267,7 +258,8 @@ func Profile(ctx *context.Context) {
IncludeDeleted: false,
Date: ctx.FormString("date"),
})
if ctx.Written() {
if err != nil {
ctx.ServerError("GetFeeds", err)
return
}
case "stars":