fix: update title/description
This commit is contained in:
parent
66842b4c7b
commit
52b308967f
@ -200,6 +200,43 @@ public class OpenGraphController : Controller
|
||||
}
|
||||
|
||||
doc.Head?.AppendChild(tag);
|
||||
|
||||
var isOgTitle = ex.Attributes.Any(a => a is {Key: "property", Value: "og:title"});
|
||||
if (isOgTitle && doc.Head != default)
|
||||
{
|
||||
var titleTag = doc.Head.QuerySelector("title");
|
||||
var ogTitle = ex.Attributes.FirstOrDefault(a => a.Key is "content");
|
||||
if (!string.IsNullOrEmpty(ogTitle.Value))
|
||||
{
|
||||
if (titleTag == default)
|
||||
{
|
||||
var newTitle = doc.CreateElement("title");
|
||||
doc.Head.AppendChild(newTitle);
|
||||
titleTag = newTitle;
|
||||
}
|
||||
|
||||
titleTag.TextContent = ogTitle.Value;
|
||||
}
|
||||
}
|
||||
|
||||
var isOgDesc = ex.Attributes.Any(a => a is {Key: "property", Value: "og:description"});
|
||||
if (isOgDesc && doc.Head != default)
|
||||
{
|
||||
var ogDesc = ex.Attributes.FirstOrDefault(a => a.Key is "content");
|
||||
var descriptionTag = doc.Head?.QuerySelector("meta[name='description']");
|
||||
if (!string.IsNullOrEmpty(ogDesc.Value))
|
||||
{
|
||||
if (descriptionTag == default)
|
||||
{
|
||||
var newDesc = doc.CreateElement("meta");
|
||||
newDesc.SetAttribute("name", "description");
|
||||
doc.Head?.AppendChild(newDesc);
|
||||
descriptionTag = newDesc;
|
||||
}
|
||||
|
||||
descriptionTag.SetAttribute("content", ogDesc.Value);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return doc;
|
||||
|
Loading…
x
Reference in New Issue
Block a user