Skip to content

Commit

Permalink
Merge pull request #360 from fbranicky/fix-347
Browse files Browse the repository at this point in the history
Fix #347 convert MetaTags extension to use TagBuilder
  • Loading branch information
Shazwazza authored Apr 8, 2021
2 parents 896b149 + a099711 commit 493364e
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 493364e

Please sign in to comment.