fix heroicons

This commit is contained in:
Nick Seguin 2024-02-25 17:48:16 -06:00
parent 2785aa0b34
commit e5a8b88d02
Signed by: nseguin
GPG Key ID: 68C99FA84079021D
5 changed files with 27 additions and 16 deletions

View File

@ -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>

View File

@ -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;

View File

@ -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;
}
}

View File

@ -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>

View File

@ -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