Skip to content

Commit 77292e5

Browse files
authored
Merge pull request #560 from rullyrmd/bug/blog-item-summary-default-mg
Fix the BlogItemSummary razor page close #555
2 parents c414bc2 + 836378a commit 77292e5

File tree

2 files changed

+30
-8
lines changed

2 files changed

+30
-8
lines changed

source/DasBlog.Web.UI/TagHelpers/Post/PostImageTagHelper.cs

+27-6
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,12 @@
66
namespace DasBlog.Web.TagHelpers.Post
77
{
88
public class PostImageTagHelper: TagHelper
9-
109
{
1110
public PostViewModel Post { get; set; }
1211

12+
public string DefaultImage { get; set; }
1313
public string Css { get; set; }
14+
public string Style { get; set; }
1415

1516
private readonly IDasBlogSettings dasBlogSettings;
1617

@@ -19,19 +20,39 @@ public PostImageTagHelper(IDasBlogSettings dasBlogSettings)
1920
this.dasBlogSettings = dasBlogSettings;
2021
}
2122

22-
public override async Task ProcessAsync(TagHelperContext context, TagHelperOutput output)
23+
public override void Process(TagHelperContext context, TagHelperOutput output)
2324
{
24-
output.TagMode = TagMode.StartTagAndEndTag;
25+
var imgUrl = Post.ImageUrl;
26+
27+
output.TagMode = TagMode.SelfClosing;
2528
output.TagName = "img";
2629

30+
if (!string.IsNullOrEmpty(imgUrl))
31+
{
32+
output.Attributes.SetAttribute("src", dasBlogSettings.RelativeToRoot(imgUrl));
33+
}
34+
else
35+
{
36+
if (!string.IsNullOrEmpty(DefaultImage))
37+
{
38+
output.Attributes.SetAttribute("src", DefaultImage);
39+
}
40+
}
41+
2742
if (!string.IsNullOrEmpty(Css))
2843
{
2944
output.Attributes.SetAttribute("class", Css);
3045
}
3146

32-
output.Attributes.SetAttribute("src", dasBlogSettings.RelativeToRoot(Post.ImageUrl));
33-
output.Attributes.SetAttribute("alt", Post.Title);
34-
await Task.CompletedTask;
47+
if (!string.IsNullOrEmpty(Style))
48+
{
49+
output.Attributes.SetAttribute("style", Style);
50+
}
51+
}
52+
53+
public override Task ProcessAsync(TagHelperContext context, TagHelperOutput output)
54+
{
55+
return Task.Run(() => Process(context, output));
3556
}
3657
}
3758
}

source/DasBlog.Web.UI/Themes/darkly/_BlogItemSummary.cshtml

+3-2
Original file line numberDiff line numberDiff line change
@@ -5,13 +5,14 @@
55
<div class="card-body d-flex flex-column align-items-start">
66
<small class="text-muted"><post-categories-list post="@Model" /></small>
77
<h3 class="mb-0">
8-
<post-title-link post=@Model />
8+
<post-title-link post=@Model />
99
</h3>
1010
<small class="mb-1 text-muted"><post-created-date post="@Model" /></small>
1111
<p class="card-text mb-auto"><post-content post="@Model" strip-html="true" content-length="20" /></p>
1212

1313
<post-title-link post=@Model>Continue reading...</post-title-link>
1414
</div>
15-
<img class="card-img-right flex-auto d-none d-lg-block" style="width: 200px; height: 250px;" alt="Thumbnail [200x250]" src="data:image/svg+xml;charset=UTF-8,%3Csvg%20width%3D%22200%22%20height%3D%22250%22%20xmlns%3D%22http%3A%2F%2Fwww.w3.org%2F2000%2Fsvg%22%20viewBox%3D%220%200%20200%20250%22%20preserveAspectRatio%3D%22none%22%3E%3Cdefs%3E%3Cstyle%20type%3D%22text%2Fcss%22%3E%23holder_166f4e7d3df%20text%20%7B%20fill%3A%23eceeef%3Bfont-weight%3Abold%3Bfont-family%3AArial%2C%20Helvetica%2C%20Open%20Sans%2C%20sans-serif%2C%20monospace%3Bfont-size%3A13pt%20%7D%20%3C%2Fstyle%3E%3C%2Fdefs%3E%3Cg%20id%3D%22holder_166f4e7d3df%22%3E%3Crect%20width%3D%22200%22%20height%3D%22250%22%20fill%3D%22%2355595c%22%3E%3C%2Frect%3E%3Cg%3E%3Ctext%20x%3D%2256.19000244140625%22%20y%3D%22130.97899951934815%22%3EThumbnail%3C%2Ftext%3E%3C%2Fg%3E%3C%2Fg%3E%3C%2Fsvg%3E" data-src="holder.js/200x250?theme=thumb" data-holder-rendered="true">
15+
16+
<post-image post=@Model css="card-img-right flex-auto d-none d-lg-block" style="width: 200px; height: 250px;" />
1617
</div>
1718
</div>

0 commit comments

Comments
 (0)