Include extracted images in draft social metadata
Previously, we didn't extract images for draft posts. This fixes that.
This commit is contained in:
parent
8e8eb3c563
commit
34d196376e
2 changed files with 10 additions and 4 deletions
10
posts.go
10
posts.go
|
@ -62,6 +62,7 @@ type (
|
|||
Description string
|
||||
Author string
|
||||
Views int64
|
||||
Images []string
|
||||
IsPlainText bool
|
||||
IsCode bool
|
||||
IsLinkable bool
|
||||
|
@ -381,6 +382,7 @@ func handleViewPost(app *App, w http.ResponseWriter, r *http.Request) error {
|
|||
}
|
||||
if !isRaw {
|
||||
post.HTMLContent = template.HTML(applyMarkdown([]byte(content), "", app.cfg))
|
||||
post.Images = extractImages(post.Content)
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -1544,7 +1546,11 @@ func (rp *RawPost) Created8601() string {
|
|||
var imageURLRegex = regexp.MustCompile(`(?i)^https?:\/\/[^ ]*\.(gif|png|jpg|jpeg|image)$`)
|
||||
|
||||
func (p *Post) extractImages() {
|
||||
matches := extract.ExtractUrls(p.Content)
|
||||
p.Images = extractImages(p.Content)
|
||||
}
|
||||
|
||||
func extractImages(content string) []string {
|
||||
matches := extract.ExtractUrls(content)
|
||||
urls := map[string]bool{}
|
||||
for i := range matches {
|
||||
u := matches[i].Text
|
||||
|
@ -1558,5 +1564,5 @@ func (p *Post) extractImages() {
|
|||
for k := range urls {
|
||||
resURLs = append(resURLs, k)
|
||||
}
|
||||
p.Images = resURLs
|
||||
return resURLs
|
||||
}
|
||||
|
|
|
@ -23,13 +23,13 @@
|
|||
<meta name="twitter:description" content="{{.Description}}">
|
||||
{{if gt .Views 1}}<meta name="twitter:label1" value="Views">
|
||||
<meta name="twitter:data1" value="{{largeNumFmt .Views}}">{{end}}
|
||||
<meta name="twitter:image" content="{{.Host}}/img/wf-sq.png">
|
||||
{{if gt (len .Images) 0}}<meta name="twitter:image" content="{{index .Images 0}}">{{else}}<meta name="twitter:image" content="{{.Host}}/img/wf-sq.png">{{end}}
|
||||
<meta property="og:title" content="{{if .Title}}{{.Title}}{{else}}{{.GenTitle}}{{end}}" />
|
||||
<meta property="og:site_name" content="{{.SiteName}}" />
|
||||
<meta property="og:type" content="article" />
|
||||
<meta property="og:url" content="{{.Host}}/{{if .SingleUser}}d/{{end}}{{.ID}}" />
|
||||
<meta property="og:description" content="{{.Description}}" />
|
||||
<meta property="og:image" content="{{.Host}}/img/wf-sq.png">
|
||||
{{range .Images}}<meta property="og:image" content="{{.}}" />{{else}}<meta property="og:image" content="{{.Host}}/img/wf-sq.png">{{end}}
|
||||
{{if .Author}}<meta property="article:author" content="https://{{.Author}}" />{{end}}
|
||||
<!-- Add highlighting logic -->
|
||||
{{template "highlighting" .}}
|
||||
|
|
Loading…
Add table
Reference in a new issue