mirror of https://gitee.com/answerdev/answer.git
xml template
This commit is contained in:
parent
6459f6b7cb
commit
b9db22e9f6
|
@ -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)
|
||||
}
|
||||
|
||||
|
|
|
@ -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) {
|
||||
|
|
|
@ -1,7 +1,8 @@
|
|||
package templaterender
|
||||
|
||||
import (
|
||||
"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",
|
||||
},
|
||||
)
|
||||
}
|
||||
|
|
|
@ -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>
|
|
@ -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>
|
Loading…
Reference in New Issue