You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@answer.apache.org by li...@apache.org on 2024/06/07 08:39:20 UTC
(incubator-answer) branch fix/1.3.5/template created (now c1cbe20c)
This is an automated email from the ASF dual-hosted git repository.
linkinstar pushed a change to branch fix/1.3.5/template
in repository https://gitbox.apache.org/repos/asf/incubator-answer.git
at c1cbe20c fix(template): add og meta tag in template
This branch includes the following new commits:
new c1cbe20c fix(template): add og meta tag in template
The 1 revisions listed above as "new" are entirely new to this
repository and will be described in separate emails. The revisions
listed as "add" were already present in the repository and have only
been added to this reference.
(incubator-answer) 01/01: fix(template): add og meta tag in template
Posted by li...@apache.org.
This is an automated email from the ASF dual-hosted git repository.
linkinstar pushed a commit to branch fix/1.3.5/template
in repository https://gitbox.apache.org/repos/asf/incubator-answer.git
commit c1cbe20c3a5276924fef0f4cc42cd2888b6e39b5
Author: LinkinStars <li...@foxmail.com>
AuthorDate: Fri Jun 7 16:39:07 2024 +0800
fix(template): add og meta tag in template
---
internal/controller/template_controller.go | 3 +++
internal/schema/template_schema.go | 3 +++
ui/template/header.html | 18 ++++++++++++++++++
3 files changed, 24 insertions(+)
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>