Skip to content

Commit 36a9be4

Browse files
committed
✨ Fix b3log#20
1 parent 51af03f commit 36a9be4

3 files changed

Lines changed: 39 additions & 2 deletions

File tree

‎controller/router.go‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,7 @@ func MapRoutes() *gin.Engine {
7070
ret.Use(sessions.Sessions("pipe", store))
7171
ret.POST(util.PathUpload, uploadAction)
7272
ret.GET(util.PathPlatInfo, showPlatInfo)
73+
ret.GET(util.PathSitemap, outputSitemapAction)
7374

7475
api := ret.Group(util.PathAPI)
7576
api.POST("/init", initAction)

‎controller/sitemapctl.go‎

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
// Pipe - A small and beautiful blogging platform written in golang.
2+
// Copyright (C) 2017-2018, b3log.org
3+
//
4+
// This program is free software: you can redistribute it and/or modify
5+
// it under the terms of the GNU General Public License as published by
6+
// the Free Software Foundation, either version 3 of the License, or
7+
// (at your option) any later version.
8+
//
9+
// This program is distributed in the hope that it will be useful,
10+
// but WITHOUT ANY WARRANTY; without even the implied warranty of
11+
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12+
// GNU General Public License for more details.
13+
//
14+
// You should have received a copy of the GNU General Public License
15+
// along with this program. If not, see <http://www.gnu.org/licenses/>.
16+
17+
package controller
18+
19+
import (
20+
"github.com/b3log/pipe/service"
21+
"github.com/gin-gonic/gin"
22+
"github.com/ikeikeikeike/go-sitemap-generator/stm"
23+
)
24+
25+
func outputSitemapAction(c *gin.Context) {
26+
sm := stm.NewSitemap()
27+
sm.Create()
28+
29+
blogs := service.User.GetTopBlogs(10)
30+
for _, blog := range blogs {
31+
sm.Add(stm.URL{"loc": blog.URL})
32+
}
33+
34+
c.Writer.Write(sm.XMLContent())
35+
}

‎util/paths.go‎

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@ const (
4040
PathComments = "/comments"
4141
PathAtom = "/atom"
4242
PathRSS = "/rss"
43+
PathSitemap = "/sitemap.xml"
4344
PathUpload = "/upload"
4445
PathFetchUpload = "/fetch-upload"
4546
PathChangelogs = "/changelogs"
@@ -52,8 +53,8 @@ const (
5253
var reservedPaths = []string{
5354
PathInit, PathSearch, PathBlogs, PathConsoleDist, PathAdmin, PathAPI, PathFavicon, PathTheme,
5455
PathActivities, PathArchives, PathAuthors, PathCategories, PathTags, PathComments, PathAtom, PathRSS,
55-
PathUpload, PathFetchUpload, PathChangelogs, PathRobots, PathAPIsSymArticles, PathAPIsSymComments,
56-
PathPlatInfo,
56+
PathSitemap, PathUpload, PathFetchUpload, PathChangelogs, PathRobots, PathAPIsSymArticles,
57+
PathAPIsSymComments, PathPlatInfo,
5758
}
5859

5960
// IsReservedPath checks the specified path is a reserved path or not.

0 commit comments

Comments
 (0)