A Q&A platform software for teams at any scales. Whether it's a community forum, help center, or knowledge management platform, you can always count on Apache Answer.
xml template
aichy126b9db22e9f60a
diff --git a/internal/base/server/http.go b/internal/base/server/http.goindex 646b0579..cba6d81a 100644--- a/internal/base/server/http.go+++ b/internal/base/server/http.go@@ -172,7 +172,7 @@ func NewHTTPServer(debug bool,r.LoadHTMLGlob("../../ui/template/*")} else {html, _ := fs.Sub(ui.Template, "template")- htmlTemplate := template.Must(template.New("").Funcs(funcMap).ParseFS(html, "*.html"))+ htmlTemplate := template.Must(template.New("").Funcs(funcMap).ParseFS(html, "*"))r.SetHTMLTemplate(htmlTemplate)}diff --git a/internal/controller/template_controller.go b/internal/controller/template_controller.goindex f5585b89..4a525e10 100644--- a/internal/controller/template_controller.go+++ b/internal/controller/template_controller.go@@ -404,12 +404,7 @@ func (tc *TemplateController) html(ctx *gin.Context, code int, tpl string, siteI}func (tc *TemplateController) Sitemap(ctx *gin.Context) {- xml, err := tc.templateRenderController.Sitemap(ctx)- if err != nil {- tc.Page404(ctx)- return- }- ctx.String(http.StatusOK, xml)+ tc.templateRenderController.Sitemap(ctx)}func (tc *TemplateController) SitemapPage(ctx *gin.Context) {diff --git a/internal/controller/template_render/question.go b/internal/controller/template_render/question.goindex ce79d3ba..4f24c304 100644--- a/internal/controller/template_render/question.go+++ b/internal/controller/template_render/question.go@@ -1,7 +1,8 @@package templaterenderimport (- "fmt"+ "html/template"+ "net/http""github.com/answerdev/answer/internal/schema""github.com/gin-gonic/gin"@@ -15,10 +16,32 @@ func (t *TemplateRenderController) QuestionDetail(ctx *gin.Context, id string) (return t.questionService.GetQuestion(ctx, id, "", schema.QuestionPermission{})}-func (t *TemplateRenderController) Sitemap(ctx *gin.Context) (string, error) {- return "Sitemap", nil+func (t *TemplateRenderController) Sitemap(ctx *gin.Context) {+ //question list page+ ctx.Header("Content-Type", "application/xml")+ ctx.HTML(+ http.StatusOK, "sitemap-list.xml", gin.H{+ "xmlHeader": template.HTML(`<?xml version="1.0" encoding="UTF-8"?>`),+ "list": "string",+ },+ )++ //question url list+ ctx.Header("Content-Type", "application/xml")+ ctx.HTML(+ http.StatusOK, "sitemap.xml", gin.H{+ "xmlHeader": template.HTML(`<?xml version="1.0" encoding="UTF-8"?>`),+ "list": "string",+ },+ )}func (t *TemplateRenderController) SitemapPage(ctx *gin.Context, page int) (string, error) {- return fmt.Sprintf("SitemapPage-%d", page), nil+ ctx.Header("Content-Type", "application/xml")+ ctx.HTML(+ http.StatusOK, "sitemap.xml", gin.H{+ "xmlHeader": template.HTML(`<?xml version="1.0" encoding="UTF-8"?>`),+ "list": "string",+ },+ )}diff --git a/ui/template/sitemap-list.xml b/ui/template/sitemap-list.xmlnew file mode 100644index 00000000..55d4a0c9--- /dev/null+++ b/ui/template/sitemap-list.xml@@ -0,0 +1,6 @@+{{ .xmlHeader }}+<sitemapindex xmlns="http://www.sitemaps.org/schemas/sitemap/0.9">+ <sitemap>+ <loc>http://www.example.com/sitemap1.xml</loc>+ </sitemap>+</sitemapindex>diff --git a/ui/template/sitemap.xml b/ui/template/sitemap.xmlnew file mode 100644index 00000000..0fbbcccf--- /dev/null+++ b/ui/template/sitemap.xml@@ -0,0 +1,7 @@+{{ .xmlHeader }}+<urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9">+ <url>+ <loc>http://www.example.com/foo1</loc>+ <lastmod>2018-06-04</lastmod>+ </url>+</urlset>