mirror of https://gitee.com/answerdev/answer.git
add page meta
This commit is contained in:
parent
6e000bb5f1
commit
e59e95fe11
|
@ -6,6 +6,7 @@ import (
|
|||
"html/template"
|
||||
"net/http"
|
||||
"regexp"
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
"github.com/answerdev/answer/internal/base/handler"
|
||||
|
@ -190,6 +191,13 @@ func (tc *TemplateController) QuestionInfo(ctx *gin.Context) {
|
|||
siteInfo.JsonLD = `<script data-react-helmet="true" type="application/ld+json">` + string(jsonLDStr) + ` </script>`
|
||||
}
|
||||
|
||||
siteInfo.Description = htmltext.FetchExcerpt(detail.HTML, "...", 240)
|
||||
tags := make([]string, 0)
|
||||
for _, tag := range detail.Tags {
|
||||
tags = append(tags, tag.DisplayName)
|
||||
}
|
||||
siteInfo.Keywords = strings.Replace(strings.Trim(fmt.Sprint(tags), "[]"), " ", ",", -1)
|
||||
|
||||
tc.html(ctx, http.StatusOK, "question-detail.html", siteInfo, gin.H{
|
||||
"id": id,
|
||||
"answerid": answerid,
|
||||
|
@ -254,6 +262,10 @@ func (tc *TemplateController) TagInfo(ctx *gin.Context) {
|
|||
|
||||
siteInfo := tc.SiteInfo(ctx)
|
||||
siteInfo.Canonical = fmt.Sprintf("%s/tags/%s", siteInfo.General.SiteUrl, tag)
|
||||
|
||||
siteInfo.Description = htmltext.FetchExcerpt(taginifo.ParsedText, "...", 240)
|
||||
siteInfo.Keywords = taginifo.DisplayName
|
||||
|
||||
tc.html(ctx, http.StatusOK, "tag-detail.html", siteInfo, gin.H{
|
||||
"tag": taginifo,
|
||||
"questionList": questionList,
|
||||
|
@ -307,6 +319,11 @@ func (tc *TemplateController) html(ctx *gin.Context, code int, tpl string, siteI
|
|||
data["siteinfo"] = siteInfo
|
||||
data["scriptPath"] = tc.scriptPath
|
||||
data["cssPath"] = tc.cssPath
|
||||
data["keywords"] = siteInfo.Keywords
|
||||
if siteInfo.Description == "" {
|
||||
siteInfo.Description = siteInfo.General.Description
|
||||
}
|
||||
data["description"] = siteInfo.Description
|
||||
data["language"] = handler.GetLang(ctx)
|
||||
data["timezone"] = siteInfo.Interface.TimeZone
|
||||
|
||||
|
|
|
@ -106,12 +106,14 @@ type SiteInfoResp struct {
|
|||
Branding *SiteBrandingResp `json:"branding"`
|
||||
}
|
||||
type TemplateSiteInfoResp struct {
|
||||
General *SiteGeneralResp `json:"general"`
|
||||
Interface *SiteInterfaceResp `json:"interface"`
|
||||
Branding *SiteBrandingResp `json:"branding"`
|
||||
Year string
|
||||
Canonical string
|
||||
JsonLD string
|
||||
General *SiteGeneralResp `json:"general"`
|
||||
Interface *SiteInterfaceResp `json:"interface"`
|
||||
Branding *SiteBrandingResp `json:"branding"`
|
||||
Year string
|
||||
Canonical string
|
||||
JsonLD string
|
||||
Keywords string
|
||||
Description string
|
||||
}
|
||||
|
||||
// UpdateSMTPConfigReq get smtp config request
|
||||
|
|
|
@ -5,7 +5,8 @@
|
|||
<head>
|
||||
<meta charset="utf-8" />
|
||||
<meta name="viewport" content="width=device-width,initial-scale=1" />
|
||||
|
||||
<meta name="description" content="{{.description}}" />
|
||||
{{if .keywords }}<meta name="keywords" content="{{.keywords}}" />{{end}}
|
||||
<link rel="canonical" href="{{.siteinfo.Canonical}}" />
|
||||
<link rel="manifest" href="/manifest.json"/>
|
||||
<link href="{{.cssPath}}" rel="stylesheet" />
|
||||
|
|
Loading…
Reference in New Issue