瀏覽代碼

Started Implementing User Sitemap

Yoginth 7 年之前
父節點
當前提交
c2ce26dc0a
共有 3 個文件被更改,包括 27 次插入2 次删除
  1. 2 0
      cmd/web.go
  2. 0 2
      routes/user/certificate.go
  3. 25 0
      routes/user/sitemap.go

+ 2 - 0
cmd/web.go

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

+ 0 - 2
routes/user/certificate.go

@@ -11,8 +11,6 @@ const (
 
 func InternCertificate(c *context.Context) {
 	ctxUser := GetUserByName(c, strings.TrimSuffix(c.Params(":username"), ""))
-
-	c.Data["PageIsUserProfile"] = true
 	c.Data["Owner"] = ctxUser
 
 	c.HTML(200, INTERNCERTIFICATE)

+ 25 - 0
routes/user/sitemap.go

@@ -0,0 +1,25 @@
+package user
+
+import (
+	"encoding/xml"
+	"net/http"
+)
+
+type Urlset struct {
+	Loc        string `xml:"url>loc"`
+	Changefreq string `xml:"url>changefreq"`
+	Priority   string `xml:"url>priority"`
+}
+
+func Sitemap(w http.ResponseWriter, r *http.Request) {
+	profile := Urlset{"dfsdf", "dgg", "fsdjfn"}
+
+	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)
+}