diff --git a/YaeBlog.Core/Builder/BlogApplication.cs b/YaeBlog.Core/Builder/BlogApplication.cs deleted file mode 100644 index cfd6283..0000000 --- a/YaeBlog.Core/Builder/BlogApplication.cs +++ /dev/null @@ -1,41 +0,0 @@ -using Microsoft.Extensions.Hosting; - -namespace YaeBlog.Core.Builder; - -public class BlogApplication : IHost -{ - private readonly IHost _host; - - internal BlogApplication(IHost host) - { - _host = host; - } - - public static BlogApplicationBuilder Create(string[] args) - { - BlogApplicationOptions options = new() { Args = args }; - return new BlogApplicationBuilder(options); - } - - public Task StartAsync(CancellationToken cancellationToken = new()) - { - return _host.StartAsync(cancellationToken); - } - - public Task StopAsync(CancellationToken cancellationToken = new()) - { - return _host.StopAsync(cancellationToken); - } - - public IServiceProvider Services => _host.Services; - - public Task RunAsync() => _host.RunAsync(); - - public void Run() => _host.Run(); - - public void Dispose() - { - _host.Dispose(); - GC.SuppressFinalize(this); - } -} diff --git a/YaeBlog.Core/Builder/BlogApplicationBuilder.cs b/YaeBlog.Core/Builder/BlogApplicationBuilder.cs deleted file mode 100644 index 268c311..0000000 --- a/YaeBlog.Core/Builder/BlogApplicationBuilder.cs +++ /dev/null @@ -1,62 +0,0 @@ -using Markdig; -using Microsoft.AspNetCore.Builder; -using Microsoft.Extensions.Configuration; -using Microsoft.Extensions.DependencyInjection; -using Microsoft.Extensions.Diagnostics.Metrics; -using Microsoft.Extensions.Hosting; -using Microsoft.Extensions.Logging; -using YaeBlog.Core.Extensions; -using YamlDotNet.Serialization; - -namespace YaeBlog.Core.Builder; - -public sealed class BlogApplicationBuilder : IHostApplicationBuilder -{ - private readonly HostApplicationBuilder _hostApplicationBuilder; - - internal List> WebApplicationBuilderConfigurations { get; } = []; - - internal List> WebApplicationConfigurations { get; } = []; - - public MarkdownPipelineBuilder MarkdigPipelineBuilder { get; } - - public DeserializerBuilder YamlDeserializerBuilder { get; } - - internal BlogApplicationBuilder(BlogApplicationOptions options) - { - ConfigurationManager configuration = new(); - MarkdigPipelineBuilder = new MarkdownPipelineBuilder(); - YamlDeserializerBuilder = new DeserializerBuilder(); - - _hostApplicationBuilder = new HostApplicationBuilder(new HostApplicationBuilderSettings - { - Args = options.Args, Configuration = configuration - }); - } - - public BlogApplication Build() - { - this.ConfigureDefaultBlogApplicationBuilder(); - BlogApplication application = new(_hostApplicationBuilder.Build()); - application.ConfigureDefaultBlogApplication(); - return application; - } - - public void ConfigureContainer( - IServiceProviderFactory factory, Action? configure = null) - where TContainerBuilder : notnull - => _hostApplicationBuilder.ConfigureContainer(factory, configure); - - public IDictionary Properties - => (_hostApplicationBuilder as IHostApplicationBuilder).Properties; - - public IHostEnvironment Environment => _hostApplicationBuilder.Environment; - - public IConfigurationManager Configuration => _hostApplicationBuilder.Configuration; - - public ILoggingBuilder Logging => _hostApplicationBuilder.Logging; - - public IMetricsBuilder Metrics => _hostApplicationBuilder.Metrics; - - public IServiceCollection Services => _hostApplicationBuilder.Services; -} diff --git a/YaeBlog.Core/Builder/BlogApplicationOptions.cs b/YaeBlog.Core/Builder/BlogApplicationOptions.cs deleted file mode 100644 index c2240d6..0000000 --- a/YaeBlog.Core/Builder/BlogApplicationOptions.cs +++ /dev/null @@ -1,6 +0,0 @@ -namespace YaeBlog.Core.Builder; - -public class BlogApplicationOptions -{ - public required string[] Args { get; init; } -} diff --git a/YaeBlog.Core/Extensions/BlogApplicationBuilderExtension.cs b/YaeBlog.Core/Extensions/BlogApplicationBuilderExtension.cs deleted file mode 100644 index 537ac38..0000000 --- a/YaeBlog.Core/Extensions/BlogApplicationBuilderExtension.cs +++ /dev/null @@ -1,59 +0,0 @@ -using Markdig; -using Microsoft.AspNetCore.Builder; -using Microsoft.Extensions.Configuration; -using Microsoft.Extensions.DependencyInjection; -using YaeBlog.Core.Builder; -using YaeBlog.Core.Models; -using YaeBlog.Core.Processors; -using YaeBlog.Core.Services; -using YamlDotNet.Serialization; -using YamlDotNet.Serialization.NamingConventions; - -namespace YaeBlog.Core.Extensions; - -public static class BlogApplicationBuilderExtension -{ - internal static void ConfigureDefaultBlogApplicationBuilder(this BlogApplicationBuilder builder) - { - builder.Configuration.AddJsonFile("appsettings.json", optional: true, reloadOnChange: true); - builder.Configuration.AddJsonFile($"appsettings.{builder.Environment.EnvironmentName}.json", - optional: true, reloadOnChange: true); - builder.Configuration.AddEnvironmentVariables(); - - builder.Services.Configure( - builder.Configuration.GetSection(BlogOptions.OptionName)); - - builder.YamlDeserializerBuilder.WithNamingConvention(CamelCaseNamingConvention.Instance); - builder.YamlDeserializerBuilder.IgnoreUnmatchedProperties(); - - builder.Services.AddSingleton( - _ => builder.MarkdigPipelineBuilder.Build()); - builder.Services.AddSingleton( - _ => builder.YamlDeserializerBuilder.Build()); - - builder.Services.AddHostedService(); - builder.Services.AddSingleton(); - builder.Services.AddSingleton(); - builder.Services.AddSingleton(); - - // 设置图像处理器 - builder.Services.AddSingleton(); - ImagePostRenderProcessor.AddImageApiEndpoint(builder); - - builder.Services.AddHostedService((provider) - => new WebApplicationHostedService(builder.WebApplicationBuilderConfigurations, - builder.WebApplicationConfigurations, provider)); - } - - public static void ConfigureWebApplicationBuilder(this BlogApplicationBuilder builder, - Action configureWebApplicationBuilder) - { - builder.WebApplicationBuilderConfigurations.Add(configureWebApplicationBuilder); - } - - public static void ConfigureWebApplication(this BlogApplicationBuilder builder, - Action configureWebApplication) - { - builder.WebApplicationConfigurations.Add(configureWebApplication); - } -} diff --git a/YaeBlog.Core/Extensions/BlogApplicationExtension.cs b/YaeBlog.Core/Extensions/BlogApplicationExtension.cs deleted file mode 100644 index 01d7d59..0000000 --- a/YaeBlog.Core/Extensions/BlogApplicationExtension.cs +++ /dev/null @@ -1,35 +0,0 @@ -using Microsoft.Extensions.DependencyInjection; -using YaeBlog.Core.Abstractions; -using YaeBlog.Core.Builder; -using YaeBlog.Core.Processors; -using YaeBlog.Core.Services; - -namespace YaeBlog.Core.Extensions; - -public static class BlogApplicationExtension -{ - internal static void ConfigureDefaultBlogApplication(this BlogApplication application) - { - application.UsePostRenderProcessor(); - } - - public static void UsePreRenderProcessor(this BlogApplication application) - where T : IPreRenderProcessor - { - RendererService rendererService = - application.Services.GetRequiredService(); - T preRenderProcessor = - application.Services.GetRequiredService(); - rendererService.AddPreRenderProcessor(preRenderProcessor); - } - - public static void UsePostRenderProcessor(this BlogApplication application) - where T : IPostRenderProcessor - { - RendererService rendererService = - application.Services.GetRequiredService(); - T postRenderProcessor = - application.Services.GetRequiredService(); - rendererService.AddPostRenderProcessor(postRenderProcessor); - } -} diff --git a/YaeBlog.Core/Extensions/ServiceCollectionExtensions.cs b/YaeBlog.Core/Extensions/ServiceCollectionExtensions.cs new file mode 100644 index 0000000..346f07f --- /dev/null +++ b/YaeBlog.Core/Extensions/ServiceCollectionExtensions.cs @@ -0,0 +1,30 @@ +using Markdig; +using Microsoft.Extensions.DependencyInjection; +using YamlDotNet.Serialization; +using YamlDotNet.Serialization.NamingConventions; + +namespace YaeBlog.Core.Extensions; + +public static class ServiceCollectionExtensions +{ + public static IServiceCollection AddMarkdig(this IServiceCollection collection) + { + MarkdownPipelineBuilder builder = new(); + + collection.AddSingleton(_ => builder.Build()); + + return collection; + } + + public static IServiceCollection AddYamlParser(this IServiceCollection collection) + { + DeserializerBuilder builder = new(); + + builder.WithNamingConvention(CamelCaseNamingConvention.Instance); + builder.IgnoreUnmatchedProperties(); + + collection.AddSingleton(_ => builder.Build()); + + return collection; + } +} diff --git a/YaeBlog.Core/Extensions/WebApplicationBuilderExtensions.cs b/YaeBlog.Core/Extensions/WebApplicationBuilderExtensions.cs new file mode 100644 index 0000000..ab3bb3b --- /dev/null +++ b/YaeBlog.Core/Extensions/WebApplicationBuilderExtensions.cs @@ -0,0 +1,33 @@ +using Microsoft.AspNetCore.Builder; +using Microsoft.Extensions.DependencyInjection; +using Microsoft.Extensions.Options; +using Microsoft.FluentUI.AspNetCore.Components; +using YaeBlog.Core.Models; +using YaeBlog.Core.Processors; +using YaeBlog.Core.Services; + +namespace YaeBlog.Core.Extensions; + +public static class WebApplicationBuilderExtensions +{ + public static WebApplicationBuilder AddYaeBlog(this WebApplicationBuilder builder) + { + builder.Services.Configure(builder.Configuration.GetSection(BlogOptions.OptionName)); + + builder.Services.AddHttpClient(); + builder.Services.AddFluentUIComponents(); + + builder.Services.AddMarkdig(); + builder.Services.AddYamlParser(); + builder.Services.AddSingleton(); + builder.Services.AddSingleton(); + builder.Services.AddSingleton(); + builder.Services.AddTransient(); + builder.Services.AddTransient(provider => + provider.GetRequiredService>().Value); + + builder.Services.AddHostedService(); + + return builder; + } +} diff --git a/YaeBlog.Core/Extensions/WebApplicationExtensions.cs b/YaeBlog.Core/Extensions/WebApplicationExtensions.cs new file mode 100644 index 0000000..f541f4a --- /dev/null +++ b/YaeBlog.Core/Extensions/WebApplicationExtensions.cs @@ -0,0 +1,33 @@ +using Microsoft.AspNetCore.Builder; +using Microsoft.Extensions.DependencyInjection; +using YaeBlog.Core.Abstractions; +using YaeBlog.Core.Processors; +using YaeBlog.Core.Services; + +namespace YaeBlog.Core.Extensions; + +public static class WebApplicationExtensions +{ + public static WebApplication UseMiddleRenderProcessors(this WebApplication application) + { + application.UsePostRenderProcessor(); + + return application; + } + + private static void UsePreRenderProcessor(this WebApplication application) where T : IPreRenderProcessor + { + RendererService rendererService = application.Services.GetRequiredService(); + T preRenderProcessor = application.Services.GetRequiredService(); + + rendererService.AddPreRenderProcessor(preRenderProcessor); + } + + private static void UsePostRenderProcessor(this WebApplication application) where T : IPostRenderProcessor + { + RendererService rendererService = application.Services.GetRequiredService(); + T postRenderProcessor = application.Services.GetRequiredService(); + + rendererService.AddPostRenderProcessor(postRenderProcessor); + } +} diff --git a/YaeBlog.Core/Models/BlogOptions.cs b/YaeBlog.Core/Models/BlogOptions.cs index 36f7fb4..69c0858 100644 --- a/YaeBlog.Core/Models/BlogOptions.cs +++ b/YaeBlog.Core/Models/BlogOptions.cs @@ -9,11 +9,6 @@ public class BlogOptions /// public required string Root { get; set; } - /// - /// 博客挂载的子路径 - /// - public required string SubPath { get; set; } - /// /// 博客作者 /// @@ -26,11 +21,6 @@ public class BlogOptions /// public required int StartYear { get; set; } - /// - /// 博客项目的名称 - /// - public required string ProjectName { get; set; } - /// /// 博客起始页面的背景图片 /// diff --git a/YaeBlog.Core/Processors/ImagePostRenderProcessor.cs b/YaeBlog.Core/Processors/ImagePostRenderProcessor.cs index f1ea7ba..d4a61a8 100644 --- a/YaeBlog.Core/Processors/ImagePostRenderProcessor.cs +++ b/YaeBlog.Core/Processors/ImagePostRenderProcessor.cs @@ -1,13 +1,8 @@ using AngleSharp; using AngleSharp.Dom; -using Microsoft.AspNetCore.Builder; -using Microsoft.AspNetCore.Http; -using Microsoft.AspNetCore.Http.HttpResults; using Microsoft.Extensions.Logging; using Microsoft.Extensions.Options; using YaeBlog.Core.Abstractions; -using YaeBlog.Core.Builder; -using YaeBlog.Core.Extensions; using YaeBlog.Core.Models; namespace YaeBlog.Core.Processors; @@ -45,31 +40,6 @@ public class ImagePostRenderProcessor(ILogger logger, public string Name => "ImagePostRenderProcessor"; - public static void AddImageApiEndpoint(BlogApplicationBuilder builder) - { - builder.ConfigureWebApplication((application) => - { - application.MapGet("/api/files/{*filename}", ImageHandler); - }); - } - - private static Results ImageHandler(string filename) - { - string contentType = "image/png"; - if (filename.EndsWith("jpg") || filename.EndsWith("jpeg")) - { - contentType = "image/jpeg"; - } - - if (!Path.Exists(filename)) - { - return TypedResults.NotFound(); - } - - Stream imageStream = File.OpenRead(filename); - return TypedResults.Stream(imageStream, contentType); - } - private string GenerateImageLink(string filename, string essayFilename) { if (!filename.Contains(essayFilename)) @@ -81,8 +51,8 @@ public class ImagePostRenderProcessor(ILogger logger, if (!Path.Exists(filename)) { - logger.LogWarning("Failed to found image: {}.", filename); - return _options.BannerImage; + logger.LogError("Failed to found image: {}.", filename); + throw new InvalidOperationException(); } string imageLink = "api/files/" + filename; diff --git a/YaeBlog.Core/Services/BlogHostedService.cs b/YaeBlog.Core/Services/BlogHostedService.cs index b1e8734..9ee9a8c 100644 --- a/YaeBlog.Core/Services/BlogHostedService.cs +++ b/YaeBlog.Core/Services/BlogHostedService.cs @@ -19,6 +19,4 @@ public class BlogHostedService( logger.LogInformation("YaeBlog stopped!\nHave a nice day!"); return Task.CompletedTask; } - - } diff --git a/YaeBlog.Core/Services/WebApplicationHostedService.cs b/YaeBlog.Core/Services/WebApplicationHostedService.cs deleted file mode 100644 index 5a7465a..0000000 --- a/YaeBlog.Core/Services/WebApplicationHostedService.cs +++ /dev/null @@ -1,116 +0,0 @@ -using Microsoft.AspNetCore.Builder; -using Microsoft.Extensions.DependencyInjection; -using Microsoft.Extensions.Hosting; -using Microsoft.Extensions.Options; -using YaeBlog.Core.Models; - -namespace YaeBlog.Core.Services; - -public class WebApplicationHostedService : IHostedService -{ - private readonly WebApplicationBuilder _websiteBuilder = WebApplication.CreateBuilder(); - - private readonly List> _webApplicationConfigurations; - - private readonly IOptions _options; - - private Website? _currentWebsite; - - public WebApplicationHostedService(List> webApplicationBuilderConfigurations, - List> webApplicationConfigurations, - IServiceProvider hostServiceProvider) - { - _webApplicationConfigurations = webApplicationConfigurations; - _options = hostServiceProvider.GetRequiredService>(); - - foreach (Action configure in webApplicationBuilderConfigurations) - { - configure(_websiteBuilder); - } - - AddHostServices(hostServiceProvider); - } - - public async Task BuildWebsite() - { - if (_currentWebsite is not null) - { - await _currentWebsite.ShutdownAsync(new CancellationToken()); - } - - WebApplication application = _websiteBuilder.Build(); - application.UsePathBase("/" + _options.Value.SubPath); - foreach (Action configure in _webApplicationConfigurations) - { - configure(application); - } - IHostLifetime websiteLifetime = application.Services.GetRequiredService(); - _currentWebsite = new Website(application, websiteLifetime); - } - - public Task RunAsync() - { - if (_currentWebsite is not null) - { - return _currentWebsite.RunAsync(); - } - - throw new InvalidOperationException("Website has not been built."); - } - - public Task ShutdownAsync() - { - if (_currentWebsite is { Running: true }) - { - return _currentWebsite.ShutdownAsync(new CancellationToken()); - } - - throw new InvalidOperationException("Website is not running."); - } - - public async Task StartAsync(CancellationToken cancellationToken) - { - await BuildWebsite(); - _ = RunAsync(); - } - - public Task StopAsync(CancellationToken cancellationToken) - { - if (_currentWebsite is { Running: true }) - { - return _currentWebsite.ShutdownAsync(cancellationToken); - } - - return Task.CompletedTask; - } - - private void AddHostServices(IServiceProvider provider) - { - _websiteBuilder.Services.AddSingleton(_ => - provider.GetRequiredService()); - _websiteBuilder.Services.AddTransient(_ => - provider.GetRequiredService>().Value); - } - - - private class Website(WebApplication application, IHostLifetime websiteLifetime) - { - public bool Running { get; private set; } - - public Task RunAsync() - { - Running = true; - return application.RunAsync(); - } - - public async Task ShutdownAsync(CancellationToken cancellationToken) - { - if (!Running) - { - await websiteLifetime.StopAsync(cancellationToken); - } - - Running = false; - } - } -} diff --git a/YaeBlog.Core/YaeBlog.Core.csproj b/YaeBlog.Core/YaeBlog.Core.csproj index 6a27255..094659c 100644 --- a/YaeBlog.Core/YaeBlog.Core.csproj +++ b/YaeBlog.Core/YaeBlog.Core.csproj @@ -27,9 +27,11 @@ - + + + diff --git a/YaeBlog.Example/Program.cs b/YaeBlog.Example/Program.cs deleted file mode 100644 index cf95524..0000000 --- a/YaeBlog.Example/Program.cs +++ /dev/null @@ -1,23 +0,0 @@ -using YaeBlog.Example.Components; - -var builder = WebApplication.CreateBuilder(args); - -// Add services to the container. -builder.Services.AddRazorComponents() - .AddInteractiveServerComponents(); - -var app = builder.Build(); - -// Configure the HTTP request pipeline. -if (!app.Environment.IsDevelopment()) -{ - app.UseExceptionHandler("/Error", createScopeForErrors: true); -} - -app.UseStaticFiles(); -app.UseAntiforgery(); - -app.MapRazorComponents() - .AddInteractiveServerRenderMode(); - -app.Run(); diff --git a/YaeBlog.Example/Properties/launchSettings.json b/YaeBlog.Example/Properties/launchSettings.json deleted file mode 100644 index 910d9fd..0000000 --- a/YaeBlog.Example/Properties/launchSettings.json +++ /dev/null @@ -1,29 +0,0 @@ -{ - "$schema": "http://json.schemastore.org/launchsettings.json", - "iisSettings": { - "windowsAuthentication": false, - "anonymousAuthentication": true, - "iisExpress": { - "applicationUrl": "http://localhost:60424", - "sslPort": 0 - } - }, - "profiles": { - "http": { - "commandName": "Project", - "dotnetRunMessages": true, - "launchBrowser": true, - "applicationUrl": "http://localhost:5015", - "environmentVariables": { - "ASPNETCORE_ENVIRONMENT": "Development" - } - }, - "IIS Express": { - "commandName": "IISExpress", - "launchBrowser": true, - "environmentVariables": { - "ASPNETCORE_ENVIRONMENT": "Development" - } - } - } - } diff --git a/YaeBlog.Example/YaeBlog.Example.csproj b/YaeBlog.Example/YaeBlog.Example.csproj deleted file mode 100644 index 1b28a01..0000000 --- a/YaeBlog.Example/YaeBlog.Example.csproj +++ /dev/null @@ -1,9 +0,0 @@ - - - - net8.0 - enable - enable - - - diff --git a/YaeBlog.Example/appsettings.Development.json b/YaeBlog.Example/appsettings.Development.json deleted file mode 100644 index 0c208ae..0000000 --- a/YaeBlog.Example/appsettings.Development.json +++ /dev/null @@ -1,8 +0,0 @@ -{ - "Logging": { - "LogLevel": { - "Default": "Information", - "Microsoft.AspNetCore": "Warning" - } - } -} diff --git a/YaeBlog.Example/appsettings.json b/YaeBlog.Example/appsettings.json deleted file mode 100644 index 10f68b8..0000000 --- a/YaeBlog.Example/appsettings.json +++ /dev/null @@ -1,9 +0,0 @@ -{ - "Logging": { - "LogLevel": { - "Default": "Information", - "Microsoft.AspNetCore": "Warning" - } - }, - "AllowedHosts": "*" -} diff --git a/YaeBlog.Tests/GlobalUsings.cs b/YaeBlog.Tests/GlobalUsings.cs deleted file mode 100644 index 8c927eb..0000000 --- a/YaeBlog.Tests/GlobalUsings.cs +++ /dev/null @@ -1 +0,0 @@ -global using Xunit; \ No newline at end of file diff --git a/YaeBlog.Tests/YaeBlog.Tests.csproj b/YaeBlog.Tests/YaeBlog.Tests.csproj deleted file mode 100644 index b6a9c2e..0000000 --- a/YaeBlog.Tests/YaeBlog.Tests.csproj +++ /dev/null @@ -1,30 +0,0 @@ - - - - net8.0 - enable - enable - - false - true - - - - - - - - runtime; build; native; contentfiles; analyzers; buildtransitive - all - - - runtime; build; native; contentfiles; analyzers; buildtransitive - all - - - - - - - - diff --git a/YaeBlog.Theme.FluentUI/BlogApplicationBuilderExtensions.cs b/YaeBlog.Theme.FluentUI/BlogApplicationBuilderExtensions.cs deleted file mode 100644 index 3d8ccca..0000000 --- a/YaeBlog.Theme.FluentUI/BlogApplicationBuilderExtensions.cs +++ /dev/null @@ -1,30 +0,0 @@ -using Microsoft.AspNetCore.Builder; -using Microsoft.Extensions.DependencyInjection; -using Microsoft.FluentUI.AspNetCore.Components; -using YaeBlog.Core.Builder; -using YaeBlog.Core.Extensions; - -namespace YaeBlog.Theme.FluentUI; - -public static class BlogApplicationBuilderExtensions -{ - public static void UseFluentTheme(this BlogApplicationBuilder builder) - { - builder.ConfigureWebApplicationBuilder(ConfigureWebApplicationBuilder); - builder.ConfigureWebApplication(ConfigureWebApplication); - } - - private static void ConfigureWebApplicationBuilder(WebApplicationBuilder builder) - { - builder.Services.AddRazorComponents(); - builder.Services.AddFluentUIComponents(); - } - - private static void ConfigureWebApplication(WebApplication application) - { - application.UseStaticFiles(); - application.UseAntiforgery(); - application.UseStatusCodePagesWithRedirects("~/NotFound"); - application.MapRazorComponents(); - } -} diff --git a/YaeBlog.Theme.FluentUI/README.md b/YaeBlog.Theme.FluentUI/README.md deleted file mode 100644 index 6780fc3..0000000 --- a/YaeBlog.Theme.FluentUI/README.md +++ /dev/null @@ -1,3 +0,0 @@ -# YaeBlog.Theme.FluentUI - -A fluent design style theme for YaeBlog! diff --git a/YaeBlog.Theme.FluentUI/Routes.razor b/YaeBlog.Theme.FluentUI/Routes.razor deleted file mode 100644 index acb0e45..0000000 --- a/YaeBlog.Theme.FluentUI/Routes.razor +++ /dev/null @@ -1,5 +0,0 @@ - - - - - diff --git a/YaeBlog.Theme.FluentUI/YaeBlog.Theme.FluentUI.csproj b/YaeBlog.Theme.FluentUI/YaeBlog.Theme.FluentUI.csproj deleted file mode 100644 index 7f167bc..0000000 --- a/YaeBlog.Theme.FluentUI/YaeBlog.Theme.FluentUI.csproj +++ /dev/null @@ -1,36 +0,0 @@ - - - - net8.0 - enable - enable - - - - YaeBlog.Theme.FluentUI - 0.1.1 - Ricardo Ren - Ricardo Ren - MIT - README.md - - - - - - - - - - - - - - - - - - - - - diff --git a/YaeBlog.sln b/YaeBlog.sln index da8f005..04bb5d8 100644 --- a/YaeBlog.sln +++ b/YaeBlog.sln @@ -5,11 +5,7 @@ VisualStudioVersion = 17.0.31903.59 MinimumVisualStudioVersion = 10.0.40219.1 Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "YaeBlog.Core", "YaeBlog.Core\YaeBlog.Core.csproj", "{1671A8AE-78F6-4641-B97D-D8ABA5E9CBEF}" EndProject -Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "YaeBlog.Theme.FluentUI", "YaeBlog.Theme.FluentUI\YaeBlog.Theme.FluentUI.csproj", "{E3EB73E2-0267-416A-BA0A-9D0FC93AAFA0}" -EndProject -Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "YaeBlog.Example", "YaeBlog.Example\YaeBlog.Example.csproj", "{3A768948-D4E8-4111-A1FE-DF98EBFC4991}" -EndProject -Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "YaeBlog.Tests", "YaeBlog.Tests\YaeBlog.Tests.csproj", "{5866CB58-6FE2-4DB8-AE20-8439D8C6C3B9}" +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "YaeBlog", "YaeBlog\YaeBlog.csproj", "{20438EFD-8DDE-43AF-92E2-76495C29233C}" EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution @@ -21,18 +17,10 @@ Global {1671A8AE-78F6-4641-B97D-D8ABA5E9CBEF}.Debug|Any CPU.Build.0 = Debug|Any CPU {1671A8AE-78F6-4641-B97D-D8ABA5E9CBEF}.Release|Any CPU.ActiveCfg = Release|Any CPU {1671A8AE-78F6-4641-B97D-D8ABA5E9CBEF}.Release|Any CPU.Build.0 = Release|Any CPU - {E3EB73E2-0267-416A-BA0A-9D0FC93AAFA0}.Debug|Any CPU.ActiveCfg = Debug|Any CPU - {E3EB73E2-0267-416A-BA0A-9D0FC93AAFA0}.Debug|Any CPU.Build.0 = Debug|Any CPU - {E3EB73E2-0267-416A-BA0A-9D0FC93AAFA0}.Release|Any CPU.ActiveCfg = Release|Any CPU - {E3EB73E2-0267-416A-BA0A-9D0FC93AAFA0}.Release|Any CPU.Build.0 = Release|Any CPU - {3A768948-D4E8-4111-A1FE-DF98EBFC4991}.Debug|Any CPU.ActiveCfg = Debug|Any CPU - {3A768948-D4E8-4111-A1FE-DF98EBFC4991}.Debug|Any CPU.Build.0 = Debug|Any CPU - {3A768948-D4E8-4111-A1FE-DF98EBFC4991}.Release|Any CPU.ActiveCfg = Release|Any CPU - {3A768948-D4E8-4111-A1FE-DF98EBFC4991}.Release|Any CPU.Build.0 = Release|Any CPU - {5866CB58-6FE2-4DB8-AE20-8439D8C6C3B9}.Debug|Any CPU.ActiveCfg = Debug|Any CPU - {5866CB58-6FE2-4DB8-AE20-8439D8C6C3B9}.Debug|Any CPU.Build.0 = Debug|Any CPU - {5866CB58-6FE2-4DB8-AE20-8439D8C6C3B9}.Release|Any CPU.ActiveCfg = Release|Any CPU - {5866CB58-6FE2-4DB8-AE20-8439D8C6C3B9}.Release|Any CPU.Build.0 = Release|Any CPU + {20438EFD-8DDE-43AF-92E2-76495C29233C}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {20438EFD-8DDE-43AF-92E2-76495C29233C}.Debug|Any CPU.Build.0 = Debug|Any CPU + {20438EFD-8DDE-43AF-92E2-76495C29233C}.Release|Any CPU.ActiveCfg = Release|Any CPU + {20438EFD-8DDE-43AF-92E2-76495C29233C}.Release|Any CPU.Build.0 = Release|Any CPU EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE diff --git a/YaeBlog.Theme.FluentUI/Components/Announcement.razor b/YaeBlog/Components/Announcement.razor similarity index 100% rename from YaeBlog.Theme.FluentUI/Components/Announcement.razor rename to YaeBlog/Components/Announcement.razor diff --git a/YaeBlog.Theme.FluentUI/Components/Announcement.razor.css b/YaeBlog/Components/Announcement.razor.css similarity index 100% rename from YaeBlog.Theme.FluentUI/Components/Announcement.razor.css rename to YaeBlog/Components/Announcement.razor.css diff --git a/YaeBlog.Theme.FluentUI/App.razor b/YaeBlog/Components/App.razor similarity index 58% rename from YaeBlog.Theme.FluentUI/App.razor rename to YaeBlog/Components/App.razor index 0eab9ae..2fb0132 100644 --- a/YaeBlog.Theme.FluentUI/App.razor +++ b/YaeBlog/Components/App.razor @@ -1,17 +1,13 @@ -@using YaeBlog.Core.Models -@inject BlogOptions BlogOptionsInstance - - + - - + + - - + diff --git a/YaeBlog.Theme.FluentUI/Components/AuthorInformation.razor b/YaeBlog/Components/AuthorInformation.razor similarity index 100% rename from YaeBlog.Theme.FluentUI/Components/AuthorInformation.razor rename to YaeBlog/Components/AuthorInformation.razor diff --git a/YaeBlog.Theme.FluentUI/Components/AuthorInformation.razor.css b/YaeBlog/Components/AuthorInformation.razor.css similarity index 100% rename from YaeBlog.Theme.FluentUI/Components/AuthorInformation.razor.css rename to YaeBlog/Components/AuthorInformation.razor.css diff --git a/YaeBlog.Theme.FluentUI/Components/BlogFooter.razor b/YaeBlog/Components/BlogFooter.razor similarity index 100% rename from YaeBlog.Theme.FluentUI/Components/BlogFooter.razor rename to YaeBlog/Components/BlogFooter.razor diff --git a/YaeBlog.Theme.FluentUI/Components/BlogFooter.razor.css b/YaeBlog/Components/BlogFooter.razor.css similarity index 100% rename from YaeBlog.Theme.FluentUI/Components/BlogFooter.razor.css rename to YaeBlog/Components/BlogFooter.razor.css diff --git a/YaeBlog/Components/Routes.razor b/YaeBlog/Components/Routes.razor new file mode 100644 index 0000000..2641859 --- /dev/null +++ b/YaeBlog/Components/Routes.razor @@ -0,0 +1,6 @@ + + + + + + diff --git a/YaeBlog/Controllers/FilesController.cs b/YaeBlog/Controllers/FilesController.cs new file mode 100644 index 0000000..ace5d47 --- /dev/null +++ b/YaeBlog/Controllers/FilesController.cs @@ -0,0 +1,28 @@ +using Microsoft.AspNetCore.Mvc; + +namespace YaeBlog.Controllers; + +[ApiController] +[Route("api/files")] +public class FilesController : ControllerBase +{ + [HttpGet("{*filename}")] + public IActionResult Images(string filename) + { + string contentType = "image/png"; + if (filename.EndsWith("jpg") || filename.EndsWith("jpeg")) + { + contentType = "image/jpeg"; + } + + FileInfo imageFile = new(filename); + + if (!imageFile.Exists) + { + return NotFound(); + } + + Stream imageStream = imageFile.OpenRead(); + return File(imageStream, contentType); + } +} diff --git a/YaeBlog.Theme.FluentUI/Layout/MainLayout.razor b/YaeBlog/Layout/MainLayout.razor similarity index 98% rename from YaeBlog.Theme.FluentUI/Layout/MainLayout.razor rename to YaeBlog/Layout/MainLayout.razor index 9fd90b2..1b3010a 100644 --- a/YaeBlog.Theme.FluentUI/Layout/MainLayout.razor +++ b/YaeBlog/Layout/MainLayout.razor @@ -1,4 +1,4 @@ -@using YaeBlog.Core.Models +@using YaeBlog.Core.Models @inherits LayoutComponentBase @inject BlogOptions BlogOptionsInstance diff --git a/YaeBlog.Theme.FluentUI/Layout/MainLayout.razor.css b/YaeBlog/Layout/MainLayout.razor.css similarity index 100% rename from YaeBlog.Theme.FluentUI/Layout/MainLayout.razor.css rename to YaeBlog/Layout/MainLayout.razor.css diff --git a/YaeBlog.Theme.FluentUI/Pages/About.razor b/YaeBlog/Pages/About.razor similarity index 100% rename from YaeBlog.Theme.FluentUI/Pages/About.razor rename to YaeBlog/Pages/About.razor diff --git a/YaeBlog.Theme.FluentUI/Pages/About.razor.css b/YaeBlog/Pages/About.razor.css similarity index 100% rename from YaeBlog.Theme.FluentUI/Pages/About.razor.css rename to YaeBlog/Pages/About.razor.css diff --git a/YaeBlog.Theme.FluentUI/Pages/Archives.razor b/YaeBlog/Pages/Archives.razor similarity index 100% rename from YaeBlog.Theme.FluentUI/Pages/Archives.razor rename to YaeBlog/Pages/Archives.razor diff --git a/YaeBlog.Theme.FluentUI/Pages/Archives.razor.css b/YaeBlog/Pages/Archives.razor.css similarity index 100% rename from YaeBlog.Theme.FluentUI/Pages/Archives.razor.css rename to YaeBlog/Pages/Archives.razor.css diff --git a/YaeBlog/Pages/Error.razor b/YaeBlog/Pages/Error.razor new file mode 100644 index 0000000..e1369dc --- /dev/null +++ b/YaeBlog/Pages/Error.razor @@ -0,0 +1,36 @@ +@page "/Error" +@using System.Diagnostics + +Error + +

Error.

+

An error occurred while processing your request.

+ +@if (ShowRequestId) +{ +

+ Request ID: @RequestId +

+} + +

Development Mode

+

+ Swapping to Development environment will display more detailed information about the error that occurred. +

+

+ The Development environment shouldn't be enabled for deployed applications. + It can result in displaying sensitive information from exceptions to end users. + For local debugging, enable the Development environment by setting the ASPNETCORE_ENVIRONMENT environment variable to Development + and restarting the app. +

+ +@code{ + [CascadingParameter] private HttpContext? HttpContext { get; set; } + + private string? RequestId { get; set; } + private bool ShowRequestId => !string.IsNullOrEmpty(RequestId); + + protected override void OnInitialized() => + RequestId = Activity.Current?.Id ?? HttpContext?.TraceIdentifier; + +} diff --git a/YaeBlog.Theme.FluentUI/Pages/Essay.razor b/YaeBlog/Pages/Essay.razor similarity index 100% rename from YaeBlog.Theme.FluentUI/Pages/Essay.razor rename to YaeBlog/Pages/Essay.razor diff --git a/YaeBlog.Theme.FluentUI/Pages/Essay.razor.css b/YaeBlog/Pages/Essay.razor.css similarity index 100% rename from YaeBlog.Theme.FluentUI/Pages/Essay.razor.css rename to YaeBlog/Pages/Essay.razor.css diff --git a/YaeBlog.Theme.FluentUI/Pages/Home.razor b/YaeBlog/Pages/Home.razor similarity index 100% rename from YaeBlog.Theme.FluentUI/Pages/Home.razor rename to YaeBlog/Pages/Home.razor diff --git a/YaeBlog.Theme.FluentUI/Pages/Home.razor.css b/YaeBlog/Pages/Home.razor.css similarity index 100% rename from YaeBlog.Theme.FluentUI/Pages/Home.razor.css rename to YaeBlog/Pages/Home.razor.css diff --git a/YaeBlog.Theme.FluentUI/Pages/Links.razor b/YaeBlog/Pages/Links.razor similarity index 100% rename from YaeBlog.Theme.FluentUI/Pages/Links.razor rename to YaeBlog/Pages/Links.razor diff --git a/YaeBlog.Theme.FluentUI/Pages/Links.razor.css b/YaeBlog/Pages/Links.razor.css similarity index 100% rename from YaeBlog.Theme.FluentUI/Pages/Links.razor.css rename to YaeBlog/Pages/Links.razor.css diff --git a/YaeBlog.Theme.FluentUI/Pages/NotFound.razor b/YaeBlog/Pages/NotFound.razor similarity index 100% rename from YaeBlog.Theme.FluentUI/Pages/NotFound.razor rename to YaeBlog/Pages/NotFound.razor diff --git a/YaeBlog.Theme.FluentUI/Pages/Tags.razor b/YaeBlog/Pages/Tags.razor similarity index 100% rename from YaeBlog.Theme.FluentUI/Pages/Tags.razor rename to YaeBlog/Pages/Tags.razor diff --git a/YaeBlog.Theme.FluentUI/Pages/Tags.razor.css b/YaeBlog/Pages/Tags.razor.css similarity index 100% rename from YaeBlog.Theme.FluentUI/Pages/Tags.razor.css rename to YaeBlog/Pages/Tags.razor.css diff --git a/YaeBlog/Program.cs b/YaeBlog/Program.cs new file mode 100644 index 0000000..d00911a --- /dev/null +++ b/YaeBlog/Program.cs @@ -0,0 +1,21 @@ +using YaeBlog.Components; +using YaeBlog.Core.Extensions; + +WebApplicationBuilder builder = WebApplication.CreateBuilder(args); + +builder.Services.AddRazorComponents() + .AddInteractiveServerComponents(); +builder.Services.AddControllers(); +builder.AddYaeBlog(); + +WebApplication application = builder.Build(); + +application.UseStaticFiles(); +application.UseAntiforgery(); +application.UseMiddleRenderProcessors(); + +application.MapRazorComponents() + .AddInteractiveServerRenderMode(); +application.MapControllers(); + +await application.RunAsync(); diff --git a/YaeBlog/Properties/launchSettings.json b/YaeBlog/Properties/launchSettings.json new file mode 100644 index 0000000..37fd6e7 --- /dev/null +++ b/YaeBlog/Properties/launchSettings.json @@ -0,0 +1,22 @@ +{ + "$schema": "http://json.schemastore.org/launchsettings.json", + "iisSettings": { + "windowsAuthentication": false, + "anonymousAuthentication": true, + "iisExpress": { + "applicationUrl": "http://localhost:14405", + "sslPort": 44378 + } + }, + "profiles": { + "http": { + "commandName": "Project", + "dotnetRunMessages": true, + "launchBrowser": true, + "applicationUrl": "http://localhost:5275", + "environmentVariables": { + "ASPNETCORE_ENVIRONMENT": "Development" + } + } + } +} diff --git a/YaeBlog/YaeBlog.csproj b/YaeBlog/YaeBlog.csproj new file mode 100644 index 0000000..b498de4 --- /dev/null +++ b/YaeBlog/YaeBlog.csproj @@ -0,0 +1,37 @@ + + + + + + + + + + + + + + + + + + + + <_ContentIncludedByDefault Remove="Components\Pages\About.razor" /> + <_ContentIncludedByDefault Remove="Components\Pages\Archives.razor" /> + <_ContentIncludedByDefault Remove="Components\Pages\Error.razor" /> + <_ContentIncludedByDefault Remove="Components\Pages\Essay.razor" /> + <_ContentIncludedByDefault Remove="Components\Pages\Home.razor" /> + <_ContentIncludedByDefault Remove="Components\Pages\Links.razor" /> + <_ContentIncludedByDefault Remove="Components\Pages\NotFound.razor" /> + <_ContentIncludedByDefault Remove="Components\Pages\Tags.razor" /> + <_ContentIncludedByDefault Remove="Components\Layout\MainLayout.razor" /> + + + + net8.0 + enable + enable + + + diff --git a/YaeBlog.Theme.FluentUI/_Imports.razor b/YaeBlog/_Imports.razor similarity index 90% rename from YaeBlog.Theme.FluentUI/_Imports.razor rename to YaeBlog/_Imports.razor index c08fdc1..80eee99 100644 --- a/YaeBlog.Theme.FluentUI/_Imports.razor +++ b/YaeBlog/_Imports.razor @@ -7,4 +7,5 @@ @using Microsoft.AspNetCore.Components.Web.Virtualization @using Microsoft.JSInterop @using Microsoft.FluentUI.AspNetCore.Components -@using YaeBlog.Theme.FluentUI.Components +@using YaeBlog +@using YaeBlog.Components diff --git a/YaeBlog/appsettings.json b/YaeBlog/appsettings.json new file mode 100644 index 0000000..3ebd202 --- /dev/null +++ b/YaeBlog/appsettings.json @@ -0,0 +1,44 @@ +{ + "Logging": { + "LogLevel": { + "Default": "Information", + "Microsoft.AspNetCore": "Warning" + } + }, + "AllowedHosts": "*", + "Blog": { + "Root": "source", + "Author": "Ricardo Ren", + "Announcement": "堂!堂!开!始!", + "StartYear": 2021, + "ProjectName": "Blog", + "BannerImage": "images/banner.png", + "EssayImage": "images/banner.png", + "RegisterInformation": "蜀ICP备2022004429号-1", + "About": { + "Introduction": "A CS Student", + "Description": "还太菜了,没有做出太多的贡献。", + "AvatarImage": "images/avatar.png" + }, + "Links": [ + { + "Name": "Ichirinko", + "Description": "这是个大哥", + "Link": "https://ichirinko.top", + "AvatarImage": "https://ichirinko-blog-img-1.oss-cn-shenzhen.aliyuncs.com/Pic_res/img/202209122110798.png" + }, + { + "Name": "志田千陽", + "Description": "日出多期待", + "Link": "https://zzachary.top/", + "AvatarImage": "https://zzachary.top/img/ztqy_hub928259802d192ff5718c06370f0f2c4_48203_300x0_resize_q75_box.jpg" + }, + { + "Name": "Chenxu", + "Description": "一个普通大学生", + "Link": "https://chenxutalk.top", + "AvatarImage": "https://www.chenxutalk.top/img/photo.png" + } + ] + } +} diff --git a/YaeBlog.Theme.FluentUI/wwwroot/fonts/.gitattributes b/YaeBlog/wwwroot/fonts/.gitattributes similarity index 100% rename from YaeBlog.Theme.FluentUI/wwwroot/fonts/.gitattributes rename to YaeBlog/wwwroot/fonts/.gitattributes diff --git a/YaeBlog.Theme.FluentUI/wwwroot/fonts/fa-regular-400.ttf b/YaeBlog/wwwroot/fonts/fa-regular-400.ttf similarity index 100% rename from YaeBlog.Theme.FluentUI/wwwroot/fonts/fa-regular-400.ttf rename to YaeBlog/wwwroot/fonts/fa-regular-400.ttf diff --git a/YaeBlog.Theme.FluentUI/wwwroot/fonts/fa-regular-400.woff2 b/YaeBlog/wwwroot/fonts/fa-regular-400.woff2 similarity index 100% rename from YaeBlog.Theme.FluentUI/wwwroot/fonts/fa-regular-400.woff2 rename to YaeBlog/wwwroot/fonts/fa-regular-400.woff2 diff --git a/YaeBlog.Theme.FluentUI/wwwroot/fonts/fa-solid-900.ttf b/YaeBlog/wwwroot/fonts/fa-solid-900.ttf similarity index 100% rename from YaeBlog.Theme.FluentUI/wwwroot/fonts/fa-solid-900.ttf rename to YaeBlog/wwwroot/fonts/fa-solid-900.ttf diff --git a/YaeBlog.Theme.FluentUI/wwwroot/fonts/fa-solid-900.woff2 b/YaeBlog/wwwroot/fonts/fa-solid-900.woff2 similarity index 100% rename from YaeBlog.Theme.FluentUI/wwwroot/fonts/fa-solid-900.woff2 rename to YaeBlog/wwwroot/fonts/fa-solid-900.woff2 diff --git a/YaeBlog.Theme.FluentUI/wwwroot/globals.css b/YaeBlog/wwwroot/globals.css similarity index 100% rename from YaeBlog.Theme.FluentUI/wwwroot/globals.css rename to YaeBlog/wwwroot/globals.css diff --git a/YaeBlog/wwwroot/images/avatar.png b/YaeBlog/wwwroot/images/avatar.png new file mode 100644 index 0000000..940ac82 Binary files /dev/null and b/YaeBlog/wwwroot/images/avatar.png differ diff --git a/YaeBlog/wwwroot/images/banner.png b/YaeBlog/wwwroot/images/banner.png new file mode 100644 index 0000000..752fa05 Binary files /dev/null and b/YaeBlog/wwwroot/images/banner.png differ diff --git a/YaeBlog/wwwroot/images/favicon.ico b/YaeBlog/wwwroot/images/favicon.ico new file mode 100644 index 0000000..0b08be5 Binary files /dev/null and b/YaeBlog/wwwroot/images/favicon.ico differ