-
Notifications
You must be signed in to change notification settings - Fork 1
/
HTMLMetaTags.go
109 lines (87 loc) · 2.99 KB
/
HTMLMetaTags.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
package metatags
import (
"html/template"
"time"
"github.com/go-catupiry/catu"
"github.com/go-catupiry/system_settings"
)
type HTMLMetaTags struct {
Title string
Description string
Canonical string
SiteName string
Type string
ImageURL string
ImageHeight string
ImageWidth string
Author string
Keywords string
CreatedAt *time.Time
UpdatedAt *time.Time
PublishedAt *time.Time
TwitterSite string
}
func (r *HTMLMetaTags) Set(key string, value string) {
}
func (r *HTMLMetaTags) Get(key string) string {
return ""
}
func (r *HTMLMetaTags) Render(ctx *catu.RequestContext) template.HTML {
html := ""
pagePath := ""
twitterSite := system_settings.Get("@_TWITTER")
ogType := system_settings.GetD("METATAG_OG_TYPE", "website")
if ctx.Param("id") != "" {
ogType = system_settings.GetD("METATAG_OG_TYPE_ITEM", "article")
}
// Use the current url as canonical, if the url is a permanent with alias like /content/:id the backed will repply with redirect to the alias
if r.Canonical == "" {
pathBeforeAlias := ctx.GetString("pathBeforeAlias")
if pathBeforeAlias != "" {
pagePath = pathBeforeAlias
} else {
pagePath = ctx.EchoContext.Request().URL.Path
}
} else {
pagePath = r.Canonical
}
pageUrl := ctx.AppOrigin + pagePath
if pageUrl != "" {
html += `<meta name="url" property="og:url" content="` + pageUrl + `">`
html += `<link rel="canonical" href="` + pageUrl + `" />`
}
siteName := system_settings.Get("site_name")
if siteName != "" {
html += `<meta property="og:site_name" content="` + siteName + `">`
html += `<meta itemprop="name" content="` + siteName + `">`
}
html += `<meta name="twitter:site" content="` + twitterSite + `">`
html += `<meta property="og:type" content="` + ogType + `">`
if r.Description != "" {
html += `<meta name="description" property="og:description" content="` + r.Description + `">`
html += `<meta name="description" content="` + r.Description + `">`
html += `<meta name="twitter:description" content="` + r.Description + `">`
}
if r.Title != "" {
html += `<meta name="twitter:title" content="` + r.Title + `">`
html += `<meta name="title" property="og:title" content="` + r.Title + `">`
}
if r.ImageURL != "" {
html += `<meta property="image" content="` + r.ImageURL + `">`
html += `<meta property="og:image" content="` + r.ImageURL + `">`
// html += `<meta property="og:image:width" content="1200">`
// html += `<meta property="og:image:height" content="630">`
html += `<meta name="robots" content="max-image-preview:large">`
html += `<link rel="image_src" href="` + r.ImageURL + `"/>`
}
if r.Keywords != "" {
html += `<meta name="keywords" content="` + r.Keywords + `">`
html += `<meta name="news_keywords" content="` + r.Keywords + `">`
}
publisher := system_settings.Get("METATAG_ARTICLE_PUBLISHED")
if publisher != "" {
html += `<meta property="article:publisher" content="` + publisher + `">`
}
html += `<meta name="expires" content="never">`
return template.HTML(html)
}