diff --git a/source/DasBlog.Web.UI/TagHelpers/Post/PostImageTagHelper.cs b/source/DasBlog.Web.UI/TagHelpers/Post/PostImageTagHelper.cs index 2cf089ec..15f1f406 100644 --- a/source/DasBlog.Web.UI/TagHelpers/Post/PostImageTagHelper.cs +++ b/source/DasBlog.Web.UI/TagHelpers/Post/PostImageTagHelper.cs @@ -6,11 +6,12 @@ namespace DasBlog.Web.TagHelpers.Post { public class PostImageTagHelper: TagHelper - { public PostViewModel Post { get; set; } + public string DefaultImage { get; set; } public string Css { get; set; } + public string Style { get; set; } private readonly IDasBlogSettings dasBlogSettings; @@ -19,19 +20,39 @@ public PostImageTagHelper(IDasBlogSettings dasBlogSettings) this.dasBlogSettings = dasBlogSettings; } - public override async Task ProcessAsync(TagHelperContext context, TagHelperOutput output) + public override void Process(TagHelperContext context, TagHelperOutput output) { - output.TagMode = TagMode.StartTagAndEndTag; + var imgUrl = Post.ImageUrl; + + output.TagMode = TagMode.SelfClosing; output.TagName = "img"; + if (!string.IsNullOrEmpty(imgUrl)) + { + output.Attributes.SetAttribute("src", dasBlogSettings.RelativeToRoot(imgUrl)); + } + else + { + if (!string.IsNullOrEmpty(DefaultImage)) + { + output.Attributes.SetAttribute("src", DefaultImage); + } + } + if (!string.IsNullOrEmpty(Css)) { output.Attributes.SetAttribute("class", Css); } - output.Attributes.SetAttribute("src", dasBlogSettings.RelativeToRoot(Post.ImageUrl)); - output.Attributes.SetAttribute("alt", Post.Title); - await Task.CompletedTask; + if (!string.IsNullOrEmpty(Style)) + { + output.Attributes.SetAttribute("style", Style); + } + } + + public override Task ProcessAsync(TagHelperContext context, TagHelperOutput output) + { + return Task.Run(() => Process(context, output)); } } } diff --git a/source/DasBlog.Web.UI/Themes/darkly/_BlogItemSummary.cshtml b/source/DasBlog.Web.UI/Themes/darkly/_BlogItemSummary.cshtml index 48b3e033..a2966abb 100644 --- a/source/DasBlog.Web.UI/Themes/darkly/_BlogItemSummary.cshtml +++ b/source/DasBlog.Web.UI/Themes/darkly/_BlogItemSummary.cshtml @@ -5,13 +5,14 @@