Enhance SEO metadata handling by adding keywords support and fixing og:title attribute syntax
This commit is contained in:
parent
73ccac6ba5
commit
35911de0ea
1 changed files with 21 additions and 10 deletions
|
|
@ -224,27 +224,38 @@ func (page *Page) ReplaceDocument(doc *goquery.Document) {
|
|||
|
||||
if page.Config.SEO != nil {
|
||||
|
||||
if page.Config.SEO.Title != "" {
|
||||
if doc.Find("meta[property=og:title]") != nil {
|
||||
doc.Find("meta[property=og:title]").SetAttr("content", page.Config.SEO.Title)
|
||||
}
|
||||
}
|
||||
|
||||
if page.Config.SEO.Description != "" {
|
||||
if doc.Find("meta[name=description]") != nil {
|
||||
doc.Find("meta[name=description]").SetAttr("content", page.Config.SEO.Description)
|
||||
}
|
||||
}
|
||||
|
||||
if page.Config.SEO.Keywords != "" {
|
||||
if doc.Find("meta[name=keywords]") != nil {
|
||||
sel := doc.Find("meta[name=keywords]")
|
||||
keywords := page.Config.SEO.Keywords
|
||||
if sel.AttrOr("content", "") != "" {
|
||||
keywords = keywords + "," + sel.AttrOr("content", "")
|
||||
}
|
||||
doc.Find("meta[name=keywords]").SetAttr("content", keywords)
|
||||
}
|
||||
}
|
||||
|
||||
if page.Config.SEO.Title != "" {
|
||||
if doc.Find("meta[property='og:title']") != nil {
|
||||
doc.Find("meta[property='og:title']").SetAttr("content", page.Config.SEO.Title)
|
||||
}
|
||||
}
|
||||
|
||||
if page.Config.SEO.Image != "" {
|
||||
if doc.Find("meta[property=og:image]") != nil {
|
||||
doc.Find("meta[property=og:image]").SetAttr("content", page.Config.SEO.Image)
|
||||
if doc.Find("meta[property='og:image']") != nil {
|
||||
doc.Find("meta[property='og:image']").SetAttr("content", page.Config.SEO.Image)
|
||||
}
|
||||
}
|
||||
|
||||
if page.Config.SEO.URL != "" {
|
||||
if doc.Find("meta[property=og:url]") != nil {
|
||||
doc.Find("meta[property=og:url]").SetAttr("content", page.Config.SEO.URL)
|
||||
if doc.Find("meta[property='og:url']") != nil {
|
||||
doc.Find("meta[property='og:url']").SetAttr("content", page.Config.SEO.URL)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue