mirror of https://github.com/abpframework/abp.git
8 changed files with 126 additions and 3 deletions
@ -0,0 +1,40 @@ |
|||||
|
using System; |
||||
|
using Microsoft.AspNetCore.Mvc; |
||||
|
|
||||
|
namespace Volo.Abp.AspNetCore.Mvc.UI.Theme.Shared.Branding; |
||||
|
|
||||
|
public static class UrlHelperBrandingExtensions |
||||
|
{ |
||||
|
/// <summary>
|
||||
|
/// Resolves a branding url of <see cref="Volo.Abp.Ui.Branding.IBrandingProvider"/> for the current request.
|
||||
|
/// "logo.svg", "/logo.svg" and "~/logo.svg" all mean the same application relative url and keep working
|
||||
|
/// under a non-root <see cref="Microsoft.AspNetCore.Http.HttpRequest.PathBase"/>.
|
||||
|
/// External urls ("http://", "https://" and "//host/") are returned as they are.
|
||||
|
/// Returns null when <paramref name="url"/> is null or white space.
|
||||
|
/// </summary>
|
||||
|
public static string? ResolveBrandingUrl(this IUrlHelper urlHelper, string? url) |
||||
|
{ |
||||
|
if (url.IsNullOrWhiteSpace()) |
||||
|
{ |
||||
|
return null; |
||||
|
} |
||||
|
|
||||
|
if (IsExternalUrl(url!)) |
||||
|
{ |
||||
|
return url; |
||||
|
} |
||||
|
|
||||
|
var applicationRelativeUrl = url!.StartsWith("~/", StringComparison.Ordinal) |
||||
|
? url |
||||
|
: "~/" + url.TrimStart('/'); |
||||
|
|
||||
|
return urlHelper.Content(applicationRelativeUrl); |
||||
|
} |
||||
|
|
||||
|
private static bool IsExternalUrl(string url) |
||||
|
{ |
||||
|
return url.StartsWith("http://", StringComparison.OrdinalIgnoreCase) |
||||
|
|| url.StartsWith("https://", StringComparison.OrdinalIgnoreCase) |
||||
|
|| url.StartsWith("//", StringComparison.Ordinal); |
||||
|
} |
||||
|
} |
||||
@ -0,0 +1,20 @@ |
|||||
|
namespace Volo.Abp.Ui.Branding; |
||||
|
|
||||
|
public static class BrandingProviderLogoExtensions |
||||
|
{ |
||||
|
/// <summary>
|
||||
|
/// Returns the compact logo of the branding provider on white background when available; otherwise, null.
|
||||
|
/// </summary>
|
||||
|
public static string? GetLogoIconUrlOrNull(this IBrandingProvider brandingProvider) |
||||
|
{ |
||||
|
return (brandingProvider as IBrandingLogoProvider)?.LogoIconUrl; |
||||
|
} |
||||
|
|
||||
|
/// <summary>
|
||||
|
/// Returns the compact logo of the branding provider on dark background when available; otherwise, null.
|
||||
|
/// </summary>
|
||||
|
public static string? GetLogoIconReverseUrlOrNull(this IBrandingProvider brandingProvider) |
||||
|
{ |
||||
|
return (brandingProvider as IBrandingLogoProvider)?.LogoIconReverseUrl; |
||||
|
} |
||||
|
} |
||||
@ -0,0 +1,18 @@ |
|||||
|
namespace Volo.Abp.Ui.Branding; |
||||
|
|
||||
|
/// <summary>
|
||||
|
/// Optionally implemented by an <see cref="IBrandingProvider"/> to provide a compact logo,
|
||||
|
/// used where the full logo does not fit, like a collapsed menu.
|
||||
|
/// </summary>
|
||||
|
public interface IBrandingLogoProvider |
||||
|
{ |
||||
|
/// <summary>
|
||||
|
/// Compact logo on white background
|
||||
|
/// </summary>
|
||||
|
string? LogoIconUrl { get; } |
||||
|
|
||||
|
/// <summary>
|
||||
|
/// Compact logo on dark background
|
||||
|
/// </summary>
|
||||
|
string? LogoIconReverseUrl { get; } |
||||
|
} |
||||
@ -1,9 +1,10 @@ |
|||||
@using Volo.Abp.Ui.Branding |
@using Volo.Abp.Ui.Branding |
||||
|
@using Volo.Abp.AspNetCore.Mvc.UI.Theme.Shared.Branding |
||||
@inject IBrandingProvider BrandingProvider |
@inject IBrandingProvider BrandingProvider |
||||
<a class="navbar-brand" href="~/"> |
<a class="navbar-brand" href="~/"> |
||||
@if (!BrandingProvider.LogoUrl.IsNullOrWhiteSpace()) |
@if (!BrandingProvider.LogoUrl.IsNullOrWhiteSpace()) |
||||
{ |
{ |
||||
<img src="@BrandingProvider.LogoUrl" alt="@BrandingProvider.AppName" > |
<img src="@Url.ResolveBrandingUrl(BrandingProvider.LogoUrl)" alt="@BrandingProvider.AppName" > |
||||
} |
} |
||||
@BrandingProvider.AppName |
@BrandingProvider.AppName |
||||
</a> |
</a> |
||||
|
|||||
Loading…
Reference in new issue