Skip to content

Commit

Permalink
render default package image on error (#10061)
Browse files Browse the repository at this point in the history
  • Loading branch information
martinrrm authored Jul 10, 2024
1 parent 34ae261 commit 9482371
Show file tree
Hide file tree
Showing 4 changed files with 8 additions and 3 deletions.
5 changes: 5 additions & 0 deletions src/NuGetGallery/App_Code/ViewHelpers.cshtml
Original file line number Diff line number Diff line change
Expand Up @@ -162,6 +162,11 @@
<text>onerror="this.src='@url'; this.onerror = null;"</text>
}

@helper PackageImageFallback()
{
<text>onerror="this.className='package-icon img-responsive package-default-icon'; this.onerror = null;"</text>
}

@helper Option(string value, string label, string currentValue)
{
<option value="@value" @if (value == currentValue)
Expand Down
2 changes: 1 addition & 1 deletion src/NuGetGallery/Views/Packages/DisplayPackage.cshtml
Original file line number Diff line number Diff line change
Expand Up @@ -269,7 +269,7 @@
<h1>
<span class="pull-left">
<img class="package-icon img-responsive @(PackageHelper.ShouldRenderUrl(Model.IconUrl) && Model.ShowDetailsAndLinks ? null : "package-default-icon")" aria-hidden="true" alt=""
src="@(PackageHelper.ShouldRenderUrl(Model.IconUrl) && Model.ShowDetailsAndLinks ? Model.IconUrl : null)" />
src="@(PackageHelper.ShouldRenderUrl(Model.IconUrl) && Model.ShowDetailsAndLinks ? Model.IconUrl : null)" @ViewHelpers.ImageFallback(Url.Absolute("~/Content/gallery/img/default-package-icon-256x256.png")) />
</span>
<span class="title">
@Html.BreakWord(Model.Id)
Expand Down
2 changes: 1 addition & 1 deletion src/NuGetGallery/Views/Shared/_ListPackage.cshtml
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@
<div class="row">
<div class="col-sm-1 hidden-xs hidden-sm col-package-icon">
<img class="package-icon img-responsive @(!PackageHelper.ShouldRenderUrl(Model.IconUrl) ? "package-default-icon" : null)" aria-hidden="true" alt=""
src="@(PackageHelper.ShouldRenderUrl(Model.IconUrl) ? Model.IconUrl : null)" />
src="@(PackageHelper.ShouldRenderUrl(Model.IconUrl) ? Model.IconUrl : null)" @ViewHelpers.PackageImageFallback()/>
</div>
<div class="col-sm-11">
<div class="package-header">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@
</td>
<td class="align-middle hidden-xs">
<img class="package-icon img-responsive @(!PackageHelper.ShouldRenderUrl(package.IconUrl) ? "package-default-icon" : null)" aria-hidden="true" alt="Package Icon"
src="@(PackageHelper.ShouldRenderUrl(package.IconUrl) ? package.IconUrl : null)" />
src="@(PackageHelper.ShouldRenderUrl(package.IconUrl) ? package.IconUrl : null)" @ViewHelpers.PackageImageFallback()/>
</td>
<td class="align-middle package-id"><a href="@Url.Package(package.Id)">@Html.BreakWord(package.Id.Abbreviate(40))</a></td>
<td class="align-middle">
Expand Down

0 comments on commit 9482371

Please sign in to comment.