From 18e0f4dcbea3e3f7a49e78e552b76319f8659d67 Mon Sep 17 00:00:00 2001 From: Daniil Gentili Date: Sat, 30 Apr 2022 15:16:36 +0200 Subject: [PATCH 01/10] Add sitemap support --- go.mod | 2 +- modules/sitemap/sitemap.go | 66 ++++++++++++++++++++++++++++ modules/sitemap/sitemap_test.go | 77 +++++++++++++++++++++++++++++++++ routers/web/explore/repo.go | 22 +++++++++- routers/web/explore/user.go | 21 ++++++++- routers/web/home.go | 54 +++++++++++++++++++++++ routers/web/web.go | 3 ++ 7 files changed, 242 insertions(+), 3 deletions(-) create mode 100644 modules/sitemap/sitemap.go create mode 100644 modules/sitemap/sitemap_test.go diff --git a/go.mod b/go.mod index bfb87a1b37a8b..36b4b16a15c43 100644 --- a/go.mod +++ b/go.mod @@ -75,6 +75,7 @@ require ( github.com/santhosh-tekuri/jsonschema/v5 v5.0.0 github.com/sergi/go-diff v1.2.0 github.com/shurcooL/vfsgen v0.0.0-20200824052919-0d455de96546 + github.com/ssor/bom v0.0.0-20170718123548-6386211fdfcf // indirect github.com/stretchr/testify v1.7.0 github.com/syndtr/goleveldb v1.0.0 github.com/tstranex/u2f v1.0.0 @@ -242,7 +243,6 @@ require ( github.com/spf13/jwalterweatherman v1.1.0 // indirect github.com/spf13/pflag v1.0.5 // indirect github.com/spf13/viper v1.10.1 // indirect - github.com/ssor/bom v0.0.0-20170718123548-6386211fdfcf // indirect github.com/steveyen/gtreap v0.1.0 // indirect github.com/subosito/gotenv v1.2.0 // indirect github.com/tmc/grpc-websocket-proxy v0.0.0-20201229170055-e5319fda7802 // indirect diff --git a/modules/sitemap/sitemap.go b/modules/sitemap/sitemap.go new file mode 100644 index 0000000000000..b7d0fe6776d26 --- /dev/null +++ b/modules/sitemap/sitemap.go @@ -0,0 +1,66 @@ +// Copyright 2022 The Gitea Authors. All rights reserved. +// Use of this source code is governed by a MIT-style +// license that can be found in the LICENSE file. + +package sitemap + +import ( + "bytes" + "encoding/xml" + "fmt" + "io" + "time" +) + +// Url represents a single sitemap entry +type URL struct { + URL string `xml:"loc"` + LastMod *time.Time `xml:"lastmod,omitempty"` +} + +// SitemapUrl represents a sitemap +type Sitemap struct { + XMLName xml.Name + Namespace string `xml:"xmlns,attr"` + + URLs []URL `xml:"url"` +} + +// NewSitemap creates a sitemap +func NewSitemap() *Sitemap { + return &Sitemap{ + XMLName: xml.Name{Local: "urlset"}, + Namespace: "http://www.sitemaps.org/schemas/sitemap/0.9", + } +} + +// NewSitemap creates a sitemap index. +func NewSitemapIndex() *Sitemap { + return &Sitemap{ + XMLName: xml.Name{Local: "sitemapindex"}, + Namespace: "http://www.sitemaps.org/schemas/sitemap/0.9", + } +} + +// Add adds a URL to the sitemap +func (s *Sitemap) Add(URL URL) { + s.URLs = append(s.URLs, URL) +} + +// Write writes the sitemap to a response +func (s *Sitemap) WriteTo(w io.Writer) (int64, error) { + if len(s.URLs) > 50000 { + return 0, fmt.Errorf("The sitemap contains too many URLs: %d", len(s.URLs)) + } + buf := bytes.NewBufferString(xml.Header) + if err := xml.NewEncoder(buf).Encode(s); err != nil { + return 0, err + } + if err := buf.WriteByte('\n'); err != nil { + return 0, err + } + if buf.Len() > 50*1024*1024 { + return 0, fmt.Errorf("The sitemap is too big: %d", buf.Len()) + } + return buf.WriteTo(w) +} diff --git a/modules/sitemap/sitemap_test.go b/modules/sitemap/sitemap_test.go new file mode 100644 index 0000000000000..68b5a39db2bfa --- /dev/null +++ b/modules/sitemap/sitemap_test.go @@ -0,0 +1,77 @@ +// Copyright 2022 The Gitea Authors. All rights reserved. +// Use of this source code is governed by a MIT-style +// license that can be found in the LICENSE file. + +package sitemap + +import ( + "bytes" + "encoding/xml" + "fmt" + "strings" + "testing" + "time" + + "github.com/stretchr/testify/assert" +) + +func TestOk(t *testing.T) { + testReal := func(s *Sitemap, name string, urls []URL, expected string) { + for _, url := range urls { + s.Add(url) + } + buf := &bytes.Buffer{} + _, err := s.WriteTo(buf) + assert.NoError(t, nil, err) + assert.Equal(t, xml.Header+"<"+name+" xmlns=\"http://www.sitemaps.org/schemas/sitemap/0.9\">"+expected+"\n", buf.String()) + } + test := func(urls []URL, expected string) { + testReal(NewSitemap(), "urlset", urls, expected) + testReal(NewSitemapIndex(), "sitemapindex", urls, expected) + } + + ts := time.Unix(1651322008, 0) + + test( + []URL{}, + "", + ) + test( + []URL{ + {URL: "https://gitea.io/test1", LastMod: &ts}, + }, + "https://gitea.io/test12022-04-30T14:33:28+02:00", + ) + test( + []URL{ + {URL: "https://gitea.io/test2", LastMod: nil}, + }, + "https://gitea.io/test2", + ) + test( + []URL{ + {URL: "https://gitea.io/test1", LastMod: &ts}, + {URL: "https://gitea.io/test2", LastMod: nil}, + }, + "https://gitea.io/test12022-04-30T14:33:28+02:00"+ + "https://gitea.io/test2", + ) +} + +func TestTooManyURLs(t *testing.T) { + s := NewSitemap() + for i := 0; i < 50001; i++ { + s.Add(URL{URL: fmt.Sprintf("https://gitea.io/test%d", i)}) + } + buf := &bytes.Buffer{} + _, err := s.WriteTo(buf) + assert.EqualError(t, err, "The sitemap contains too many URLs: 50001") +} + +func TestSitemapTooBig(t *testing.T) { + s := NewSitemap() + s.Add(URL{URL: strings.Repeat("b", 50*1024*1024)}) + buf := &bytes.Buffer{} + _, err := s.WriteTo(buf) + assert.EqualError(t, err, "The sitemap is too big: 52428931") +} diff --git a/routers/web/explore/repo.go b/routers/web/explore/repo.go index 3e8aa2bb0fda7..78911f050d731 100644 --- a/routers/web/explore/repo.go +++ b/routers/web/explore/repo.go @@ -12,7 +12,9 @@ import ( repo_model "code.gitea.io/gitea/models/repo" "code.gitea.io/gitea/modules/base" "code.gitea.io/gitea/modules/context" + "code.gitea.io/gitea/modules/log" "code.gitea.io/gitea/modules/setting" + "code.gitea.io/gitea/modules/sitemap" ) const ( @@ -31,7 +33,13 @@ type RepoSearchOptions struct { // RenderRepoSearch render repositories search page func RenderRepoSearch(ctx *context.Context, opts *RepoSearchOptions) { - page := ctx.FormInt("page") + // Sitemap index for sitemap paths + page := int(ctx.ParamsInt64("idx")) + isSitemap := ctx.Params("idx") != "" + if page <= 1 { + page = ctx.FormInt("page") + } + if page <= 0 { page = 1 } @@ -101,6 +109,18 @@ func RenderRepoSearch(ctx *context.Context, opts *RepoSearchOptions) { ctx.ServerError("SearchRepository", err) return } + if isSitemap { + m := sitemap.NewSitemap() + for _, item := range repos { + m.Add(sitemap.URL{URL: item.HTMLURL(), LastMod: item.UpdatedUnix.AsTimePtr()}) + } + ctx.Resp.Header().Set("Content-Type", "text/xml") + if _, err := m.WriteTo(ctx.Resp); err != nil { + log.Error("Failed writing sitemap: %v", err) + } + return + } + ctx.Data["Keyword"] = keyword ctx.Data["Total"] = count ctx.Data["Repos"] = repos diff --git a/routers/web/explore/user.go b/routers/web/explore/user.go index ea0d7d5f9d8c3..0722ba7f124f6 100644 --- a/routers/web/explore/user.go +++ b/routers/web/explore/user.go @@ -12,7 +12,9 @@ import ( user_model "code.gitea.io/gitea/models/user" "code.gitea.io/gitea/modules/base" "code.gitea.io/gitea/modules/context" + "code.gitea.io/gitea/modules/log" "code.gitea.io/gitea/modules/setting" + "code.gitea.io/gitea/modules/sitemap" "code.gitea.io/gitea/modules/structs" "code.gitea.io/gitea/modules/util" ) @@ -33,7 +35,12 @@ func isKeywordValid(keyword string) bool { // RenderUserSearch render user search page func RenderUserSearch(ctx *context.Context, opts *user_model.SearchUserOptions, tplName base.TplName) { - opts.Page = ctx.FormInt("page") + // Sitemap index for sitemap paths + opts.Page = int(ctx.ParamsInt64("idx")) + isSitemap := ctx.Params("idx") != "" + if opts.Page <= 1 { + opts.Page = ctx.FormInt("page") + } if opts.Page <= 1 { opts.Page = 1 } @@ -73,6 +80,18 @@ func RenderUserSearch(ctx *context.Context, opts *user_model.SearchUserOptions, return } } + if isSitemap { + m := sitemap.NewSitemap() + for _, item := range users { + m.Add(sitemap.URL{URL: item.HTMLURL(), LastMod: item.UpdatedUnix.AsTimePtr()}) + } + ctx.Resp.Header().Set("Content-Type", "text/xml") + if _, err := m.WriteTo(ctx.Resp); err != nil { + log.Error("Failed writing sitemap: %v", err) + } + return + } + ctx.Data["Keyword"] = opts.Keyword ctx.Data["Total"] = count ctx.Data["Users"] = users diff --git a/routers/web/home.go b/routers/web/home.go index 9036814ddfa9d..d9bfa66eb259a 100644 --- a/routers/web/home.go +++ b/routers/web/home.go @@ -7,11 +7,18 @@ package web import ( "net/http" + "strconv" + "code.gitea.io/gitea/models" + "code.gitea.io/gitea/models/db" + user_model "code.gitea.io/gitea/models/user" "code.gitea.io/gitea/modules/base" "code.gitea.io/gitea/modules/context" "code.gitea.io/gitea/modules/log" "code.gitea.io/gitea/modules/setting" + "code.gitea.io/gitea/modules/sitemap" + "code.gitea.io/gitea/modules/structs" + "code.gitea.io/gitea/modules/util" "code.gitea.io/gitea/modules/web/middleware" "code.gitea.io/gitea/routers/web/auth" "code.gitea.io/gitea/routers/web/user" @@ -59,6 +66,53 @@ func Home(ctx *context.Context) { ctx.HTML(http.StatusOK, tplHome) } +// HomeSitemap renders the main sitemap +func HomeSitemap(ctx *context.Context) { + m := sitemap.NewSitemapIndex() + if !setting.Service.Explore.DisableUsersPage { + _, cnt, err := user_model.SearchUsers(&user_model.SearchUserOptions{ + Actor: nil, + Type: user_model.UserTypeIndividual, + ListOptions: db.ListOptions{PageSize: 1}, + IsActive: util.OptionalBoolTrue, + Visible: []structs.VisibleType{structs.VisibleTypePublic}, + }) + if err != nil { + ctx.ServerError("SearchUsers", err) + return + } + count := int(cnt) + idx := 1 + for i := 0; i < count; i += setting.UI.ExplorePagingNum { + m.Add(sitemap.URL{URL: setting.AppURL + "explore/users/sitemap-" + strconv.Itoa(idx) + ".xml"}) + idx++ + } + } + + _, cnt, err := models.SearchRepository(&models.SearchRepoOptions{ + ListOptions: db.ListOptions{ + PageSize: 1, + }, + Actor: nil, + AllPublic: true, + }) + if err != nil { + ctx.ServerError("SearchRepository", err) + return + } + count := int(cnt) + idx := 1 + for i := 0; i < count; i += setting.UI.ExplorePagingNum { + m.Add(sitemap.URL{URL: setting.AppURL + "explore/repos/sitemap-" + strconv.Itoa(idx) + ".xml"}) + idx++ + } + + ctx.Resp.Header().Set("Content-Type", "text/xml") + if _, err := m.WriteTo(ctx.Resp); err != nil { + log.Error("Failed writing sitemap: %v", err) + } +} + // NotFound render 404 page func NotFound(ctx *context.Context) { ctx.Data["Title"] = "Page Not Found" diff --git a/routers/web/web.go b/routers/web/web.go index 22b8e7cdf3abc..e45e1171e4e10 100644 --- a/routers/web/web.go +++ b/routers/web/web.go @@ -284,6 +284,7 @@ func RegisterRoutes(m *web.Route) { // Routers. // for health check m.Get("/", Home) + m.Get("/sitemap.xml", ignExploreSignIn, HomeSitemap) m.Group("/.well-known", func() { m.Get("/openid-configuration", auth.OIDCWellKnown) if setting.Federation.Enabled { @@ -299,7 +300,9 @@ func RegisterRoutes(m *web.Route) { ctx.Redirect(setting.AppSubURL + "/explore/repos") }) m.Get("/repos", explore.Repos) + m.Get("/repos/sitemap-{idx}.xml", explore.Repos) m.Get("/users", explore.Users) + m.Get("/users/sitemap-{idx}.xml", explore.Users) m.Get("/organizations", explore.Organizations) m.Get("/code", explore.Code) m.Get("/topics/search", explore.TopicSearch) From d88ed164dc6dcbb6661540a090274db2930513e5 Mon Sep 17 00:00:00 2001 From: Daniil Gentili Date: Sat, 30 Apr 2022 15:31:04 +0200 Subject: [PATCH 02/10] Fix --- modules/sitemap/sitemap.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/modules/sitemap/sitemap.go b/modules/sitemap/sitemap.go index b7d0fe6776d26..2bccd41295353 100644 --- a/modules/sitemap/sitemap.go +++ b/modules/sitemap/sitemap.go @@ -43,8 +43,8 @@ func NewSitemapIndex() *Sitemap { } // Add adds a URL to the sitemap -func (s *Sitemap) Add(URL URL) { - s.URLs = append(s.URLs, URL) +func (s *Sitemap) Add(u URL) { + s.URLs = append(s.URLs, u) } // Write writes the sitemap to a response From f6defbb7e1561c2c9bbe72ead5ac18078a16f97f Mon Sep 17 00:00:00 2001 From: Daniil Gentili Date: Sat, 30 Apr 2022 16:36:25 +0200 Subject: [PATCH 03/10] Revert --- go.mod | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/go.mod b/go.mod index 36b4b16a15c43..bfb87a1b37a8b 100644 --- a/go.mod +++ b/go.mod @@ -75,7 +75,6 @@ require ( github.com/santhosh-tekuri/jsonschema/v5 v5.0.0 github.com/sergi/go-diff v1.2.0 github.com/shurcooL/vfsgen v0.0.0-20200824052919-0d455de96546 - github.com/ssor/bom v0.0.0-20170718123548-6386211fdfcf // indirect github.com/stretchr/testify v1.7.0 github.com/syndtr/goleveldb v1.0.0 github.com/tstranex/u2f v1.0.0 @@ -243,6 +242,7 @@ require ( github.com/spf13/jwalterweatherman v1.1.0 // indirect github.com/spf13/pflag v1.0.5 // indirect github.com/spf13/viper v1.10.1 // indirect + github.com/ssor/bom v0.0.0-20170718123548-6386211fdfcf // indirect github.com/steveyen/gtreap v0.1.0 // indirect github.com/subosito/gotenv v1.2.0 // indirect github.com/tmc/grpc-websocket-proxy v0.0.0-20201229170055-e5319fda7802 // indirect From 4609861637bd14d6149b48832e171c4b22221bd2 Mon Sep 17 00:00:00 2001 From: Daniil Gentili Date: Sat, 30 Apr 2022 20:54:53 +0200 Subject: [PATCH 04/10] Update routers/web/home.go Co-authored-by: 6543 <6543@obermui.de> --- routers/web/home.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/routers/web/home.go b/routers/web/home.go index d9bfa66eb259a..7925ed1a867a2 100644 --- a/routers/web/home.go +++ b/routers/web/home.go @@ -93,7 +93,7 @@ func HomeSitemap(ctx *context.Context) { ListOptions: db.ListOptions{ PageSize: 1, }, - Actor: nil, + Actor: ctx.Doer, AllPublic: true, }) if err != nil { From 51447501ab86c49765892e6f62b6d3f9b44d17aa Mon Sep 17 00:00:00 2001 From: Daniil Gentili Date: Tue, 21 Jun 2022 19:10:32 +0200 Subject: [PATCH 05/10] Update routers/web/home.go Co-authored-by: Gusted --- routers/web/home.go | 1 - 1 file changed, 1 deletion(-) diff --git a/routers/web/home.go b/routers/web/home.go index 7925ed1a867a2..11d244e32f80e 100644 --- a/routers/web/home.go +++ b/routers/web/home.go @@ -71,7 +71,6 @@ func HomeSitemap(ctx *context.Context) { m := sitemap.NewSitemapIndex() if !setting.Service.Explore.DisableUsersPage { _, cnt, err := user_model.SearchUsers(&user_model.SearchUserOptions{ - Actor: nil, Type: user_model.UserTypeIndividual, ListOptions: db.ListOptions{PageSize: 1}, IsActive: util.OptionalBoolTrue, From b8c18cde2ca11fb820530dd8630e4a48c2320d81 Mon Sep 17 00:00:00 2001 From: Daniil Gentili Date: Thu, 23 Jun 2022 15:03:27 +0200 Subject: [PATCH 06/10] Add sitemap option and constant --- modules/setting/setting.go | 2 ++ modules/sitemap/sitemap.go | 5 ++++- modules/sitemap/sitemap_test.go | 2 +- routers/web/explore/repo.go | 4 ++++ routers/web/explore/user.go | 4 ++++ routers/web/home.go | 4 ++-- 6 files changed, 17 insertions(+), 4 deletions(-) diff --git a/modules/setting/setting.go b/modules/setting/setting.go index 88f306b3fa7e3..7be0842b56a6d 100644 --- a/modules/setting/setting.go +++ b/modules/setting/setting.go @@ -207,6 +207,7 @@ var ( // UI settings UI = struct { ExplorePagingNum int + SitemapPagingNum int IssuePagingNum int RepoSearchPagingNum int MembersPagingNum int @@ -260,6 +261,7 @@ var ( } `ini:"ui.meta"` }{ ExplorePagingNum: 20, + SitemapPagingNum: 20, IssuePagingNum: 10, RepoSearchPagingNum: 10, MembersPagingNum: 20, diff --git a/modules/sitemap/sitemap.go b/modules/sitemap/sitemap.go index 2bccd41295353..14953765abbc2 100644 --- a/modules/sitemap/sitemap.go +++ b/modules/sitemap/sitemap.go @@ -12,6 +12,9 @@ import ( "time" ) +// sitemapFileLimit contains the maximum size of a sitemap file +const sitemapFileLimit = 50 * 1024 * 1024 + // Url represents a single sitemap entry type URL struct { URL string `xml:"loc"` @@ -59,7 +62,7 @@ func (s *Sitemap) WriteTo(w io.Writer) (int64, error) { if err := buf.WriteByte('\n'); err != nil { return 0, err } - if buf.Len() > 50*1024*1024 { + if buf.Len() > sitemapFileLimit { return 0, fmt.Errorf("The sitemap is too big: %d", buf.Len()) } return buf.WriteTo(w) diff --git a/modules/sitemap/sitemap_test.go b/modules/sitemap/sitemap_test.go index 68b5a39db2bfa..26a8e04669eed 100644 --- a/modules/sitemap/sitemap_test.go +++ b/modules/sitemap/sitemap_test.go @@ -70,7 +70,7 @@ func TestTooManyURLs(t *testing.T) { func TestSitemapTooBig(t *testing.T) { s := NewSitemap() - s.Add(URL{URL: strings.Repeat("b", 50*1024*1024)}) + s.Add(URL{URL: strings.Repeat("b", sitemapFileLimit)}) buf := &bytes.Buffer{} _, err := s.WriteTo(buf) assert.EqualError(t, err, "The sitemap is too big: 52428931") diff --git a/routers/web/explore/repo.go b/routers/web/explore/repo.go index f7d56a7c39732..b5485f5832d4d 100644 --- a/routers/web/explore/repo.go +++ b/routers/web/explore/repo.go @@ -43,6 +43,10 @@ func RenderRepoSearch(ctx *context.Context, opts *RepoSearchOptions) { page = 1 } + if isSitemap { + opts.PageSize = setting.UI.SitemapPagingNum + } + var ( repos []*repo_model.Repository count int64 diff --git a/routers/web/explore/user.go b/routers/web/explore/user.go index 0722ba7f124f6..ea3d83e8d6c1c 100644 --- a/routers/web/explore/user.go +++ b/routers/web/explore/user.go @@ -45,6 +45,10 @@ func RenderUserSearch(ctx *context.Context, opts *user_model.SearchUserOptions, opts.Page = 1 } + if isSitemap { + opts.PageSize = setting.UI.SitemapPagingNum + } + var ( users []*user_model.User count int64 diff --git a/routers/web/home.go b/routers/web/home.go index 11d244e32f80e..f3793b7ebbb1c 100644 --- a/routers/web/home.go +++ b/routers/web/home.go @@ -82,7 +82,7 @@ func HomeSitemap(ctx *context.Context) { } count := int(cnt) idx := 1 - for i := 0; i < count; i += setting.UI.ExplorePagingNum { + for i := 0; i < count; i += setting.UI.SitemapPagingNum { m.Add(sitemap.URL{URL: setting.AppURL + "explore/users/sitemap-" + strconv.Itoa(idx) + ".xml"}) idx++ } @@ -101,7 +101,7 @@ func HomeSitemap(ctx *context.Context) { } count := int(cnt) idx := 1 - for i := 0; i < count; i += setting.UI.ExplorePagingNum { + for i := 0; i < count; i += setting.UI.SitemapPagingNum { m.Add(sitemap.URL{URL: setting.AppURL + "explore/repos/sitemap-" + strconv.Itoa(idx) + ".xml"}) idx++ } From 14e49ad9dd497dff7f736af0375649d4c4dfdb12 Mon Sep 17 00:00:00 2001 From: Daniil Gentili Date: Thu, 23 Jun 2022 22:05:56 +0200 Subject: [PATCH 07/10] Update docs --- docs/content/doc/advanced/config-cheat-sheet.en-us.md | 1 + 1 file changed, 1 insertion(+) diff --git a/docs/content/doc/advanced/config-cheat-sheet.en-us.md b/docs/content/doc/advanced/config-cheat-sheet.en-us.md index 15628a7def051..df659b6540119 100644 --- a/docs/content/doc/advanced/config-cheat-sheet.en-us.md +++ b/docs/content/doc/advanced/config-cheat-sheet.en-us.md @@ -174,6 +174,7 @@ The following configuration set `Content-Type: application/vnd.android.package-a - `MEMBERS_PAGING_NUM`: **20**: Number of members that are shown in organization members. - `FEED_MAX_COMMIT_NUM`: **5**: Number of maximum commits shown in one activity feed. - `FEED_PAGING_NUM`: **20**: Number of items that are displayed in home feed. +- `SITEMAP_PAGING_NUM`: **20**: Number of items that are displayed in a single subsitemap. - `GRAPH_MAX_COMMIT_NUM`: **100**: Number of maximum commits shown in the commit graph. - `CODE_COMMENT_LINES`: **4**: Number of line of codes shown for a code comment. - `DEFAULT_THEME`: **auto**: \[auto, gitea, arc-green\]: Set the default theme for the Gitea install. From 3628523ddc8d668d378b93538e83eb0a4efb768d Mon Sep 17 00:00:00 2001 From: 6543 <6543@obermui.de> Date: Thu, 23 Jun 2022 22:48:25 +0200 Subject: [PATCH 08/10] fix --- routers/web/home.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/routers/web/home.go b/routers/web/home.go index f3793b7ebbb1c..0c74987ba7c47 100644 --- a/routers/web/home.go +++ b/routers/web/home.go @@ -9,8 +9,8 @@ import ( "net/http" "strconv" - "code.gitea.io/gitea/models" "code.gitea.io/gitea/models/db" + repo_model "code.gitea.io/gitea/models/repo" user_model "code.gitea.io/gitea/models/user" "code.gitea.io/gitea/modules/base" "code.gitea.io/gitea/modules/context" @@ -88,7 +88,7 @@ func HomeSitemap(ctx *context.Context) { } } - _, cnt, err := models.SearchRepository(&models.SearchRepoOptions{ + _, cnt, err := repo_model.SearchRepository(&repo_model.SearchRepoOptions{ ListOptions: db.ListOptions{ PageSize: 1, }, From fb0cec4455da1830a09d22fd0b8a13004d659f4a Mon Sep 17 00:00:00 2001 From: Daniil Gentili Date: Sat, 25 Jun 2022 00:37:20 +0200 Subject: [PATCH 09/10] Add reference --- custom/conf/app.example.ini | 3 +++ 1 file changed, 3 insertions(+) diff --git a/custom/conf/app.example.ini b/custom/conf/app.example.ini index 80017a11764ee..5016f29cf9ffd 100644 --- a/custom/conf/app.example.ini +++ b/custom/conf/app.example.ini @@ -1097,6 +1097,9 @@ PATH = ;; Number of items that are displayed in home feed ;FEED_PAGING_NUM = 20 ;; +;; Number of items that are displayed in a single subsitemap +;SITEMAP_PAGING_NUM = 20 +;; ;; Number of maximum commits displayed in commit graph. ;GRAPH_MAX_COMMIT_NUM = 100 ;; From 72ba7e242175d1e83259e6d0bac7bf9884a88422 Mon Sep 17 00:00:00 2001 From: Daniil Gentili Date: Sat, 25 Jun 2022 13:51:46 +0200 Subject: [PATCH 10/10] Use UTC timezone in tests --- modules/sitemap/sitemap_test.go | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/modules/sitemap/sitemap_test.go b/modules/sitemap/sitemap_test.go index 26a8e04669eed..63007b84791f6 100644 --- a/modules/sitemap/sitemap_test.go +++ b/modules/sitemap/sitemap_test.go @@ -30,7 +30,7 @@ func TestOk(t *testing.T) { testReal(NewSitemapIndex(), "sitemapindex", urls, expected) } - ts := time.Unix(1651322008, 0) + ts := time.Unix(1651322008, 0).UTC() test( []URL{}, @@ -40,7 +40,7 @@ func TestOk(t *testing.T) { []URL{ {URL: "https://gitea.io/test1", LastMod: &ts}, }, - "https://gitea.io/test12022-04-30T14:33:28+02:00", + "https://gitea.io/test12022-04-30T12:33:28Z", ) test( []URL{ @@ -53,7 +53,7 @@ func TestOk(t *testing.T) { {URL: "https://gitea.io/test1", LastMod: &ts}, {URL: "https://gitea.io/test2", LastMod: nil}, }, - "https://gitea.io/test12022-04-30T14:33:28+02:00"+ + "https://gitea.io/test12022-04-30T12:33:28Z"+ "https://gitea.io/test2", ) }