fix: update title/description
This commit is contained in:
@ -200,6 +200,43 @@ public class OpenGraphController : Controller
|
|||||||
}
|
}
|
||||||
|
|
||||||
doc.Head?.AppendChild(tag);
|
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;
|
return doc;
|
||||||
|
Reference in New Issue
Block a user