diff --git a/.gitignore b/.gitignore index 104b544..f606da8 100644 --- a/.gitignore +++ b/.gitignore @@ -482,3 +482,6 @@ $RECYCLE.BIN/ # Vim temporary swap files *.swp + +# Tailwind auto-generated stylesheet +output.css diff --git a/YaeBlog.Core/Components/_Imports.razor b/YaeBlog.Core/Components/_Imports.razor deleted file mode 100644 index d88eed9..0000000 --- a/YaeBlog.Core/Components/_Imports.razor +++ /dev/null @@ -1,8 +0,0 @@ -@using System.Net.Http -@using System.Net.Http.Json -@using Microsoft.AspNetCore.Components.Forms -@using Microsoft.AspNetCore.Components.Routing -@using Microsoft.AspNetCore.Components.Web -@using static Microsoft.AspNetCore.Components.Web.RenderMode -@using Microsoft.AspNetCore.Components.Web.Virtualization -@using Microsoft.JSInterop diff --git a/YaeBlog.Core/Models/AboutInfo.cs b/YaeBlog.Core/Models/AboutInfo.cs deleted file mode 100644 index 32ff959..0000000 --- a/YaeBlog.Core/Models/AboutInfo.cs +++ /dev/null @@ -1,10 +0,0 @@ -namespace YaeBlog.Core.Models; - -public class AboutInfo -{ - public required string Introduction { get; set; } - - public required string Description { get; set; } - - public required string AvatarImage { get; set; } -} diff --git a/YaeBlog.Core/Processors/CodeBlockPostRenderProcessor.cs b/YaeBlog.Core/Processors/CodeBlockPostRenderProcessor.cs deleted file mode 100644 index 217aa38..0000000 --- a/YaeBlog.Core/Processors/CodeBlockPostRenderProcessor.cs +++ /dev/null @@ -1,29 +0,0 @@ -using AngleSharp; -using AngleSharp.Dom; -using YaeBlog.Core.Abstractions; -using YaeBlog.Core.Models; - -namespace YaeBlog.Core.Processors; - -public class CodeBlockPostRenderProcessor : IPostRenderProcessor -{ - public async Task ProcessAsync(BlogEssay essay) - { - BrowsingContext context = new(Configuration.Default); - IDocument document = await context.OpenAsync( - req => req.Content(essay.HtmlContent)); - - IEnumerable preElements = from e in document.All - where e.LocalName == "pre" - select e; - - foreach (IElement element in preElements) - { - element.ClassList.Add("p-3 text-bg-secondary rounded-1"); - } - - return essay.WithNewHtmlContent(document.DocumentElement.OuterHtml); - } - - public string Name => nameof(CodeBlockPostRenderProcessor); -} diff --git a/YaeBlog.Core/Processors/TablePostRenderProcessor.cs b/YaeBlog.Core/Processors/TablePostRenderProcessor.cs deleted file mode 100644 index e2c3444..0000000 --- a/YaeBlog.Core/Processors/TablePostRenderProcessor.cs +++ /dev/null @@ -1,34 +0,0 @@ -using AngleSharp; -using AngleSharp.Dom; -using AngleSharp.Html.Dom; -using YaeBlog.Core.Abstractions; -using YaeBlog.Core.Models; - -namespace YaeBlog.Core.Processors; - -public class TablePostRenderProcessor: IPostRenderProcessor -{ - public async Task ProcessAsync(BlogEssay essay) - { - BrowsingContext browsingContext = new(Configuration.Default); - IDocument document = await browsingContext.OpenAsync( - req => req.Content(essay.HtmlContent)); - - IEnumerable tableElements = from item in document.All - where item.LocalName == "table" - select item as IHtmlTableElement; - - foreach (IHtmlTableElement element in tableElements) - { - IHtmlDivElement divElement = document.CreateElement(); - divElement.InnerHtml = element.OuterHtml; - divElement.ClassList.Add("py-2", "table-wrapper"); - - element.Replace(divElement); - } - - return essay.WithNewHtmlContent(document.DocumentElement.OuterHtml); - } - - public string Name => nameof(TablePostRenderProcessor); -} diff --git a/YaeBlog.Core/Services/BlogHotReloadService.cs b/YaeBlog.Core/Services/BlogHotReloadService.cs deleted file mode 100644 index f112e10..0000000 --- a/YaeBlog.Core/Services/BlogHotReloadService.cs +++ /dev/null @@ -1,35 +0,0 @@ -using Microsoft.Extensions.Hosting; -using Microsoft.Extensions.Logging; -using YaeBlog.Core.Abstractions; - -namespace YaeBlog.Core.Services; - -public sealed class BlogHotReloadService( - RendererService rendererService, - IEssayContentService essayContentService, - BlogChangeWatcher watcher, - ILogger logger) : BackgroundService -{ - protected override async Task ExecuteAsync(CancellationToken stoppingToken) - { - logger.LogInformation("BlogHotReloadService is starting."); - - await rendererService.RenderAsync(); - - while (!stoppingToken.IsCancellationRequested) - { - logger.LogDebug("Watching file changes..."); - string? changFile = await watcher.WaitForChange(stoppingToken); - - if (changFile is null) - { - logger.LogInformation("BlogHotReloadService is stopping."); - break; - } - - logger.LogInformation("{} changed, re-rendering.", changFile); - essayContentService.Clear(); - await rendererService.RenderAsync(); - } - } -} diff --git a/YaeBlog.Core/YaeBlog.Core.csproj b/YaeBlog.Core/YaeBlog.Core.csproj deleted file mode 100644 index 7089599..0000000 --- a/YaeBlog.Core/YaeBlog.Core.csproj +++ /dev/null @@ -1,25 +0,0 @@ - - - - net9.0 - enable - enable - - - - - - - - - - - - - - - - - - - diff --git a/YaeBlog.sln b/YaeBlog.sln index 78aae25..c4f8f9c 100644 --- a/YaeBlog.sln +++ b/YaeBlog.sln @@ -3,8 +3,6 @@ Microsoft Visual Studio Solution File, Format Version 12.00 # Visual Studio Version 17 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("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "YaeBlog", "YaeBlog\YaeBlog.csproj", "{20438EFD-8DDE-43AF-92E2-76495C29233C}" EndProject Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = ".gitea", ".gitea", "{9B5AAA29-37D8-454A-8D8F-3E6B6BCF38E6}" @@ -29,10 +27,6 @@ Global Release|Any CPU = Release|Any CPU EndGlobalSection GlobalSection(ProjectConfigurationPlatforms) = postSolution - {1671A8AE-78F6-4641-B97D-D8ABA5E9CBEF}.Debug|Any CPU.ActiveCfg = Debug|Any CPU - {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 {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 diff --git a/YaeBlog.Core/Abstractions/IEssayContentService.cs b/YaeBlog/Abstraction/IEssayContentService.cs similarity index 69% rename from YaeBlog.Core/Abstractions/IEssayContentService.cs rename to YaeBlog/Abstraction/IEssayContentService.cs index 9be561c..8c95cce 100644 --- a/YaeBlog.Core/Abstractions/IEssayContentService.cs +++ b/YaeBlog/Abstraction/IEssayContentService.cs @@ -1,11 +1,13 @@ using System.Diagnostics.CodeAnalysis; -using YaeBlog.Core.Models; +using YaeBlog.Models; -namespace YaeBlog.Core.Abstractions; +namespace YaeBlog.Abstraction; public interface IEssayContentService { - public IReadOnlyDictionary Essays { get; } + public IEnumerable Essays { get; } + + public int Count { get; } public IReadOnlyDictionary> Tags { get; } @@ -16,6 +18,8 @@ public interface IEssayContentService public bool TryAdd(BlogEssay essay); + public bool TryGetEssay(string filename, [NotNullWhen(true)] out BlogEssay? essay); + public void RefreshTags(); public void Clear(); diff --git a/YaeBlog.Core/Abstractions/IEssayScanService.cs b/YaeBlog/Abstraction/IEssayScanService.cs similarity index 75% rename from YaeBlog.Core/Abstractions/IEssayScanService.cs rename to YaeBlog/Abstraction/IEssayScanService.cs index 5395b9a..f5aad84 100644 --- a/YaeBlog.Core/Abstractions/IEssayScanService.cs +++ b/YaeBlog/Abstraction/IEssayScanService.cs @@ -1,6 +1,6 @@ -using YaeBlog.Core.Models; +using YaeBlog.Models; -namespace YaeBlog.Core.Abstractions; +namespace YaeBlog.Abstraction; public interface IEssayScanService { diff --git a/YaeBlog.Core/Abstractions/IPostRenderProcessor.cs b/YaeBlog/Abstraction/IPostRenderProcessor.cs similarity index 64% rename from YaeBlog.Core/Abstractions/IPostRenderProcessor.cs rename to YaeBlog/Abstraction/IPostRenderProcessor.cs index 6117742..e7b4c2b 100644 --- a/YaeBlog.Core/Abstractions/IPostRenderProcessor.cs +++ b/YaeBlog/Abstraction/IPostRenderProcessor.cs @@ -1,6 +1,6 @@ -using YaeBlog.Core.Models; +using YaeBlog.Models; -namespace YaeBlog.Core.Abstractions; +namespace YaeBlog.Abstraction; public interface IPostRenderProcessor { diff --git a/YaeBlog.Core/Abstractions/IPreRenderProcessor.cs b/YaeBlog/Abstraction/IPreRenderProcessor.cs similarity index 65% rename from YaeBlog.Core/Abstractions/IPreRenderProcessor.cs rename to YaeBlog/Abstraction/IPreRenderProcessor.cs index ee3b7f2..a9b69f2 100644 --- a/YaeBlog.Core/Abstractions/IPreRenderProcessor.cs +++ b/YaeBlog/Abstraction/IPreRenderProcessor.cs @@ -1,6 +1,6 @@ -using YaeBlog.Core.Models; +using YaeBlog.Models; -namespace YaeBlog.Core.Abstractions; +namespace YaeBlog.Abstraction; public interface IPreRenderProcessor { diff --git a/YaeBlog/Commands/Binders/BlogOptionsBinder.cs b/YaeBlog/Commands/Binders/BlogOptionsBinder.cs index 9f3cb54..f6e4af6 100644 --- a/YaeBlog/Commands/Binders/BlogOptionsBinder.cs +++ b/YaeBlog/Commands/Binders/BlogOptionsBinder.cs @@ -1,7 +1,7 @@ using System.CommandLine.Binding; using System.Text.Json; using Microsoft.Extensions.Options; -using YaeBlog.Core.Models; +using YaeBlog.Models; namespace YaeBlog.Commands.Binders; diff --git a/YaeBlog/Commands/Binders/EssayScanServiceBinder.cs b/YaeBlog/Commands/Binders/EssayScanServiceBinder.cs index b0613c8..5d7e1d5 100644 --- a/YaeBlog/Commands/Binders/EssayScanServiceBinder.cs +++ b/YaeBlog/Commands/Binders/EssayScanServiceBinder.cs @@ -1,8 +1,8 @@ using System.CommandLine.Binding; using Microsoft.Extensions.Options; -using YaeBlog.Core.Abstractions; -using YaeBlog.Core.Models; -using YaeBlog.Core.Services; +using YaeBlog.Abstraction; +using YaeBlog.Models; +using YaeBlog.Services; using YamlDotNet.Serialization; using YamlDotNet.Serialization.NamingConventions; diff --git a/YaeBlog/Commands/CommandExtensions.cs b/YaeBlog/Commands/YaeBlogCommand.cs similarity index 88% rename from YaeBlog/Commands/CommandExtensions.cs rename to YaeBlog/Commands/YaeBlogCommand.cs index bb7576d..94815c5 100644 --- a/YaeBlog/Commands/CommandExtensions.cs +++ b/YaeBlog/Commands/YaeBlogCommand.cs @@ -1,15 +1,32 @@ using System.CommandLine; using YaeBlog.Commands.Binders; using YaeBlog.Components; -using YaeBlog.Core.Extensions; -using YaeBlog.Core.Models; -using YaeBlog.Core.Services; +using YaeBlog.Extensions; +using YaeBlog.Models; +using YaeBlog.Services; namespace YaeBlog.Commands; -public static class CommandExtensions +public sealed class YaeBlogCommand { - public static void AddServeCommand(this RootCommand rootCommand) + private readonly RootCommand _rootCommand = new("YaeBlog Cli"); + + public YaeBlogCommand() + { + AddServeCommand(_rootCommand); + AddWatchCommand(_rootCommand); + AddListCommand(_rootCommand); + AddNewCommand(_rootCommand); + AddPublishCommand(_rootCommand); + AddScanCommand(_rootCommand); + } + + public Task RunAsync(string[] args) + { + return _rootCommand.InvokeAsync(args); + } + + private static void AddServeCommand(RootCommand rootCommand) { Command serveCommand = new("serve", "Start http server."); rootCommand.AddCommand(serveCommand); @@ -21,7 +38,6 @@ public static class CommandExtensions builder.Services.AddRazorComponents() .AddInteractiveServerComponents(); builder.Services.AddControllers(); - builder.Services.AddBlazorBootstrap(); builder.AddYaeBlog(); builder.AddServer(); @@ -40,7 +56,7 @@ public static class CommandExtensions }); } - public static void AddWatchCommand(this RootCommand rootCommand) + private static void AddWatchCommand(RootCommand rootCommand) { Command command = new("watch", "Start a blog watcher that re-render when file changes."); rootCommand.AddCommand(command); @@ -52,7 +68,6 @@ public static class CommandExtensions builder.Services.AddRazorComponents() .AddInteractiveServerComponents(); builder.Services.AddControllers(); - builder.Services.AddBlazorBootstrap(); builder.AddYaeBlog(); builder.AddWatcher(); @@ -71,7 +86,7 @@ public static class CommandExtensions }); } - public static void AddNewCommand(this RootCommand rootCommand) + private static void AddNewCommand(RootCommand rootCommand) { Command newCommand = new("new", "Create a new blog file and image directory."); rootCommand.AddCommand(newCommand); @@ -101,7 +116,7 @@ public static class CommandExtensions new EssayScanServiceBinder()); } - public static void AddListCommand(this RootCommand rootCommand) + private static void AddListCommand(RootCommand rootCommand) { Command command = new("list", "List all blogs"); rootCommand.AddCommand(command); @@ -124,7 +139,7 @@ public static class CommandExtensions }, new BlogOptionsBinder(), new LoggerBinder(), new EssayScanServiceBinder()); } - public static void AddScanCommand(this RootCommand rootCommand) + private static void AddScanCommand(RootCommand rootCommand) { Command command = new("scan", "Scan unused and not found images."); rootCommand.AddCommand(command); @@ -165,7 +180,7 @@ public static class CommandExtensions }, new BlogOptionsBinder(), new LoggerBinder(), new EssayScanServiceBinder(), removeOption); } - public static void AddPublishCommand(this RootCommand rootCommand) + private static void AddPublishCommand(RootCommand rootCommand) { Command command = new("publish", "Publish a new blog file."); rootCommand.AddCommand(command); diff --git a/YaeBlog/Components/Anchor.razor b/YaeBlog/Components/Anchor.razor new file mode 100644 index 0000000..efab799 --- /dev/null +++ b/YaeBlog/Components/Anchor.razor @@ -0,0 +1,9 @@ +@Text + +@code { + [Parameter] public string? Address { get; set; } + + [Parameter] public string? Text { get; set; } + + [Parameter] public bool NewPage { get; set; } +} diff --git a/YaeBlog/Components/App.razor b/YaeBlog/Components/App.razor index 3a96ded..f6d881b 100644 --- a/YaeBlog/Components/App.razor +++ b/YaeBlog/Components/App.razor @@ -1,5 +1,5 @@  - + @@ -7,22 +7,14 @@ - - - + - - - - - - + + diff --git a/YaeBlog/Components/BlogInformationCard.razor b/YaeBlog/Components/BlogInformationCard.razor index fd97c76..11f8a88 100644 --- a/YaeBlog/Components/BlogInformationCard.razor +++ b/YaeBlog/Components/BlogInformationCard.razor @@ -1,57 +1,49 @@ -@using YaeBlog.Core.Abstractions -@using YaeBlog.Core.Models +@using YaeBlog.Abstraction +@using YaeBlog.Models @inject IEssayContentService Contents @inject BlogOptions Options -
-
-
- Ricardo's avatar -
+
+
+ Ricardo's Avatar
-
-
- “奇奇怪怪东西的聚合地” -
+
+ “奇奇怪怪东西的聚合地”
-
-
+ -
-
+ -
-
- 广而告之 -
+
+ 广而告之
-
-
-

