Skip to content

Commit

Permalink
Updated meta-tag generation. Fixes #1421
Browse files Browse the repository at this point in the history
  • Loading branch information
tidyui committed Dec 8, 2020
1 parent af9ecab commit b09c07a
Showing 1 changed file with 10 additions and 10 deletions.
20 changes: 10 additions & 10 deletions core/Piranha.AspNetCore/Extensions/PiranhaHtmlExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -47,49 +47,49 @@ public static HtmlString MetaTags(this IApplicationService app, IMeta content, b
if (meta)
{
// Generate meta tags
sb.AppendLine($"<meta name=\"robots\" value=\"{ MetaRobots(content) }\">");
sb.AppendLine($"<meta name=\"robots\" content=\"{ MetaRobots(content) }\">");

if (!string.IsNullOrWhiteSpace(content.MetaKeywords))
{
sb.AppendLine($"<meta name=\"keywords\" value=\"{ content.MetaKeywords }\">");
sb.AppendLine($"<meta name=\"keywords\" content=\"{ content.MetaKeywords }\">");
}
if (!string.IsNullOrWhiteSpace(content.MetaDescription))
{
sb.AppendLine($"<meta name=\"description\" value=\"{ content.MetaDescription }\">");
sb.AppendLine($"<meta name=\"description\" content=\"{ content.MetaDescription }\">");
}
}

if (generator)
{
// Generate generator tag
sb.AppendLine($"<meta name=\"generator\" value=\"Piranha CMS { Piranha.Utils.GetAssemblyVersion(typeof(Piranha.App).Assembly) }\">");
sb.AppendLine($"<meta name=\"generator\" content=\"Piranha CMS { Piranha.Utils.GetAssemblyVersion(typeof(Piranha.App).Assembly) }\">");
}

if (opengraph)
{
// Generate open graph tags
if (content is PageBase page && page.IsStartPage)
{
sb.AppendLine($"<meta property=\"og:type\" value=\"website\">");
sb.AppendLine($"<meta property=\"og:type\" content=\"website\">");
}
else
{
sb.AppendLine($"<meta property=\"og:type\" value=\"article\">");
sb.AppendLine($"<meta property=\"og:type\" content=\"article\">");
}
sb.AppendLine($"<meta property=\"og:title\" value=\"{ OgTitle(content) }\">");
sb.AppendLine($"<meta property=\"og:title\" content=\"{ OgTitle(content) }\">");
if (content.OgImage != null && content.OgImage.HasValue)
{
sb.AppendLine($"<meta property=\"og:image\" value=\"{ app.AbsoluteContentUrl(content.OgImage) }\">");
sb.AppendLine($"<meta property=\"og:image\" content=\"{ app.AbsoluteContentUrl(content.OgImage) }\">");
}
else if (content is RoutedContentBase contentBase && contentBase.PrimaryImage != null && contentBase.PrimaryImage.HasValue)
{
// If there's no OG image specified but we have a primary image,
// default to the primary image.
sb.AppendLine($"<meta property=\"og:image\" value=\"{ app.AbsoluteContentUrl(contentBase.PrimaryImage) }\">");
sb.AppendLine($"<meta property=\"og:image\" content=\"{ app.AbsoluteContentUrl(contentBase.PrimaryImage) }\">");
}
if (!string.IsNullOrWhiteSpace(OgDescription(content)))
{
sb.AppendLine($"<meta property=\"og:description\" value=\"{ OgDescription(content) }\">");
sb.AppendLine($"<meta property=\"og:description\" content=\"{ OgDescription(content) }\">");
}
}
return new HtmlString(sb.ToString());
Expand Down

0 comments on commit b09c07a

Please sign in to comment.