Repository: answerdev/answer
File: internal/controller/template_render/question.go (Go)

Code before:
	var pageList []int
	totalPages := int(math.Ceil(float64(questionNum) / float64(constant.SitemapMaxSize)))
	for i := 1; i <= totalPages; i++ {
		pageList = append(pageList, i)
	}
	ctx.HTML(
		http.StatusOK, "sitemap-list.xml", gin.H{
			"xmlHeader": template.HTML(`<?xml version="1.0" encoding="UTF-8"?>`),
			"page":      pageList,
			"general":   general,
		},
	)
}

func (t *TemplateRenderController) OpenSearch(ctx *gin.Context) {
	general, err := t.siteInfoService.GetSiteGeneral(ctx)
	if err != nil {
		log.Error("get site general failed:", err)
		return
	}

	favicon := "favicon.ico"
	branding, err := t.siteInfoService.GetSiteBranding(ctx)
	if err == nil {
		favicon = branding.Favicon
	}

	ctx.Header("Content-Type", "application/xml")
	ctx.HTML(
		http.StatusOK, "opensearch.xml", gin.H{
			"general": general,
			"favicon": favicon,
		},
	)
}

func (t *TemplateRenderController) SitemapPage(ctx *gin.Context, page int) error {
	general, err := t.siteInfoService.GetSiteGeneral(ctx)
	if err != nil {
		log.Error("get site general failed:", err)
		return err
	}
	siteInfo, err := t.siteInfoService.GetSiteSeo(ctx)
	if err != nil {
		log.Error("get site GetSiteSeo failed:", err)
		return err
	}

	questions, err := t.questionRepo.SitemapQuestions(ctx, page, constant.SitemapMaxSize)
	if err != nil {
		log.Errorf("get sitemap questions failed: %s", err)

Review comment (suggestion):
It would be better to set a default value(full url) for the favicon. This is because the branding favicon might be empty.

```go
	favicon := general.SiteUrl + "/favicon.ico"
	branding, err := t.siteInfoService.GetSiteBranding(ctx)
	if err == nil && len(branding.Favicon) > 0 {
		favicon = branding.Favicon
	}
```

Code after:
	var pageList []int
	totalPages := int(math.Ceil(float64(questionNum) / float64(constant.SitemapMaxSize)))
	for i := 1; i <= totalPages; i++ {
		pageList = append(pageList, i)
	}
	ctx.HTML(
		http.StatusOK, "sitemap-list.xml", gin.H{
			"xmlHeader": template.HTML(`<?xml version="1.0" encoding="UTF-8"?>`),
			"page":      pageList,
			"general":   general,
		},
	)
}

func (t *TemplateRenderController) OpenSearch(ctx *gin.Context) {
	general, err := t.siteInfoService.GetSiteGeneral(ctx)
	if err != nil {
		log.Error("get site general failed:", err)
		return
	}

	favicon := general.SiteUrl + "/favicon.ico"
	branding, err := t.siteInfoService.GetSiteBranding(ctx)
	if err == nil && len(branding.Favicon) > 0 {
		favicon = branding.Favicon
	}

	ctx.Header("Content-Type", "application/xml")
	ctx.HTML(
		http.StatusOK, "opensearch.xml", gin.H{
			"general": general,
			"favicon": favicon,
		},
	)
}

func (t *TemplateRenderController) SitemapPage(ctx *gin.Context, page int) error {
	general, err := t.siteInfoService.GetSiteGeneral(ctx)
	if err != nil {
		log.Error("get site general failed:", err)
		return err
	}
	siteInfo, err := t.siteInfoService.GetSiteSeo(ctx)
	if err != nil {
		log.Error("get site GetSiteSeo failed:", err)
		return err
	}

	questions, err := t.questionRepo.SitemapQuestions(ctx, page, constant.SitemapMaxSize)
	if err != nil {
		log.Errorf("get sitemap questions failed: %s", err)