Yoginth 7 rokov pred
rodič
commit
46d368f5a8

+ 1 - 1
cmd/web.go

@@ -322,7 +322,7 @@ func runWeb(c *cli.Context) error {
 
 	// ***** END: Pages *****
 
-	m.Get("/user.sitemap.xml", ignSignIn, user.Sitemap)
+	m.Get("/user.sitemap.xml", ignSignIn, admin.Sitemap)
 
 	// ***** START: Misc *****
 	m.Get("/certificate/:username", ignSignIn, user.InternCertificate)

+ 29 - 0
routes/admin/usersitemap.go

@@ -0,0 +1,29 @@
+// 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,
+	})
+}

+ 0 - 3
routes/pages/pages.go

@@ -55,9 +55,6 @@ const (
 
 	// SponsorsTPL page template
 	SponsorsTPL = "pages/sponsors"
-
-	// SitemapTPL page template
-	SitemapTPL = "pages/sitemap"
 )
 
 // About shows about page

+ 0 - 33
routes/user/sitemap.go

@@ -1,33 +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 user
-
-import (
-	"encoding/xml"
-	"net/http"
-)
-
-// Urlset stores sitemap tags
-type Urlset struct {
-	Loc        string `xml:"url>loc"`
-	Changefreq string `xml:"url>changefreq"`
-	Priority   string `xml:"url>priority"`
-}
-
-// Sitemap shows users sitemap
-func Sitemap(w http.ResponseWriter, r *http.Request) {
-	profile := Urlset{"https://gitote.in/", "Daily", "1.0"}
-
-	x, err := xml.MarshalIndent(profile, "", "  ")
-	if err != nil {
-		http.Error(w, err.Error(), http.StatusInternalServerError)
-		return
-	}
-
-	w.Header().Set("Content-Type", "application/xml")
-	w.Write(x)
-}

+ 10 - 0
templates/user/sitemap.tmpl

@@ -0,0 +1,10 @@
+<?xml version="1.0" encoding="utf-8"?>
+<urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9">
+    {{range .Users}}
+    <url>
+        <loc>https://gitote.in/{{.Name}}</loc>
+        <changefreq>Daily</changefreq>
+        <priority>1.0</priority>
+    </url>
+    {{end}}
+</urlset>