fix heroicons
This commit is contained in:
parent
2785aa0b34
commit
e5a8b88d02
|
@ -21,6 +21,7 @@
|
|||
<PackageVersion Include="Microsoft.Extensions.Configuration.Binder" Version="8.0.1" />
|
||||
<PackageVersion Include="Microsoft.Extensions.DependencyInjection.Abstractions" Version="8.0.0" />
|
||||
<PackageVersion Include="Microsoft.Extensions.Configuration.AzureAppConfiguration" Version="7.0.0" />
|
||||
<PackageVersion Include="Microsoft.Extensions.FileProviders.Embedded" Version="8.0.2" />
|
||||
<PackageVersion Include="Microsoft.Extensions.Http" Version="8.0.0" />
|
||||
<PackageVersion Include="Microsoft.Extensions.Options" Version="8.0.2" />
|
||||
<PackageVersion Include="Microsoft.Extensions.Options.ConfigurationExtensions" Version="8.0.0" />
|
||||
|
@ -29,10 +30,10 @@
|
|||
<PackageVersion Include="Microsoft.Identity.Web" Version="2.17.0" />
|
||||
<PackageVersion Include="Microsoft.Identity.Web.UI" Version="2.17.0" />
|
||||
<PackageVersion Include="Microsoft.Web.LibraryManager.Build" Version="2.1.175" />
|
||||
<PackageVersion Include="Microsoft.TypeScript.MSBuild" Version="5.3.3"/>
|
||||
<PackageVersion Include="Microsoft.TypeScript.MSBuild" Version="5.3.3" />
|
||||
<PackageVersion Include="StyleCop.Analyzers" Version="1.2.0-beta.507" />
|
||||
<PackageVersion Include="Microsoft.CodeAnalysis.Analyzers" Version="3.3.4"/>
|
||||
<PackageVersion Include="Microsoft.CodeAnalysis.CSharp" Version="4.8.0"/>
|
||||
<PackageVersion Include="Microsoft.CodeAnalysis.CSharp.Workspaces" Version="4.8.0"/>
|
||||
<PackageVersion Include="Microsoft.CodeAnalysis.Analyzers" Version="3.3.4" />
|
||||
<PackageVersion Include="Microsoft.CodeAnalysis.CSharp" Version="4.8.0" />
|
||||
<PackageVersion Include="Microsoft.CodeAnalysis.CSharp.Workspaces" Version="4.8.0" />
|
||||
</ItemGroup>
|
||||
</Project>
|
|
@ -3,6 +3,7 @@ using System.Threading.Tasks;
|
|||
|
||||
using Microsoft.AspNetCore.Components;
|
||||
using Microsoft.AspNetCore.Components.Rendering;
|
||||
using Microsoft.Extensions.FileProviders;
|
||||
|
||||
namespace NSeguin.Dev.Web.HeroIcons;
|
||||
|
||||
|
|
|
@ -3,6 +3,8 @@ using System.Collections.Concurrent;
|
|||
using System.IO;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
using Microsoft.Extensions.FileProviders;
|
||||
|
||||
namespace NSeguin.Dev.Web.HeroIcons;
|
||||
|
||||
internal readonly record struct HeroIconParameters(HeroIconKind Kind, HeroIconVariant Variant)
|
||||
|
@ -10,8 +12,7 @@ internal readonly record struct HeroIconParameters(HeroIconKind Kind, HeroIconVa
|
|||
private const string PathBase = "lib/heroicons";
|
||||
|
||||
private static readonly ConcurrentDictionary<HeroIconParameters, string> SvgCache = new();
|
||||
|
||||
private string GetPath() => GetPath(Variant, Kind);
|
||||
private static ManifestEmbeddedFileProvider FileProvider = new(typeof(HeroIcon).Assembly);
|
||||
|
||||
public Task<string> GetSvgAsync()
|
||||
{
|
||||
|
@ -23,14 +24,6 @@ internal readonly record struct HeroIconParameters(HeroIconKind Kind, HeroIconVa
|
|||
return LoadSvgAsync();
|
||||
}
|
||||
|
||||
private async Task<string> LoadSvgAsync()
|
||||
{
|
||||
var path = GetPath();
|
||||
var svg = await File.ReadAllTextAsync(path);
|
||||
SvgCache.TryAdd(this, svg);
|
||||
return svg;
|
||||
}
|
||||
|
||||
private static string GetPath(HeroIconVariant variant, HeroIconKind kind)
|
||||
{
|
||||
var pathSuffix = variant switch
|
||||
|
@ -44,4 +37,16 @@ internal readonly record struct HeroIconParameters(HeroIconKind Kind, HeroIconVa
|
|||
|
||||
return Path.Combine(PathBase, pathSuffix, kind.FileName);
|
||||
}
|
||||
|
||||
private string GetPath() => GetPath(Variant, Kind);
|
||||
|
||||
private async Task<string> LoadSvgAsync()
|
||||
{
|
||||
var path = GetPath();
|
||||
await using var fileStream = FileProvider.GetFileInfo(path).CreateReadStream();
|
||||
using var reader = new StreamReader(fileStream);
|
||||
var svg = await reader.ReadToEndAsync();
|
||||
SvgCache.TryAdd(this, svg);
|
||||
return svg;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -4,13 +4,16 @@
|
|||
<TargetFramework>net8.0</TargetFramework>
|
||||
<ImplicitUsings>disable</ImplicitUsings>
|
||||
<Nullable>enable</Nullable>
|
||||
<GenerateEmbeddedFilesManifest>true</GenerateEmbeddedFilesManifest>
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<FrameworkReference Include="Microsoft.AspNetCore.App"/>
|
||||
<PackageReference Include="Microsoft.Extensions.FileProviders.Embedded" />
|
||||
<PackageReference Include="Microsoft.Web.LibraryManager.Build"/>
|
||||
<ProjectReference Include="..\NSeguin.Dev.Web.HeroIcons.SourceGenerator\NSeguin.Dev.Web.HeroIcons.SourceGenerator.csproj" OutputItemType="Analyzer" ReferenceOutputAssembly="false"/>
|
||||
<AdditionalFiles Include="lib/heroicons/**/*" CopyToOutputDirectory="Always" />
|
||||
<AdditionalFiles Include="lib/heroicons/**/*" />
|
||||
<EmbeddedResource Include="lib/heroicons/**/*" />
|
||||
</ItemGroup>
|
||||
|
||||
</Project>
|
|
@ -12,4 +12,5 @@
|
|||
@using NSeguin.Dev.Web.Components.Shared
|
||||
@using NSeguin.Dev.Web.Components.Layout
|
||||
@using NSeguin.Dev.Web.Client
|
||||
@using NSeguin.Dev.Web.Client.Shared
|
||||
@using NSeguin.Dev.Web.Client.Shared
|
||||
@using NSeguin.Dev.Web.HeroIcons
|
Loading…
Reference in a new issue