Skip to content

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.

fix(template): add og meta tag in template

LinkinStarsc1cbe20c3a52
diff --git a/internal/controller/template_controller.go b/internal/controller/template_controller.go
index 7dbcebda..b1738b00 100644
--- a/internal/controller/template_controller.go
+++ b/internal/controller/template_controller.go
@@ -342,6 +342,7 @@ func (tc *TemplateController) QuestionInfo(ctx *gin.Context) {
jsonLD.MainEntity.DateCreated = time.Unix(detail.CreateTime, 0)
jsonLD.MainEntity.Author.Type = "Person"
jsonLD.MainEntity.Author.Name = detail.UserInfo.DisplayName
+ jsonLD.MainEntity.Author.URL = fmt.Sprintf("%s/users/%s", siteInfo.General.SiteUrl, detail.UserInfo.Username)
answerList := make([]*schema.SuggestedAnswerItem, 0)
for _, answer := range answers {
if answer.Accepted == schema.AnswerAcceptedEnable {
@@ -353,6 +354,7 @@ func (tc *TemplateController) QuestionInfo(ctx *gin.Context) {
acceptedAnswerItem.URL = fmt.Sprintf("%s/%s", siteInfo.Canonical, answer.ID)
acceptedAnswerItem.Author.Type = "Person"
acceptedAnswerItem.Author.Name = answer.UserInfo.DisplayName
+ acceptedAnswerItem.Author.URL = fmt.Sprintf("%s/users/%s", siteInfo.General.SiteUrl, answer.UserInfo.Username)
jsonLD.MainEntity.AcceptedAnswer = acceptedAnswerItem
} else {
item := &schema.SuggestedAnswerItem{}
@@ -363,6 +365,7 @@ func (tc *TemplateController) QuestionInfo(ctx *gin.Context) {
item.URL = fmt.Sprintf("%s/%s", siteInfo.Canonical, answer.ID)
item.Author.Type = "Person"
item.Author.Name = answer.UserInfo.DisplayName
+ item.Author.URL = fmt.Sprintf("%s/users/%s", siteInfo.General.SiteUrl, answer.UserInfo.Username)
answerList = append(answerList, item)
}
diff --git a/internal/schema/template_schema.go b/internal/schema/template_schema.go
index dfe03624..ae90aa94 100644
--- a/internal/schema/template_schema.go
+++ b/internal/schema/template_schema.go
@@ -40,6 +40,7 @@ type QAPageJsonLD struct {
UpvoteCount int `json:"upvoteCount"`
DateCreated time.Time `json:"dateCreated"`
Author struct {
+ URL string `json:"url"`
Type string `json:"@type"`
Name string `json:"name"`
} `json:"author"`
@@ -55,6 +56,7 @@ type AcceptedAnswerItem struct {
UpvoteCount int `json:"upvoteCount"`
URL string `json:"url"`
Author struct {
+ URL string `json:"url"`
Type string `json:"@type"`
Name string `json:"name"`
} `json:"author"`
@@ -67,6 +69,7 @@ type SuggestedAnswerItem struct {
UpvoteCount int `json:"upvoteCount"`
URL string `json:"url"`
Author struct {
+ URL string `json:"url"`
Type string `json:"@type"`
Name string `json:"name"`
} `json:"author"`
diff --git a/ui/template/header.html b/ui/template/header.html
index c956bb70..b7f4aaf8 100644
--- a/ui/template/header.html
+++ b/ui/template/header.html
@@ -58,6 +58,24 @@
<script defer="defer" src="{{$path}}"></script>
{{end}}
{{if $.siteinfo.JsonLD }}{{ .siteinfo.JsonLD | templateHTML}}{{end}}
+
+ <meta property="og:type" content="website" />
+ <meta property="og:title" name="twitter:title" content="{{.title}}" />
+ <meta property="og:site_name" content="{{.siteinfo.General.Name}}" />
+ <meta property="og:url" content="{{.siteinfo.Canonical}}" />
+ <meta property="og:description" content="{{.description}}" />
+ <meta
+ property="og:image"
+ itemProp="image primaryImageOfPage"
+ content="{{if $.siteinfo.Branding.Favicon }}{{$.siteinfo.Branding.Favicon}}{{else}}{{$.baseURL}}/favicon.ico{{end}}"}
+ />
+ <meta name="twitter:card" content="summary" />
+ <meta name="twitter:domain" content="{{.siteinfo.General.SiteUrl}}" />
+ <meta name="twitter:description" content="{{.description}}" />
+ <meta
+ name="twitter:image"
+ content="{{if $.siteinfo.Branding.Favicon }}{{$.siteinfo.Branding.Favicon}}{{else}}{{$.baseURL}}/favicon.ico{{end}}"}
+ />
</head>
<body>