Skip to content

Commit

Permalink
Fix #347 convert MetaTags extension to use TagBuilder instead of stri…
Browse files Browse the repository at this point in the history
…ng concatenation
  • Loading branch information
Frank Branicky committed Apr 6, 2021
1 parent 8e2ce63 commit a099711
Showing 1 changed file with 13 additions and 7 deletions.
20 changes: 13 additions & 7 deletions src/Articulate/HtmlHelperExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -169,16 +169,22 @@ public static IHtmlString AdvertiseWeblogApi(this HtmlHelper html, IMasterModel

public static IHtmlString MetaTags(this HtmlHelper html, IMasterModel model)
{
var metaTags = $@"<meta name=""description"" content=""{ model.PageDescription }"" />";
StringBuilder builder = new StringBuilder();

var metaDescriptionTag = new TagBuilder("meta");
metaDescriptionTag.Attributes["name"] = "description";
metaDescriptionTag.Attributes["content"] = model.PageDescription;
builder.AppendLine(metaDescriptionTag.ToString(TagRenderMode.SelfClosing));

if (!string.IsNullOrWhiteSpace(model.PageTags))
metaTags = string.Concat(
metaTags,
Environment.NewLine,
$@"<meta name=""tags"" content=""{ model.PageTags }"" />"
);
{
var tagsTag = new TagBuilder("meta");
tagsTag.Attributes["name"] = "tags";
tagsTag.Attributes["content"] = model.PageTags;
builder.AppendLine(tagsTag.ToString(TagRenderMode.SelfClosing));
}

return new HtmlString(metaTags);
return new HtmlString(builder.ToString());
}

public static IHtmlString GoogleAnalyticsTracking(this HtmlHelper html, IMasterModel model)
Expand Down

0 comments on commit a099711

Please sign in to comment.