浏览代码

Added Sitemaps for Orgs and Repos

Yoginth 7 年之前
父节点
当前提交
b8192cad07
共有 5 个文件被更改,包括 105 次插入30 次删除
  1. 3 1
      cmd/web.go
  2. 96 0
      routes/admin/sitemap.go
  3. 0 29
      routes/admin/usersitemap.go
  4. 3 0
      templates/org/sitemap.tmpl
  5. 3 0
      templates/repo/sitemap.tmpl

+ 3 - 1
cmd/web.go

@@ -323,7 +323,9 @@ func runWeb(c *cli.Context) error {
 	// ***** END: Pages *****
 
 	m.Group("/sitemap", func() {
-		m.Get("/users", ignSignIn, admin.Sitemap)
+		m.Get("/users", ignSignIn, admin.UserSitemap)
+		m.Get("/orgs", ignSignIn, admin.OrgSitemap)
+		m.Get("/repos", ignSignIn, admin.RepoSitemap)
 	})
 
 	// ***** START: Misc *****

+ 96 - 0
routes/admin/sitemap.go

@@ -0,0 +1,96 @@
+// Copyright 2015 The Gogs Authors. All rights reserved.
+// Copyright 2018 Gitote. All rights reserved.
+//
+// This source code is licensed under the MIT license found in the
+// LICENSE file in the root directory of this source tree.
+
+package admin
+
+import (
+	"gitote/gitote/models"
+	"gitote/gitote/pkg/context"
+	"gitote/gitote/pkg/setting"
+	"gitote/gitote/routes"
+
+	"gitlab.com/yoginth/paginater"
+)
+
+const (
+	// UserSitemapTPL page template
+	UserSitemapTPL = "user/sitemap"
+
+	// OrgSitemapTPL page template
+	OrgSitemapTPL = "org/sitemap"
+
+	// RepoSitemapTPL page template
+	RepoSitemapTPL = "repo/sitemap"
+)
+
+// UserSitemap shows about page
+func UserSitemap(c *context.Context) {
+	routes.RenderUserSearch(c, &routes.UserSearchOptions{
+		Type:    models.UserTypeIndividual,
+		Counter: models.CountUsers,
+		Ranger:  models.Users,
+		OrderBy: "id ASC",
+		TplName: UserSitemapTPL,
+	})
+}
+
+// OrgSitemap shows about page
+func OrgSitemap(c *context.Context) {
+	routes.RenderUserSearch(c, &routes.UserSearchOptions{
+		Type:    models.UserTypeOrganization,
+		Counter: models.CountOrganizations,
+		Ranger:  models.Organizations,
+		OrderBy: "id ASC",
+		TplName: OrgSitemapTPL,
+	})
+}
+
+// RepoSitemap shows about page
+func RepoSitemap(c *context.Context) {
+	page := c.QueryInt("page")
+	if page <= 0 {
+		page = 1
+	}
+
+	var (
+		repos []*models.Repository
+		count int64
+		err   error
+	)
+
+	keyword := c.Query("q")
+	if len(keyword) == 0 {
+		repos, err = models.Repositories(page, setting.UI.Admin.RepoPagingNum)
+		if err != nil {
+			c.Handle(500, "Repositories", err)
+			return
+		}
+		count = models.CountRepositories(true)
+	} else {
+		repos, count, err = models.SearchRepositoryByName(&models.SearchRepoOptions{
+			Keyword:  keyword,
+			OrderBy:  "id ASC",
+			Private:  true,
+			Page:     page,
+			PageSize: setting.UI.Admin.RepoPagingNum,
+		})
+		if err != nil {
+			c.Handle(500, "SearchRepositoryByName", err)
+			return
+		}
+	}
+	c.Data["Keyword"] = keyword
+	c.Data["Total"] = count
+	c.Data["Page"] = paginater.New(int(count), setting.UI.Admin.RepoPagingNum, page, 5)
+
+	if err = models.RepositoryList(repos).LoadAttributes(); err != nil {
+		c.Handle(500, "LoadAttributes", err)
+		return
+	}
+	c.Data["Repos"] = repos
+
+	c.HTML(200, RepoSitemapTPL)
+}

+ 0 - 29
routes/admin/usersitemap.go

@@ -1,29 +0,0 @@
-// Copyright 2015 The Gogs Authors. All rights reserved.
-// Copyright 2018 Gitote. All rights reserved.
-//
-// This source code is licensed under the MIT license found in the
-// LICENSE file in the root directory of this source tree.
-
-package admin
-
-import (
-	"gitote/gitote/models"
-	"gitote/gitote/pkg/context"
-	"gitote/gitote/routes"
-)
-
-const (
-	// SitemapTPL page template
-	SitemapTPL = "user/sitemap"
-)
-
-// About shows about page
-func Sitemap(c *context.Context) {
-	routes.RenderUserSearch(c, &routes.UserSearchOptions{
-		Type:    models.UserTypeIndividual,
-		Counter: models.CountUsers,
-		Ranger:  models.Users,
-		OrderBy: "id ASC",
-		TplName: SitemapTPL,
-	})
-}

+ 3 - 0
templates/org/sitemap.tmpl

@@ -0,0 +1,3 @@
+{{range .Users}}
+https://gitote.in/{{.Name}}
+{{end}}

+ 3 - 0
templates/repo/sitemap.tmpl

@@ -0,0 +1,3 @@
+{{range .Repos}}
+https://gitote.in/{{.Owner.Name}}/{{.Name}}
+{{end}}