Compare commits
52 Commits
9111affeec
...
feat/intro
| Author | SHA1 | Date | |
|---|---|---|---|
|
a3791596da
|
|||
|
2be09b8319
|
|||
|
fa01b74f09
|
|||
|
dd81e9a6f4
|
|||
|
35f069f40a
|
|||
|
80e48a2043
|
|||
|
1be39327aa
|
|||
|
c050d1b790
|
|||
|
56374a4e6b
|
|||
|
58ba4b2a2f
|
|||
|
009e86b553
|
|||
|
d1ec3a51d1
|
|||
|
dab866f13a
|
|||
| 94421168c6 | |||
| 938fe1c715 | |||
| eedfc1ffce | |||
| 0f346d9ded | |||
| a662ecc14b | |||
| a254d0123d | |||
| 22d28e763d | |||
| d0a4f4b76b | |||
| 3126005731 | |||
| 2b9c374e8c | |||
| 4df3b98e6d | |||
| c293d2f6d7 | |||
| 132261831b | |||
| 043376c6d3 | |||
| 4682dacc79 | |||
| 383dd41695 | |||
| 7f3221fde9 | |||
| 05ea729950 | |||
| dcad453eb1 | |||
| dec2bc937a | |||
| b9c44408ad | |||
| e1c5362cf5 | |||
| bdcfed5506 | |||
| 3aae468e65 | |||
| 1ceaf30061 | |||
| 87204dab8e | |||
| 05d40ce3b6 | |||
| 309db7e5f1 | |||
| fb71ce64cf | |||
| d87e3830a5 | |||
| 32104bbfb8 | |||
| f77d2a47d1 | |||
| f6e43f466d | |||
| f889d51857 | |||
| 45c35d7442 | |||
| 9ebacf87e5 | |||
| bb5cb77b7b | |||
| 933eec0f7f | |||
| 4085b0d99c |
@@ -15,6 +15,9 @@ trim_trailing_whitespace = true
|
|||||||
[project.json]
|
[project.json]
|
||||||
indent_size = 2
|
indent_size = 2
|
||||||
|
|
||||||
|
[*.{yaml,yml}]
|
||||||
|
indent_size = 2
|
||||||
|
|
||||||
# C# and Visual Basic files
|
# C# and Visual Basic files
|
||||||
[*.{cs,vb}]
|
[*.{cs,vb}]
|
||||||
charset = utf-8-bom
|
charset = utf-8-bom
|
||||||
|
|||||||
3
.gitattributes
vendored
3
.gitattributes
vendored
@@ -1,2 +1,5 @@
|
|||||||
*.png filter=lfs diff=lfs merge=lfs -text
|
*.png filter=lfs diff=lfs merge=lfs -text
|
||||||
*.jpg filter=lfs diff=lfs merge=lfs -text
|
*.jpg filter=lfs diff=lfs merge=lfs -text
|
||||||
|
*.jpeg filter=lfs diff=lfs merge=lfs -text
|
||||||
|
*.avif filter=lfs diff=lfs merge=lfs -text
|
||||||
|
*.webp filter=lfs diff=lfs merge=lfs -text
|
||||||
|
|||||||
@@ -7,23 +7,24 @@ jobs:
|
|||||||
Build-Blog-Image:
|
Build-Blog-Image:
|
||||||
runs-on: archlinux
|
runs-on: archlinux
|
||||||
steps:
|
steps:
|
||||||
- uses: https://git.rrricardo.top/actions/checkout@v4
|
- name: Check out code.
|
||||||
name: Check out code
|
uses: https://mirrors.rrricardo.top/actions/checkout.git@v4
|
||||||
with:
|
with:
|
||||||
lfs: true
|
lfs: true
|
||||||
- name: Build project
|
- name: Build project.
|
||||||
run: |
|
run: |
|
||||||
|
podman pull mcr.azure.cn/dotnet/aspnet:10.0
|
||||||
cd YaeBlog
|
cd YaeBlog
|
||||||
dotnet publish
|
pwsh build.ps1 build
|
||||||
- name: Build docker image
|
- name: Workaround to make sure podman-login working.
|
||||||
run: |
|
run: |
|
||||||
cd YaeBlog
|
mkdir /root/.docker
|
||||||
docker build . -t registry.cn-beijing.aliyuncs.com/jackfiled/blog:latest
|
- name: Login tencent cloud docker registry.
|
||||||
- name: Login aliyun docker registry
|
uses: https://mirrors.rrricardo.top/actions/podman-login.git@v1
|
||||||
uses: https://git.rrricardo.top/actions/login-action@v3
|
|
||||||
with:
|
with:
|
||||||
registry: registry.cn-beijing.aliyuncs.com
|
registry: ccr.ccs.tencentyun.com
|
||||||
username: 初冬的朝阳
|
username: 100044380877
|
||||||
password: ${{ secrets.ALIYUN_PASSWORD }}
|
password: ${{ secrets.TENCENT_REGISTRY_PASSWORD }}
|
||||||
- name: Push docker image
|
auth_file_path: /etc/containers/auth.json
|
||||||
run: docker push registry.cn-beijing.aliyuncs.com/jackfiled/blog:latest
|
- name: Push docker image.
|
||||||
|
run: podman push ccr.ccs.tencentyun.com/jackfiled/blog:latest
|
||||||
|
|||||||
3
.gitignore
vendored
3
.gitignore
vendored
@@ -482,3 +482,6 @@ $RECYCLE.BIN/
|
|||||||
|
|
||||||
# Vim temporary swap files
|
# Vim temporary swap files
|
||||||
*.swp
|
*.swp
|
||||||
|
|
||||||
|
# Tailwind auto-generated stylesheet
|
||||||
|
*.g.css
|
||||||
|
|||||||
3
.gitmodules
vendored
Normal file
3
.gitmodules
vendored
Normal file
@@ -0,0 +1,3 @@
|
|||||||
|
[submodule "third-party/BlazorSvgComponents"]
|
||||||
|
path = third-party/BlazorSvgComponents
|
||||||
|
url = https://git.rrricardo.top/jackfiled/BlazorSvgComponents.git
|
||||||
@@ -1,10 +0,0 @@
|
|||||||
using YaeBlog.Core.Models;
|
|
||||||
|
|
||||||
namespace YaeBlog.Core.Abstractions;
|
|
||||||
|
|
||||||
public interface IEssayScanService
|
|
||||||
{
|
|
||||||
public Task<BlogContents> ScanContents();
|
|
||||||
|
|
||||||
public Task SaveBlogContent(BlogContent content, bool isDraft = true);
|
|
||||||
}
|
|
||||||
@@ -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; }
|
|
||||||
}
|
|
||||||
@@ -1,10 +0,0 @@
|
|||||||
namespace YaeBlog.Core.Models;
|
|
||||||
|
|
||||||
public class BlogContent
|
|
||||||
{
|
|
||||||
public required string FileName { get; init; }
|
|
||||||
|
|
||||||
public required MarkdownMetadata Metadata { get; init; }
|
|
||||||
|
|
||||||
public required string FileContent { get; set; }
|
|
||||||
}
|
|
||||||
@@ -1,10 +0,0 @@
|
|||||||
using System.Collections.Concurrent;
|
|
||||||
|
|
||||||
namespace YaeBlog.Core.Models;
|
|
||||||
|
|
||||||
public sealed class BlogContents(ConcurrentBag<BlogContent> drafts, ConcurrentBag<BlogContent> posts)
|
|
||||||
{
|
|
||||||
public ConcurrentBag<BlogContent> Drafts { get; } = drafts;
|
|
||||||
|
|
||||||
public ConcurrentBag<BlogContent> Posts { get; } = posts;
|
|
||||||
}
|
|
||||||
@@ -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<BlogEssay> ProcessAsync(BlogEssay essay)
|
|
||||||
{
|
|
||||||
BrowsingContext context = new(Configuration.Default);
|
|
||||||
IDocument document = await context.OpenAsync(
|
|
||||||
req => req.Content(essay.HtmlContent));
|
|
||||||
|
|
||||||
IEnumerable<IElement> 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);
|
|
||||||
}
|
|
||||||
@@ -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<BlogEssay> ProcessAsync(BlogEssay essay)
|
|
||||||
{
|
|
||||||
BrowsingContext browsingContext = new(Configuration.Default);
|
|
||||||
IDocument document = await browsingContext.OpenAsync(
|
|
||||||
req => req.Content(essay.HtmlContent));
|
|
||||||
|
|
||||||
IEnumerable<IHtmlTableElement> tableElements = from item in document.All
|
|
||||||
where item.LocalName == "table"
|
|
||||||
select item as IHtmlTableElement;
|
|
||||||
|
|
||||||
foreach (IHtmlTableElement element in tableElements)
|
|
||||||
{
|
|
||||||
IHtmlDivElement divElement = document.CreateElement<IHtmlDivElement>();
|
|
||||||
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);
|
|
||||||
}
|
|
||||||
@@ -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<BlogHotReloadService> 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();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,122 +0,0 @@
|
|||||||
using System.Collections.Concurrent;
|
|
||||||
using Microsoft.Extensions.Logging;
|
|
||||||
using Microsoft.Extensions.Options;
|
|
||||||
using YaeBlog.Core.Abstractions;
|
|
||||||
using YaeBlog.Core.Exceptions;
|
|
||||||
using YaeBlog.Core.Models;
|
|
||||||
using YamlDotNet.Core;
|
|
||||||
using YamlDotNet.Serialization;
|
|
||||||
|
|
||||||
namespace YaeBlog.Core.Services;
|
|
||||||
|
|
||||||
public class EssayScanService(
|
|
||||||
ISerializer yamlSerializer,
|
|
||||||
IDeserializer yamlDeserializer,
|
|
||||||
IOptions<BlogOptions> blogOptions,
|
|
||||||
ILogger<EssayScanService> logger) : IEssayScanService
|
|
||||||
{
|
|
||||||
private readonly BlogOptions _blogOptions = blogOptions.Value;
|
|
||||||
|
|
||||||
public async Task<BlogContents> ScanContents()
|
|
||||||
{
|
|
||||||
ValidateDirectory(_blogOptions.Root, out DirectoryInfo drafts, out DirectoryInfo posts);
|
|
||||||
|
|
||||||
return new BlogContents(
|
|
||||||
await ScanContentsInternal(drafts),
|
|
||||||
await ScanContentsInternal(posts));
|
|
||||||
}
|
|
||||||
|
|
||||||
public async Task SaveBlogContent(BlogContent content, bool isDraft = true)
|
|
||||||
{
|
|
||||||
ValidateDirectory(_blogOptions.Root, out DirectoryInfo drafts, out DirectoryInfo posts);
|
|
||||||
|
|
||||||
FileInfo targetFile = isDraft
|
|
||||||
? new FileInfo(Path.Combine(drafts.FullName, content.FileName + ".md"))
|
|
||||||
: new FileInfo(Path.Combine(posts.FullName, content.FileName + ".md"));
|
|
||||||
|
|
||||||
if (targetFile.Exists)
|
|
||||||
{
|
|
||||||
logger.LogWarning("Blog {} exists, overriding.", targetFile.Name);
|
|
||||||
}
|
|
||||||
|
|
||||||
await using StreamWriter writer = targetFile.CreateText();
|
|
||||||
|
|
||||||
await writer.WriteAsync("---\n");
|
|
||||||
await writer.WriteAsync(yamlSerializer.Serialize(content.Metadata));
|
|
||||||
await writer.WriteAsync("---\n");
|
|
||||||
await writer.WriteAsync("<!--more-->\n");
|
|
||||||
}
|
|
||||||
|
|
||||||
private async Task<ConcurrentBag<BlogContent>> ScanContentsInternal(DirectoryInfo directory)
|
|
||||||
{
|
|
||||||
IEnumerable<FileInfo> markdownFiles = from file in directory.EnumerateFiles()
|
|
||||||
where file.Extension == ".md"
|
|
||||||
select file;
|
|
||||||
|
|
||||||
ConcurrentBag<(string, string)> fileContents = [];
|
|
||||||
|
|
||||||
await Parallel.ForEachAsync(markdownFiles, async (file, token) =>
|
|
||||||
{
|
|
||||||
using StreamReader reader = file.OpenText();
|
|
||||||
fileContents.Add((file.Name, await reader.ReadToEndAsync(token)));
|
|
||||||
});
|
|
||||||
|
|
||||||
ConcurrentBag<BlogContent> contents = [];
|
|
||||||
|
|
||||||
await Task.Run(() =>
|
|
||||||
{
|
|
||||||
foreach ((string filename, string content) in fileContents)
|
|
||||||
{
|
|
||||||
int endPos = content.IndexOf("---", 4, StringComparison.Ordinal);
|
|
||||||
if (!content.StartsWith("---") || endPos is -1 or 0)
|
|
||||||
{
|
|
||||||
logger.LogWarning("Failed to parse metadata from {}, skipped.", filename);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
string metadataString = content[4..endPos];
|
|
||||||
|
|
||||||
try
|
|
||||||
{
|
|
||||||
MarkdownMetadata metadata = yamlDeserializer.Deserialize<MarkdownMetadata>(metadataString);
|
|
||||||
logger.LogDebug("Scan metadata title: '{}' for {}.", metadata.Title, filename);
|
|
||||||
|
|
||||||
contents.Add(new BlogContent
|
|
||||||
{
|
|
||||||
FileName = filename[..^3], Metadata = metadata, FileContent = content[(endPos + 3)..]
|
|
||||||
});
|
|
||||||
}
|
|
||||||
catch (YamlException e)
|
|
||||||
{
|
|
||||||
logger.LogWarning("Failed to parser metadata from {} due to {}, skipping", filename, e);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
return contents;
|
|
||||||
}
|
|
||||||
|
|
||||||
private void ValidateDirectory(string root, out DirectoryInfo drafts, out DirectoryInfo posts)
|
|
||||||
{
|
|
||||||
root = Path.Combine(Environment.CurrentDirectory, root);
|
|
||||||
DirectoryInfo rootDirectory = new(root);
|
|
||||||
|
|
||||||
if (!rootDirectory.Exists)
|
|
||||||
{
|
|
||||||
throw new BlogFileException($"'{root}' is not a directory.");
|
|
||||||
}
|
|
||||||
|
|
||||||
if (rootDirectory.EnumerateDirectories().All(dir => dir.Name != "drafts"))
|
|
||||||
{
|
|
||||||
throw new BlogFileException($"'{root}/drafts' not exists.");
|
|
||||||
}
|
|
||||||
|
|
||||||
if (rootDirectory.EnumerateDirectories().All(dir => dir.Name != "posts"))
|
|
||||||
{
|
|
||||||
throw new BlogFileException($"'{root}/posts' not exists.");
|
|
||||||
}
|
|
||||||
|
|
||||||
drafts = new DirectoryInfo(Path.Combine(root, "drafts"));
|
|
||||||
posts = new DirectoryInfo(Path.Combine(root, "posts"));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,25 +0,0 @@
|
|||||||
<Project Sdk="Microsoft.NET.Sdk.Razor">
|
|
||||||
|
|
||||||
<PropertyGroup>
|
|
||||||
<TargetFramework>net8.0</TargetFramework>
|
|
||||||
<Nullable>enable</Nullable>
|
|
||||||
<ImplicitUsings>enable</ImplicitUsings>
|
|
||||||
</PropertyGroup>
|
|
||||||
|
|
||||||
<ItemGroup>
|
|
||||||
<FrameworkReference Include="Microsoft.AspNetCore.App" />
|
|
||||||
</ItemGroup>
|
|
||||||
|
|
||||||
<ItemGroup>
|
|
||||||
<PackageReference Include="AngleSharp" Version="1.1.0" />
|
|
||||||
<PackageReference Include="Markdig" Version="0.34.0" />
|
|
||||||
<PackageReference Include="Microsoft.AspNetCore.Components.Web" Version="8.0.6" />
|
|
||||||
<PackageReference Include="Microsoft.Extensions.Hosting" Version="8.0.0" />
|
|
||||||
<PackageReference Include="YamlDotNet" Version="13.7.1" />
|
|
||||||
</ItemGroup>
|
|
||||||
|
|
||||||
<ItemGroup>
|
|
||||||
<Folder Include="wwwroot\" />
|
|
||||||
</ItemGroup>
|
|
||||||
|
|
||||||
</Project>
|
|
||||||
13
YaeBlog.Tests/DateTimeOffsetTests.cs
Normal file
13
YaeBlog.Tests/DateTimeOffsetTests.cs
Normal file
@@ -0,0 +1,13 @@
|
|||||||
|
namespace YaeBlog.Tests;
|
||||||
|
|
||||||
|
public class DateTimeOffsetTests
|
||||||
|
{
|
||||||
|
[Fact]
|
||||||
|
public void DateTimeOffsetParseTest()
|
||||||
|
{
|
||||||
|
const string input = "2026-01-04T16:36:36.5629759+08:00";
|
||||||
|
DateTimeOffset time = DateTimeOffset.Parse(input);
|
||||||
|
|
||||||
|
Assert.Equal("2026年01月04日 16:36:36", time.ToString("yyyy年MM月dd日 HH:mm:ss"));
|
||||||
|
}
|
||||||
|
}
|
||||||
25
YaeBlog.Tests/YaeBlog.Tests.csproj
Normal file
25
YaeBlog.Tests/YaeBlog.Tests.csproj
Normal file
@@ -0,0 +1,25 @@
|
|||||||
|
<Project Sdk="Microsoft.NET.Sdk">
|
||||||
|
|
||||||
|
<PropertyGroup>
|
||||||
|
<TargetFramework>net10.0</TargetFramework>
|
||||||
|
<ImplicitUsings>enable</ImplicitUsings>
|
||||||
|
<Nullable>enable</Nullable>
|
||||||
|
<IsPackable>false</IsPackable>
|
||||||
|
</PropertyGroup>
|
||||||
|
|
||||||
|
<ItemGroup>
|
||||||
|
<PackageReference Include="coverlet.collector" Version="6.0.4" />
|
||||||
|
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.14.1" />
|
||||||
|
<PackageReference Include="xunit" Version="2.9.3" />
|
||||||
|
<PackageReference Include="xunit.runner.visualstudio" Version="3.1.4" />
|
||||||
|
</ItemGroup>
|
||||||
|
|
||||||
|
<ItemGroup>
|
||||||
|
<Using Include="Xunit" />
|
||||||
|
</ItemGroup>
|
||||||
|
|
||||||
|
<ItemGroup>
|
||||||
|
<ProjectReference Include="..\YaeBlog\YaeBlog.csproj" />
|
||||||
|
</ItemGroup>
|
||||||
|
|
||||||
|
</Project>
|
||||||
47
YaeBlog.sln
47
YaeBlog.sln
@@ -1,47 +0,0 @@
|
|||||||
|
|
||||||
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}"
|
|
||||||
EndProject
|
|
||||||
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "workflows", "workflows", "{ADBC3DA8-F65C-4B5D-A97A-DC351F8E6592}"
|
|
||||||
ProjectSection(SolutionItems) = preProject
|
|
||||||
.gitea\workflows\build.yaml = .gitea\workflows\build.yaml
|
|
||||||
EndProjectSection
|
|
||||||
EndProject
|
|
||||||
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution Items", "{753B998C-1B9E-498F-B949-845CE86C4075}"
|
|
||||||
ProjectSection(SolutionItems) = preProject
|
|
||||||
.editorconfig = .editorconfig
|
|
||||||
.gitattributes = .gitattributes
|
|
||||||
.gitignore = .gitignore
|
|
||||||
README.md = README.md
|
|
||||||
LICENSE = LICENSE
|
|
||||||
EndProjectSection
|
|
||||||
EndProject
|
|
||||||
Global
|
|
||||||
GlobalSection(SolutionConfigurationPlatforms) = preSolution
|
|
||||||
Debug|Any CPU = Debug|Any CPU
|
|
||||||
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
|
|
||||||
{20438EFD-8DDE-43AF-92E2-76495C29233C}.Release|Any CPU.Build.0 = Release|Any CPU
|
|
||||||
EndGlobalSection
|
|
||||||
GlobalSection(SolutionProperties) = preSolution
|
|
||||||
HideSolutionNode = FALSE
|
|
||||||
EndGlobalSection
|
|
||||||
GlobalSection(NestedProjects) = preSolution
|
|
||||||
{ADBC3DA8-F65C-4B5D-A97A-DC351F8E6592} = {9B5AAA29-37D8-454A-8D8F-3E6B6BCF38E6}
|
|
||||||
EndGlobalSection
|
|
||||||
EndGlobal
|
|
||||||
15
YaeBlog.slnx
Normal file
15
YaeBlog.slnx
Normal file
@@ -0,0 +1,15 @@
|
|||||||
|
<Solution>
|
||||||
|
<Folder Name="/.gitea/" />
|
||||||
|
<Folder Name="/.gitea/workflows/">
|
||||||
|
<File Path=".gitea/workflows/build.yaml" />
|
||||||
|
</Folder>
|
||||||
|
<Folder Name="/Solution Items/">
|
||||||
|
<File Path=".editorconfig" />
|
||||||
|
<File Path=".gitattributes" />
|
||||||
|
<File Path=".gitignore" />
|
||||||
|
<File Path="LICENSE" />
|
||||||
|
<File Path="README.md" />
|
||||||
|
</Folder>
|
||||||
|
<Project Path="YaeBlog.Tests/YaeBlog.Tests.csproj" />
|
||||||
|
<Project Path="YaeBlog/YaeBlog.csproj" />
|
||||||
|
</Solution>
|
||||||
@@ -1,11 +1,13 @@
|
|||||||
using System.Diagnostics.CodeAnalysis;
|
using System.Diagnostics.CodeAnalysis;
|
||||||
using YaeBlog.Core.Models;
|
using YaeBlog.Models;
|
||||||
|
|
||||||
namespace YaeBlog.Core.Abstractions;
|
namespace YaeBlog.Abstraction;
|
||||||
|
|
||||||
public interface IEssayContentService
|
public interface IEssayContentService
|
||||||
{
|
{
|
||||||
public IReadOnlyDictionary<string, BlogEssay> Essays { get; }
|
public IEnumerable<BlogEssay> Essays { get; }
|
||||||
|
|
||||||
|
public int Count { get; }
|
||||||
|
|
||||||
public IReadOnlyDictionary<EssayTag, List<BlogEssay>> Tags { get; }
|
public IReadOnlyDictionary<EssayTag, List<BlogEssay>> Tags { get; }
|
||||||
|
|
||||||
@@ -16,6 +18,8 @@ public interface IEssayContentService
|
|||||||
|
|
||||||
public bool TryAdd(BlogEssay essay);
|
public bool TryAdd(BlogEssay essay);
|
||||||
|
|
||||||
|
public bool TryGetEssay(string filename, [NotNullWhen(true)] out BlogEssay? essay);
|
||||||
|
|
||||||
public void RefreshTags();
|
public void RefreshTags();
|
||||||
|
|
||||||
public void Clear();
|
public void Clear();
|
||||||
16
YaeBlog/Abstraction/IEssayScanService.cs
Normal file
16
YaeBlog/Abstraction/IEssayScanService.cs
Normal file
@@ -0,0 +1,16 @@
|
|||||||
|
using YaeBlog.Models;
|
||||||
|
|
||||||
|
namespace YaeBlog.Abstraction;
|
||||||
|
|
||||||
|
public interface IEssayScanService
|
||||||
|
{
|
||||||
|
public Task<BlogContents> ScanContents();
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 将对应的博客文章保存在磁盘上
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="content"></param>
|
||||||
|
/// <param name="isDraft">指定对应博客文章是否为草稿。因为BlogContent是不可变对象,因此提供该参数以方便publish的实现。</param>
|
||||||
|
/// <returns></returns>
|
||||||
|
public Task SaveBlogContent(BlogContent content, bool isDraft = true);
|
||||||
|
}
|
||||||
@@ -1,6 +1,6 @@
|
|||||||
using YaeBlog.Core.Models;
|
using YaeBlog.Models;
|
||||||
|
|
||||||
namespace YaeBlog.Core.Abstractions;
|
namespace YaeBlog.Abstraction;
|
||||||
|
|
||||||
public interface IPostRenderProcessor
|
public interface IPostRenderProcessor
|
||||||
{
|
{
|
||||||
@@ -1,6 +1,6 @@
|
|||||||
using YaeBlog.Core.Models;
|
using YaeBlog.Models;
|
||||||
|
|
||||||
namespace YaeBlog.Core.Abstractions;
|
namespace YaeBlog.Abstraction;
|
||||||
|
|
||||||
public interface IPreRenderProcessor
|
public interface IPreRenderProcessor
|
||||||
{
|
{
|
||||||
@@ -1,7 +1,7 @@
|
|||||||
using System.CommandLine.Binding;
|
using System.CommandLine.Binding;
|
||||||
using System.Text.Json;
|
using System.Text.Json;
|
||||||
using Microsoft.Extensions.Options;
|
using Microsoft.Extensions.Options;
|
||||||
using YaeBlog.Core.Models;
|
using YaeBlog.Models;
|
||||||
|
|
||||||
namespace YaeBlog.Commands.Binders;
|
namespace YaeBlog.Commands.Binders;
|
||||||
|
|
||||||
|
|||||||
@@ -1,8 +1,8 @@
|
|||||||
using System.CommandLine.Binding;
|
using System.CommandLine.Binding;
|
||||||
using Microsoft.Extensions.Options;
|
using Microsoft.Extensions.Options;
|
||||||
using YaeBlog.Core.Abstractions;
|
using YaeBlog.Abstraction;
|
||||||
using YaeBlog.Core.Models;
|
using YaeBlog.Models;
|
||||||
using YaeBlog.Core.Services;
|
using YaeBlog.Services;
|
||||||
using YamlDotNet.Serialization;
|
using YamlDotNet.Serialization;
|
||||||
using YamlDotNet.Serialization.NamingConventions;
|
using YamlDotNet.Serialization.NamingConventions;
|
||||||
|
|
||||||
|
|||||||
21
YaeBlog/Commands/Binders/ImageCompressServiceBinder.cs
Normal file
21
YaeBlog/Commands/Binders/ImageCompressServiceBinder.cs
Normal file
@@ -0,0 +1,21 @@
|
|||||||
|
using System.CommandLine.Binding;
|
||||||
|
using YaeBlog.Abstraction;
|
||||||
|
using YaeBlog.Services;
|
||||||
|
|
||||||
|
namespace YaeBlog.Commands.Binders;
|
||||||
|
|
||||||
|
public sealed class ImageCompressServiceBinder : BinderBase<ImageCompressService>
|
||||||
|
{
|
||||||
|
protected override ImageCompressService GetBoundValue(BindingContext bindingContext)
|
||||||
|
{
|
||||||
|
bindingContext.AddService(provider =>
|
||||||
|
{
|
||||||
|
IEssayScanService essayScanService = provider.GetRequiredService<IEssayScanService>();
|
||||||
|
ILogger<ImageCompressService> logger = provider.GetRequiredService<ILogger<ImageCompressService>>();
|
||||||
|
|
||||||
|
return new ImageCompressService(essayScanService, logger);
|
||||||
|
});
|
||||||
|
|
||||||
|
return bindingContext.GetRequiredService<ImageCompressService>();
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -1,118 +0,0 @@
|
|||||||
using System.CommandLine;
|
|
||||||
using YaeBlog.Commands.Binders;
|
|
||||||
using YaeBlog.Components;
|
|
||||||
using YaeBlog.Core.Extensions;
|
|
||||||
using YaeBlog.Core.Models;
|
|
||||||
using YaeBlog.Core.Services;
|
|
||||||
|
|
||||||
namespace YaeBlog.Commands;
|
|
||||||
|
|
||||||
public static class CommandExtensions
|
|
||||||
{
|
|
||||||
public static void AddServeCommand(this RootCommand rootCommand)
|
|
||||||
{
|
|
||||||
Command serveCommand = new("serve", "Start http server.");
|
|
||||||
rootCommand.AddCommand(serveCommand);
|
|
||||||
|
|
||||||
serveCommand.SetHandler(async context =>
|
|
||||||
{
|
|
||||||
WebApplicationBuilder builder = WebApplication.CreateBuilder();
|
|
||||||
|
|
||||||
builder.Services.AddRazorComponents()
|
|
||||||
.AddInteractiveServerComponents();
|
|
||||||
builder.Services.AddControllers();
|
|
||||||
builder.Services.AddBlazorBootstrap();
|
|
||||||
builder.AddYaeBlog();
|
|
||||||
builder.AddServer();
|
|
||||||
|
|
||||||
WebApplication application = builder.Build();
|
|
||||||
|
|
||||||
application.UseStaticFiles();
|
|
||||||
application.UseAntiforgery();
|
|
||||||
application.UseYaeBlog();
|
|
||||||
|
|
||||||
application.MapRazorComponents<App>()
|
|
||||||
.AddInteractiveServerRenderMode();
|
|
||||||
application.MapControllers();
|
|
||||||
|
|
||||||
CancellationToken token = context.GetCancellationToken();
|
|
||||||
await application.RunAsync(token);
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
public static void AddWatchCommand(this RootCommand rootCommand)
|
|
||||||
{
|
|
||||||
Command command = new("watch", "Start a blog watcher that re-render when file changes.");
|
|
||||||
rootCommand.AddCommand(command);
|
|
||||||
|
|
||||||
command.SetHandler(async context =>
|
|
||||||
{
|
|
||||||
WebApplicationBuilder builder = WebApplication.CreateBuilder();
|
|
||||||
|
|
||||||
builder.Services.AddRazorComponents()
|
|
||||||
.AddInteractiveServerComponents();
|
|
||||||
builder.Services.AddControllers();
|
|
||||||
builder.Services.AddBlazorBootstrap();
|
|
||||||
builder.AddYaeBlog();
|
|
||||||
builder.AddWatcher();
|
|
||||||
|
|
||||||
WebApplication application = builder.Build();
|
|
||||||
|
|
||||||
application.UseStaticFiles();
|
|
||||||
application.UseAntiforgery();
|
|
||||||
application.UseYaeBlog();
|
|
||||||
|
|
||||||
application.MapRazorComponents<App>()
|
|
||||||
.AddInteractiveServerRenderMode();
|
|
||||||
application.MapControllers();
|
|
||||||
|
|
||||||
CancellationToken token = context.GetCancellationToken();
|
|
||||||
await application.RunAsync(token);
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
public static void AddNewCommand(this RootCommand rootCommand)
|
|
||||||
{
|
|
||||||
Command newCommand = new("new", "Create a new blog file and image directory.");
|
|
||||||
rootCommand.AddCommand(newCommand);
|
|
||||||
|
|
||||||
Argument<string> filenameArgument = new(name: "blog name", description: "The created blog filename.");
|
|
||||||
newCommand.AddArgument(filenameArgument);
|
|
||||||
|
|
||||||
newCommand.SetHandler(async (file, _, _, essayScanService) =>
|
|
||||||
{
|
|
||||||
await essayScanService.SaveBlogContent(new BlogContent
|
|
||||||
{
|
|
||||||
FileName = file,
|
|
||||||
FileContent = string.Empty,
|
|
||||||
Metadata = new MarkdownMetadata { Title = file, Date = DateTime.Now }
|
|
||||||
});
|
|
||||||
|
|
||||||
Console.WriteLine($"Created new blog '{file}.");
|
|
||||||
}, filenameArgument, new BlogOptionsBinder(), new LoggerBinder<EssayScanService>(),
|
|
||||||
new EssayScanServiceBinder());
|
|
||||||
}
|
|
||||||
|
|
||||||
public static void AddListCommand(this RootCommand rootCommand)
|
|
||||||
{
|
|
||||||
Command command = new("list", "List all blogs");
|
|
||||||
rootCommand.Add(command);
|
|
||||||
|
|
||||||
command.SetHandler(async (_, _, essyScanService) =>
|
|
||||||
{
|
|
||||||
BlogContents contents = await essyScanService.ScanContents();
|
|
||||||
|
|
||||||
Console.WriteLine($"All {contents.Posts.Count} Posts:");
|
|
||||||
foreach (BlogContent content in contents.Posts)
|
|
||||||
{
|
|
||||||
Console.WriteLine($" - {content.FileName}");
|
|
||||||
}
|
|
||||||
|
|
||||||
Console.WriteLine($"All {contents.Drafts.Count} Drafts:");
|
|
||||||
foreach (BlogContent content in contents.Drafts)
|
|
||||||
{
|
|
||||||
Console.WriteLine($" - {content.FileName}");
|
|
||||||
}
|
|
||||||
}, new BlogOptionsBinder(), new LoggerBinder<EssayScanService>(), new EssayScanServiceBinder());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
296
YaeBlog/Commands/YaeBlogCommand.cs
Normal file
296
YaeBlog/Commands/YaeBlogCommand.cs
Normal file
@@ -0,0 +1,296 @@
|
|||||||
|
using System.CommandLine;
|
||||||
|
using Microsoft.Extensions.Options;
|
||||||
|
using YaeBlog.Abstraction;
|
||||||
|
using YaeBlog.Commands.Binders;
|
||||||
|
using YaeBlog.Components;
|
||||||
|
using YaeBlog.Extensions;
|
||||||
|
using YaeBlog.Models;
|
||||||
|
using YaeBlog.Services;
|
||||||
|
|
||||||
|
namespace YaeBlog.Commands;
|
||||||
|
|
||||||
|
public sealed class YaeBlogCommand
|
||||||
|
{
|
||||||
|
private readonly RootCommand _rootCommand = new("YaeBlog Cli");
|
||||||
|
|
||||||
|
public YaeBlogCommand()
|
||||||
|
{
|
||||||
|
AddServeCommand(_rootCommand);
|
||||||
|
AddWatchCommand(_rootCommand);
|
||||||
|
AddListCommand(_rootCommand);
|
||||||
|
AddNewCommand(_rootCommand);
|
||||||
|
AddUpdateCommand(_rootCommand);
|
||||||
|
AddPublishCommand(_rootCommand);
|
||||||
|
AddScanCommand(_rootCommand);
|
||||||
|
AddCompressCommand(_rootCommand);
|
||||||
|
}
|
||||||
|
|
||||||
|
public Task<int> RunAsync(string[] args)
|
||||||
|
{
|
||||||
|
return _rootCommand.InvokeAsync(args);
|
||||||
|
}
|
||||||
|
|
||||||
|
private static void AddServeCommand(RootCommand rootCommand)
|
||||||
|
{
|
||||||
|
Command serveCommand = new("serve", "Start http server.");
|
||||||
|
rootCommand.AddCommand(serveCommand);
|
||||||
|
|
||||||
|
serveCommand.SetHandler(async context =>
|
||||||
|
{
|
||||||
|
WebApplicationBuilder builder = WebApplication.CreateBuilder();
|
||||||
|
|
||||||
|
builder.Services.AddRazorComponents()
|
||||||
|
.AddInteractiveServerComponents();
|
||||||
|
builder.Services.AddControllers();
|
||||||
|
builder.AddYaeBlog();
|
||||||
|
builder.AddServer();
|
||||||
|
|
||||||
|
WebApplication application = builder.Build();
|
||||||
|
|
||||||
|
application.MapStaticAssets();
|
||||||
|
application.UseAntiforgery();
|
||||||
|
application.UseYaeBlog();
|
||||||
|
|
||||||
|
application.MapRazorComponents<App>()
|
||||||
|
.AddInteractiveServerRenderMode();
|
||||||
|
application.MapControllers();
|
||||||
|
|
||||||
|
CancellationToken token = context.GetCancellationToken();
|
||||||
|
await application.RunAsync(token);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
private static void AddWatchCommand(RootCommand rootCommand)
|
||||||
|
{
|
||||||
|
Command command = new("watch", "Start a blog watcher that re-render when file changes.");
|
||||||
|
rootCommand.AddCommand(command);
|
||||||
|
|
||||||
|
command.SetHandler(async context =>
|
||||||
|
{
|
||||||
|
WebApplicationBuilder builder = WebApplication.CreateBuilder();
|
||||||
|
|
||||||
|
builder.Services.AddRazorComponents()
|
||||||
|
.AddInteractiveServerComponents();
|
||||||
|
builder.Services.AddControllers();
|
||||||
|
builder.AddYaeBlog();
|
||||||
|
builder.AddWatcher();
|
||||||
|
|
||||||
|
WebApplication application = builder.Build();
|
||||||
|
|
||||||
|
application.MapStaticAssets();
|
||||||
|
application.UseAntiforgery();
|
||||||
|
application.UseYaeBlog();
|
||||||
|
|
||||||
|
application.MapRazorComponents<App>()
|
||||||
|
.AddInteractiveServerRenderMode();
|
||||||
|
application.MapControllers();
|
||||||
|
|
||||||
|
CancellationToken token = context.GetCancellationToken();
|
||||||
|
await application.RunAsync(token);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
private static void AddNewCommand(RootCommand rootCommand)
|
||||||
|
{
|
||||||
|
Command newCommand = new("new", "Create a new blog file and image directory.");
|
||||||
|
rootCommand.AddCommand(newCommand);
|
||||||
|
|
||||||
|
Argument<string> filenameArgument = new(name: "blog name", description: "The created blog filename.");
|
||||||
|
newCommand.AddArgument(filenameArgument);
|
||||||
|
|
||||||
|
newCommand.SetHandler(async (file, blogOption, _, essayScanService) =>
|
||||||
|
{
|
||||||
|
BlogContents contents = await essayScanService.ScanContents();
|
||||||
|
|
||||||
|
if (contents.Posts.Any(content => content.BlogName == file))
|
||||||
|
{
|
||||||
|
Console.WriteLine("There exists the same title blog in posts.");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
await essayScanService.SaveBlogContent(new BlogContent(
|
||||||
|
new FileInfo(Path.Combine(blogOption.Value.Root, "drafts", file + ".md")),
|
||||||
|
new MarkdownMetadata
|
||||||
|
{
|
||||||
|
Title = file,
|
||||||
|
Date = DateTimeOffset.Now.ToString("o"),
|
||||||
|
UpdateTime = DateTimeOffset.Now.ToString("o")
|
||||||
|
},
|
||||||
|
string.Empty, true, [], []));
|
||||||
|
|
||||||
|
Console.WriteLine($"Created new blog '{file}.");
|
||||||
|
}, filenameArgument, new BlogOptionsBinder(), new LoggerBinder<EssayScanService>(),
|
||||||
|
new EssayScanServiceBinder());
|
||||||
|
}
|
||||||
|
|
||||||
|
private static void AddUpdateCommand(RootCommand rootCommand)
|
||||||
|
{
|
||||||
|
Command newCommand = new("update", "Update the blog essay.");
|
||||||
|
rootCommand.AddCommand(newCommand);
|
||||||
|
|
||||||
|
Argument<string> filenameArgument = new(name: "blog name", description: "The blog filename to update.");
|
||||||
|
newCommand.AddArgument(filenameArgument);
|
||||||
|
|
||||||
|
newCommand.SetHandler(async (file, _, _, essayScanService) =>
|
||||||
|
{
|
||||||
|
Console.WriteLine("HINT: The update command only consider published blogs.");
|
||||||
|
BlogContents contents = await essayScanService.ScanContents();
|
||||||
|
|
||||||
|
BlogContent? content = contents.Posts.FirstOrDefault(c => c.BlogName == file);
|
||||||
|
if (content is null)
|
||||||
|
{
|
||||||
|
Console.WriteLine($"Target essay {file} is not exist.");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
content.Metadata.UpdateTime = DateTimeOffset.Now.ToString("o");
|
||||||
|
await essayScanService.SaveBlogContent(content, content.IsDraft);
|
||||||
|
}, filenameArgument,
|
||||||
|
new BlogOptionsBinder(), new LoggerBinder<EssayScanService>(), new EssayScanServiceBinder());
|
||||||
|
}
|
||||||
|
|
||||||
|
private static void AddListCommand(RootCommand rootCommand)
|
||||||
|
{
|
||||||
|
Command command = new("list", "List all blogs");
|
||||||
|
rootCommand.AddCommand(command);
|
||||||
|
|
||||||
|
command.SetHandler(async (_, _, essyScanService) =>
|
||||||
|
{
|
||||||
|
BlogContents contents = await essyScanService.ScanContents();
|
||||||
|
|
||||||
|
Console.WriteLine($"All {contents.Posts.Count} Posts:");
|
||||||
|
foreach (BlogContent content in contents.Posts.OrderBy(x => x.BlogName))
|
||||||
|
{
|
||||||
|
Console.WriteLine($" - {content.BlogName}");
|
||||||
|
}
|
||||||
|
|
||||||
|
Console.WriteLine($"All {contents.Drafts.Count} Drafts:");
|
||||||
|
foreach (BlogContent content in contents.Drafts.OrderBy(x => x.BlogName))
|
||||||
|
{
|
||||||
|
Console.WriteLine($" - {content.BlogName}");
|
||||||
|
}
|
||||||
|
}, new BlogOptionsBinder(), new LoggerBinder<EssayScanService>(), new EssayScanServiceBinder());
|
||||||
|
}
|
||||||
|
|
||||||
|
private static void AddScanCommand(RootCommand rootCommand)
|
||||||
|
{
|
||||||
|
Command command = new("scan", "Scan unused and not found images.");
|
||||||
|
rootCommand.AddCommand(command);
|
||||||
|
|
||||||
|
Option<bool> removeOption =
|
||||||
|
new(name: "--rm", description: "Remove unused images.", getDefaultValue: () => false);
|
||||||
|
command.AddOption(removeOption);
|
||||||
|
|
||||||
|
command.SetHandler(async (_, _, essayScanService, removeOptionValue) =>
|
||||||
|
{
|
||||||
|
BlogContents contents = await essayScanService.ScanContents();
|
||||||
|
List<BlogImageInfo> unusedImages = (from content in contents
|
||||||
|
from image in content.Images
|
||||||
|
where image is { IsUsed: false }
|
||||||
|
select image).ToList();
|
||||||
|
|
||||||
|
if (unusedImages.Count != 0)
|
||||||
|
{
|
||||||
|
Console.WriteLine("Found unused images:");
|
||||||
|
Console.WriteLine("HINT: use '--rm' to remove unused images.");
|
||||||
|
}
|
||||||
|
|
||||||
|
foreach (BlogImageInfo image in unusedImages)
|
||||||
|
{
|
||||||
|
Console.WriteLine($" - {image.File.FullName}");
|
||||||
|
}
|
||||||
|
|
||||||
|
if (removeOptionValue)
|
||||||
|
{
|
||||||
|
foreach (BlogImageInfo image in unusedImages)
|
||||||
|
{
|
||||||
|
image.File.Delete();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
Console.WriteLine("Used not existed images:");
|
||||||
|
|
||||||
|
foreach (BlogContent content in contents)
|
||||||
|
{
|
||||||
|
foreach (FileInfo file in content.NotfoundImages)
|
||||||
|
{
|
||||||
|
Console.WriteLine($"- {file.Name} in {content.BlogName}");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}, new BlogOptionsBinder(), new LoggerBinder<EssayScanService>(), new EssayScanServiceBinder(), removeOption);
|
||||||
|
}
|
||||||
|
|
||||||
|
private static void AddPublishCommand(RootCommand rootCommand)
|
||||||
|
{
|
||||||
|
Command command = new("publish", "Publish a new blog file.");
|
||||||
|
rootCommand.AddCommand(command);
|
||||||
|
|
||||||
|
Argument<string> filenameArgument = new(name: "blog name", description: "The published blog filename.");
|
||||||
|
command.AddArgument(filenameArgument);
|
||||||
|
|
||||||
|
command.SetHandler(async (blogOptions, _, essayScanService, filename) =>
|
||||||
|
{
|
||||||
|
BlogContents contents = await essayScanService.ScanContents();
|
||||||
|
|
||||||
|
BlogContent? content = (from blog in contents.Drafts
|
||||||
|
where blog.BlogName == filename
|
||||||
|
select blog).FirstOrDefault();
|
||||||
|
|
||||||
|
if (content is null)
|
||||||
|
{
|
||||||
|
Console.WriteLine("Target blog does not exist.");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
// 设置发布的时间
|
||||||
|
content.Metadata.Date = DateTimeOffset.Now.ToString("o");
|
||||||
|
content.Metadata.UpdateTime = DateTimeOffset.Now.ToString("o");
|
||||||
|
|
||||||
|
// 将选中的博客文件复制到posts
|
||||||
|
await essayScanService.SaveBlogContent(content, isDraft: false);
|
||||||
|
|
||||||
|
// 复制图片文件夹
|
||||||
|
DirectoryInfo sourceImageDirectory =
|
||||||
|
new(Path.Combine(blogOptions.Value.Root, "drafts", content.BlogName));
|
||||||
|
DirectoryInfo targetImageDirectory =
|
||||||
|
new(Path.Combine(blogOptions.Value.Root, "posts", content.BlogName));
|
||||||
|
|
||||||
|
if (sourceImageDirectory.Exists)
|
||||||
|
{
|
||||||
|
targetImageDirectory.Create();
|
||||||
|
foreach (FileInfo file in sourceImageDirectory.EnumerateFiles())
|
||||||
|
{
|
||||||
|
file.CopyTo(Path.Combine(targetImageDirectory.FullName, file.Name), true);
|
||||||
|
}
|
||||||
|
|
||||||
|
sourceImageDirectory.Delete(true);
|
||||||
|
}
|
||||||
|
|
||||||
|
// 删除原始的文件
|
||||||
|
FileInfo sourceBlogFile = new(Path.Combine(blogOptions.Value.Root, "drafts", content.BlogName + ".md"));
|
||||||
|
sourceBlogFile.Delete();
|
||||||
|
}, new BlogOptionsBinder(),
|
||||||
|
new LoggerBinder<EssayScanService>(), new EssayScanServiceBinder(), filenameArgument);
|
||||||
|
}
|
||||||
|
|
||||||
|
private static void AddCompressCommand(RootCommand rootCommand)
|
||||||
|
{
|
||||||
|
Command command = new("compress", "Compress png/jpeg image to webp image to reduce size.");
|
||||||
|
rootCommand.Add(command);
|
||||||
|
|
||||||
|
Option<bool> dryRunOption = new("--dry-run", description: "Dry run the compression task but not write.",
|
||||||
|
getDefaultValue: () => false);
|
||||||
|
command.AddOption(dryRunOption);
|
||||||
|
|
||||||
|
command.SetHandler(ImageCommandHandler,
|
||||||
|
new BlogOptionsBinder(), new LoggerBinder<EssayScanService>(), new LoggerBinder<ImageCompressService>(),
|
||||||
|
new EssayScanServiceBinder(), new ImageCompressServiceBinder(), dryRunOption);
|
||||||
|
}
|
||||||
|
|
||||||
|
private static async Task ImageCommandHandler(IOptions<BlogOptions> _, ILogger<EssayScanService> _1,
|
||||||
|
ILogger<ImageCompressService> _2,
|
||||||
|
IEssayScanService _3, ImageCompressService imageCompressService, bool dryRun)
|
||||||
|
{
|
||||||
|
await imageCompressService.Compress(dryRun);
|
||||||
|
}
|
||||||
|
}
|
||||||
9
YaeBlog/Components/Anchor.razor
Normal file
9
YaeBlog/Components/Anchor.razor
Normal file
@@ -0,0 +1,9 @@
|
|||||||
|
<a href="@Address" class="text-blue-600" target="@(NewPage ? "_blank" : "_self")">@Text</a>
|
||||||
|
|
||||||
|
@code {
|
||||||
|
[Parameter] public string? Address { get; set; }
|
||||||
|
|
||||||
|
[Parameter] public string? Text { get; set; }
|
||||||
|
|
||||||
|
[Parameter] public bool NewPage { get; set; }
|
||||||
|
}
|
||||||
@@ -1,28 +1,46 @@
|
|||||||
<!DOCTYPE html>
|
<!DOCTYPE html>
|
||||||
<html lang="en">
|
<html lang="zh">
|
||||||
|
|
||||||
<head>
|
<head>
|
||||||
<meta charset="utf-8"/>
|
<meta charset="utf-8"/>
|
||||||
|
<meta lang="zh-CN"/>
|
||||||
<meta name="viewport" content="width=device-width, initial-scale=1.0"/>
|
<meta name="viewport" content="width=device-width, initial-scale=1.0"/>
|
||||||
<base href="/"/>
|
<base href="/"/>
|
||||||
<link rel="stylesheet" href="YaeBlog.styles.css"/>
|
<link rel="stylesheet" href="@Assets["YaeBlog.styles.css"]"/>
|
||||||
<link rel="icon" href="images/favicon.ico"/>
|
<link rel="icon" href="@Assets["images/favicon.ico"]"/>
|
||||||
<link rel="stylesheet" href="bootstrap.min.css"/>
|
<link rel="stylesheet" href="@Assets["tailwind.g.css"]"/>
|
||||||
<link rel="stylesheet" href="bootstrap-icons.min.css"/>
|
<style>
|
||||||
<link rel="stylesheet" href="_content/Blazor.Bootstrap/blazor.bootstrap.css"/>
|
@@font-face {
|
||||||
<link rel="stylesheet" href="globals.css"/>
|
font-family: "Font Awesome 7 Free";
|
||||||
|
font-style: normal;
|
||||||
|
font-weight: 400;
|
||||||
|
font-display: block;
|
||||||
|
src: url(@Assets["fonts/fa-regular-400.woff2"]) format("woff2");
|
||||||
|
}
|
||||||
|
|
||||||
|
@@font-face {
|
||||||
|
font-family: "Font Awesome 7 Free";
|
||||||
|
font-style: normal;
|
||||||
|
font-weight: 900;
|
||||||
|
font-display: block;
|
||||||
|
src: url(@Assets["fonts/fa-solid-900.woff2"]) format("woff2")
|
||||||
|
}
|
||||||
|
|
||||||
|
@@font-face {
|
||||||
|
font-family: "Font Awesome 7 Brands";
|
||||||
|
font-style: normal;
|
||||||
|
font-weight: 400;
|
||||||
|
font-display: block;
|
||||||
|
src: url(@Assets["fonts/fa-brands-400.woff2"]) format("woff2")
|
||||||
|
}
|
||||||
|
</style>
|
||||||
<HeadOutlet/>
|
<HeadOutlet/>
|
||||||
|
<ImportMap/>
|
||||||
</head>
|
</head>
|
||||||
|
|
||||||
<body>
|
<body>
|
||||||
<Routes/>
|
<Routes/>
|
||||||
|
<script src="@Assets["_framework/blazor.web.js"]"></script>
|
||||||
<script src="_framework/blazor.web.js"></script>
|
|
||||||
<script src="bootstrap.bundle.min.js"></script>
|
|
||||||
<script src="clipboard.min.js"></script>
|
|
||||||
<script>
|
|
||||||
const clipboard = new ClipboardJS('.btn');
|
|
||||||
</script>
|
|
||||||
</body>
|
</body>
|
||||||
|
|
||||||
</html>
|
</html>
|
||||||
|
|||||||
29
YaeBlog/Components/AppreciationCode.razor
Normal file
29
YaeBlog/Components/AppreciationCode.razor
Normal file
@@ -0,0 +1,29 @@
|
|||||||
|
<div class="flex flex-wrap justify-center gap-12 max-w-md md:max-w-lg">
|
||||||
|
<div class="relative w-40 h-48 md:w-48 md:w-48 overflow-hidden
|
||||||
|
transition-all duration-300 ease-out hover:scale-125 group">
|
||||||
|
<img
|
||||||
|
src="./images/wechat-code.jpeg"
|
||||||
|
alt="微信赞赏码"
|
||||||
|
class="w-full h-full object-cover"
|
||||||
|
/>
|
||||||
|
<div class="absolute -bottom-8 left-0 right-0 text-center
|
||||||
|
text-white bg-black opacity-60 text-sm font-medium
|
||||||
|
backdrop-blur-sm group-hover:bottom-2 transition-all duration-300">
|
||||||
|
请我喝奶茶<br/>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div class="relative w-40 h-48 md:w-48 md:h-48 overflow-hidden
|
||||||
|
transition-all duration-300 ease-out hover:scale-125 group">
|
||||||
|
<img
|
||||||
|
src="./images/alipay-code.jpeg"
|
||||||
|
alt="支付宝赞赏码"
|
||||||
|
class="w-full h-full object-cover"/>
|
||||||
|
<div class="absolute -bottom-8 left-0 right-0 text-center
|
||||||
|
text-white bg-black opacity-60 text-sm font-medium
|
||||||
|
backdrop-blur-sm group-hover:bottom-2 transition-all duration-300">
|
||||||
|
请我吃晚饭<br/>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
</div>
|
||||||
@@ -1,57 +1,49 @@
|
|||||||
@using YaeBlog.Core.Abstractions
|
@using YaeBlog.Abstraction
|
||||||
@using YaeBlog.Core.Models
|
@using YaeBlog.Models
|
||||||
|
|
||||||
@inject IEssayContentService Contents
|
@inject IEssayContentService Contents
|
||||||
@inject BlogOptions Options
|
@inject BlogOptions Options
|
||||||
|
|
||||||
<div class="container">
|
<div class="flex flex-col">
|
||||||
<div class="row justify-content-center">
|
<div class="p-10">
|
||||||
<div class="col-auto p-4">
|
<img src="images/avatar.png" alt="Ricardo's Avatar" class="h-auto max-w-full"/>
|
||||||
<Image Src="images/avatar.png" Alt="Ricardo's avatar"/>
|
|
||||||
</div>
|
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div class="row justify-content-center p-3">
|
<div class="px-10 py-2 text-xl">
|
||||||
<div class="col-auto fs-4">
|
|
||||||
“奇奇怪怪东西的聚合地”
|
“奇奇怪怪东西的聚合地”
|
||||||
</div>
|
</div>
|
||||||
</div>
|
|
||||||
|
|
||||||
<div class="row justify-content-between px-2 py-1 fs-5">
|
<div class="flex flex-row justify-between px-6 py-2 text-xl">
|
||||||
<div class="col-auto">
|
<div>
|
||||||
文章
|
文章
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div class="col-auto">
|
<a href="/blog/archives/">
|
||||||
<a href="/blog/archives">
|
<div>
|
||||||
@(Contents.Essays.Count)
|
@(Contents.Count)
|
||||||
|
</div>
|
||||||
</a>
|
</a>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
|
||||||
|
|
||||||
<div class="row justify-content-between px-2 py-1 fs-5">
|
<div class="flex flex-row justify-between px-6 py-2 text-xl">
|
||||||
<div class="col-auto">
|
<div>
|
||||||
标签
|
标签
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div class="col-auto">
|
<a href="/blog/tags/">
|
||||||
<a href="/blog/tags">
|
<div>
|
||||||
@(Contents.Tags.Count)
|
@(Contents.Tags.Count)
|
||||||
|
</div>
|
||||||
</a>
|
</a>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
|
||||||
|
|
||||||
<div class="row justify-content-start fs-5" style="padding-top: 2em">
|
<div class="text-xl px-2 py-2">
|
||||||
<div class="col-auto">
|
|
||||||
广而告之
|
广而告之
|
||||||
</div>
|
</div>
|
||||||
</div>
|
|
||||||
|
|
||||||
<div class="row">
|
<div class="px-6">
|
||||||
<div class="col">
|
<p class="text-lg">
|
||||||
<p style="text-indent: 2em">
|
|
||||||
@(Options.Announcement)
|
@(Options.Announcement)
|
||||||
</p>
|
</p>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
|
||||||
</div>
|
</div>
|
||||||
|
|||||||
@@ -1,40 +1,29 @@
|
|||||||
@using System.Text.Encodings.Web
|
@using System.Text.Encodings.Web
|
||||||
@using YaeBlog.Core.Models
|
@using YaeBlog.Models
|
||||||
|
|
||||||
<div class="container p-3">
|
<div class="flex flex-col p-3">
|
||||||
<div class="row fs-2 fw-bold py-2 essay-title">
|
<div class="text-3xl font-bold py-2">
|
||||||
<a href="/blog/essays/@(Essay.FileName)" target="_blank">@(Essay.Title)</a>
|
<a href="@(Essay.EssayLink)">@(Essay.Title)</a>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div class="row p-2 justify-content-start">
|
<div class="p-2 flex flex-row justify-content-start gap-2">
|
||||||
<div class="col-auto fw-light">
|
<div class="font-light">
|
||||||
@(Essay.PublishTime.ToString("yyyy-MM-dd"))
|
@(Essay.PublishTime.ToString("yyyy-MM-dd"))
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
@foreach (string key in Essay.Tags)
|
@foreach (string key in Essay.Tags)
|
||||||
{
|
{
|
||||||
<div class="col-auto">
|
<div class="text-sky-600">
|
||||||
<a href="/blog/tags/?tagName=@(UrlEncoder.Default.Encode(key))">
|
<Anchor Address="@($"/blog/tags/?tagName={UrlEncoder.Default.Encode(key)}")" Text="@($"# {key}")"/>
|
||||||
# @key
|
|
||||||
</a>
|
|
||||||
</div>
|
</div>
|
||||||
}
|
}
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div class="row p-2">
|
<div class="p-2">
|
||||||
<div class="col">
|
|
||||||
@(Essay.Description)
|
@(Essay.Description)
|
||||||
</div>
|
</div>
|
||||||
</div>
|
|
||||||
|
|
||||||
<div class="row">
|
|
||||||
<div class="col border-bottom">
|
|
||||||
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
@code {
|
@code {
|
||||||
[Parameter]
|
[Parameter] public required BlogEssay Essay { get; set; }
|
||||||
public required BlogEssay Essay { get; set; }
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,3 +0,0 @@
|
|||||||
.essay-title a {
|
|
||||||
color: var(--bs-body-color);
|
|
||||||
}
|
|
||||||
@@ -1,14 +1,30 @@
|
|||||||
<div class="row align-items-end text-center">
|
<div class="flex flex-col text-center py-2">
|
||||||
<div class="row">
|
<div>
|
||||||
<p class="fs-6">
|
<p class="text-md">
|
||||||
2021 - @(DateTimeOffset.Now.Year) © <a href="https://rrricardo.top" target="_blank">Ricardo Ren</a>,
|
2021 - @(DateTimeOffset.Now.Year) ©
|
||||||
由 <a href="https://dotnet.microsoft.com/zh-cn/" target="_blank">.NET @(Environment.Version)</a> 驱动。
|
<Anchor Address="https://rrricardot.top" Text="初冬的朝阳"/>
|
||||||
|
,由
|
||||||
|
<Anchor Address="https://dotnet.microsoft.com" Text="@DotnetVersion"/>
|
||||||
|
驱动。
|
||||||
|
</p>
|
||||||
|
<p class="text-md">
|
||||||
|
Build Commit #
|
||||||
|
<Anchor Address="@BuildCommitUrl" Text="@BuildCommitId"/>
|
||||||
</p>
|
</p>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div class="row">
|
<div>
|
||||||
<p class="fs-6">
|
<p class="text-md">
|
||||||
<a href="https://beian.miit.gov.cn" target="_blank">蜀ICP备2022004429号-1</a>
|
<Anchor Address="https://beian.miit.gov.cn" Text="蜀ICP备2022004429号-1" NewPage="true"/>
|
||||||
</p>
|
</p>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
@code
|
||||||
|
{
|
||||||
|
private static string DotnetVersion => $".NET {Environment.Version}";
|
||||||
|
|
||||||
|
private static string BuildCommitId => Environment.GetEnvironmentVariable("COMMIT_ID") ?? "local_build";
|
||||||
|
|
||||||
|
private static string BuildCommitUrl => $"https://git.rrricardo.top/jackfiled/YaeBlog/commit/{BuildCommitId}";
|
||||||
|
}
|
||||||
|
|||||||
28
YaeBlog/Components/Layout/BlogLayout.razor
Normal file
28
YaeBlog/Components/Layout/BlogLayout.razor
Normal file
@@ -0,0 +1,28 @@
|
|||||||
|
@inherits LayoutComponentBase
|
||||||
|
|
||||||
|
@attribute [StreamRendering]
|
||||||
|
|
||||||
|
<main class="container mx-auto flex flex-col min-h-screen">
|
||||||
|
<div class="grid grid-cols-3 mx-3">
|
||||||
|
<div class="md:col-span-2 col-span-3 h-20 flex items-center">
|
||||||
|
<a href="/blog/">
|
||||||
|
<span class="text-blue-600 text-2xl">Ricardo's Blog</span>
|
||||||
|
</a>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div class="md:col-span-1 col-span-3 h-20 flex items-center">
|
||||||
|
<div class="flex flex-row w-full px-2 md:justify-center justify-end text-xl gap-3">
|
||||||
|
<Anchor Address="/blog/archives" Text="归档"/>
|
||||||
|
<Anchor Address="/blog/tags/" Text="标签"/>
|
||||||
|
<Anchor Address="/about/" Text="关于" NewPage="@(true)"/>
|
||||||
|
<Anchor Address="/friends" Text="友链" NewPage="@(true)"/>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div class="px-4 py-2 flex-grow">
|
||||||
|
@Body
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<Foonter/>
|
||||||
|
</main>
|
||||||
36
YaeBlog/Components/Layout/MainLayout.razor
Normal file
36
YaeBlog/Components/Layout/MainLayout.razor
Normal file
@@ -0,0 +1,36 @@
|
|||||||
|
@inherits LayoutComponentBase
|
||||||
|
|
||||||
|
<main class="container mx-auto min-h-screen flex flex-col">
|
||||||
|
<div class="grid grid-cols-4">
|
||||||
|
<div class="px-2 md:col-span-3 col-span-4 h-20 flex items-center">
|
||||||
|
<a href="/" class="text-2xl">
|
||||||
|
<h4 class="text-blue-600">Ricardo's Index</h4>
|
||||||
|
</a>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div class="md:col-span-1 col-span-4 h-20 flex items-center">
|
||||||
|
<div class="flex flex-row w-full px-2 md:justify-center justify-end text-xl gap-3">
|
||||||
|
<Anchor
|
||||||
|
Address="/blog/"
|
||||||
|
Text="博客"
|
||||||
|
NewPage="@(true)"/>
|
||||||
|
|
||||||
|
<Anchor
|
||||||
|
Address="/about/"
|
||||||
|
Text="关于"/>
|
||||||
|
|
||||||
|
<Anchor
|
||||||
|
Address="/friends"
|
||||||
|
Text="友链"/>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div class="px-4 mx-auto flex-grow">
|
||||||
|
<div class="py-2">
|
||||||
|
@Body
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<Foonter/>
|
||||||
|
</main>
|
||||||
@@ -1,36 +1,41 @@
|
|||||||
@using YaeBlog.Core.Models
|
<div class="px-4 py-8 border border-sky-700 rounded-md bg-sky-200">
|
||||||
|
<div class="flex flex-col gap-3 text-md">
|
||||||
@inject BlogOptions Options
|
<div>
|
||||||
|
文章作者:<a href="https://rrricardo.top" target="_blank" class="text-blue-600">Ricardo Ren</a>
|
||||||
<div class="row px-2 py-4 copyright border border-primary rounded-1 bg-primary-subtle">
|
|
||||||
<div class="col">
|
|
||||||
<div class="row p-1">
|
|
||||||
<div class="col">
|
|
||||||
文章作者:<a href="https://rrricardo.top" target="_blank">Ricardo Ren</a>
|
|
||||||
</div>
|
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div class="row p-1">
|
<div>
|
||||||
<div class="col">
|
|
||||||
文章地址:
|
文章地址:
|
||||||
<a href="/blog/essays/@(EssayAddress)" target="_blank">
|
<a href="/blog/essays/@(EssayFilename)" target="_blank" class="text-blue-600">
|
||||||
@($"https://rrricardo.top/blog/essays/{EssayAddress}")
|
@($"https://rrricardo.top/blog/essays/{EssayFilename}")
|
||||||
</a>
|
</a>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
<div>
|
||||||
|
版权声明:本博客所有文章除特别声明外,均采用
|
||||||
|
<a href="https://creativecommons.org/licenses/by-nc-sa/4.0/" target="_blank" class="text-blue-600">
|
||||||
|
CC BY-NC-SA 4.0
|
||||||
|
</a>
|
||||||
|
许可协议,诸位读者如有兴趣可任意转载,不必征询许可,但请注明“转载自
|
||||||
|
<a href="https://rrricardo.top/blog/" target="_blank" class="text-blue-600">
|
||||||
|
Ricardo's Blog
|
||||||
|
</a>”。
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div class="row p-1">
|
<div class="flex flex-col">
|
||||||
<div class="col">
|
<div class="flex justify-center">
|
||||||
版权声明:本博客所有文章除特别声明外,均采用
|
<p>如果觉得不错的话,可以支持一下作者哦~</p>
|
||||||
<a href="https://creativecommons.org/licenses/by-nc-sa/4.0/" target="_blank">CC BY-NC-SA 4.0</a>
|
</div>
|
||||||
许可协议,转载请注明来自
|
|
||||||
<a href="https://rrricardo.top/blog/" target="_blank">Ricardo's Blog</a>。
|
<div class="flex justify-center">
|
||||||
|
<AppreciationCode/>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
@code
|
@code
|
||||||
{
|
{
|
||||||
[Parameter] public string? EssayAddress { get; set; }
|
[Parameter] public string? EssayFilename { get; set; }
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,2 +0,0 @@
|
|||||||
.copyright {
|
|
||||||
}
|
|
||||||
22
YaeBlog/Components/PageAnchor.razor
Normal file
22
YaeBlog/Components/PageAnchor.razor
Normal file
@@ -0,0 +1,22 @@
|
|||||||
|
@if (Selected)
|
||||||
|
{
|
||||||
|
<div class="border rounded-lg shadow-neutral-500 bg-sky-400 w-8 h-8 inline-block leading-8 text-center">
|
||||||
|
<span class="text-white">@(Text)</span>
|
||||||
|
</div>
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
<a href="@Address">
|
||||||
|
<div class="border rounded-lg shadow-neutral-500 w-8 h-8 inline-block leading-8 text-center">
|
||||||
|
<span>@(Text)</span>
|
||||||
|
</div>
|
||||||
|
</a>
|
||||||
|
}
|
||||||
|
|
||||||
|
@code {
|
||||||
|
[Parameter] public string? Address { get; set; }
|
||||||
|
|
||||||
|
[Parameter] public string? Text { get; set; }
|
||||||
|
|
||||||
|
[Parameter] public bool Selected { get; set; }
|
||||||
|
}
|
||||||
92
YaeBlog/Components/Pages/About.razor
Normal file
92
YaeBlog/Components/Pages/About.razor
Normal file
@@ -0,0 +1,92 @@
|
|||||||
|
@page "/about"
|
||||||
|
|
||||||
|
<PageTitle>
|
||||||
|
关于
|
||||||
|
</PageTitle>
|
||||||
|
|
||||||
|
<div class="flex flex-col">
|
||||||
|
<div>
|
||||||
|
<h1 class="text-4xl">关于</h1>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div class="py-4">
|
||||||
|
<span class="italic">把字刻在石头上!(・’ω’・)</span>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div class="flex flex-col p-2">
|
||||||
|
<div class="flex flex-col p-2">
|
||||||
|
<div class="pb-2">
|
||||||
|
<h3 class="text-2xl">关于我</h3>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div class="mx-4">
|
||||||
|
<div class="my-4">
|
||||||
|
<p class="my-2">
|
||||||
|
正在明光村幼儿园附属研究生院攻读计算机科学与技术的硕士学位,研究AI编译器和异构编译器。
|
||||||
|
</p>
|
||||||
|
|
||||||
|
<p class="my-2">
|
||||||
|
一般在互联网上使用<span class="italic">初冬的朝阳</span>或者<span
|
||||||
|
class="italic">jackfiled</span>的名字活动。
|
||||||
|
<span class="line-through">(都是ICP备案过的人了,网名似乎没有太大的用处)</span>
|
||||||
|
</p>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div class="my-4">
|
||||||
|
<p class="my-1">
|
||||||
|
主要是一个C#程序员,目前也在尝试写一点Rust。
|
||||||
|
<span class="line-through">
|
||||||
|
总体上对于编程语言的态度是“大家都是我的翅膀.jpg”。
|
||||||
|
</span>
|
||||||
|
</p>
|
||||||
|
<p class="my-1">
|
||||||
|
写过一些前后端分离的项目,对于RISC-V相关的开发项目也颇感兴趣。
|
||||||
|
</p>
|
||||||
|
<p class="my-1">
|
||||||
|
常常因为现实的压力而写一些C/C++,现在就在和MLIR殊死搏斗。
|
||||||
|
</p>
|
||||||
|
<p class="my-1">
|
||||||
|
日常使用Arch Linux。
|
||||||
|
</p>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div class="my-2">
|
||||||
|
<p class="my-1">
|
||||||
|
100%社恐。日常生活是宅在电脑前面自言自语。
|
||||||
|
</p>
|
||||||
|
<p class="my-1">
|
||||||
|
兴趣活动是读书和看番,目前在玩戴森球计划和三角洲。
|
||||||
|
</p>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div class="flex flex-col p-2">
|
||||||
|
<div class="pb-2">
|
||||||
|
<h3 class="text-2xl">关于本站</h3>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div class="mx-4">
|
||||||
|
<div class="my-4">
|
||||||
|
<p class="my-2">
|
||||||
|
本站肇始于2021年下半年,在开始的两年中个人网站和博客是分别的两个网站,个人网站是裸HTML写的,博客是用
|
||||||
|
<Anchor Text="Hexo" Address="https://hexo.io" NewPage="@(true)"/>
|
||||||
|
的。
|
||||||
|
</p>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div class="my-4">
|
||||||
|
<p class="my-2">
|
||||||
|
2024年,我们决定使用.NET技术完全重构两个网站,合二为一。虽然目前这个版本还是一个半成品,但是我们一定会努力的~(确信。
|
||||||
|
</p>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div class="my-4">
|
||||||
|
<p class="my-2">
|
||||||
|
2025年,我们将使用的样式库从Bootstrap迁移到Tailwind CSS,将现代的前端技术同Blazor结合起来。
|
||||||
|
</p>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
63
YaeBlog/Components/Pages/Archives.razor
Normal file
63
YaeBlog/Components/Pages/Archives.razor
Normal file
@@ -0,0 +1,63 @@
|
|||||||
|
@page "/blog/archives"
|
||||||
|
@using YaeBlog.Abstraction
|
||||||
|
@using YaeBlog.Models
|
||||||
|
|
||||||
|
@inject IEssayContentService Contents
|
||||||
|
|
||||||
|
<PageTitle>
|
||||||
|
归档
|
||||||
|
</PageTitle>
|
||||||
|
|
||||||
|
<div class="flex flex-col">
|
||||||
|
<div>
|
||||||
|
<h1 class="text-4xl">归档</h1>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div class="py-4">
|
||||||
|
<span class="italic">
|
||||||
|
时光图书馆,黑历史集散地。(๑◔‿◔๑)
|
||||||
|
</span>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
@foreach (IGrouping<DateTimeOffset, BlogEssay> group in _essays)
|
||||||
|
{
|
||||||
|
<div class="p-2">
|
||||||
|
<div class="flex flex-col">
|
||||||
|
<div>
|
||||||
|
<h3 class="text-xl">@(group.Key.Year)</h3>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div class="px-4 py-4 flex flex-col">
|
||||||
|
@foreach (BlogEssay essay in group)
|
||||||
|
{
|
||||||
|
<a href="@($"/blog/essays/{essay.FileName}")">
|
||||||
|
<div class="flex flex-row p-2 mx-1 rounded-lg hover:bg-gray-300">
|
||||||
|
<div class="w-20">
|
||||||
|
@(essay.PublishTime.ToString("MM月dd日"))
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div>
|
||||||
|
<span class="text-blue-600">
|
||||||
|
@(essay.Title)
|
||||||
|
</span>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</a>
|
||||||
|
}
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
}
|
||||||
|
</div>
|
||||||
|
|
||||||
|
@code {
|
||||||
|
private readonly List<IGrouping<DateTimeOffset, BlogEssay>> _essays = [];
|
||||||
|
|
||||||
|
protected override void OnInitialized()
|
||||||
|
{
|
||||||
|
base.OnInitialized();
|
||||||
|
|
||||||
|
_essays.AddRange(from essay in Contents.Essays
|
||||||
|
group essay by new DateTimeOffset(essay.PublishTime.Year, 1, 1,0, 0, 0, TimeSpan.Zero));
|
||||||
|
}
|
||||||
|
}
|
||||||
59
YaeBlog/Components/Pages/BlogIndex.razor
Normal file
59
YaeBlog/Components/Pages/BlogIndex.razor
Normal file
@@ -0,0 +1,59 @@
|
|||||||
|
@page "/blog"
|
||||||
|
@using YaeBlog.Abstraction
|
||||||
|
@using YaeBlog.Models
|
||||||
|
|
||||||
|
@inject IEssayContentService Contents
|
||||||
|
@inject NavigationManager NavigationInstance
|
||||||
|
|
||||||
|
<PageTitle>
|
||||||
|
Ricardo's Blog
|
||||||
|
</PageTitle>
|
||||||
|
|
||||||
|
<div>
|
||||||
|
<div class="grid grid-cols-4">
|
||||||
|
<div class="col-span-4 md:col-span-3">
|
||||||
|
@foreach (BlogEssay essay in _essays)
|
||||||
|
{
|
||||||
|
<EssayCard Essay="@(essay)"/>
|
||||||
|
}
|
||||||
|
|
||||||
|
<Pagination BaseUrl="/blog/" Page="_page" PageCount="_pageCount"/>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div class="col-span-4 md:col-span-1">
|
||||||
|
<BlogInformationCard/>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
@code {
|
||||||
|
|
||||||
|
[SupplyParameterFromQuery] private int? Page { get; set; }
|
||||||
|
|
||||||
|
private readonly List<BlogEssay> _essays = [];
|
||||||
|
private const int EssaysPerPage = 8;
|
||||||
|
private int _pageCount = 1;
|
||||||
|
private int _page = 1;
|
||||||
|
|
||||||
|
protected override void OnInitialized()
|
||||||
|
{
|
||||||
|
_page = Page ?? 1;
|
||||||
|
_pageCount = Contents.Count / EssaysPerPage + 1;
|
||||||
|
(_pageCount, int reminder) = int.DivRem(Contents.Count, EssaysPerPage);
|
||||||
|
if (reminder > 0)
|
||||||
|
{
|
||||||
|
_pageCount += 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (EssaysPerPage * _page > Contents.Count + EssaysPerPage)
|
||||||
|
{
|
||||||
|
NavigationInstance.NavigateTo("/NotFount");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
_essays.AddRange(Contents.Essays
|
||||||
|
.Skip((_page - 1) * EssaysPerPage)
|
||||||
|
.Take(EssaysPerPage));
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
132
YaeBlog/Components/Pages/Essays.razor
Normal file
132
YaeBlog/Components/Pages/Essays.razor
Normal file
@@ -0,0 +1,132 @@
|
|||||||
|
@page "/blog/essays/{BlogKey}"
|
||||||
|
@using System.Text.Encodings.Web
|
||||||
|
@using YaeBlog.Abstraction
|
||||||
|
@using YaeBlog.Models
|
||||||
|
|
||||||
|
@inject IEssayContentService Contents
|
||||||
|
@inject NavigationManager NavigationInstance
|
||||||
|
|
||||||
|
<PageTitle>
|
||||||
|
@(_essay!.Title)
|
||||||
|
</PageTitle>
|
||||||
|
|
||||||
|
<div class="flex flex-col py-8">
|
||||||
|
<div>
|
||||||
|
<div class="flex flex-col items-center">
|
||||||
|
<div>
|
||||||
|
<h1 id="title" class="text-4xl">@(_essay!.Title)</h1>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div class="flex flex-row gap-4 py-2">
|
||||||
|
@foreach (string tag in _essay!.Tags)
|
||||||
|
{
|
||||||
|
<div class="text-sky-500">
|
||||||
|
<a href="/blog/tags/?tagName=@(UrlEncoder.Default.Encode(tag))">
|
||||||
|
# @(tag)
|
||||||
|
</a>
|
||||||
|
</div>
|
||||||
|
}
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div class="font-light pb-1">
|
||||||
|
发布于: @(_essay.PublishTime.ToString("yyyy年MM月dd日 HH:mm:ss"))
|
||||||
|
</div>
|
||||||
|
|
||||||
|
@if (_essay.UpdateTime != _essay.PublishTime)
|
||||||
|
{
|
||||||
|
<div class="font-light pb-1">
|
||||||
|
更新于: @(_essay.UpdateTime.ToString("yyyy年MM月dd日 HH:mm:ss"))
|
||||||
|
</div>
|
||||||
|
}
|
||||||
|
|
||||||
|
<div class="font-light pb-1">
|
||||||
|
总字数:@(_essay!.WordCount)字,预计阅读时间 @(_essay!.ReadTime)
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div class="grid grid-cols-3">
|
||||||
|
<div class="col-span-3 md:col-span-1">
|
||||||
|
<div class="flex flex-col sticky top-20 px-8 pt-20">
|
||||||
|
<div>
|
||||||
|
<h3 class="text-2xl">文章目录</h3>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div>
|
||||||
|
@foreach (BlogHeadline level2 in _headline!.Children)
|
||||||
|
{
|
||||||
|
<div class="py-2 pl-3">
|
||||||
|
<Anchor Address="@(GenerateSelectorUrl(level2.SelectorId))"
|
||||||
|
Text="@(level2.Title)"/>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
@foreach (BlogHeadline level3 in level2.Children)
|
||||||
|
{
|
||||||
|
<div class="py-2 pl-6">
|
||||||
|
<Anchor Address="@(GenerateSelectorUrl(level3.SelectorId))"
|
||||||
|
Text="@(level3.Title)"/>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
@foreach (BlogHeadline level4 in level3.Children)
|
||||||
|
{
|
||||||
|
<div class="py-2 pl-9">
|
||||||
|
<Anchor Address="@(GenerateSelectorUrl(level4.SelectorId))"
|
||||||
|
Text="@(level4.Title)"/>
|
||||||
|
</div>
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
</div>
|
||||||
|
|
||||||
|
@if (_headline!.Children.Count == 0)
|
||||||
|
{
|
||||||
|
<div class="row">
|
||||||
|
<div class="col fst-italic">
|
||||||
|
坏了(* Ŏ∀Ŏ),没有在文章中识别到目录
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
}
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div class="col-span-3 md:col-span-2 flex flex-col gap-3">
|
||||||
|
<div>
|
||||||
|
@((MarkupString)_essay!.HtmlContent)
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div>
|
||||||
|
<LicenseDisclaimer EssayFilename="@BlogKey"/>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
@code {
|
||||||
|
[Parameter] public string? BlogKey { get; set; }
|
||||||
|
|
||||||
|
private BlogEssay? _essay;
|
||||||
|
|
||||||
|
private BlogHeadline? _headline;
|
||||||
|
|
||||||
|
protected override void OnInitialized()
|
||||||
|
{
|
||||||
|
base.OnInitialized();
|
||||||
|
|
||||||
|
if (string.IsNullOrWhiteSpace(BlogKey))
|
||||||
|
{
|
||||||
|
NavigationInstance.NavigateTo("/NotFound");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!Contents.TryGetEssay(BlogKey, out _essay))
|
||||||
|
{
|
||||||
|
NavigationInstance.NavigateTo("/NotFound");
|
||||||
|
}
|
||||||
|
|
||||||
|
_headline = Contents.Headlines[BlogKey];
|
||||||
|
}
|
||||||
|
|
||||||
|
private string GenerateSelectorUrl(string selectorId)
|
||||||
|
=> $"/blog/essays/{BlogKey!}#{selectorId}";
|
||||||
|
|
||||||
|
}
|
||||||
49
YaeBlog/Components/Pages/Friends.razor
Normal file
49
YaeBlog/Components/Pages/Friends.razor
Normal file
@@ -0,0 +1,49 @@
|
|||||||
|
@page "/friends"
|
||||||
|
@using YaeBlog.Models
|
||||||
|
@inject BlogOptions Options
|
||||||
|
|
||||||
|
<PageTitle>
|
||||||
|
友链
|
||||||
|
</PageTitle>
|
||||||
|
|
||||||
|
<div class="flex flex-col">
|
||||||
|
<div>
|
||||||
|
<h1 class="text-4xl">
|
||||||
|
友链
|
||||||
|
</h1>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div class="py-4">
|
||||||
|
欢迎所有人联系我添加友链!(´。✪ω✪。`)
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div class="grid grid-cols-4 g-4 p-2">
|
||||||
|
@foreach (FriendLink link in Options.Links)
|
||||||
|
{
|
||||||
|
<div>
|
||||||
|
<a href="@(link.Link)" target="_blank" class="mx-5">
|
||||||
|
<div class="flex flex-row">
|
||||||
|
<div class="basis-1/3">
|
||||||
|
<img src="@(link.AvatarImage)" alt="@($"Avatar of {link.Name}")"
|
||||||
|
class="w-full h-auto rounded-full">
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div class="flex flex-col basis-2/3 px-2">
|
||||||
|
<div class="text-lg">
|
||||||
|
@(link.Name)
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div class="text-sm italic">
|
||||||
|
@(link.Description)
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</a>
|
||||||
|
</div>
|
||||||
|
}
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
@code {
|
||||||
|
|
||||||
|
}
|
||||||
97
YaeBlog/Components/Pages/Index.razor
Normal file
97
YaeBlog/Components/Pages/Index.razor
Normal file
@@ -0,0 +1,97 @@
|
|||||||
|
@page "/"
|
||||||
|
@using YaeBlog.Abstraction
|
||||||
|
@using YaeBlog.Models
|
||||||
|
@inject IEssayContentService EssayContentInstance
|
||||||
|
|
||||||
|
<PageTitle>
|
||||||
|
Ricardo's Index
|
||||||
|
</PageTitle>
|
||||||
|
|
||||||
|
<div class="mx-14 lg:mx-20">
|
||||||
|
<div class="grid grid-cols-3 py-4 lg:mx-20">
|
||||||
|
<div class="col-span-3 md:col-span-1 lg:m-10">
|
||||||
|
<img src="@Assets["images/avatar.png"]" alt="Ricardo's Avatar"
|
||||||
|
class="h-auto max-w-full rounded-md border border-gray-400">
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div class="col-span-3 md:col-span-2">
|
||||||
|
<div class="flex flex-col gap-y-3 items-center md:items-start md:px-6">
|
||||||
|
<div class="">
|
||||||
|
<div class="text-3xl font-bold">初冬的朝阳</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div class="">
|
||||||
|
<p class="text-lg">a.k.a jackfiled</p>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div class="">
|
||||||
|
<p class="text-lg italic">世界很大,时间很长。</p>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div class="flex flex-row gap-2">
|
||||||
|
<a href="https://github.com/jackfiled" target="_blank">
|
||||||
|
<div>
|
||||||
|
<span class="fa-brands fa-github text-xl"></span>
|
||||||
|
</div>
|
||||||
|
</a>
|
||||||
|
|
||||||
|
<a href="https://git.rrricardo.top/jackfiled/" target="_blank">
|
||||||
|
<div>
|
||||||
|
<span class="gitea-icon text-xl"></span>
|
||||||
|
</div>
|
||||||
|
</a>
|
||||||
|
|
||||||
|
<a href="https://space.bilibili.com/378831522" target="_blank">
|
||||||
|
<div>
|
||||||
|
<span class="fa-brands fa-bilibili text-xl"></span>
|
||||||
|
</div>
|
||||||
|
</a>
|
||||||
|
|
||||||
|
<a href="https://xhslink.com/m/5GVDzyKf3De" target="_blank">
|
||||||
|
<div>
|
||||||
|
<span class="rednote-icon text-xl"></span>
|
||||||
|
</div>
|
||||||
|
</a>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div class="py-5">
|
||||||
|
<p class="text-lg">恕我不能亲自为您沏茶,还是非常欢迎您来,能在广阔的互联网世界中发现这里实属不易。</p>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div class="text-lg pt-2">
|
||||||
|
<p class="py-1">
|
||||||
|
正在攻读计算机科学与技术的硕士学位,研究方向是AI编译和异构编译!
|
||||||
|
</p>
|
||||||
|
<p class="py-1">
|
||||||
|
喜欢优雅的代码,香甜的蛋糕等等一切可爱的事物。
|
||||||
|
</p>
|
||||||
|
<p class="py-1">
|
||||||
|
<Anchor Address="/blog/" Text="个人博客"/>中收集了我的各种奇思妙想,如果感兴趣欢迎移步。
|
||||||
|
@if (_latestEssay is not null)
|
||||||
|
{
|
||||||
|
<span>
|
||||||
|
最新的一期博客关注 <Anchor Text="@(_latestEssay.Title)" Address="@(_latestEssay.EssayLink)"/>。
|
||||||
|
</span>
|
||||||
|
}
|
||||||
|
</p>
|
||||||
|
<p class="py-1">
|
||||||
|
日常的代码开发使用自建的<Anchor Text="Gitea" Address="https://git.rrricardo.top" NewPage="@(true)"/>进行,个人
|
||||||
|
开发的各种项目都可以在上面找到。
|
||||||
|
</p>
|
||||||
|
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
@code {
|
||||||
|
private BlogEssay? _latestEssay;
|
||||||
|
|
||||||
|
protected override void OnInitialized()
|
||||||
|
{
|
||||||
|
base.OnInitialized();
|
||||||
|
_latestEssay = EssayContentInstance.Essays.OrderByDescending(e => e.UpdateTime).FirstOrDefault();
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
47
YaeBlog/Components/Pages/Index.razor.css
Normal file
47
YaeBlog/Components/Pages/Index.razor.css
Normal file
@@ -0,0 +1,47 @@
|
|||||||
|
.fa-brands {
|
||||||
|
font-family: "Font Awesome 7 Brands", "Font Awesome 7 Free";
|
||||||
|
font-style: normal;
|
||||||
|
font-synthesis: none;
|
||||||
|
font-variant: normal;
|
||||||
|
line-height: 1;
|
||||||
|
text-rendering: auto;
|
||||||
|
font-weight: 400;
|
||||||
|
}
|
||||||
|
|
||||||
|
.fa-github::before {
|
||||||
|
content: "\f09b";
|
||||||
|
color: #24292e;
|
||||||
|
}
|
||||||
|
|
||||||
|
.fa-bilibili::before {
|
||||||
|
content: "\e3d9";
|
||||||
|
color: #00AEEC;
|
||||||
|
}
|
||||||
|
|
||||||
|
.gitea-icon {
|
||||||
|
display: inline-block;
|
||||||
|
vertical-align: -0.125em;
|
||||||
|
width: 1em;
|
||||||
|
height: 1em;
|
||||||
|
|
||||||
|
background-image: url("https://docs.gitea.com/img/gitea.svg");
|
||||||
|
background-size: contain;
|
||||||
|
background-repeat: no-repeat;
|
||||||
|
background-position: center;
|
||||||
|
|
||||||
|
user-select: none;
|
||||||
|
}
|
||||||
|
|
||||||
|
.rednote-icon {
|
||||||
|
display: inline-block;
|
||||||
|
vertical-align: -0.125em;
|
||||||
|
width: 1em;
|
||||||
|
height: 1em;
|
||||||
|
|
||||||
|
background-image: url("images/xiaohongshu-seeklogo.svg");
|
||||||
|
background-size: contain;
|
||||||
|
background-repeat: no-repeat;
|
||||||
|
background-position: center;
|
||||||
|
|
||||||
|
user-select: none;
|
||||||
|
}
|
||||||
@@ -4,8 +4,8 @@
|
|||||||
啊~ 页面走丢啦~
|
啊~ 页面走丢啦~
|
||||||
</PageTitle>
|
</PageTitle>
|
||||||
|
|
||||||
<div class="container">
|
<div>
|
||||||
<h3>NotFound!</h3>
|
<h3 class="text-3xl">NotFound!</h3>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
@code {
|
@code {
|
||||||
@@ -1,7 +1,7 @@
|
|||||||
@page "/blog/tags/"
|
@page "/blog/tags/"
|
||||||
@using System.Text.Encodings.Web
|
@using System.Text.Encodings.Web
|
||||||
@using YaeBlog.Core.Abstractions
|
@using YaeBlog.Abstraction
|
||||||
@using YaeBlog.Core.Models
|
@using YaeBlog.Models
|
||||||
|
|
||||||
@inject IEssayContentService Contents
|
@inject IEssayContentService Contents
|
||||||
@inject NavigationManager NavigationInstance
|
@inject NavigationManager NavigationInstance
|
||||||
@@ -10,24 +10,22 @@
|
|||||||
@(TagName ?? "标签")
|
@(TagName ?? "标签")
|
||||||
</PageTitle>
|
</PageTitle>
|
||||||
|
|
||||||
<div class="container">
|
<div class="flex flex-col">
|
||||||
<div class="row">
|
<div>
|
||||||
<div class="col">
|
|
||||||
@if (TagName is null)
|
@if (TagName is null)
|
||||||
{
|
{
|
||||||
<h1>标签</h1>
|
<h1 class="text-4xl">标签</h1>
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
<h2>@(TagName)</h2>
|
<h2 class="text-2xl">@(TagName)</h2>
|
||||||
}
|
}
|
||||||
</div>
|
</div>
|
||||||
</div>
|
|
||||||
|
|
||||||
<div class="row">
|
<div class="py-4">
|
||||||
<div class="col fst-italic py-4">
|
<span class="italic">
|
||||||
在野外游荡的指针,走向未知的方向。٩(๑˃̵ᴗ˂̵๑)۶
|
在野外游荡的指针,走向未知的方向。٩(๑˃̵ᴗ˂̵๑)۶
|
||||||
</div>
|
</span>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
@if (TagName is null)
|
@if (TagName is null)
|
||||||
@@ -38,19 +36,17 @@
|
|||||||
Contents.Tags.OrderByDescending(pair => pair.Value.Count))
|
Contents.Tags.OrderByDescending(pair => pair.Value.Count))
|
||||||
{
|
{
|
||||||
<li class="p-2">
|
<li class="p-2">
|
||||||
|
<div class="flex flex-row">
|
||||||
<a href="/blog/tags/?tagName=@(pair.Key.UrlEncodedTagName)">
|
<a href="/blog/tags/?tagName=@(pair.Key.UrlEncodedTagName)">
|
||||||
<div class="container fs-5">
|
<div class="text-sky-600 text-lg">
|
||||||
<div class="row">
|
|
||||||
<div class="col-auto">
|
|
||||||
# @(pair.Key.TagName)
|
# @(pair.Key.TagName)
|
||||||
</div>
|
</div>
|
||||||
|
</a>
|
||||||
|
|
||||||
<div class="col-auto tag-count">
|
<div class="mx-2 px-1 text-lg bg-gray-300 rounded-lg">
|
||||||
@(pair.Value.Count)
|
@(pair.Value.Count)
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
|
||||||
</a>
|
|
||||||
</li>
|
</li>
|
||||||
}
|
}
|
||||||
</ul>
|
</ul>
|
||||||
46
YaeBlog/Components/Pagination.razor
Normal file
46
YaeBlog/Components/Pagination.razor
Normal file
@@ -0,0 +1,46 @@
|
|||||||
|
<div class="flex flex-row justify-center gap-3">
|
||||||
|
@if (Page != 1)
|
||||||
|
{
|
||||||
|
<PageAnchor Address="@GenerateAddress(Page - 1)" Text="<"/>
|
||||||
|
}
|
||||||
|
|
||||||
|
@if (Page == 1)
|
||||||
|
{
|
||||||
|
<PageAnchor Address="@GenerateAddress(1)" Text="1" Selected="@true"/>
|
||||||
|
|
||||||
|
<PageAnchor Address="@GenerateAddress(2)" Text="2"/>
|
||||||
|
|
||||||
|
<PageAnchor Address="@GenerateAddress(3)" Text="3"/>
|
||||||
|
}
|
||||||
|
else if (Page == PageCount)
|
||||||
|
{
|
||||||
|
<PageAnchor Address="@GenerateAddress(PageCount - 2)" Text="@($"{PageCount - 2}")"/>
|
||||||
|
|
||||||
|
<PageAnchor Address="@GenerateAddress(PageCount - 1)" Text="@($"{PageCount - 1}")"/>
|
||||||
|
|
||||||
|
<PageAnchor Address="@GenerateAddress(PageCount)" Text="@($"{PageCount}")" Selected="@true"/>
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
<PageAnchor Address="@GenerateAddress(Page - 1)" Text="@($"{Page - 1}")"/>
|
||||||
|
|
||||||
|
<PageAnchor Address="@GenerateAddress(Page)" Text="@($"{Page}")" Selected="@true"/>
|
||||||
|
|
||||||
|
<PageAnchor Address="@GenerateAddress(Page + 1)" Text="@($"{Page + 1}")"/>
|
||||||
|
}
|
||||||
|
|
||||||
|
@if (Page != PageCount)
|
||||||
|
{
|
||||||
|
<PageAnchor Address="@GenerateAddress(Page + 1)" Text=">"/>
|
||||||
|
}
|
||||||
|
</div>
|
||||||
|
|
||||||
|
@code {
|
||||||
|
[Parameter] public string? BaseUrl { get; set; }
|
||||||
|
|
||||||
|
[Parameter] public int PageCount { get; set; }
|
||||||
|
|
||||||
|
[Parameter] public int Page { get; set; }
|
||||||
|
|
||||||
|
private string GenerateAddress(int page) => $"{BaseUrl}?page={page}";
|
||||||
|
}
|
||||||
@@ -6,3 +6,4 @@
|
|||||||
@using static Microsoft.AspNetCore.Components.Web.RenderMode
|
@using static Microsoft.AspNetCore.Components.Web.RenderMode
|
||||||
@using Microsoft.AspNetCore.Components.Web.Virtualization
|
@using Microsoft.AspNetCore.Components.Web.Virtualization
|
||||||
@using Microsoft.JSInterop
|
@using Microsoft.JSInterop
|
||||||
|
@using YaeBlog.Components
|
||||||
@@ -9,12 +9,20 @@ public class FilesController : ControllerBase
|
|||||||
[HttpGet("{*filename}")]
|
[HttpGet("{*filename}")]
|
||||||
public IActionResult Images(string filename)
|
public IActionResult Images(string filename)
|
||||||
{
|
{
|
||||||
|
// 这里疑似有点太愚蠢了
|
||||||
string contentType = "image/png";
|
string contentType = "image/png";
|
||||||
|
|
||||||
if (filename.EndsWith("jpg") || filename.EndsWith("jpeg"))
|
if (filename.EndsWith("jpg") || filename.EndsWith("jpeg"))
|
||||||
{
|
{
|
||||||
contentType = "image/jpeg";
|
contentType = "image/jpeg";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (filename.EndsWith("svg"))
|
||||||
|
{
|
||||||
|
contentType = "image/svg+xml";
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
FileInfo imageFile = new(filename);
|
FileInfo imageFile = new(filename);
|
||||||
|
|
||||||
if (!imageFile.Exists)
|
if (!imageFile.Exists)
|
||||||
|
|||||||
53
YaeBlog/Directory.Build.targets
Normal file
53
YaeBlog/Directory.Build.targets
Normal file
@@ -0,0 +1,53 @@
|
|||||||
|
<Project>
|
||||||
|
<PropertyGroup>
|
||||||
|
<ClientAssetsRestoreCommand Condition="'$(ClientAssesRestoreCommand)' == ''">pnpm install</ClientAssetsRestoreCommand>
|
||||||
|
<ClientAssetsBuildCommand Condition="'$(ClientAssetsBuildCommand)' == ''">pnpm run build</ClientAssetsBuildCommand>
|
||||||
|
<ClientAssetsBuildOutputParameter Condition="'$(ClientAssetsBuildOutputParameter)' == ''">--output</ClientAssetsBuildOutputParameter>
|
||||||
|
</PropertyGroup>
|
||||||
|
|
||||||
|
<PropertyGroup>
|
||||||
|
<_RestoreClientAssetsBeforeTargets Condition="'$(TargetFramework)' == ''">DispatchToInnerBuilds</_RestoreClientAssetsBeforeTargets>
|
||||||
|
</PropertyGroup>
|
||||||
|
|
||||||
|
<Target Name="RestoreClientAssets" BeforeTargets="$(_RestoreClientAssetsBeforeTargets)">
|
||||||
|
<Message Importance="high" Text="Running $(ClientAssetsRestoreCommand)"/>
|
||||||
|
<Exec Command="$(ClientAssetsRestoreCommand)"/>
|
||||||
|
</Target>
|
||||||
|
|
||||||
|
<Target Name="BuildClientAssets" DependsOnTargets="RestoreClientAssets" BeforeTargets="AssignTargetPaths">
|
||||||
|
<PropertyGroup>
|
||||||
|
<_ClientAssetsOutputFullPath>$([System.IO.Path]::GetFullPath('$(IntermediateOutputPath)ClientAssets'))</_ClientAssetsOutputFullPath>
|
||||||
|
</PropertyGroup>
|
||||||
|
|
||||||
|
<MakeDir Directories="$(_ClientAssetsOutputFullPath)"/>
|
||||||
|
<Exec Command="$(ClientAssetsBuildCommand) $(ClientAssetsBuildOutputParameter) $(_ClientAssetsOutputFullPath)"/>
|
||||||
|
|
||||||
|
<ItemGroup>
|
||||||
|
<_ClientAssetsBuildOutput Include="$(IntermediateOutputPath)ClientAssets\**"/>
|
||||||
|
</ItemGroup>
|
||||||
|
</Target>
|
||||||
|
|
||||||
|
<Target Name="DefineClientAssets" AfterTargets="BuildClientAssets" DependsOnTargets="ResolveStaticWebAssetsConfiguration">
|
||||||
|
<ItemGroup>
|
||||||
|
<FileWrites Include="@(_ClientAssetsBuildOutput)"/>
|
||||||
|
</ItemGroup>
|
||||||
|
|
||||||
|
<DefineStaticWebAssets
|
||||||
|
CandidateAssets="@(_ClientAssetsBuildOutput)"
|
||||||
|
SourceId="$(PackageId)"
|
||||||
|
SourceType="Computed"
|
||||||
|
ContentRoot="$(_ClientAssetsOutputFullPath)"
|
||||||
|
BasePath="$(StaticWebAssetBasePath)"
|
||||||
|
>
|
||||||
|
<Output TaskParameter="Assets" ItemName="StaticWebAsset"/>
|
||||||
|
<Output TaskParameter="Assets" ItemName="_ClientAssetsStaticWebAsset"/>
|
||||||
|
</DefineStaticWebAssets>
|
||||||
|
|
||||||
|
<DefineStaticWebAssetEndpoints
|
||||||
|
CandidateAssets="@(_ClientAssetsStaticWebAsset)"
|
||||||
|
ContentTypeMappings="@(StaticWebAssetContentTypeMapping)"
|
||||||
|
>
|
||||||
|
<Output TaskParameter="Endpoints" ItemName="StaticWebAssetEndpoint" />
|
||||||
|
</DefineStaticWebAssetEndpoints>
|
||||||
|
</Target>
|
||||||
|
</Project>
|
||||||
@@ -1,7 +1,10 @@
|
|||||||
FROM mcr.microsoft.com/dotnet/aspnet:8.0
|
FROM mcr.azure.cn/dotnet/aspnet:10.0
|
||||||
|
|
||||||
|
ARG COMMIT_ID
|
||||||
|
ENV COMMIT_ID=${COMMIT_ID}
|
||||||
|
|
||||||
WORKDIR /app
|
WORKDIR /app
|
||||||
COPY bin/Release/net8.0/publish/ ./
|
COPY bin/Release/net10.0/publish/ ./
|
||||||
COPY source/ ./source/
|
COPY source/ ./source/
|
||||||
COPY appsettings.json .
|
COPY appsettings.json .
|
||||||
|
|
||||||
|
|||||||
12
YaeBlog/Exceptions/BlogCommandException.cs
Normal file
12
YaeBlog/Exceptions/BlogCommandException.cs
Normal file
@@ -0,0 +1,12 @@
|
|||||||
|
namespace YaeBlog.Core.Exceptions;
|
||||||
|
|
||||||
|
public class BlogCommandException : Exception
|
||||||
|
{
|
||||||
|
public BlogCommandException(string message) : base(message)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
public BlogCommandException(string message, Exception innerException) : base(message, innerException)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
}
|
||||||
18
YaeBlog/Extensions/AngleSharpExtensions.cs
Normal file
18
YaeBlog/Extensions/AngleSharpExtensions.cs
Normal file
@@ -0,0 +1,18 @@
|
|||||||
|
using AngleSharp.Dom;
|
||||||
|
|
||||||
|
namespace YaeBlog.Extensions;
|
||||||
|
|
||||||
|
public static class AngleSharpExtensions
|
||||||
|
{
|
||||||
|
public static IEnumerable<IElement> EnumerateParentElements(this IElement element)
|
||||||
|
{
|
||||||
|
IElement? e = element.ParentElement;
|
||||||
|
|
||||||
|
while (e is not null)
|
||||||
|
{
|
||||||
|
IElement c = e;
|
||||||
|
e = e.ParentElement;
|
||||||
|
yield return c;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -1,9 +1,8 @@
|
|||||||
using Markdig;
|
using Markdig;
|
||||||
using Microsoft.Extensions.DependencyInjection;
|
|
||||||
using YamlDotNet.Serialization;
|
using YamlDotNet.Serialization;
|
||||||
using YamlDotNet.Serialization.NamingConventions;
|
using YamlDotNet.Serialization.NamingConventions;
|
||||||
|
|
||||||
namespace YaeBlog.Core.Extensions;
|
namespace YaeBlog.Extensions;
|
||||||
|
|
||||||
public static class ServiceCollectionExtensions
|
public static class ServiceCollectionExtensions
|
||||||
{
|
{
|
||||||
@@ -1,13 +1,11 @@
|
|||||||
using AngleSharp;
|
using AngleSharp;
|
||||||
using Microsoft.AspNetCore.Builder;
|
|
||||||
using Microsoft.Extensions.DependencyInjection;
|
|
||||||
using Microsoft.Extensions.Options;
|
using Microsoft.Extensions.Options;
|
||||||
using YaeBlog.Core.Abstractions;
|
using YaeBlog.Abstraction;
|
||||||
using YaeBlog.Core.Models;
|
using YaeBlog.Services;
|
||||||
using YaeBlog.Core.Processors;
|
using YaeBlog.Models;
|
||||||
using YaeBlog.Core.Services;
|
using YaeBlog.Processors;
|
||||||
|
|
||||||
namespace YaeBlog.Core.Extensions;
|
namespace YaeBlog.Extensions;
|
||||||
|
|
||||||
public static class WebApplicationBuilderExtensions
|
public static class WebApplicationBuilderExtensions
|
||||||
{
|
{
|
||||||
@@ -19,14 +17,13 @@ public static class WebApplicationBuilderExtensions
|
|||||||
|
|
||||||
builder.Services.AddMarkdig();
|
builder.Services.AddMarkdig();
|
||||||
builder.Services.AddYamlParser();
|
builder.Services.AddYamlParser();
|
||||||
builder.Services.AddSingleton<IConfiguration>(_ => Configuration.Default);
|
builder.Services.AddSingleton<AngleSharp.IConfiguration>(_ => Configuration.Default);
|
||||||
builder.Services.AddSingleton<IEssayScanService, EssayScanService>();
|
builder.Services.AddSingleton<IEssayScanService, EssayScanService>();
|
||||||
builder.Services.AddSingleton<RendererService>();
|
builder.Services.AddSingleton<RendererService>();
|
||||||
builder.Services.AddSingleton<IEssayContentService, EssayContentService>();
|
builder.Services.AddSingleton<IEssayContentService, EssayContentService>();
|
||||||
builder.Services.AddTransient<ImagePostRenderProcessor>();
|
builder.Services.AddTransient<ImagePostRenderProcessor>();
|
||||||
builder.Services.AddTransient<CodeBlockPostRenderProcessor>();
|
|
||||||
builder.Services.AddTransient<TablePostRenderProcessor>();
|
|
||||||
builder.Services.AddTransient<HeadlinePostRenderProcessor>();
|
builder.Services.AddTransient<HeadlinePostRenderProcessor>();
|
||||||
|
builder.Services.AddTransient<EssayStylesPostRenderProcessor>();
|
||||||
builder.Services.AddTransient<BlogOptions>(provider =>
|
builder.Services.AddTransient<BlogOptions>(provider =>
|
||||||
provider.GetRequiredService<IOptions<BlogOptions>>().Value);
|
provider.GetRequiredService<IOptions<BlogOptions>>().Value);
|
||||||
|
|
||||||
@@ -1,19 +1,16 @@
|
|||||||
using Microsoft.AspNetCore.Builder;
|
using YaeBlog.Abstraction;
|
||||||
using Microsoft.Extensions.DependencyInjection;
|
using YaeBlog.Processors;
|
||||||
using YaeBlog.Core.Abstractions;
|
using YaeBlog.Services;
|
||||||
using YaeBlog.Core.Processors;
|
|
||||||
using YaeBlog.Core.Services;
|
|
||||||
|
|
||||||
namespace YaeBlog.Core.Extensions;
|
namespace YaeBlog.Extensions;
|
||||||
|
|
||||||
public static class WebApplicationExtensions
|
public static class WebApplicationExtensions
|
||||||
{
|
{
|
||||||
public static void UseYaeBlog(this WebApplication application)
|
public static void UseYaeBlog(this WebApplication application)
|
||||||
{
|
{
|
||||||
application.UsePostRenderProcessor<ImagePostRenderProcessor>();
|
application.UsePostRenderProcessor<ImagePostRenderProcessor>();
|
||||||
application.UsePostRenderProcessor<CodeBlockPostRenderProcessor>();
|
|
||||||
application.UsePostRenderProcessor<TablePostRenderProcessor>();
|
|
||||||
application.UsePostRenderProcessor<HeadlinePostRenderProcessor>();
|
application.UsePostRenderProcessor<HeadlinePostRenderProcessor>();
|
||||||
|
application.UsePostRenderProcessor<EssayStylesPostRenderProcessor>();
|
||||||
}
|
}
|
||||||
|
|
||||||
private static void UsePreRenderProcessor<T>(this WebApplication application) where T : IPreRenderProcessor
|
private static void UsePreRenderProcessor<T>(this WebApplication application) where T : IPreRenderProcessor
|
||||||
@@ -1,63 +0,0 @@
|
|||||||
@inherits LayoutComponentBase
|
|
||||||
|
|
||||||
@attribute [StreamRendering]
|
|
||||||
|
|
||||||
<main class="container">
|
|
||||||
<div class="row d-none d-xl-flex" style="height: 80px">
|
|
||||||
<div class="px-2 col-9">
|
|
||||||
<a href="/blog/" class="p-2">
|
|
||||||
<h4>Ricardo's Blog</h4>
|
|
||||||
</a>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<div class="col-3 d-flex justify-content-around align-items-center">
|
|
||||||
<a href="/blog/" class="p-2">
|
|
||||||
<h5>首页</h5>
|
|
||||||
</a>
|
|
||||||
|
|
||||||
<a href="/blog/archives/" class="p-2">
|
|
||||||
<h5>归档</h5>
|
|
||||||
</a>
|
|
||||||
|
|
||||||
<a href="/blog/tags/" class="p-2">
|
|
||||||
<h5>标签</h5>
|
|
||||||
</a>
|
|
||||||
|
|
||||||
<a href="/blog/about/" class="p-2">
|
|
||||||
<h5>关于</h5>
|
|
||||||
</a>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<div class="row d-xl-none">
|
|
||||||
<div class="px-2 col-12">
|
|
||||||
<a href="/blog/" class="p-2">
|
|
||||||
<h4>Ricardo's Blog</h4>
|
|
||||||
</a>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<div class="px-2 col-12 justify-content-end d-flex">
|
|
||||||
<a href="/blog/" class="p-2">
|
|
||||||
<h5>首页</h5>
|
|
||||||
</a>
|
|
||||||
|
|
||||||
<a href="/blog/archives/" class="p-2">
|
|
||||||
<h5>归档</h5>
|
|
||||||
</a>
|
|
||||||
|
|
||||||
<a href="/blog/tags/" class="p-2">
|
|
||||||
<h5>标签</h5>
|
|
||||||
</a>
|
|
||||||
|
|
||||||
<a href="/blog/about/" class="p-2">
|
|
||||||
<h5>关于</h5>
|
|
||||||
</a>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<div class="row px-4 py-2">
|
|
||||||
@Body
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<Foonter/>
|
|
||||||
</main>
|
|
||||||
@@ -1,25 +0,0 @@
|
|||||||
@inherits LayoutComponentBase
|
|
||||||
|
|
||||||
<main class="container">
|
|
||||||
<div class="row" style="height: 80px">
|
|
||||||
<div class="px-2 col-8">
|
|
||||||
<a href="/" class="p-2">
|
|
||||||
<h4>Ricardo's Index</h4>
|
|
||||||
</a>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<div class="col-4 d-flex justify-content-around align-items-center">
|
|
||||||
<a href="mailto://shicangjuner@outlook.com" class="p-2" target="_blank">
|
|
||||||
<h5>E-mail</h5>
|
|
||||||
</a>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<div class="row px-4 center">
|
|
||||||
<div class="py-2">
|
|
||||||
@Body
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<Foonter/>
|
|
||||||
</main>
|
|
||||||
@@ -1,8 +0,0 @@
|
|||||||
.center {
|
|
||||||
margin: 0 auto;
|
|
||||||
max-width: 48em;
|
|
||||||
min-height: calc(100vh - 80px);
|
|
||||||
position: relative;
|
|
||||||
display: flex;
|
|
||||||
flex-direction: column;
|
|
||||||
}
|
|
||||||
20
YaeBlog/Models/BlogContent.cs
Normal file
20
YaeBlog/Models/BlogContent.cs
Normal file
@@ -0,0 +1,20 @@
|
|||||||
|
namespace YaeBlog.Models;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 单个博客文件的所有数据和元数据
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="BlogFile">博客文件</param>
|
||||||
|
/// <param name="Metadata">文件中的MD元数据</param>
|
||||||
|
/// <param name="Content">文件内容</param>
|
||||||
|
/// <param name="IsDraft">是否为草稿</param>
|
||||||
|
/// <param name="Images">博客中使用的文件</param>
|
||||||
|
public record BlogContent(
|
||||||
|
FileInfo BlogFile,
|
||||||
|
MarkdownMetadata Metadata,
|
||||||
|
string Content,
|
||||||
|
bool IsDraft,
|
||||||
|
List<BlogImageInfo> Images,
|
||||||
|
List<FileInfo> NotfoundImages)
|
||||||
|
{
|
||||||
|
public string BlogName => BlogFile.Name.Split('.')[0];
|
||||||
|
}
|
||||||
12
YaeBlog/Models/BlogContents.cs
Normal file
12
YaeBlog/Models/BlogContents.cs
Normal file
@@ -0,0 +1,12 @@
|
|||||||
|
using System.Collections;
|
||||||
|
using System.Collections.Concurrent;
|
||||||
|
|
||||||
|
namespace YaeBlog.Models;
|
||||||
|
|
||||||
|
public record BlogContents(ConcurrentBag<BlogContent> Drafts, ConcurrentBag<BlogContent> Posts)
|
||||||
|
: IEnumerable<BlogContent>
|
||||||
|
{
|
||||||
|
public IEnumerator<BlogContent> GetEnumerator() => Posts.Concat(Drafts).GetEnumerator();
|
||||||
|
|
||||||
|
IEnumerator IEnumerable.GetEnumerator() => GetEnumerator();
|
||||||
|
}
|
||||||
@@ -1,4 +1,4 @@
|
|||||||
namespace YaeBlog.Core.Models;
|
namespace YaeBlog.Models;
|
||||||
|
|
||||||
public class BlogEssay : IComparable<BlogEssay>
|
public class BlogEssay : IComparable<BlogEssay>
|
||||||
{
|
{
|
||||||
@@ -6,7 +6,11 @@ public class BlogEssay : IComparable<BlogEssay>
|
|||||||
|
|
||||||
public required string FileName { get; init; }
|
public required string FileName { get; init; }
|
||||||
|
|
||||||
public required DateTime PublishTime { get; init; }
|
public required bool IsDraft { get; init; }
|
||||||
|
|
||||||
|
public required DateTimeOffset PublishTime { get; init; }
|
||||||
|
|
||||||
|
public required DateTimeOffset UpdateTime { get; init; }
|
||||||
|
|
||||||
public required string Description { get; init; }
|
public required string Description { get; init; }
|
||||||
|
|
||||||
@@ -18,13 +22,17 @@ public class BlogEssay : IComparable<BlogEssay>
|
|||||||
|
|
||||||
public required string HtmlContent { get; init; }
|
public required string HtmlContent { get; init; }
|
||||||
|
|
||||||
|
public string EssayLink => $"/blog/essays/{FileName}";
|
||||||
|
|
||||||
public BlogEssay WithNewHtmlContent(string newHtmlContent)
|
public BlogEssay WithNewHtmlContent(string newHtmlContent)
|
||||||
{
|
{
|
||||||
var essay = new BlogEssay
|
var essay = new BlogEssay
|
||||||
{
|
{
|
||||||
Title = Title,
|
Title = Title,
|
||||||
FileName = FileName,
|
FileName = FileName,
|
||||||
|
IsDraft = IsDraft,
|
||||||
PublishTime = PublishTime,
|
PublishTime = PublishTime,
|
||||||
|
UpdateTime = UpdateTime,
|
||||||
Description = Description,
|
Description = Description,
|
||||||
WordCount = WordCount,
|
WordCount = WordCount,
|
||||||
ReadTime = ReadTime,
|
ReadTime = ReadTime,
|
||||||
@@ -39,10 +47,16 @@ public class BlogEssay : IComparable<BlogEssay>
|
|||||||
{
|
{
|
||||||
if (other is null)
|
if (other is null)
|
||||||
{
|
{
|
||||||
return 1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
return PublishTime.CompareTo(other.PublishTime);
|
// 草稿文章应当排在前面
|
||||||
|
if (IsDraft != other.IsDraft)
|
||||||
|
{
|
||||||
|
return IsDraft ? -1 : 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
return other.PublishTime.CompareTo(PublishTime);
|
||||||
}
|
}
|
||||||
|
|
||||||
public override string ToString()
|
public override string ToString()
|
||||||
@@ -1,4 +1,4 @@
|
|||||||
namespace YaeBlog.Core.Models;
|
namespace YaeBlog.Models;
|
||||||
|
|
||||||
public class BlogHeadline(string title, string selectorId)
|
public class BlogHeadline(string title, string selectorId)
|
||||||
{
|
{
|
||||||
44
YaeBlog/Models/BlogImageInfo.cs
Normal file
44
YaeBlog/Models/BlogImageInfo.cs
Normal file
@@ -0,0 +1,44 @@
|
|||||||
|
using System.Text;
|
||||||
|
|
||||||
|
namespace YaeBlog.Models;
|
||||||
|
|
||||||
|
public record BlogImageInfo(FileInfo File, long Width, long Height, string MineType, byte[] Content, bool IsUsed)
|
||||||
|
: IComparable<BlogImageInfo>
|
||||||
|
{
|
||||||
|
public int Size => Content.Length;
|
||||||
|
|
||||||
|
public override string ToString()
|
||||||
|
{
|
||||||
|
StringBuilder builder = new();
|
||||||
|
|
||||||
|
builder.AppendLine($"Blog image {File.Name}:");
|
||||||
|
builder.AppendLine($"\tWidth: {Width}; Height: {Height}");
|
||||||
|
builder.AppendLine($"\tSize: {FormatSize()}");
|
||||||
|
builder.AppendLine($"\tImage Format: {MineType}");
|
||||||
|
|
||||||
|
return builder.ToString();
|
||||||
|
}
|
||||||
|
|
||||||
|
public int CompareTo(BlogImageInfo? other)
|
||||||
|
{
|
||||||
|
if (other is null)
|
||||||
|
{
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
return other.Size.CompareTo(Size);
|
||||||
|
}
|
||||||
|
|
||||||
|
private string FormatSize()
|
||||||
|
{
|
||||||
|
double size = Size;
|
||||||
|
if (size / 1024 > 3)
|
||||||
|
{
|
||||||
|
size /= 1024;
|
||||||
|
|
||||||
|
return size / 1024 > 3 ? $"{size / 1024}MB" : $"{size}KB";
|
||||||
|
}
|
||||||
|
|
||||||
|
return $"{size}B";
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -1,4 +1,4 @@
|
|||||||
namespace YaeBlog.Core.Models;
|
namespace YaeBlog.Models;
|
||||||
|
|
||||||
public class BlogOptions
|
public class BlogOptions
|
||||||
{
|
{
|
||||||
@@ -1,6 +1,6 @@
|
|||||||
using System.Text.Encodings.Web;
|
using System.Text.Encodings.Web;
|
||||||
|
|
||||||
namespace YaeBlog.Core.Models;
|
namespace YaeBlog.Models;
|
||||||
|
|
||||||
public class EssayTag(string tagName) : IEquatable<EssayTag>
|
public class EssayTag(string tagName) : IEquatable<EssayTag>
|
||||||
{
|
{
|
||||||
@@ -1,4 +1,4 @@
|
|||||||
namespace YaeBlog.Core.Models;
|
namespace YaeBlog.Models;
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// 友链模型类
|
/// 友链模型类
|
||||||
@@ -1,10 +1,12 @@
|
|||||||
namespace YaeBlog.Core.Models;
|
namespace YaeBlog.Models;
|
||||||
|
|
||||||
public class MarkdownMetadata
|
public class MarkdownMetadata
|
||||||
{
|
{
|
||||||
public string? Title { get; set; }
|
public string? Title { get; set; }
|
||||||
|
|
||||||
public DateTime? Date { get; set; }
|
public string? Date { get; set; }
|
||||||
|
|
||||||
|
public string? UpdateTime { get; set; }
|
||||||
|
|
||||||
public List<string>? Tags { get; set; }
|
public List<string>? Tags { get; set; }
|
||||||
}
|
}
|
||||||
@@ -1,146 +0,0 @@
|
|||||||
@page "/blog/about"
|
|
||||||
@using YaeBlog.Core.Models
|
|
||||||
|
|
||||||
@inject BlogOptions Options
|
|
||||||
|
|
||||||
<PageTitle>
|
|
||||||
关于
|
|
||||||
</PageTitle>
|
|
||||||
|
|
||||||
<div class="container">
|
|
||||||
<div class="row">
|
|
||||||
<div class="col">
|
|
||||||
<h1>关于</h1>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<div class="row">
|
|
||||||
<div class="col fst-italic py-2">
|
|
||||||
把字刻在石头上!(・’ω’・)
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<div class="row p-2">
|
|
||||||
<div class="col">
|
|
||||||
<div class="row">
|
|
||||||
<div class="col">
|
|
||||||
<h3>关于我</h3>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<div class="row py-2">
|
|
||||||
<div class="col">
|
|
||||||
计算机科学与技术在读大学生,明光村幼儿园附属大学所属。正处于读书和失业的叠加态。
|
|
||||||
一般在互联网上使用<span class="fst-italic">初冬的朝阳</span>或者<span class="fst-italic">jackfiled</span>的名字活动。
|
|
||||||
<span class="text-decoration-line-through">都是ICP备案过的人了,网名似乎没有太大的用处(</span>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<div class="row py-2">
|
|
||||||
<div class="col">
|
|
||||||
主要是一个C#程序员,目前也在尝试写一点Rust。
|
|
||||||
总体上对于编程语言的态度是“<span>大家都是我的翅膀.jpg</span>”。
|
|
||||||
前后端分离的项目本当上手。
|
|
||||||
常常因为现实的压力而写一些C/C++。
|
|
||||||
<span class="text-decoration-line-through">对于Java和Go的评价很低。</span>
|
|
||||||
日常使用ArchLinux。
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<div class="row py-2">
|
|
||||||
<div class="col">
|
|
||||||
100%社恐。日常生活是宅在电脑前面自言自语。兴趣活动是读书和看番。
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<div class="row py-2">
|
|
||||||
<div class="col">
|
|
||||||
常常被人批评没有梦想,这里就随便瞎编一下。
|
|
||||||
成为嵌入式工程师,修好桌面上的<a href="https://www.bilibili.com/video/BV1VA411p7MD">HoloCubic</a>。
|
|
||||||
完成第一个不是课程设计的个人开源项目。
|
|
||||||
遇到能够搭伙过日子的人也算是一大梦想,虽然社恐人根本不知道从何开始的说,
|
|
||||||
<span class="text-decoration-line-through">什么时候天上才能掉美少女?</span>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<div class="row py-2">
|
|
||||||
<div class="col">
|
|
||||||
公开的联系渠道是<a href="mailto:shicangjuner@outlook.com">电子邮件</a>。
|
|
||||||
也可以试试在各大平台搜索上面提到的名字。
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<div class="row p-2">
|
|
||||||
<div class="col">
|
|
||||||
<div class="row">
|
|
||||||
<div class="col">
|
|
||||||
<h3>关于本站</h3>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<div class="row py-2">
|
|
||||||
<div class="col">
|
|
||||||
本站肇始于2021年下半年,在开始的两年中个人网站和博客是分别的两个网站,个人网站是裸HTML写的,博客是用
|
|
||||||
<a href="https://hexo.io">Hexo</a>渲染的。
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<div class="row py-2">
|
|
||||||
<div class="col">
|
|
||||||
2024年,我们决定使用.NET技术完全重构两个网站,合二为一。虽然目前这个版本还是一个半成品,但是我们一定会努力的~(确信。
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<div class="row p-2">
|
|
||||||
<div class="col">
|
|
||||||
<div class="row">
|
|
||||||
<div class="col">
|
|
||||||
<h3>友链</h3>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<div class="row py-2">
|
|
||||||
<div class="col fst-italic">
|
|
||||||
欢迎所有人联系我添加友链!(´。✪ω✪。`)
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<div class="row py-2">
|
|
||||||
@foreach (FriendLink link in Options.Links)
|
|
||||||
{
|
|
||||||
<div class="col-sm-12 col-md-4 col-lg-3">
|
|
||||||
<a href="@(link.Link)" target="_blank" class="m-3">
|
|
||||||
<div class="row link-item">
|
|
||||||
<div class="col-4">
|
|
||||||
<Image Src="@(link.AvatarImage)" Alt="@(link.Name)" Style="border-radius: 50%"/>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<div class="col-8">
|
|
||||||
<div class="row">
|
|
||||||
<div class="col-auto fs-5">
|
|
||||||
@(link.Name)
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<div class="row">
|
|
||||||
<div class="col-auto fst-italic">
|
|
||||||
@(link.Description)
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
</a>
|
|
||||||
</div>
|
|
||||||
}
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
@code {
|
|
||||||
|
|
||||||
}
|
|
||||||
@@ -1,8 +0,0 @@
|
|||||||
.link-item {
|
|
||||||
padding: 1rem;
|
|
||||||
border-radius: 4px;
|
|
||||||
}
|
|
||||||
|
|
||||||
.link-item:hover {
|
|
||||||
background-color: var(--bs-secondary-bg);
|
|
||||||
}
|
|
||||||
@@ -1,75 +0,0 @@
|
|||||||
@page "/blog/archives"
|
|
||||||
@using YaeBlog.Core.Abstractions
|
|
||||||
@using YaeBlog.Core.Models
|
|
||||||
|
|
||||||
@inject IEssayContentService Contents
|
|
||||||
|
|
||||||
<PageTitle>
|
|
||||||
归档
|
|
||||||
</PageTitle>
|
|
||||||
|
|
||||||
<div class="container">
|
|
||||||
<div class="row">
|
|
||||||
<div class="col">
|
|
||||||
<div class="container">
|
|
||||||
<div class="row">
|
|
||||||
<div class="col">
|
|
||||||
<h1>归档</h1>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<div class="row">
|
|
||||||
<div class="col fst-italic py-4">
|
|
||||||
时光图书馆,黑历史集散地。(๑◔‿◔๑)
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
@foreach (IGrouping<DateTime, KeyValuePair<string, BlogEssay>> group in _essays)
|
|
||||||
{
|
|
||||||
<div class="row">
|
|
||||||
<div class="col">
|
|
||||||
<div class="container">
|
|
||||||
<div class="row">
|
|
||||||
<div class="col">
|
|
||||||
<h3>@(group.Key.Year)</h3>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<div class="container px-3 py-2">
|
|
||||||
@foreach (KeyValuePair<string, BlogEssay> essay in group)
|
|
||||||
{
|
|
||||||
<div class="row py-1">
|
|
||||||
<div class="col-auto">
|
|
||||||
@(essay.Value.PublishTime.ToString("MM-dd"))
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<div class="col-auto">
|
|
||||||
<a href="/blog/essays/@(essay.Key)">
|
|
||||||
@(essay.Value.Title)
|
|
||||||
</a>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
}
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
}
|
|
||||||
|
|
||||||
</div>
|
|
||||||
|
|
||||||
@code {
|
|
||||||
private readonly List<IGrouping<DateTime, KeyValuePair<string, BlogEssay>>> _essays = [];
|
|
||||||
|
|
||||||
protected override void OnInitialized()
|
|
||||||
{
|
|
||||||
base.OnInitialized();
|
|
||||||
|
|
||||||
_essays.AddRange(from essay in Contents.Essays
|
|
||||||
orderby essay.Value.PublishTime descending
|
|
||||||
group essay by new DateTime(essay.Value.PublishTime.Year, 1, 1));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,116 +0,0 @@
|
|||||||
@page "/blog"
|
|
||||||
@using YaeBlog.Core.Abstractions
|
|
||||||
@using YaeBlog.Core.Models
|
|
||||||
|
|
||||||
@inject IEssayContentService Contents
|
|
||||||
@inject NavigationManager NavigationInstance
|
|
||||||
|
|
||||||
<PageTitle>
|
|
||||||
Ricardo's Blog
|
|
||||||
</PageTitle>
|
|
||||||
|
|
||||||
<div class="container">
|
|
||||||
<div class="row">
|
|
||||||
<div class="col-sm-12 col-md-9">
|
|
||||||
@foreach (KeyValuePair<string, BlogEssay> pair in _essays)
|
|
||||||
{
|
|
||||||
<EssayCard Essay="@(pair.Value)"/>
|
|
||||||
}
|
|
||||||
|
|
||||||
<div class="row align-items-center justify-content-center p-3">
|
|
||||||
@if (_page == 1)
|
|
||||||
{
|
|
||||||
<div class="col-auto fw-light">上一页</div>
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
<div class="col-auto">
|
|
||||||
<a href="/blog/?page=@(_page - 1)">上一页</a>
|
|
||||||
</div>
|
|
||||||
}
|
|
||||||
|
|
||||||
@if (_page == 1)
|
|
||||||
{
|
|
||||||
<div class="col-auto">
|
|
||||||
1
|
|
||||||
</div>
|
|
||||||
<div class="col-auto">
|
|
||||||
<a href="/blog/?page=2">2</a>
|
|
||||||
</div>
|
|
||||||
<div class="col-auto">
|
|
||||||
<a href="/blog/?page=3">3</a>
|
|
||||||
</div>
|
|
||||||
}
|
|
||||||
else if (_page == _pageCount)
|
|
||||||
{
|
|
||||||
<div class="col-auto">
|
|
||||||
<a href="/blog/?page=@(_pageCount - 2)">@(_pageCount - 2)</a>
|
|
||||||
</div>
|
|
||||||
<div class="col-auto">
|
|
||||||
<a href="/blog/?page=@(_pageCount - 1)">@(_pageCount - 1)</a>
|
|
||||||
</div>
|
|
||||||
<div class="col-auto">
|
|
||||||
@(_pageCount)
|
|
||||||
</div>
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
<div class="col-auto">
|
|
||||||
<a href="/blog/?page=@(_page - 1)">@(_page - 1)</a>
|
|
||||||
</div>
|
|
||||||
<div class="col-auto">
|
|
||||||
@(_page)
|
|
||||||
</div>
|
|
||||||
<div class="col-auto">
|
|
||||||
<a href="/blog/?page=@(_page + 1)">@(_page + 1)</a>
|
|
||||||
</div>
|
|
||||||
}
|
|
||||||
|
|
||||||
@if (_page == _pageCount)
|
|
||||||
{
|
|
||||||
<div class="col-auto fw-light">
|
|
||||||
下一页
|
|
||||||
</div>
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
<div class="col-auto">
|
|
||||||
<a href="/blog/?page=@(_page + 1)">下一页</a>
|
|
||||||
</div>
|
|
||||||
}
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<div class="col-sm-12 col-md-3">
|
|
||||||
<BlogInformationCard/>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
@code {
|
|
||||||
|
|
||||||
[SupplyParameterFromQuery] private int? Page { get; set; }
|
|
||||||
|
|
||||||
private readonly List<KeyValuePair<string, BlogEssay>> _essays = [];
|
|
||||||
private const int EssaysPerPage = 8;
|
|
||||||
private int _pageCount = 1;
|
|
||||||
private int _page = 1;
|
|
||||||
|
|
||||||
protected override void OnInitialized()
|
|
||||||
{
|
|
||||||
_page = Page ?? 1;
|
|
||||||
_pageCount = Contents.Essays.Count / EssaysPerPage + 1;
|
|
||||||
|
|
||||||
if (EssaysPerPage * _page > Contents.Essays.Count + EssaysPerPage)
|
|
||||||
{
|
|
||||||
NavigationInstance.NavigateTo("/NotFount");
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
_essays.AddRange(Contents.Essays
|
|
||||||
.OrderByDescending(p => p.Value.PublishTime)
|
|
||||||
.Skip((_page - 1) * EssaysPerPage)
|
|
||||||
.Take(EssaysPerPage));
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
@@ -1,7 +0,0 @@
|
|||||||
.essay-title a {
|
|
||||||
color: var(--bs-body-color);
|
|
||||||
}
|
|
||||||
|
|
||||||
.read-more a {
|
|
||||||
color: var(--bs-body-color);
|
|
||||||
}
|
|
||||||
@@ -1,137 +0,0 @@
|
|||||||
@page "/blog/essays/{BlogKey}"
|
|
||||||
@using System.Text.Encodings.Web
|
|
||||||
@using YaeBlog.Core.Abstractions
|
|
||||||
@using YaeBlog.Core.Models
|
|
||||||
|
|
||||||
@inject IEssayContentService Contents
|
|
||||||
@inject NavigationManager NavigationInstance
|
|
||||||
|
|
||||||
<PageTitle>
|
|
||||||
@(_essay!.Title)
|
|
||||||
</PageTitle>
|
|
||||||
|
|
||||||
<div class="container py-4">
|
|
||||||
<div class="row">
|
|
||||||
<div class="col-auto">
|
|
||||||
<h1 id="title">@(_essay!.Title)</h1>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<div class="row px-4 py-1">
|
|
||||||
<div class="col-auto fw-light">
|
|
||||||
@(_essay!.PublishTime.ToString("yyyy-MM-dd"))
|
|
||||||
</div>
|
|
||||||
|
|
||||||
@foreach (string tag in _essay!.Tags)
|
|
||||||
{
|
|
||||||
<div class="col-auto">
|
|
||||||
<a href="/blog/tags/?tagName=@(UrlEncoder.Default.Encode(tag))">
|
|
||||||
# @(tag)
|
|
||||||
</a>
|
|
||||||
</div>
|
|
||||||
}
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<div class="row px-4 py-1">
|
|
||||||
<div class="col-auto fw-light">
|
|
||||||
总字数:@(_essay!.WordCount)字,预计阅读时间 @(_essay!.ReadTime)。
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<div class="row">
|
|
||||||
<div class="col-lg-8 col-md-12">
|
|
||||||
@((MarkupString)_essay!.HtmlContent)
|
|
||||||
|
|
||||||
<LicenseDisclaimer EssayAddress="@BlogKey"/>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<div class="col-lg-4 col-md-12">
|
|
||||||
<div class="row sticky-lg-top justify-content-center">
|
|
||||||
<div class="col-auto">
|
|
||||||
<div class="row">
|
|
||||||
<div class="col-auto">
|
|
||||||
<h3 style="margin-block-start: 1em; margin-block-end: 0.5em">
|
|
||||||
文章目录
|
|
||||||
</h3>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<div class="row" style="padding-left: 10px">
|
|
||||||
<div class="col-auto">
|
|
||||||
@foreach (BlogHeadline level2 in _headline!.Children)
|
|
||||||
{
|
|
||||||
<div class="row py-1">
|
|
||||||
<div class="col-auto">
|
|
||||||
<a href="@(GenerateSelectorUrl(level2.SelectorId))">@(level2.Title)</a>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
@foreach (BlogHeadline level3 in level2.Children)
|
|
||||||
{
|
|
||||||
<div class="row py-1">
|
|
||||||
<div class="col-auto">
|
|
||||||
<a style="padding-left: 20px" href="@GenerateSelectorUrl(level3.SelectorId)">
|
|
||||||
@(level3.Title)
|
|
||||||
</a>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
@foreach (BlogHeadline level4 in level3.Children)
|
|
||||||
{
|
|
||||||
<div class="row py-1">
|
|
||||||
<div class="col-auto">
|
|
||||||
<a style="padding-left: 40px" href="@(GenerateSelectorUrl(level4.SelectorId))">
|
|
||||||
@(level4.Title)
|
|
||||||
</a>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
@if (_headline!.Children.Count == 0)
|
|
||||||
{
|
|
||||||
<div class="row">
|
|
||||||
<div class="col fst-italic">
|
|
||||||
坏了(* Ŏ∀Ŏ),没有在文章中识别到目录
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
}
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
</div>
|
|
||||||
|
|
||||||
@code {
|
|
||||||
[Parameter] public string? BlogKey { get; set; }
|
|
||||||
|
|
||||||
private BlogEssay? _essay;
|
|
||||||
|
|
||||||
private BlogHeadline? _headline;
|
|
||||||
|
|
||||||
protected override void OnInitialized()
|
|
||||||
{
|
|
||||||
base.OnInitialized();
|
|
||||||
|
|
||||||
if (string.IsNullOrWhiteSpace(BlogKey))
|
|
||||||
{
|
|
||||||
NavigationInstance.NavigateTo("/NotFound");
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!Contents.Essays.TryGetValue(BlogKey, out _essay))
|
|
||||||
{
|
|
||||||
NavigationInstance.NavigateTo("/NotFound");
|
|
||||||
}
|
|
||||||
|
|
||||||
_headline = Contents.Headlines[BlogKey];
|
|
||||||
}
|
|
||||||
|
|
||||||
private string GenerateSelectorUrl(string selectorId)
|
|
||||||
=> $"/blog/essays/{BlogKey!}#{selectorId}";
|
|
||||||
|
|
||||||
}
|
|
||||||
@@ -1,57 +0,0 @@
|
|||||||
@page "/"
|
|
||||||
|
|
||||||
<PageTitle>
|
|
||||||
Ricardo's Index
|
|
||||||
</PageTitle>
|
|
||||||
|
|
||||||
<div class="container">
|
|
||||||
<div class="row py-4">
|
|
||||||
<div class="col-lg-4 col-12 p-5 p-lg-0">
|
|
||||||
<Image Src="images/avatar.png" Alt="Ricardo's Avatar"/>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<div class="col-lg-8 col-12">
|
|
||||||
<div class="container px-3">
|
|
||||||
<div class="row">
|
|
||||||
<h4 class="fw-bold">初冬的朝阳 (Ricardo Ren)</h4>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<div class="row">
|
|
||||||
<p class="fs-5">a.k.a jackfiled</p>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<div class="row">
|
|
||||||
<p class="fs-5 fst-italic">世界很大,时间很长。</p>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<div class="row">
|
|
||||||
<p class="fs-5">
|
|
||||||
平平无奇的计算机科学与技术学徒,连微小的贡献都没做。
|
|
||||||
</p>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<div class="row" style="padding-top: 80px">
|
|
||||||
<p class="fs-5">恕我不能亲自为您沏茶(?),还是非常欢迎您能够来到我的主页。</p>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<div class="row">
|
|
||||||
<p class="fs-5">
|
|
||||||
如果您想四处看看,了解一下屏幕对面的人,可以在我的 <a href="/blog/">博客</a> 看看。
|
|
||||||
如果您对于明光村幼儿园某附属技校的计算机教学感兴趣,您可以移步到
|
|
||||||
<a href="https://jackfiled.github.io/wiki/">我的学习笔记</a>,
|
|
||||||
<span class="fs-5 text-decoration-line-through">虽然这笔记我自己也木有看过。</span>
|
|
||||||
如果您想批判一下我的代码,在 <a href="https://github.com/jackfiled" target="_blank">Github</a> 和
|
|
||||||
<a href="https://git.rrricardo.top/jackfiled/" target="_blank">Gitea</a> 都可以找到。
|
|
||||||
</p>
|
|
||||||
<p class="fs-5">
|
|
||||||
如果您真的很闲,也可以四处搜寻一下,也许存在着一些不为人知的彩蛋。
|
|
||||||
</p>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
@code {
|
|
||||||
|
|
||||||
}
|
|
||||||
@@ -1,6 +0,0 @@
|
|||||||
.tag-count {
|
|
||||||
background: var(--bs-secondary-bg);
|
|
||||||
border-radius: 5px;
|
|
||||||
padding: 0 6px;
|
|
||||||
}
|
|
||||||
|
|
||||||
161
YaeBlog/Processors/EssayStylesPostRenderProcessor.cs
Normal file
161
YaeBlog/Processors/EssayStylesPostRenderProcessor.cs
Normal file
@@ -0,0 +1,161 @@
|
|||||||
|
using AngleSharp;
|
||||||
|
using AngleSharp.Dom;
|
||||||
|
using YaeBlog.Abstraction;
|
||||||
|
using YaeBlog.Extensions;
|
||||||
|
using YaeBlog.Models;
|
||||||
|
|
||||||
|
namespace YaeBlog.Processors;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 向渲染的HTML中插入Tailwind CSS的渲染后处理器
|
||||||
|
/// </summary>
|
||||||
|
public sealed class EssayStylesPostRenderProcessor : IPostRenderProcessor
|
||||||
|
{
|
||||||
|
public string Name => nameof(EssayStylesPostRenderProcessor);
|
||||||
|
|
||||||
|
public async Task<BlogEssay> ProcessAsync(BlogEssay essay)
|
||||||
|
{
|
||||||
|
BrowsingContext context = new(Configuration.Default);
|
||||||
|
IDocument document = await context.OpenAsync(req => req.Content(essay.HtmlContent));
|
||||||
|
|
||||||
|
ApplyGlobalCssStyles(document);
|
||||||
|
BeatifyTable(document);
|
||||||
|
BeatifyList(document);
|
||||||
|
BeatifyInlineCode(document);
|
||||||
|
|
||||||
|
return essay.WithNewHtmlContent(document.DocumentElement.OuterHtml);
|
||||||
|
}
|
||||||
|
|
||||||
|
private readonly Dictionary<string, string> _globalCssStyles = new()
|
||||||
|
{
|
||||||
|
{ "pre", "p-4 bg-gray-100 rounded-sm overflow-x-auto" },
|
||||||
|
{ "h2", "text-3xl font-bold py-4" },
|
||||||
|
{ "h3", "text-2xl font-bold py-3" },
|
||||||
|
{ "h4", "text-xl font-bold py-2" },
|
||||||
|
{ "h5", "text-lg font-bold py-1" },
|
||||||
|
{ "p", "p-2" },
|
||||||
|
{ "img", "w-11/12 block mx-auto my-2 rounded-md shadow-md" },
|
||||||
|
{ "a", "text-blue-600" }
|
||||||
|
};
|
||||||
|
|
||||||
|
private void ApplyGlobalCssStyles(IDocument document)
|
||||||
|
{
|
||||||
|
foreach ((string tag, string style) in _globalCssStyles)
|
||||||
|
{
|
||||||
|
foreach (IElement element in document.GetElementsByTagName(tag))
|
||||||
|
{
|
||||||
|
element.ClassList.Add(style);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private static void BeatifyTable(IDocument document)
|
||||||
|
{
|
||||||
|
foreach (IElement element in from e in document.All
|
||||||
|
where e.LocalName == "table"
|
||||||
|
select e)
|
||||||
|
{
|
||||||
|
element.ClassList.Add("mx-auto border-collapse table-auto overflow-x-auto");
|
||||||
|
|
||||||
|
// thead元素
|
||||||
|
foreach (IElement headElement in from e in element.Children
|
||||||
|
where e.LocalName == "thead"
|
||||||
|
select e)
|
||||||
|
{
|
||||||
|
headElement.ClassList.Add("bg-slate-200");
|
||||||
|
|
||||||
|
// tr in thead
|
||||||
|
foreach (IElement trElement in from e in headElement.Children
|
||||||
|
where e.LocalName == "tr"
|
||||||
|
select e)
|
||||||
|
{
|
||||||
|
trElement.ClassList.Add("border border-slate-300");
|
||||||
|
|
||||||
|
// th in tr
|
||||||
|
foreach (IElement thElement in from e in trElement.Children
|
||||||
|
where e.LocalName == "th"
|
||||||
|
select e)
|
||||||
|
{
|
||||||
|
thElement.ClassList.Add("px-4 py-1");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// tbody元素
|
||||||
|
foreach (IElement bodyElement in from e in element.Children
|
||||||
|
where e.LocalName == "tbody"
|
||||||
|
select e)
|
||||||
|
{
|
||||||
|
// tr in tbody
|
||||||
|
foreach (IElement trElement in from e in bodyElement.Children
|
||||||
|
where e.LocalName == "tr"
|
||||||
|
select e)
|
||||||
|
{
|
||||||
|
foreach (IElement tdElement in from e in trElement.Children
|
||||||
|
where e.LocalName == "td"
|
||||||
|
select e)
|
||||||
|
{
|
||||||
|
tdElement.ClassList.Add("px-4 py-1 border border-slate-300");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 美化各种列表元素
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="document"></param>
|
||||||
|
private static void BeatifyList(IDocument document)
|
||||||
|
{
|
||||||
|
foreach (IElement listElement in from e in document.All
|
||||||
|
where e.LocalName is "ol" or "ul"
|
||||||
|
select e)
|
||||||
|
{
|
||||||
|
// 给有序或者无序列表添加不同的样式
|
||||||
|
listElement.ClassList.Add("ml-10");
|
||||||
|
switch (listElement.LocalName)
|
||||||
|
{
|
||||||
|
case "ul":
|
||||||
|
{
|
||||||
|
listElement.ClassList.Add("list-disc");
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
case "ol":
|
||||||
|
{
|
||||||
|
listElement.ClassList.Add("list-decimal");
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
foreach (IElement liElement in from e in listElement.Children
|
||||||
|
where e.LocalName == "li"
|
||||||
|
select e)
|
||||||
|
{
|
||||||
|
// 修改<li>元素中的<p>元素样式
|
||||||
|
// 默认的p-2间距有点太宽了
|
||||||
|
foreach (IElement pElement in from e in liElement.Children
|
||||||
|
where e.LocalName == "p"
|
||||||
|
select e)
|
||||||
|
{
|
||||||
|
pElement.ClassList.Remove("p-2");
|
||||||
|
pElement.ClassList.Add("p-1");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private static void BeatifyInlineCode(IDocument document)
|
||||||
|
{
|
||||||
|
// 选择不在<pre>元素内的<code>元素
|
||||||
|
// 即行内代码
|
||||||
|
IEnumerable<IElement> inlineCodes = from e in document.All
|
||||||
|
where e.LocalName == "code" && e.EnumerateParentElements().All(p => p.LocalName != "pre")
|
||||||
|
select e;
|
||||||
|
|
||||||
|
foreach (IElement e in inlineCodes)
|
||||||
|
{
|
||||||
|
e.ClassList.Add("bg-gray-100 inline p-1 rounded-xs");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -1,13 +1,12 @@
|
|||||||
using AngleSharp;
|
using AngleSharp;
|
||||||
using AngleSharp.Dom;
|
using AngleSharp.Dom;
|
||||||
using Microsoft.Extensions.Logging;
|
using YaeBlog.Abstraction;
|
||||||
using YaeBlog.Core.Abstractions;
|
using YaeBlog.Models;
|
||||||
using YaeBlog.Core.Models;
|
|
||||||
|
|
||||||
namespace YaeBlog.Core.Processors;
|
namespace YaeBlog.Processors;
|
||||||
|
|
||||||
public class HeadlinePostRenderProcessor(
|
public class HeadlinePostRenderProcessor(
|
||||||
IConfiguration angleConfiguration,
|
AngleSharp.IConfiguration angleConfiguration,
|
||||||
IEssayContentService essayContentService,
|
IEssayContentService essayContentService,
|
||||||
ILogger<HeadlinePostRenderProcessor> logger) : IPostRenderProcessor
|
ILogger<HeadlinePostRenderProcessor> logger) : IPostRenderProcessor
|
||||||
{
|
{
|
||||||
@@ -1,24 +1,22 @@
|
|||||||
using AngleSharp;
|
using AngleSharp;
|
||||||
using AngleSharp.Dom;
|
using AngleSharp.Dom;
|
||||||
using Microsoft.Extensions.Logging;
|
|
||||||
using Microsoft.Extensions.Options;
|
using Microsoft.Extensions.Options;
|
||||||
using YaeBlog.Core.Abstractions;
|
using YaeBlog.Abstraction;
|
||||||
using YaeBlog.Core.Exceptions;
|
using YaeBlog.Core.Exceptions;
|
||||||
using YaeBlog.Core.Models;
|
using YaeBlog.Models;
|
||||||
|
|
||||||
namespace YaeBlog.Core.Processors;
|
namespace YaeBlog.Processors;
|
||||||
|
|
||||||
public class ImagePostRenderProcessor(ILogger<ImagePostRenderProcessor> logger,
|
public class ImagePostRenderProcessor(
|
||||||
|
ILogger<ImagePostRenderProcessor> logger,
|
||||||
IOptions<BlogOptions> options)
|
IOptions<BlogOptions> options)
|
||||||
: IPostRenderProcessor
|
: IPostRenderProcessor
|
||||||
{
|
{
|
||||||
private static readonly IConfiguration s_configuration = Configuration.Default;
|
|
||||||
|
|
||||||
private readonly BlogOptions _options = options.Value;
|
private readonly BlogOptions _options = options.Value;
|
||||||
|
|
||||||
public async Task<BlogEssay> ProcessAsync(BlogEssay essay)
|
public async Task<BlogEssay> ProcessAsync(BlogEssay essay)
|
||||||
{
|
{
|
||||||
BrowsingContext context = new(s_configuration);
|
BrowsingContext context = new(Configuration.Default);
|
||||||
IDocument html = await context.OpenAsync(
|
IDocument html = await context.OpenAsync(
|
||||||
req => req.Content(essay.HtmlContent));
|
req => req.Content(essay.HtmlContent));
|
||||||
|
|
||||||
@@ -32,23 +30,27 @@ public class ImagePostRenderProcessor(ILogger<ImagePostRenderProcessor> logger,
|
|||||||
if (attr is not null)
|
if (attr is not null)
|
||||||
{
|
{
|
||||||
logger.LogDebug("Found image link: '{}'", attr.Value);
|
logger.LogDebug("Found image link: '{}'", attr.Value);
|
||||||
attr.Value = GenerateImageLink(attr.Value, essay.FileName);
|
attr.Value = GenerateImageLink(attr.Value, essay.FileName, essay.IsDraft);
|
||||||
}
|
}
|
||||||
element.ClassList.Add("essay-image");
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return essay.WithNewHtmlContent(html.DocumentElement.OuterHtml);
|
return essay.WithNewHtmlContent(html.DocumentElement.OuterHtml);
|
||||||
}
|
}
|
||||||
|
|
||||||
public string Name => nameof(ImagePostRenderProcessor);
|
public string Name => nameof(ImagePostRenderProcessor);
|
||||||
|
|
||||||
private string GenerateImageLink(string filename, string essayFilename)
|
private string GenerateImageLink(string filename, string essayFilename, bool isDraft)
|
||||||
{
|
{
|
||||||
|
// 如果图片路径中没有包含文件名
|
||||||
|
// 则添加文件名
|
||||||
if (!filename.Contains(essayFilename))
|
if (!filename.Contains(essayFilename))
|
||||||
{
|
{
|
||||||
filename = Path.Combine(essayFilename, filename);
|
filename = Path.Combine(essayFilename, filename);
|
||||||
}
|
}
|
||||||
|
|
||||||
filename = Path.Combine(_options.Root, "posts", filename);
|
filename = isDraft
|
||||||
|
? Path.Combine(_options.Root, "drafts", filename)
|
||||||
|
: Path.Combine(_options.Root, "posts", filename);
|
||||||
|
|
||||||
if (!Path.Exists(filename))
|
if (!Path.Exists(filename))
|
||||||
{
|
{
|
||||||
@@ -1,11 +1,4 @@
|
|||||||
using System.CommandLine;
|
|
||||||
using YaeBlog.Commands;
|
using YaeBlog.Commands;
|
||||||
|
|
||||||
RootCommand rootCommand = new("YaeBlog CLI");
|
YaeBlogCommand command = new();
|
||||||
|
await command.RunAsync(args);
|
||||||
rootCommand.AddServeCommand();
|
|
||||||
rootCommand.AddNewCommand();
|
|
||||||
rootCommand.AddListCommand();
|
|
||||||
rootCommand.AddWatchCommand();
|
|
||||||
|
|
||||||
await rootCommand.InvokeAsync(args);
|
|
||||||
|
|||||||
@@ -1,8 +1,7 @@
|
|||||||
using Microsoft.Extensions.Logging;
|
using Microsoft.Extensions.Options;
|
||||||
using Microsoft.Extensions.Options;
|
using YaeBlog.Models;
|
||||||
using YaeBlog.Core.Models;
|
|
||||||
|
|
||||||
namespace YaeBlog.Core.Services;
|
namespace YaeBlog.Services;
|
||||||
|
|
||||||
public sealed class BlogChangeWatcher : IDisposable
|
public sealed class BlogChangeWatcher : IDisposable
|
||||||
{
|
{
|
||||||
@@ -1,7 +1,4 @@
|
|||||||
using Microsoft.Extensions.Hosting;
|
namespace YaeBlog.Services;
|
||||||
using Microsoft.Extensions.Logging;
|
|
||||||
|
|
||||||
namespace YaeBlog.Core.Services;
|
|
||||||
|
|
||||||
public class BlogHostedService(
|
public class BlogHostedService(
|
||||||
ILogger<BlogHostedService> logger,
|
ILogger<BlogHostedService> logger,
|
||||||
@@ -9,14 +6,12 @@ public class BlogHostedService(
|
|||||||
{
|
{
|
||||||
public async Task StartAsync(CancellationToken cancellationToken)
|
public async Task StartAsync(CancellationToken cancellationToken)
|
||||||
{
|
{
|
||||||
logger.LogInformation("Welcome to YaeBlog!");
|
logger.LogInformation("Failed to load cache, render essays.");
|
||||||
|
|
||||||
await rendererService.RenderAsync();
|
await rendererService.RenderAsync();
|
||||||
}
|
}
|
||||||
|
|
||||||
public Task StopAsync(CancellationToken cancellationToken)
|
public Task StopAsync(CancellationToken cancellationToken)
|
||||||
{
|
{
|
||||||
logger.LogInformation("YaeBlog stopped!\nHave a nice day!");
|
|
||||||
return Task.CompletedTask;
|
return Task.CompletedTask;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
50
YaeBlog/Services/BlogHotReloadService.cs
Normal file
50
YaeBlog/Services/BlogHotReloadService.cs
Normal file
@@ -0,0 +1,50 @@
|
|||||||
|
using YaeBlog.Abstraction;
|
||||||
|
|
||||||
|
namespace YaeBlog.Services;
|
||||||
|
|
||||||
|
public sealed class BlogHotReloadService(
|
||||||
|
RendererService rendererService,
|
||||||
|
IEssayContentService essayContentService,
|
||||||
|
BlogChangeWatcher watcher,
|
||||||
|
ILogger<BlogHotReloadService> logger) : BackgroundService
|
||||||
|
{
|
||||||
|
protected override async Task ExecuteAsync(CancellationToken stoppingToken)
|
||||||
|
{
|
||||||
|
logger.LogInformation("Hot reload is starting...");
|
||||||
|
logger.LogInformation("Change essays will lead to hot reload!");
|
||||||
|
logger.LogInformation("HINT: draft essays will be included.");
|
||||||
|
|
||||||
|
await rendererService.RenderAsync(true);
|
||||||
|
|
||||||
|
Task[] reloadTasks = [WatchFileAsync(stoppingToken)];
|
||||||
|
await Task.WhenAll(reloadTasks);
|
||||||
|
}
|
||||||
|
|
||||||
|
private async Task WatchFileAsync(CancellationToken token)
|
||||||
|
{
|
||||||
|
while (!token.IsCancellationRequested)
|
||||||
|
{
|
||||||
|
logger.LogInformation("Watching file changes...");
|
||||||
|
string? changeFile = await watcher.WaitForChange(token);
|
||||||
|
|
||||||
|
if (changeFile is null)
|
||||||
|
{
|
||||||
|
logger.LogInformation("File watcher is stopping.");
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
FileInfo changeFileInfo = new(changeFile);
|
||||||
|
|
||||||
|
if (changeFileInfo.Name.StartsWith('.'))
|
||||||
|
{
|
||||||
|
// Ignore dot-started file and directory.
|
||||||
|
logger.LogDebug("Ignore hidden file: {}.", changeFile);
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
logger.LogInformation("{} changed, re-rendering.", changeFile);
|
||||||
|
essayContentService.Clear();
|
||||||
|
await rendererService.RenderAsync(true);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -1,23 +1,36 @@
|
|||||||
using System.Collections.Concurrent;
|
using System.Collections.Concurrent;
|
||||||
using System.Diagnostics.CodeAnalysis;
|
using System.Diagnostics.CodeAnalysis;
|
||||||
using YaeBlog.Core.Abstractions;
|
using YaeBlog.Abstraction;
|
||||||
using YaeBlog.Core.Models;
|
using YaeBlog.Models;
|
||||||
|
|
||||||
namespace YaeBlog.Core.Services;
|
namespace YaeBlog.Services;
|
||||||
|
|
||||||
public class EssayContentService : IEssayContentService
|
public class EssayContentService : IEssayContentService
|
||||||
{
|
{
|
||||||
private readonly ConcurrentDictionary<string, BlogEssay> _essays = new();
|
private readonly ConcurrentDictionary<string, BlogEssay> _essays = new();
|
||||||
|
|
||||||
|
private readonly List<BlogEssay> _sortedEssays = [];
|
||||||
|
|
||||||
private readonly Dictionary<EssayTag, List<BlogEssay>> _tags = [];
|
private readonly Dictionary<EssayTag, List<BlogEssay>> _tags = [];
|
||||||
|
|
||||||
private readonly ConcurrentDictionary<string, BlogHeadline> _headlines = new();
|
private readonly ConcurrentDictionary<string, BlogHeadline> _headlines = new();
|
||||||
|
|
||||||
public bool TryAdd(BlogEssay essay) => _essays.TryAdd(essay.FileName, essay);
|
public bool TryAdd(BlogEssay essay)
|
||||||
|
{
|
||||||
|
_sortedEssays.Add(essay);
|
||||||
|
return _essays.TryAdd(essay.FileName, essay);
|
||||||
|
}
|
||||||
|
|
||||||
public bool TryAddHeadline(string filename, BlogHeadline headline) => _headlines.TryAdd(filename, headline);
|
public bool TryAddHeadline(string filename, BlogHeadline headline) => _headlines.TryAdd(filename, headline);
|
||||||
|
|
||||||
public IReadOnlyDictionary<string, BlogEssay> Essays => _essays;
|
public IEnumerable<BlogEssay> Essays => _sortedEssays;
|
||||||
|
|
||||||
|
public int Count => _sortedEssays.Count;
|
||||||
|
|
||||||
|
public bool TryGetEssay(string filename, [NotNullWhen(true)] out BlogEssay? essay)
|
||||||
|
{
|
||||||
|
return _essays.TryGetValue(filename, out essay);
|
||||||
|
}
|
||||||
|
|
||||||
public IReadOnlyDictionary<EssayTag, List<BlogEssay>> Tags => _tags;
|
public IReadOnlyDictionary<EssayTag, List<BlogEssay>> Tags => _tags;
|
||||||
|
|
||||||
237
YaeBlog/Services/EssayScanService.cs
Normal file
237
YaeBlog/Services/EssayScanService.cs
Normal file
@@ -0,0 +1,237 @@
|
|||||||
|
using System.Collections.Concurrent;
|
||||||
|
using System.Text.RegularExpressions;
|
||||||
|
using Imageflow.Bindings;
|
||||||
|
using Imageflow.Fluent;
|
||||||
|
using Microsoft.Extensions.Options;
|
||||||
|
using YaeBlog.Abstraction;
|
||||||
|
using YaeBlog.Core.Exceptions;
|
||||||
|
using YaeBlog.Models;
|
||||||
|
using YamlDotNet.Core;
|
||||||
|
using YamlDotNet.Serialization;
|
||||||
|
|
||||||
|
namespace YaeBlog.Services;
|
||||||
|
|
||||||
|
public partial class EssayScanService : IEssayScanService
|
||||||
|
{
|
||||||
|
private readonly BlogOptions _blogOptions;
|
||||||
|
private readonly ISerializer _yamlSerializer;
|
||||||
|
private readonly IDeserializer _yamlDeserializer;
|
||||||
|
private readonly ILogger<EssayScanService> _logger;
|
||||||
|
|
||||||
|
public EssayScanService(ISerializer yamlSerializer,
|
||||||
|
IDeserializer yamlDeserializer,
|
||||||
|
IOptions<BlogOptions> blogOptions,
|
||||||
|
ILogger<EssayScanService> logger)
|
||||||
|
{
|
||||||
|
_yamlSerializer = yamlSerializer;
|
||||||
|
_yamlDeserializer = yamlDeserializer;
|
||||||
|
_logger = logger;
|
||||||
|
_blogOptions = blogOptions.Value;
|
||||||
|
RootDirectory = ValidateRootDirectory();
|
||||||
|
}
|
||||||
|
|
||||||
|
private DirectoryInfo RootDirectory { get; }
|
||||||
|
|
||||||
|
public async Task<BlogContents> ScanContents()
|
||||||
|
{
|
||||||
|
ValidateDirectory(out DirectoryInfo drafts, out DirectoryInfo posts);
|
||||||
|
|
||||||
|
return new BlogContents(
|
||||||
|
await ScanContentsInternal(drafts, true),
|
||||||
|
await ScanContentsInternal(posts, false));
|
||||||
|
}
|
||||||
|
|
||||||
|
public async Task SaveBlogContent(BlogContent content, bool isDraft = true)
|
||||||
|
{
|
||||||
|
ValidateDirectory(out DirectoryInfo drafts, out DirectoryInfo posts);
|
||||||
|
|
||||||
|
FileInfo targetFile = isDraft
|
||||||
|
? new FileInfo(Path.Combine(drafts.FullName, content.BlogName + ".md"))
|
||||||
|
: new FileInfo(Path.Combine(posts.FullName, content.BlogName + ".md"));
|
||||||
|
|
||||||
|
if (targetFile.Exists)
|
||||||
|
{
|
||||||
|
_logger.LogWarning("Blog {} exists, overriding.", targetFile.Name);
|
||||||
|
}
|
||||||
|
|
||||||
|
await using StreamWriter writer = targetFile.CreateText();
|
||||||
|
|
||||||
|
await writer.WriteAsync("---\n");
|
||||||
|
await writer.WriteAsync(_yamlSerializer.Serialize(content.Metadata));
|
||||||
|
await writer.WriteAsync("---\n");
|
||||||
|
|
||||||
|
if (string.IsNullOrEmpty(content.Content) && isDraft)
|
||||||
|
{
|
||||||
|
// 如果博客为操作且内容为空
|
||||||
|
// 创建简介隔断符号
|
||||||
|
await writer.WriteLineAsync("<!--more-->");
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
await writer.WriteAsync(content.Content);
|
||||||
|
}
|
||||||
|
|
||||||
|
// 保存图片文件
|
||||||
|
await Task.WhenAll(from image in content.Images
|
||||||
|
select File.WriteAllBytesAsync(image.File.FullName, image.Content));
|
||||||
|
}
|
||||||
|
|
||||||
|
private record struct BlogResult(
|
||||||
|
FileInfo BlogFile,
|
||||||
|
string BlogContent,
|
||||||
|
List<BlogImageInfo> Images,
|
||||||
|
List<FileInfo> NotFoundImages);
|
||||||
|
|
||||||
|
private async Task<ConcurrentBag<BlogContent>> ScanContentsInternal(DirectoryInfo directory, bool isDraft)
|
||||||
|
{
|
||||||
|
// 扫描以md结尾且不是隐藏文件的文件
|
||||||
|
IEnumerable<FileInfo> markdownFiles = from file in directory.EnumerateFiles()
|
||||||
|
where file.Extension == ".md" && !file.Name.StartsWith('.')
|
||||||
|
select file;
|
||||||
|
|
||||||
|
ConcurrentBag<BlogResult> fileContents = [];
|
||||||
|
|
||||||
|
await Parallel.ForEachAsync(markdownFiles, async (file, token) =>
|
||||||
|
{
|
||||||
|
using StreamReader reader = file.OpenText();
|
||||||
|
string blogName = file.Name.Split('.')[0];
|
||||||
|
string blogContent = await reader.ReadToEndAsync(token);
|
||||||
|
ImageResult imageResult =
|
||||||
|
await ScanImagePreBlog(directory, blogName,
|
||||||
|
blogContent);
|
||||||
|
|
||||||
|
fileContents.Add(new BlogResult(file, blogContent, imageResult.Images, imageResult.NotfoundImages));
|
||||||
|
});
|
||||||
|
|
||||||
|
ConcurrentBag<BlogContent> contents = [];
|
||||||
|
|
||||||
|
await Task.Run(() =>
|
||||||
|
{
|
||||||
|
foreach (BlogResult blog in fileContents)
|
||||||
|
{
|
||||||
|
if (blog.BlogContent.Length < 4)
|
||||||
|
{
|
||||||
|
// Even not contains a legal header.
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
int endPos = blog.BlogContent.IndexOf("---", 4, StringComparison.Ordinal);
|
||||||
|
if (!blog.BlogContent.StartsWith("---") || endPos is -1 or 0)
|
||||||
|
{
|
||||||
|
_logger.LogWarning("Failed to parse metadata from {}, skipped.", blog.BlogFile.Name);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
string metadataString = blog.BlogContent[4..endPos];
|
||||||
|
|
||||||
|
try
|
||||||
|
{
|
||||||
|
MarkdownMetadata metadata = _yamlDeserializer.Deserialize<MarkdownMetadata>(metadataString);
|
||||||
|
_logger.LogDebug("Scan metadata title: '{title}' for {name}.", metadata.Title, blog.BlogFile.Name);
|
||||||
|
|
||||||
|
contents.Add(new BlogContent(blog.BlogFile, metadata, blog.BlogContent[(endPos + 3)..], isDraft,
|
||||||
|
blog.Images, blog.NotFoundImages));
|
||||||
|
}
|
||||||
|
catch (YamlException e)
|
||||||
|
{
|
||||||
|
_logger.LogWarning("Failed to parser metadata from {name} due to {exception}, skipping", blog.BlogFile.Name, e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
return contents;
|
||||||
|
}
|
||||||
|
|
||||||
|
private record struct ImageResult(List<BlogImageInfo> Images, List<FileInfo> NotfoundImages);
|
||||||
|
|
||||||
|
private async Task<ImageResult> ScanImagePreBlog(DirectoryInfo directory, string blogName, string content)
|
||||||
|
{
|
||||||
|
MatchCollection matchResult = ImagePattern.Matches(content);
|
||||||
|
DirectoryInfo imageDirectory = new(Path.Combine(directory.FullName, blogName));
|
||||||
|
|
||||||
|
Dictionary<string, bool> usedImages = imageDirectory.Exists
|
||||||
|
? imageDirectory.EnumerateFiles().ToDictionary(file => file.FullName, _ => false)
|
||||||
|
: [];
|
||||||
|
List<FileInfo> notFoundImages = [];
|
||||||
|
|
||||||
|
foreach (Match match in matchResult)
|
||||||
|
{
|
||||||
|
string imageName = match.Groups[1].Value;
|
||||||
|
|
||||||
|
// 判断md文件中的图片名称中是否包含文件夹名称
|
||||||
|
// 例如 blog-1/image.png 或者 image.png
|
||||||
|
// 如果不带文件夹名称
|
||||||
|
// 默认添加同博客名文件夹
|
||||||
|
FileInfo usedFile = imageName.Contains(blogName)
|
||||||
|
? new FileInfo(Path.Combine(directory.FullName, imageName))
|
||||||
|
: new FileInfo(Path.Combine(directory.FullName, blogName, imageName));
|
||||||
|
|
||||||
|
if (usedImages.TryGetValue(usedFile.FullName, out _))
|
||||||
|
{
|
||||||
|
usedImages[usedFile.FullName] = true;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
notFoundImages.Add(usedFile);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
List<BlogImageInfo> images = (await Task.WhenAll((from pair in usedImages
|
||||||
|
select GetImageInfo(new FileInfo(pair.Key), pair.Value)).ToArray())).ToList();
|
||||||
|
|
||||||
|
return new ImageResult(images, notFoundImages);
|
||||||
|
}
|
||||||
|
|
||||||
|
private static async Task<BlogImageInfo> GetImageInfo(FileInfo file, bool isUsed)
|
||||||
|
{
|
||||||
|
byte[] image = await File.ReadAllBytesAsync(file.FullName);
|
||||||
|
|
||||||
|
if (file.Extension is ".jpg" or ".jpeg" or ".png")
|
||||||
|
{
|
||||||
|
ImageInfo imageInfo =
|
||||||
|
await ImageJob.GetImageInfoAsync(MemorySource.Borrow(image), SourceLifetime.NowOwnedAndDisposedByTask);
|
||||||
|
|
||||||
|
return new BlogImageInfo(file, imageInfo.ImageWidth, imageInfo.ImageWidth, imageInfo.PreferredMimeType,
|
||||||
|
image, isUsed);
|
||||||
|
}
|
||||||
|
|
||||||
|
return new BlogImageInfo(file, 0, 0, file.Extension switch
|
||||||
|
{
|
||||||
|
"svg" => "image/svg",
|
||||||
|
"avif" => "image/avif",
|
||||||
|
_ => string.Empty
|
||||||
|
}, image, isUsed);
|
||||||
|
}
|
||||||
|
|
||||||
|
[GeneratedRegex(@"\!\[.*?\]\((.*?)\)")]
|
||||||
|
private static partial Regex ImagePattern { get; }
|
||||||
|
|
||||||
|
|
||||||
|
private DirectoryInfo ValidateRootDirectory()
|
||||||
|
{
|
||||||
|
DirectoryInfo rootDirectory = new(Path.Combine(Environment.CurrentDirectory, _blogOptions.Root));
|
||||||
|
|
||||||
|
if (!rootDirectory.Exists)
|
||||||
|
{
|
||||||
|
throw new BlogFileException($"'{_blogOptions.Root}' is not a directory.");
|
||||||
|
}
|
||||||
|
|
||||||
|
return rootDirectory;
|
||||||
|
}
|
||||||
|
|
||||||
|
private void ValidateDirectory(out DirectoryInfo drafts, out DirectoryInfo posts)
|
||||||
|
{
|
||||||
|
if (RootDirectory.EnumerateDirectories().All(dir => dir.Name != "drafts"))
|
||||||
|
{
|
||||||
|
throw new BlogFileException($"'{_blogOptions.Root}/drafts' not exists.");
|
||||||
|
}
|
||||||
|
|
||||||
|
if (RootDirectory.EnumerateDirectories().All(dir => dir.Name != "posts"))
|
||||||
|
{
|
||||||
|
throw new BlogFileException($"'{_blogOptions.Root}/posts' not exists.");
|
||||||
|
}
|
||||||
|
|
||||||
|
drafts = new DirectoryInfo(Path.Combine(_blogOptions.Root, "drafts"));
|
||||||
|
posts = new DirectoryInfo(Path.Combine(_blogOptions.Root, "posts"));
|
||||||
|
}
|
||||||
|
}
|
||||||
119
YaeBlog/Services/ImageCompressService.cs
Normal file
119
YaeBlog/Services/ImageCompressService.cs
Normal file
@@ -0,0 +1,119 @@
|
|||||||
|
using Imageflow.Fluent;
|
||||||
|
using YaeBlog.Abstraction;
|
||||||
|
using YaeBlog.Core.Exceptions;
|
||||||
|
using YaeBlog.Models;
|
||||||
|
|
||||||
|
namespace YaeBlog.Services;
|
||||||
|
|
||||||
|
public sealed class ImageCompressService(IEssayScanService essayScanService, ILogger<ImageCompressService> logger)
|
||||||
|
{
|
||||||
|
private record struct CompressResult(BlogImageInfo ImageInfo, byte[] CompressContent);
|
||||||
|
|
||||||
|
public async Task<List<BlogImageInfo>> ScanUsedImages()
|
||||||
|
{
|
||||||
|
BlogContents contents = await essayScanService.ScanContents();
|
||||||
|
List<BlogImageInfo> originalImages = (from content in contents.Posts.Concat(contents.Drafts)
|
||||||
|
from image in content.Images
|
||||||
|
where image.IsUsed
|
||||||
|
select image).ToList();
|
||||||
|
|
||||||
|
originalImages.Sort();
|
||||||
|
|
||||||
|
return originalImages;
|
||||||
|
}
|
||||||
|
|
||||||
|
public async Task Compress(bool dryRun)
|
||||||
|
{
|
||||||
|
BlogContents contents = await essayScanService.ScanContents();
|
||||||
|
|
||||||
|
// 筛选需要压缩的图片
|
||||||
|
// 即图片被博客使用且是jpeg/png格式
|
||||||
|
List<BlogContent> needCompressContents = (from content in contents
|
||||||
|
where content.Images.Any(i => i is { IsUsed: true } and { File.Extension: ".jpg" or ".jpeg" or ".png" })
|
||||||
|
select content).ToList();
|
||||||
|
|
||||||
|
if (needCompressContents.Count == 0)
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
int uncompressedSize = 0;
|
||||||
|
int compressedSize = 0;
|
||||||
|
List<BlogContent> compressedContent = new(needCompressContents.Count);
|
||||||
|
|
||||||
|
foreach (BlogContent content in needCompressContents)
|
||||||
|
{
|
||||||
|
List<BlogImageInfo> uncompressedImages = (from image in content.Images
|
||||||
|
where image is { IsUsed: true } and { File.Extension: ".jpg" or ".jpeg" or ".png" }
|
||||||
|
select image).ToList();
|
||||||
|
|
||||||
|
uncompressedSize += uncompressedImages.Select(i => i.Size).Sum();
|
||||||
|
|
||||||
|
foreach (BlogImageInfo image in uncompressedImages)
|
||||||
|
{
|
||||||
|
logger.LogInformation("Uncompressed image: {} belonging to blog {}.", image.File.Name,
|
||||||
|
content.BlogName);
|
||||||
|
}
|
||||||
|
|
||||||
|
CompressResult[] compressedImages = (await Task.WhenAll(from image in uncompressedImages
|
||||||
|
select Task.Run(async () => new CompressResult(image, await ConvertToWebp(image))))).ToArray();
|
||||||
|
|
||||||
|
compressedSize += compressedImages.Select(i => i.CompressContent.Length).Sum();
|
||||||
|
|
||||||
|
// 直接在原有的图片列表上添加图片
|
||||||
|
List<BlogImageInfo> images = content.Images.Concat(from r in compressedImages
|
||||||
|
select r.ImageInfo with
|
||||||
|
{
|
||||||
|
File = new FileInfo(r.ImageInfo.File.FullName.Split('.')[0] + ".webp"),
|
||||||
|
Content = r.CompressContent,
|
||||||
|
MineType = "image/webp"
|
||||||
|
}).ToList();
|
||||||
|
// 修改文本
|
||||||
|
string blogContent = compressedImages.Aggregate(content.Content, (c, r) =>
|
||||||
|
{
|
||||||
|
string originalName = r.ImageInfo.File.Name;
|
||||||
|
string outputName = originalName.Split('.')[0] + ".webp";
|
||||||
|
|
||||||
|
return c.Replace(originalName, outputName);
|
||||||
|
});
|
||||||
|
|
||||||
|
compressedContent.Add(content with { Images = images, Content = blogContent });
|
||||||
|
}
|
||||||
|
|
||||||
|
logger.LogInformation("Compression ratio: {}%.", (double)compressedSize / uncompressedSize * 100.0);
|
||||||
|
|
||||||
|
if (dryRun is false)
|
||||||
|
{
|
||||||
|
await Task.WhenAll(from content in compressedContent
|
||||||
|
select essayScanService.SaveBlogContent(content, content.IsDraft));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private static async Task<byte[]> ConvertToWebp(BlogImageInfo image)
|
||||||
|
{
|
||||||
|
using ImageJob job = new();
|
||||||
|
BuildJobResult result = await job.Decode(MemorySource.Borrow(image.Content))
|
||||||
|
.Branch(f => f.EncodeToBytes(new WebPLosslessEncoder()))
|
||||||
|
.EncodeToBytes(new WebPLossyEncoder(75))
|
||||||
|
.Finish()
|
||||||
|
.InProcessAsync();
|
||||||
|
|
||||||
|
// 超过128KB的图片使用有损压缩
|
||||||
|
// 反之使用无损压缩
|
||||||
|
|
||||||
|
ArraySegment<byte>? losslessImage = result.TryGet(1)?.TryGetBytes();
|
||||||
|
ArraySegment<byte>? lossyImage = result.TryGet(2)?.TryGetBytes();
|
||||||
|
|
||||||
|
if (image.Size <= 128 * 1024 && losslessImage.HasValue)
|
||||||
|
{
|
||||||
|
return losslessImage.Value.ToArray();
|
||||||
|
}
|
||||||
|
|
||||||
|
if (lossyImage.HasValue)
|
||||||
|
{
|
||||||
|
return lossyImage.Value.ToArray();
|
||||||
|
}
|
||||||
|
|
||||||
|
throw new BlogCommandException($"Failed to convert {image.File.Name} to webp format: return value is null.");
|
||||||
|
}
|
||||||
|
}
|
||||||
62
YaeBlog/Services/MarkdownWordCounter.cs
Normal file
62
YaeBlog/Services/MarkdownWordCounter.cs
Normal file
@@ -0,0 +1,62 @@
|
|||||||
|
using YaeBlog.Extensions;
|
||||||
|
using YaeBlog.Models;
|
||||||
|
|
||||||
|
namespace YaeBlog.Services
|
||||||
|
{
|
||||||
|
public class MarkdownWordCounter
|
||||||
|
{
|
||||||
|
private bool _inCodeBlock;
|
||||||
|
private int _index;
|
||||||
|
private readonly string _content;
|
||||||
|
|
||||||
|
private uint WordCount { get; set; }
|
||||||
|
|
||||||
|
private MarkdownWordCounter(BlogContent content)
|
||||||
|
{
|
||||||
|
_content = content.Content;
|
||||||
|
}
|
||||||
|
|
||||||
|
private void CountWordInner()
|
||||||
|
{
|
||||||
|
while (_index < _content.Length)
|
||||||
|
{
|
||||||
|
if (IsCodeBlockTag())
|
||||||
|
{
|
||||||
|
_inCodeBlock = !_inCodeBlock;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!_inCodeBlock && char.IsLetterOrDigit(_content, _index))
|
||||||
|
{
|
||||||
|
WordCount += 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
_index++;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private bool IsCodeBlockTag()
|
||||||
|
{
|
||||||
|
// 首先考虑识别代码块
|
||||||
|
bool outerCodeBlock =
|
||||||
|
Enumerable.Range(0, 3)
|
||||||
|
.Select(i => _index + i < _content.Length && _content.AsSpan().Slice(_index + i, 1) is "`")
|
||||||
|
.All(i => i);
|
||||||
|
|
||||||
|
if (outerCodeBlock)
|
||||||
|
{
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
// 然后识别行内代码
|
||||||
|
return _index < _content.Length && _content.AsSpan().Slice(_index, 1) is "`";
|
||||||
|
}
|
||||||
|
|
||||||
|
public static uint CountWord(BlogContent content)
|
||||||
|
{
|
||||||
|
MarkdownWordCounter counter = new(content);
|
||||||
|
counter.CountWordInner();
|
||||||
|
|
||||||
|
return counter.WordCount;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -3,14 +3,13 @@ using System.Diagnostics;
|
|||||||
using System.Text;
|
using System.Text;
|
||||||
using System.Text.RegularExpressions;
|
using System.Text.RegularExpressions;
|
||||||
using Markdig;
|
using Markdig;
|
||||||
using Microsoft.Extensions.Logging;
|
using YaeBlog.Abstraction;
|
||||||
using YaeBlog.Core.Abstractions;
|
|
||||||
using YaeBlog.Core.Exceptions;
|
using YaeBlog.Core.Exceptions;
|
||||||
using YaeBlog.Core.Models;
|
using YaeBlog.Models;
|
||||||
|
|
||||||
namespace YaeBlog.Core.Services;
|
namespace YaeBlog.Services;
|
||||||
|
|
||||||
public partial class RendererService(
|
public sealed partial class RendererService(
|
||||||
ILogger<RendererService> logger,
|
ILogger<RendererService> logger,
|
||||||
IEssayScanService essayScanService,
|
IEssayScanService essayScanService,
|
||||||
MarkdownPipeline markdownPipeline,
|
MarkdownPipeline markdownPipeline,
|
||||||
@@ -22,30 +21,43 @@ public partial class RendererService(
|
|||||||
|
|
||||||
private readonly List<IPostRenderProcessor> _postRenderProcessors = [];
|
private readonly List<IPostRenderProcessor> _postRenderProcessors = [];
|
||||||
|
|
||||||
public async Task RenderAsync()
|
public async Task RenderAsync(bool includeDrafts = false)
|
||||||
{
|
{
|
||||||
_stopwatch.Start();
|
_stopwatch.Start();
|
||||||
logger.LogInformation("Render essays start.");
|
logger.LogInformation("Render essays start.");
|
||||||
|
|
||||||
BlogContents contents = await essayScanService.ScanContents();
|
BlogContents contents = await essayScanService.ScanContents();
|
||||||
List<BlogContent> posts = contents.Posts.ToList();
|
List<BlogContent> posts = contents.Posts.ToList();
|
||||||
|
if (includeDrafts)
|
||||||
|
{
|
||||||
|
posts.AddRange(contents.Drafts);
|
||||||
|
}
|
||||||
|
|
||||||
IEnumerable<BlogContent> preProcessedContents = await PreProcess(posts);
|
IEnumerable<BlogContent> preProcessedContents = await PreProcess(posts);
|
||||||
|
|
||||||
List<BlogEssay> essays = [];
|
List<BlogEssay> essays = [];
|
||||||
await Task.Run(() =>
|
|
||||||
{
|
|
||||||
foreach (BlogContent content in preProcessedContents)
|
foreach (BlogContent content in preProcessedContents)
|
||||||
{
|
{
|
||||||
uint wordCount = GetWordCount(content);
|
(uint wordCount, string readTime) = GetWordCount(content);
|
||||||
|
DateTimeOffset publishDate = content.Metadata.Date is null
|
||||||
|
? DateTimeOffset.Now
|
||||||
|
: DateTimeOffset.Parse(content.Metadata.Date);
|
||||||
|
// 如果不存在最后的更新时间,就把更新时间设置为发布时间
|
||||||
|
DateTimeOffset updateTime = content.Metadata.UpdateTime is null
|
||||||
|
? publishDate
|
||||||
|
: DateTimeOffset.Parse(content.Metadata.UpdateTime);
|
||||||
|
|
||||||
BlogEssay essay = new()
|
BlogEssay essay = new()
|
||||||
{
|
{
|
||||||
Title = content.Metadata.Title ?? content.FileName,
|
Title = content.Metadata.Title ?? content.BlogName,
|
||||||
FileName = content.FileName,
|
FileName = content.BlogName,
|
||||||
|
IsDraft = content.IsDraft,
|
||||||
Description = GetDescription(content),
|
Description = GetDescription(content),
|
||||||
WordCount = wordCount,
|
WordCount = wordCount,
|
||||||
ReadTime = CalculateReadTime(wordCount),
|
ReadTime = readTime,
|
||||||
PublishTime = content.Metadata.Date ?? DateTime.Now,
|
PublishTime = publishDate,
|
||||||
HtmlContent = content.FileContent
|
UpdateTime = updateTime,
|
||||||
|
HtmlContent = content.Content
|
||||||
};
|
};
|
||||||
|
|
||||||
if (content.Metadata.Tags is not null)
|
if (content.Metadata.Tags is not null)
|
||||||
@@ -55,7 +67,6 @@ public partial class RendererService(
|
|||||||
|
|
||||||
essays.Add(essay);
|
essays.Add(essay);
|
||||||
}
|
}
|
||||||
});
|
|
||||||
|
|
||||||
ConcurrentBag<BlogEssay> postProcessEssays = [];
|
ConcurrentBag<BlogEssay> postProcessEssays = [];
|
||||||
Parallel.ForEach(essays, essay =>
|
Parallel.ForEach(essays, essay =>
|
||||||
@@ -67,7 +78,16 @@ public partial class RendererService(
|
|||||||
logger.LogDebug("Render markdown file {}.", newEssay);
|
logger.LogDebug("Render markdown file {}.", newEssay);
|
||||||
});
|
});
|
||||||
|
|
||||||
await PostProcess(postProcessEssays);
|
IEnumerable<BlogEssay> postProcessedEssays = await PostProcess(postProcessEssays);
|
||||||
|
|
||||||
|
foreach (BlogEssay essay in postProcessedEssays)
|
||||||
|
{
|
||||||
|
if (!essayContentService.TryAdd(essay))
|
||||||
|
{
|
||||||
|
throw new BlogFileException($"There are at least two essays with filename '{essay.FileName}'.");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
essayContentService.RefreshTags();
|
essayContentService.RefreshTags();
|
||||||
|
|
||||||
_stopwatch.Stop();
|
_stopwatch.Stop();
|
||||||
@@ -118,8 +138,10 @@ public partial class RendererService(
|
|||||||
return processedContents;
|
return processedContents;
|
||||||
}
|
}
|
||||||
|
|
||||||
private async Task PostProcess(IEnumerable<BlogEssay> essays)
|
private async Task<IEnumerable<BlogEssay>> PostProcess(IEnumerable<BlogEssay> essays)
|
||||||
{
|
{
|
||||||
|
ConcurrentBag<BlogEssay> processedContents = [];
|
||||||
|
|
||||||
await Parallel.ForEachAsync(essays, async (essay, _) =>
|
await Parallel.ForEachAsync(essays, async (essay, _) =>
|
||||||
{
|
{
|
||||||
foreach (IPostRenderProcessor processor in _postRenderProcessors)
|
foreach (IPostRenderProcessor processor in _postRenderProcessors)
|
||||||
@@ -127,32 +149,34 @@ public partial class RendererService(
|
|||||||
essay = await processor.ProcessAsync(essay);
|
essay = await processor.ProcessAsync(essay);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!essayContentService.TryAdd(essay))
|
processedContents.Add(essay);
|
||||||
{
|
|
||||||
throw new BlogFileException(
|
|
||||||
$"There are two essays with the same name: '{essay.FileName}'.");
|
|
||||||
}
|
|
||||||
});
|
});
|
||||||
|
|
||||||
|
List<BlogEssay> result = processedContents.ToList();
|
||||||
|
result.Sort();
|
||||||
|
|
||||||
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
[GeneratedRegex(@"(?<!\\)[^\#\*_\-\+\`{}\[\]!~]+")]
|
[GeneratedRegex(@"(?<!\\)[^\#\*_\-\+\`{}\[\]!~]+")]
|
||||||
private static partial Regex DescriptionPattern();
|
// private static partial Regex DescriptionPattern();
|
||||||
|
private static partial Regex DescriptionPattern { get; }
|
||||||
|
|
||||||
private string GetDescription(BlogContent content)
|
private string GetDescription(BlogContent content)
|
||||||
{
|
{
|
||||||
const string delimiter = "<!--more-->";
|
const string delimiter = "<!--more-->";
|
||||||
int pos = content.FileContent.IndexOf(delimiter, StringComparison.Ordinal);
|
int pos = content.Content.IndexOf(delimiter, StringComparison.Ordinal);
|
||||||
bool breakSentence = false;
|
bool breakSentence = false;
|
||||||
|
|
||||||
if (pos == -1)
|
if (pos == -1)
|
||||||
{
|
{
|
||||||
// 自动截取前50个字符
|
// 自动截取前50个字符
|
||||||
pos = content.FileContent.Length < 50 ? content.FileContent.Length : 50;
|
pos = content.Content.Length < 50 ? content.Content.Length : 50;
|
||||||
breakSentence = true;
|
breakSentence = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
string rawContent = content.FileContent[..pos];
|
string rawContent = content.Content[..pos];
|
||||||
MatchCollection matches = DescriptionPattern().Matches(rawContent);
|
MatchCollection matches = DescriptionPattern.Matches(rawContent);
|
||||||
|
|
||||||
StringBuilder builder = new();
|
StringBuilder builder = new();
|
||||||
foreach (Match match in matches)
|
foreach (Match match in matches)
|
||||||
@@ -167,28 +191,21 @@ public partial class RendererService(
|
|||||||
|
|
||||||
string description = builder.ToString();
|
string description = builder.ToString();
|
||||||
|
|
||||||
logger.LogDebug("Description of {} is {}.", content.FileName,
|
logger.LogDebug("Description of {name} is {desc}.", content.BlogName,
|
||||||
description);
|
description);
|
||||||
return description;
|
return description;
|
||||||
}
|
}
|
||||||
|
|
||||||
private uint GetWordCount(BlogContent content)
|
private (uint, string) GetWordCount(BlogContent content)
|
||||||
{
|
{
|
||||||
int count = (from c in content.FileContent
|
uint count = MarkdownWordCounter.CountWord(content);
|
||||||
where char.IsLetterOrDigit(c)
|
|
||||||
select c).Count();
|
|
||||||
|
|
||||||
logger.LogDebug("Word count of {} is {}", content.FileName,
|
logger.LogDebug("Word count of {blog} is {count}", content.BlogName,
|
||||||
count);
|
count);
|
||||||
return (uint)count;
|
|
||||||
}
|
|
||||||
|
|
||||||
private static string CalculateReadTime(uint wordCount)
|
|
||||||
{
|
|
||||||
// 据说语文教学大纲规定,中国高中生阅读现代文的速度是600字每分钟
|
// 据说语文教学大纲规定,中国高中生阅读现代文的速度是600字每分钟
|
||||||
int second = (int)wordCount / 10;
|
uint second = count / 10;
|
||||||
TimeSpan span = new(0, 0, second);
|
TimeSpan span = new(0, 0, (int)second);
|
||||||
|
|
||||||
return span.ToString("mm'分 'ss'秒'");
|
return (count, span.ToString("mm'分'ss'秒'"));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -1,18 +1,23 @@
|
|||||||
<Project Sdk="Microsoft.NET.Sdk.Web">
|
<Project Sdk="Microsoft.NET.Sdk.Web">
|
||||||
|
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<ProjectReference Include="..\YaeBlog.Core\YaeBlog.Core.csproj" />
|
<PackageReference Include="ImageFlow.NativeRuntime.ubuntu-x86_64" Version="2.1.0-rc11" Condition="$([MSBuild]::IsOsPlatform('Linux'))"/>
|
||||||
</ItemGroup>
|
<PackageReference Include="ImageFlow.NativeRuntime.osx-arm64" Version="2.1.0-rc11" Condition="$([MSBuild]::IsOsPlatform('OSX'))"/>
|
||||||
|
<PackageReference Include="ImageFlow.Net" Version="0.13.2"/>
|
||||||
<ItemGroup>
|
<PackageReference Include="System.CommandLine" Version="2.0.0-beta4.22272.1"/>
|
||||||
<PackageReference Include="Blazor.Bootstrap" Version="3.0.0-preview.2" />
|
<PackageReference Include="AngleSharp" Version="1.1.0"/>
|
||||||
<PackageReference Include="System.CommandLine" Version="2.0.0-beta4.22272.1" />
|
<PackageReference Include="Markdig" Version="0.38.0"/>
|
||||||
|
<PackageReference Include="YamlDotNet" Version="16.2.1"/>
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
|
|
||||||
<PropertyGroup>
|
<PropertyGroup>
|
||||||
<TargetFramework>net8.0</TargetFramework>
|
<TargetFramework>net10.0</TargetFramework>
|
||||||
<Nullable>enable</Nullable>
|
<Nullable>enable</Nullable>
|
||||||
<ImplicitUsings>enable</ImplicitUsings>
|
<ImplicitUsings>enable</ImplicitUsings>
|
||||||
</PropertyGroup>
|
</PropertyGroup>
|
||||||
|
|
||||||
|
<PropertyGroup>
|
||||||
|
<ClientAssetsRestoreCommand>pnpm install</ClientAssetsRestoreCommand>
|
||||||
|
<ClientAssetsBuildCommand>pwsh build.ps1 tailwind</ClientAssetsBuildCommand>
|
||||||
|
</PropertyGroup>
|
||||||
</Project>
|
</Project>
|
||||||
|
|||||||
@@ -1,11 +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
|
|
||||||
@using BlazorBootstrap
|
|
||||||
@using YaeBlog
|
|
||||||
@using YaeBlog.Components
|
|
||||||
@@ -6,6 +6,10 @@
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
"AllowedHosts": "*",
|
"AllowedHosts": "*",
|
||||||
|
"Tailwind": {
|
||||||
|
"InputFile": "wwwroot/input.css",
|
||||||
|
"OutputFile": "wwwroot/output.css"
|
||||||
|
},
|
||||||
"Blog": {
|
"Blog": {
|
||||||
"Root": "source",
|
"Root": "source",
|
||||||
"Announcement": "博客锐意装修中,敬请期待!测试阶段如有问题还请海涵。",
|
"Announcement": "博客锐意装修中,敬请期待!测试阶段如有问题还请海涵。",
|
||||||
@@ -18,16 +22,16 @@
|
|||||||
"AvatarImage": "https://ichirinko-blog-img-1.oss-cn-shenzhen.aliyuncs.com/Pic_res/img/202209122110798.png"
|
"AvatarImage": "https://ichirinko-blog-img-1.oss-cn-shenzhen.aliyuncs.com/Pic_res/img/202209122110798.png"
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"Name": "志田千陽",
|
"Name": "不会写程序的晨旭",
|
||||||
"Description": "日出多值得",
|
|
||||||
"Link": "https://zzachary.top/",
|
|
||||||
"AvatarImage": "https://zzachary.top/img/ztqy_hub928259802d192ff5718c06370f0f2c4_48203_300x0_resize_q75_box.jpg"
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"Name": "Chenxu",
|
|
||||||
"Description": "一个普通大学生",
|
"Description": "一个普通大学生",
|
||||||
"Link": "https://chenxutalk.top",
|
"Link": "https://chenxutalk.top",
|
||||||
"AvatarImage": "https://www.chenxutalk.top/img/photo.png"
|
"AvatarImage": "https://www.chenxutalk.top/img/photo.png"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"Name": "万木长风",
|
||||||
|
"Description": "世界渲染中...",
|
||||||
|
"Link": "https://ryohai.fun",
|
||||||
|
"AvatarImage": "https://ryohai.fun/static/favicons/favicon-32x32.png"
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
|
|||||||
124
YaeBlog/build.ps1
Executable file
124
YaeBlog/build.ps1
Executable file
@@ -0,0 +1,124 @@
|
|||||||
|
#!pwsh
|
||||||
|
|
||||||
|
[cmdletbinding()]
|
||||||
|
param(
|
||||||
|
[Parameter(Mandatory = $true, Position = 0, HelpMessage = "Specify the build target")]
|
||||||
|
[ValidateSet("tailwind", "publish", "compress", "build", "dev", "new")]
|
||||||
|
[string]$Target,
|
||||||
|
[string]$Output = "wwwroot",
|
||||||
|
[string]$Essay,
|
||||||
|
[switch]$Compress
|
||||||
|
)
|
||||||
|
|
||||||
|
begin {
|
||||||
|
Write-Host "Building $Target..."
|
||||||
|
|
||||||
|
if ($Target -eq "publish")
|
||||||
|
{
|
||||||
|
if ($Essay -eq "")
|
||||||
|
{
|
||||||
|
Write-Error "No publish target, please add with --essay argument."
|
||||||
|
exit 1
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if ($Target -eq "new")
|
||||||
|
{
|
||||||
|
if ($Essay -eq "")
|
||||||
|
{
|
||||||
|
Write-Error "No new name, please add with --essay argument."
|
||||||
|
exit 1
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
process {
|
||||||
|
function Compress-Image
|
||||||
|
{
|
||||||
|
Write-Host "Compress image assets..."
|
||||||
|
dotnet run -- compress --dry-run
|
||||||
|
$confirm = Read-Host "Really compress images? (y/n)"
|
||||||
|
if ($confirm -notmatch "^[yY]$")
|
||||||
|
{
|
||||||
|
Write-Host "Not compress images."
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
Write-Host "Do compress image..."
|
||||||
|
dotnet run -- compress
|
||||||
|
|
||||||
|
dotnet run -- scan
|
||||||
|
$confirm = Read-Host "Really delete unused images? (y/n)"
|
||||||
|
if ($confirm -notmatch "^[yY]$")
|
||||||
|
{
|
||||||
|
Write-Host "Not delete images."
|
||||||
|
return
|
||||||
|
}
|
||||||
|
Write-Host "Do delete unused images.."
|
||||||
|
dotnet run -- scan --rm
|
||||||
|
}
|
||||||
|
|
||||||
|
function Build-Image
|
||||||
|
{
|
||||||
|
$commitId = git rev-parse --short=10 HEAD
|
||||||
|
dotnet publish
|
||||||
|
podman build . -t ccr.ccs.tencentyun.com/jackfiled/blog --build-arg COMMIT_ID=$commitId
|
||||||
|
}
|
||||||
|
|
||||||
|
function Start-Develop {
|
||||||
|
Write-Host "Start tailwindcss and dotnet watch servers..."
|
||||||
|
$pnpmProcess = Start-Process pnpm "tailwindcss -i wwwroot/tailwind.css -o obj/Debug/net10.0/ClientAssets/tailwind.g.css -w" `
|
||||||
|
-PassThru
|
||||||
|
|
||||||
|
try
|
||||||
|
{
|
||||||
|
Write-Host "Started pnpm process exit? " $pnpmProcess.HasExited
|
||||||
|
Start-Process dotnet "watch -- serve" -PassThru | Wait-Process
|
||||||
|
}
|
||||||
|
finally
|
||||||
|
{
|
||||||
|
if ($pnpmProcess.HasExited)
|
||||||
|
{
|
||||||
|
Write-Error "pnpm process has exited!"
|
||||||
|
exit 1
|
||||||
|
}
|
||||||
|
Write-Host "Kill tailwindcss and dotnet watch servers..."
|
||||||
|
$pnpmProcess | Stop-Process
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
switch ($Target)
|
||||||
|
{
|
||||||
|
"tailwind" {
|
||||||
|
Write-Host "Build tailwind css into $Output."
|
||||||
|
pnpm tailwindcss -i wwwroot/tailwind.css -o $Output/tailwind.g.css
|
||||||
|
break
|
||||||
|
}
|
||||||
|
"publish" {
|
||||||
|
Write-Host "Publish essay $Essay..."
|
||||||
|
dotnet run -- publish $Essay
|
||||||
|
|
||||||
|
if ($Compress)
|
||||||
|
{
|
||||||
|
Compress-Image
|
||||||
|
}
|
||||||
|
break
|
||||||
|
}
|
||||||
|
"compress" {
|
||||||
|
Compress-Image
|
||||||
|
break
|
||||||
|
}
|
||||||
|
"build" {
|
||||||
|
Build-Image
|
||||||
|
break
|
||||||
|
}
|
||||||
|
"dev" {
|
||||||
|
Start-Develop
|
||||||
|
break
|
||||||
|
}
|
||||||
|
"new" {
|
||||||
|
dotnet run -- new $Essay
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user