-
-
Notifications
You must be signed in to change notification settings - Fork 357
/
social.go
70 lines (53 loc) · 1.45 KB
/
social.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
package app
import "strings"
// A Twitter card: https://developer.twitter.com/en/docs/twitter-for-websites/cards
type TwitterCard struct {
// The card type, which will be one of “summary”, “summary_large_image”,
// “app”, or “player”.
Card string
// Username for the website used in the card footer.
Site string
// Username for the content creator / author.
Creator string
// A concise title for the related content.
Title string
// A description that concisely summarizes the content as appropriate for
// presentation within a Tweet.
Description string
// A URL to a unique image representing the content of the page.
Image string
// A text description of the image conveying the essential nature of an
// image to users who are visually impaired. Maximum 420 characters.
ImageAlt string
}
func (c TwitterCard) toMap() map[string]string {
m := make(map[string]string)
if c.Card != "" {
m["twitter:card"] = c.Card
}
if c.Site != "" {
if !strings.HasPrefix(c.Site, "@") {
c.Site = "@" + c.Site
}
m["twitter:site"] = c.Site
}
if c.Creator != "" {
if !strings.HasPrefix(c.Creator, "@") {
c.Creator = "@" + c.Creator
}
m["twitter:creator"] = c.Creator
}
if c.Title != "" {
m["twitter:title"] = c.Title
}
if c.Description != "" {
m["twitter:description"] = c.Description
}
if c.Image != "" {
m["twitter:image"] = c.Image
}
if c.ImageAlt != "" {
m["twitter:image:alt"] = c.ImageAlt
}
return m
}