- @(Options.Announcement) -

-
+
+

+ @(Options.Announcement) +

diff --git a/YaeBlog/Components/BlogInformationCard.razor.css b/YaeBlog/Components/BlogInformationCard.razor.css deleted file mode 100644 index e69de29..0000000 diff --git a/YaeBlog/Components/EssayCard.razor b/YaeBlog/Components/EssayCard.razor index 02fe971..99cb3f1 100644 --- a/YaeBlog/Components/EssayCard.razor +++ b/YaeBlog/Components/EssayCard.razor @@ -1,19 +1,19 @@ @using System.Text.Encodings.Web -@using YaeBlog.Core.Models +@using YaeBlog.Models -
-
+
+ -
-
+
+
@(Essay.PublishTime.ToString("yyyy-MM-dd"))
@foreach (string key in Essay.Tags) { -
+
# @key @@ -21,20 +21,11 @@ }
-
-
- @(Essay.Description) -
-
- -
-
- -
+
+ @(Essay.Description)
@code { - [Parameter] - public required BlogEssay Essay { get; set; } + [Parameter] public required BlogEssay Essay { get; set; } } diff --git a/YaeBlog/Components/EssayCard.razor.css b/YaeBlog/Components/EssayCard.razor.css deleted file mode 100644 index 4dd8b69..0000000 --- a/YaeBlog/Components/EssayCard.razor.css +++ /dev/null @@ -1,3 +0,0 @@ -.essay-title a { - color: var(--bs-body-color); -} diff --git a/YaeBlog/Components/Foonter.razor b/YaeBlog/Components/Foonter.razor index d3f9910..8a5935b 100644 --- a/YaeBlog/Components/Foonter.razor +++ b/YaeBlog/Components/Foonter.razor @@ -1,14 +1,22 @@ -
-
-

- 2021 - @(DateTimeOffset.Now.Year) © Ricardo Ren, - 由 .NET @(Environment.Version) 驱动。 +

+
+

+ 2021 - @(DateTimeOffset.Now.Year) © + + ,由 + + 驱动。

- + +@code +{ + private string DotnetVersion => $".NET {Environment.Version}"; +} diff --git a/YaeBlog/Components/Foonter.razor.css b/YaeBlog/Components/Foonter.razor.css deleted file mode 100644 index e69de29..0000000 diff --git a/YaeBlog/Components/LicenseDisclaimer.razor b/YaeBlog/Components/LicenseDisclaimer.razor index 75aab2e..ab77a81 100644 --- a/YaeBlog/Components/LicenseDisclaimer.razor +++ b/YaeBlog/Components/LicenseDisclaimer.razor @@ -1,36 +1,33 @@ -@using YaeBlog.Core.Models - +@using YaeBlog.Models @inject BlogOptions Options -