Compare commits
29 Commits
67c72284d5
...
master
| Author | SHA1 | Date | |
|---|---|---|---|
|
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 |
@@ -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
|
||||||
|
|||||||
@@ -1,29 +1,36 @@
|
|||||||
name: Build blog docker image
|
name: Build blog docker image
|
||||||
on:
|
on:
|
||||||
push:
|
push:
|
||||||
branches:
|
branches:
|
||||||
- master
|
- master
|
||||||
jobs:
|
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: |
|
||||||
cd YaeBlog
|
cd YaeBlog
|
||||||
dotnet publish
|
dotnet publish
|
||||||
- name: Build docker image
|
- name: Build docker image.
|
||||||
run: |
|
run: |
|
||||||
cd YaeBlog
|
proxy
|
||||||
docker build . -t registry.cn-beijing.aliyuncs.com/jackfiled/blog:latest
|
podman pull mcr.microsoft.com/dotnet/aspnet:9.0
|
||||||
- name: Login aliyun docker registry
|
unproxy
|
||||||
uses: https://git.rrricardo.top/actions/login-action@v3
|
cd YaeBlog
|
||||||
with:
|
podman build . -t ccr.ccs.tencentyun.com/jackfiled/blog --build-arg COMMIT_ID=$(git rev-parse --short=10 HEAD)
|
||||||
registry: registry.cn-beijing.aliyuncs.com
|
- name: Workaround to make sure podman-login working.
|
||||||
username: 初冬的朝阳
|
run: |
|
||||||
password: ${{ secrets.ALIYUN_PASSWORD }}
|
mkdir /root/.docker
|
||||||
- name: Push docker image
|
- name: Login tencent cloud docker registry.
|
||||||
run: docker push registry.cn-beijing.aliyuncs.com/jackfiled/blog:latest
|
uses: https://mirrors.rrricardo.top/actions/podman-login.git@v1
|
||||||
|
with:
|
||||||
|
registry: ccr.ccs.tencentyun.com
|
||||||
|
username: 100044380877
|
||||||
|
password: ${{ secrets.TENCENT_REGISTRY_PASSWORD }}
|
||||||
|
auth_file_path: /etc/containers/auth.json
|
||||||
|
- name: Push docker image.
|
||||||
|
run: podman push ccr.ccs.tencentyun.com/jackfiled/blog:latest
|
||||||
|
|||||||
2
.gitignore
vendored
2
.gitignore
vendored
@@ -484,4 +484,4 @@ $RECYCLE.BIN/
|
|||||||
*.swp
|
*.swp
|
||||||
|
|
||||||
# Tailwind auto-generated stylesheet
|
# Tailwind auto-generated stylesheet
|
||||||
output.css
|
*.g.css
|
||||||
|
|||||||
41
YaeBlog.sln
41
YaeBlog.sln
@@ -1,41 +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("{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
|
|
||||||
{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
|
|
||||||
14
YaeBlog.slnx
Normal file
14
YaeBlog.slnx
Normal file
@@ -0,0 +1,14 @@
|
|||||||
|
<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/YaeBlog.csproj" />
|
||||||
|
</Solution>
|
||||||
@@ -5,7 +5,9 @@ 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();
|
||||||
|
|||||||
@@ -7,6 +7,4 @@ public interface IEssayScanService
|
|||||||
public Task<BlogContents> ScanContents();
|
public Task<BlogContents> ScanContents();
|
||||||
|
|
||||||
public Task SaveBlogContent(BlogContent content, bool isDraft = true);
|
public Task SaveBlogContent(BlogContent content, bool isDraft = true);
|
||||||
|
|
||||||
public Task<ImageScanResult> ScanImages();
|
|
||||||
}
|
}
|
||||||
|
|||||||
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,4 +1,6 @@
|
|||||||
using System.CommandLine;
|
using System.CommandLine;
|
||||||
|
using Microsoft.Extensions.Options;
|
||||||
|
using YaeBlog.Abstraction;
|
||||||
using YaeBlog.Commands.Binders;
|
using YaeBlog.Commands.Binders;
|
||||||
using YaeBlog.Components;
|
using YaeBlog.Components;
|
||||||
using YaeBlog.Extensions;
|
using YaeBlog.Extensions;
|
||||||
@@ -19,6 +21,7 @@ public sealed class YaeBlogCommand
|
|||||||
AddNewCommand(_rootCommand);
|
AddNewCommand(_rootCommand);
|
||||||
AddPublishCommand(_rootCommand);
|
AddPublishCommand(_rootCommand);
|
||||||
AddScanCommand(_rootCommand);
|
AddScanCommand(_rootCommand);
|
||||||
|
AddCompressCommand(_rootCommand);
|
||||||
}
|
}
|
||||||
|
|
||||||
public Task<int> RunAsync(string[] args)
|
public Task<int> RunAsync(string[] args)
|
||||||
@@ -70,7 +73,6 @@ public sealed class YaeBlogCommand
|
|||||||
builder.Services.AddControllers();
|
builder.Services.AddControllers();
|
||||||
builder.AddYaeBlog();
|
builder.AddYaeBlog();
|
||||||
builder.AddWatcher();
|
builder.AddWatcher();
|
||||||
builder.AddTailwindWatcher();
|
|
||||||
|
|
||||||
WebApplication application = builder.Build();
|
WebApplication application = builder.Build();
|
||||||
|
|
||||||
@@ -95,22 +97,20 @@ public sealed class YaeBlogCommand
|
|||||||
Argument<string> filenameArgument = new(name: "blog name", description: "The created blog filename.");
|
Argument<string> filenameArgument = new(name: "blog name", description: "The created blog filename.");
|
||||||
newCommand.AddArgument(filenameArgument);
|
newCommand.AddArgument(filenameArgument);
|
||||||
|
|
||||||
newCommand.SetHandler(async (file, _, _, essayScanService) =>
|
newCommand.SetHandler(async (file, blogOption, _, essayScanService) =>
|
||||||
{
|
{
|
||||||
BlogContents contents = await essayScanService.ScanContents();
|
BlogContents contents = await essayScanService.ScanContents();
|
||||||
|
|
||||||
if (contents.Posts.Any(content => content.FileName == file))
|
if (contents.Posts.Any(content => content.BlogName == file))
|
||||||
{
|
{
|
||||||
Console.WriteLine("There exists the same title blog in posts.");
|
Console.WriteLine("There exists the same title blog in posts.");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
await essayScanService.SaveBlogContent(new BlogContent
|
await essayScanService.SaveBlogContent(new BlogContent(
|
||||||
{
|
new FileInfo(Path.Combine(blogOption.Value.Root, "drafts", file + ".md")),
|
||||||
FileName = file,
|
new MarkdownMetadata { Title = file, Date = DateTime.Now },
|
||||||
FileContent = string.Empty,
|
string.Empty, true, [], []));
|
||||||
Metadata = new MarkdownMetadata { Title = file, Date = DateTime.Now }
|
|
||||||
});
|
|
||||||
|
|
||||||
Console.WriteLine($"Created new blog '{file}.");
|
Console.WriteLine($"Created new blog '{file}.");
|
||||||
}, filenameArgument, new BlogOptionsBinder(), new LoggerBinder<EssayScanService>(),
|
}, filenameArgument, new BlogOptionsBinder(), new LoggerBinder<EssayScanService>(),
|
||||||
@@ -127,15 +127,15 @@ public sealed class YaeBlogCommand
|
|||||||
BlogContents contents = await essyScanService.ScanContents();
|
BlogContents contents = await essyScanService.ScanContents();
|
||||||
|
|
||||||
Console.WriteLine($"All {contents.Posts.Count} Posts:");
|
Console.WriteLine($"All {contents.Posts.Count} Posts:");
|
||||||
foreach (BlogContent content in contents.Posts.OrderBy(x => x.FileName))
|
foreach (BlogContent content in contents.Posts.OrderBy(x => x.BlogName))
|
||||||
{
|
{
|
||||||
Console.WriteLine($" - {content.FileName}");
|
Console.WriteLine($" - {content.BlogName}");
|
||||||
}
|
}
|
||||||
|
|
||||||
Console.WriteLine($"All {contents.Drafts.Count} Drafts:");
|
Console.WriteLine($"All {contents.Drafts.Count} Drafts:");
|
||||||
foreach (BlogContent content in contents.Drafts.OrderBy(x => x.FileName))
|
foreach (BlogContent content in contents.Drafts.OrderBy(x => x.BlogName))
|
||||||
{
|
{
|
||||||
Console.WriteLine($" - {content.FileName}");
|
Console.WriteLine($" - {content.BlogName}");
|
||||||
}
|
}
|
||||||
}, new BlogOptionsBinder(), new LoggerBinder<EssayScanService>(), new EssayScanServiceBinder());
|
}, new BlogOptionsBinder(), new LoggerBinder<EssayScanService>(), new EssayScanServiceBinder());
|
||||||
}
|
}
|
||||||
@@ -151,32 +151,39 @@ public sealed class YaeBlogCommand
|
|||||||
|
|
||||||
command.SetHandler(async (_, _, essayScanService, removeOptionValue) =>
|
command.SetHandler(async (_, _, essayScanService, removeOptionValue) =>
|
||||||
{
|
{
|
||||||
ImageScanResult result = await essayScanService.ScanImages();
|
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 (result.UnusedImages.Count != 0)
|
if (unusedImages.Count != 0)
|
||||||
{
|
{
|
||||||
Console.WriteLine("Found unused images:");
|
Console.WriteLine("Found unused images:");
|
||||||
Console.WriteLine("HINT: use '--rm' to remove unused images.");
|
Console.WriteLine("HINT: use '--rm' to remove unused images.");
|
||||||
}
|
}
|
||||||
|
|
||||||
foreach (FileInfo image in result.UnusedImages)
|
foreach (BlogImageInfo image in unusedImages)
|
||||||
{
|
{
|
||||||
Console.WriteLine($" - {image.FullName}");
|
Console.WriteLine($" - {image.File.FullName}");
|
||||||
}
|
}
|
||||||
|
|
||||||
if (removeOptionValue)
|
if (removeOptionValue)
|
||||||
{
|
{
|
||||||
foreach (FileInfo image in result.UnusedImages)
|
foreach (BlogImageInfo image in unusedImages)
|
||||||
{
|
{
|
||||||
image.Delete();
|
image.File.Delete();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
Console.WriteLine("Used not existed images:");
|
Console.WriteLine("Used not existed images:");
|
||||||
|
|
||||||
foreach (FileInfo image in result.NotFoundImages)
|
foreach (BlogContent content in contents)
|
||||||
{
|
{
|
||||||
Console.WriteLine($" - {image.FullName}");
|
foreach (FileInfo file in content.NotfoundImages)
|
||||||
|
{
|
||||||
|
Console.WriteLine($"- {file.Name} in {content.BlogName}");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}, new BlogOptionsBinder(), new LoggerBinder<EssayScanService>(), new EssayScanServiceBinder(), removeOption);
|
}, new BlogOptionsBinder(), new LoggerBinder<EssayScanService>(), new EssayScanServiceBinder(), removeOption);
|
||||||
}
|
}
|
||||||
@@ -194,7 +201,7 @@ public sealed class YaeBlogCommand
|
|||||||
BlogContents contents = await essayScanService.ScanContents();
|
BlogContents contents = await essayScanService.ScanContents();
|
||||||
|
|
||||||
BlogContent? content = (from blog in contents.Drafts
|
BlogContent? content = (from blog in contents.Drafts
|
||||||
where blog.FileName == filename
|
where blog.BlogName == filename
|
||||||
select blog).FirstOrDefault();
|
select blog).FirstOrDefault();
|
||||||
|
|
||||||
if (content is null)
|
if (content is null)
|
||||||
@@ -203,14 +210,17 @@ public sealed class YaeBlogCommand
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// 设置发布的时间
|
||||||
|
content.Metadata.Date = DateTime.Now;
|
||||||
|
|
||||||
// 将选中的博客文件复制到posts
|
// 将选中的博客文件复制到posts
|
||||||
await essayScanService.SaveBlogContent(content, isDraft: false);
|
await essayScanService.SaveBlogContent(content, isDraft: false);
|
||||||
|
|
||||||
// 复制图片文件夹
|
// 复制图片文件夹
|
||||||
DirectoryInfo sourceImageDirectory =
|
DirectoryInfo sourceImageDirectory =
|
||||||
new(Path.Combine(blogOptions.Value.Root, "drafts", content.FileName));
|
new(Path.Combine(blogOptions.Value.Root, "drafts", content.BlogName));
|
||||||
DirectoryInfo targetImageDirectory =
|
DirectoryInfo targetImageDirectory =
|
||||||
new(Path.Combine(blogOptions.Value.Root, "posts", content.FileName));
|
new(Path.Combine(blogOptions.Value.Root, "posts", content.BlogName));
|
||||||
|
|
||||||
if (sourceImageDirectory.Exists)
|
if (sourceImageDirectory.Exists)
|
||||||
{
|
{
|
||||||
@@ -224,9 +234,30 @@ public sealed class YaeBlogCommand
|
|||||||
}
|
}
|
||||||
|
|
||||||
// 删除原始的文件
|
// 删除原始的文件
|
||||||
FileInfo sourceBlogFile = new(Path.Combine(blogOptions.Value.Root, "drafts", content.FileName + ".md"));
|
FileInfo sourceBlogFile = new(Path.Combine(blogOptions.Value.Root, "drafts", content.BlogName + ".md"));
|
||||||
sourceBlogFile.Delete();
|
sourceBlogFile.Delete();
|
||||||
}, new BlogOptionsBinder(),
|
}, new BlogOptionsBinder(),
|
||||||
new LoggerBinder<EssayScanService>(), new EssayScanServiceBinder(), filenameArgument);
|
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,5 +1,5 @@
|
|||||||
<!DOCTYPE html>
|
<!DOCTYPE html>
|
||||||
<html lang="en">
|
<html lang="zh">
|
||||||
|
|
||||||
<head>
|
<head>
|
||||||
<meta charset="utf-8"/>
|
<meta charset="utf-8"/>
|
||||||
@@ -8,18 +8,13 @@
|
|||||||
<link rel="stylesheet" href="YaeBlog.styles.css"/>
|
<link rel="stylesheet" href="YaeBlog.styles.css"/>
|
||||||
<link rel="icon" href="images/favicon.ico"/>
|
<link rel="icon" href="images/favicon.ico"/>
|
||||||
<link rel="stylesheet" href="globals.css"/>
|
<link rel="stylesheet" href="globals.css"/>
|
||||||
<link rel="stylesheet" href="output.css"/>
|
<link rel="stylesheet" href="tailwind.g.css"/>
|
||||||
<HeadOutlet/>
|
<HeadOutlet/>
|
||||||
</head>
|
</head>
|
||||||
|
|
||||||
<body>
|
<body>
|
||||||
<Routes/>
|
<Routes/>
|
||||||
|
<script src="_framework/blazor.web.js"></script>
|
||||||
<script src="_framework/blazor.web.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>
|
||||||
@@ -4,54 +4,46 @@
|
|||||||
@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)
|
||||||
</a>
|
</div>
|
||||||
</div>
|
</a>
|
||||||
</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)
|
||||||
</a>
|
</div>
|
||||||
</div>
|
</a>
|
||||||
</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,19 +1,19 @@
|
|||||||
@using System.Text.Encodings.Web
|
@using System.Text.Encodings.Web
|
||||||
@using YaeBlog.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="/blog/essays/@(Essay.FileName)" target="_blank">@(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))">
|
<a href="/blog/tags/?tagName=@(UrlEncoder.Default.Encode(key))">
|
||||||
# @key
|
# @key
|
||||||
</a>
|
</a>
|
||||||
@@ -21,20 +21,11 @@
|
|||||||
}
|
}
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div class="row p-2">
|
<div class="p-2">
|
||||||
<div class="col">
|
@(Essay.Description)
|
||||||
@(Essay.Description)
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<div class="row">
|
|
||||||
<div class="col border-bottom">
|
|
||||||
|
|
||||||
</div>
|
|
||||||
</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="Ricardo Ren"/>
|
||||||
|
,由
|
||||||
|
<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 string DotnetVersion => $".NET {Environment.Version}";
|
||||||
|
|
||||||
|
private string BuildCommitId => Environment.GetEnvironmentVariable("COMMIT_ID") ?? "local_build";
|
||||||
|
|
||||||
|
private string BuildCommitUrl => $"https://git.rrricardo.top/jackfiled/YaeBlog/commit/{BuildCommitId}";
|
||||||
|
}
|
||||||
|
|||||||
@@ -1,35 +1,41 @@
|
|||||||
@using YaeBlog.Models
|
<div class="px-4 py-8 border border-sky-700 rounded-md bg-sky-200">
|
||||||
@inject BlogOptions Options
|
<div class="flex flex-col gap-3 text-md">
|
||||||
|
<div>
|
||||||
|
文章作者:<a href="https://rrricardo.top" target="_blank" class="text-blue-600">Ricardo Ren</a>
|
||||||
|
</div>
|
||||||
|
|
||||||
<div class="row px-2 py-4 copyright border border-primary rounded-1 bg-primary-subtle">
|
<div>
|
||||||
<div class="col">
|
文章地址:
|
||||||
<div class="row p-1">
|
<a href="/blog/essays/@(EssayFilename)" target="_blank" class="text-blue-600">
|
||||||
<div class="col">
|
@($"https://rrricardo.top/blog/essays/{EssayFilename}")
|
||||||
文章作者:<a href="https://rrricardo.top" target="_blank">Ricardo Ren</a>
|
</a>
|
||||||
|
</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 class="flex flex-col">
|
||||||
|
<div class="flex justify-center">
|
||||||
|
<p>如果觉得不错的话,可以支持一下作者哦~</p>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div class="flex justify-center">
|
||||||
|
<AppreciationCode/>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div class="row p-1">
|
|
||||||
<div class="col">
|
|
||||||
文章地址:
|
|
||||||
<a href="/blog/essays/@(EssayAddress)" target="_blank">
|
|
||||||
@($"https://rrricardo.top/blog/essays/{EssayAddress}")
|
|
||||||
</a>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<div class="row p-1">
|
|
||||||
<div class="col">
|
|
||||||
版权声明:本博客所有文章除特别声明外,均采用
|
|
||||||
<a href="https://creativecommons.org/licenses/by-nc-sa/4.0/" target="_blank">CC BY-NC-SA 4.0</a>
|
|
||||||
许可协议,转载请注明来自
|
|
||||||
<a href="https://rrricardo.top/blog/" target="_blank">Ricardo's Blog</a>。
|
|
||||||
</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; }
|
||||||
|
}
|
||||||
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}";
|
||||||
|
}
|
||||||
@@ -1,5 +1,8 @@
|
|||||||
FROM mcr.microsoft.com/dotnet/aspnet:9.0
|
FROM mcr.microsoft.com/dotnet/aspnet:9.0
|
||||||
|
|
||||||
|
ARG COMMIT_ID
|
||||||
|
ENV COMMIT_ID=${COMMIT_ID}
|
||||||
|
|
||||||
WORKDIR /app
|
WORKDIR /app
|
||||||
COPY bin/Release/net9.0/publish/ ./
|
COPY bin/Release/net9.0/publish/ ./
|
||||||
COPY source/ ./source/
|
COPY source/ ./source/
|
||||||
|
|||||||
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)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -1,12 +0,0 @@
|
|||||||
namespace YaeBlog.Core.Exceptions;
|
|
||||||
|
|
||||||
public sealed class ProcessInteropException : Exception
|
|
||||||
{
|
|
||||||
public ProcessInteropException(string message) : base(message)
|
|
||||||
{
|
|
||||||
}
|
|
||||||
|
|
||||||
public ProcessInteropException(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;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -22,9 +22,8 @@ public static class WebApplicationBuilderExtensions
|
|||||||
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);
|
||||||
|
|
||||||
@@ -45,13 +44,4 @@ public static class WebApplicationBuilderExtensions
|
|||||||
|
|
||||||
return builder;
|
return builder;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static WebApplicationBuilder AddTailwindWatcher(this WebApplicationBuilder builder)
|
|
||||||
{
|
|
||||||
builder.Services.AddSingleton<ProcessInteropService>();
|
|
||||||
builder.Services.Configure<TailwindOptions>(builder.Configuration.GetSection(TailwindOptions.OptionName));
|
|
||||||
builder.Services.AddHostedService<TailwindRefreshService>();
|
|
||||||
|
|
||||||
return builder;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -9,9 +9,8 @@ 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
|
||||||
|
|||||||
@@ -2,41 +2,41 @@
|
|||||||
|
|
||||||
@attribute [StreamRendering]
|
@attribute [StreamRendering]
|
||||||
|
|
||||||
<main class="container mx-auto">
|
<main class="container mx-auto flex flex-col min-h-screen">
|
||||||
<div class="grid grid-cols-3 mx-3">
|
<div class="grid grid-cols-3 mx-3">
|
||||||
<div class="md:col-span-2 col-span-3 my-6">
|
<div class="md:col-span-2 col-span-3 h-20 flex items-center">
|
||||||
<a href="/blog/">
|
<a href="/blog/">
|
||||||
<span class="text-blue-600 text-2xl">Ricardo's Blog</span>
|
<span class="text-blue-600 text-2xl">Ricardo's Blog</span>
|
||||||
</a>
|
</a>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div class="md:col-span-1 col-span-3 my-6">
|
<div class="md:col-span-1 col-span-3 h-20 flex items-center">
|
||||||
<div class="flex flex-row">
|
<div class="flex flex-row w-full px-2 gap-3 md:justify-center justify-end">
|
||||||
<div class="px-2 ">
|
<div>
|
||||||
<a href="/blog/">
|
|
||||||
<span class="text-xl text-blue-600">首页</span>
|
|
||||||
</a>
|
|
||||||
</div>
|
|
||||||
<div class="px-2 ">
|
|
||||||
<a href="/blog/archives/">
|
<a href="/blog/archives/">
|
||||||
<span class="text-xl text-blue-600">归档</span>
|
<span class="text-xl text-blue-600">归档</span>
|
||||||
</a>
|
</a>
|
||||||
</div>
|
</div>
|
||||||
<div class="px-2 ">
|
<div>
|
||||||
<a href="/blog/tags/">
|
<a href="/blog/tags/">
|
||||||
<span class="text-xl text-blue-600">标签</span>
|
<span class="text-xl text-blue-600">标签</span>
|
||||||
</a>
|
</a>
|
||||||
</div>
|
</div>
|
||||||
<div class="px-2 ">
|
<div>
|
||||||
<a href="/blog/about/">
|
<a href="/about/" target="_blank">
|
||||||
<span class="text-xl text-blue-600">关于</span>
|
<span class="text-xl text-blue-600">关于</span>
|
||||||
</a>
|
</a>
|
||||||
</div>
|
</div>
|
||||||
|
<div>
|
||||||
|
<a href="/friends/" target="_blank">
|
||||||
|
<span class="text-xl text-blue-600">友链</span>
|
||||||
|
</a>
|
||||||
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div class="px-4 py-2">
|
<div class="px-4 py-2 flex-grow">
|
||||||
@Body
|
@Body
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
|||||||
@@ -1,22 +1,34 @@
|
|||||||
@inherits LayoutComponentBase
|
@inherits LayoutComponentBase
|
||||||
|
|
||||||
<main class="container mx-auto">
|
<main class="container mx-auto min-h-screen flex flex-col">
|
||||||
<div class="flex flex-row h-20">
|
<div class="grid grid-cols-4">
|
||||||
<div class="px-2 basis-3/4">
|
<div class="px-2 md:col-span-3 col-span-4 h-20 flex items-center">
|
||||||
<a href="/" class="text-2xl p-2">
|
<a href="/" class="text-2xl">
|
||||||
<h4 class="text-blue-600">Ricardo's Index</h4>
|
<h4 class="text-blue-600">Ricardo's Index</h4>
|
||||||
</a>
|
</a>
|
||||||
<h1></h1>
|
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div class="basis-1/4">
|
<div class="md:col-span-1 col-span-4 h-20 flex items-center">
|
||||||
<a href="mailto://shicangjuner@outlook.com" class="p-2 text-xl" target="_blank">
|
<div class="flex flex-row w-full px-2 md:justify-center justify-end text-xl gap-3">
|
||||||
<h5 class="text-blue-600">E-mail</h5>
|
<Anchor
|
||||||
</a>
|
Address="/blog/"
|
||||||
|
Text="博客"
|
||||||
|
NewPage="@(true)"/>
|
||||||
|
|
||||||
|
<Anchor
|
||||||
|
Address="/about/"
|
||||||
|
Text="关于"
|
||||||
|
NewPage="@(true)"/>
|
||||||
|
|
||||||
|
<Anchor
|
||||||
|
Address="/friends"
|
||||||
|
Text="友链"
|
||||||
|
NewPage="@(true)"/>
|
||||||
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div class="px-4 mx-auto">
|
<div class="px-4 mx-auto flex-grow">
|
||||||
<div class="py-2">
|
<div class="py-2">
|
||||||
@Body
|
@Body
|
||||||
</div>
|
</div>
|
||||||
|
|||||||
@@ -1,8 +0,0 @@
|
|||||||
.center {
|
|
||||||
margin: 0 auto;
|
|
||||||
max-width: 48em;
|
|
||||||
min-height: calc(100vh - 80px);
|
|
||||||
position: relative;
|
|
||||||
display: flex;
|
|
||||||
flex-direction: column;
|
|
||||||
}
|
|
||||||
@@ -1,10 +0,0 @@
|
|||||||
namespace YaeBlog.Models;
|
|
||||||
|
|
||||||
public class AboutInfo
|
|
||||||
{
|
|
||||||
public required string Introduction { get; set; }
|
|
||||||
|
|
||||||
public required string Description { get; set; }
|
|
||||||
|
|
||||||
public required string AvatarImage { get; set; }
|
|
||||||
}
|
|
||||||
@@ -1,10 +1,20 @@
|
|||||||
namespace YaeBlog.Models;
|
namespace YaeBlog.Models;
|
||||||
|
|
||||||
public class BlogContent
|
/// <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 required string FileName { get; init; }
|
public string BlogName => BlogFile.Name.Split('.')[0];
|
||||||
|
|
||||||
public required MarkdownMetadata Metadata { get; init; }
|
|
||||||
|
|
||||||
public required string FileContent { get; set; }
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,10 +1,12 @@
|
|||||||
using System.Collections.Concurrent;
|
using System.Collections;
|
||||||
|
using System.Collections.Concurrent;
|
||||||
|
|
||||||
namespace YaeBlog.Models;
|
namespace YaeBlog.Models;
|
||||||
|
|
||||||
public sealed class BlogContents(ConcurrentBag<BlogContent> drafts, ConcurrentBag<BlogContent> posts)
|
public record BlogContents(ConcurrentBag<BlogContent> Drafts, ConcurrentBag<BlogContent> Posts)
|
||||||
|
: IEnumerable<BlogContent>
|
||||||
{
|
{
|
||||||
public ConcurrentBag<BlogContent> Drafts { get; } = drafts;
|
public IEnumerator<BlogContent> GetEnumerator() => Posts.Concat(Drafts).GetEnumerator();
|
||||||
|
|
||||||
public ConcurrentBag<BlogContent> Posts { get; } = posts;
|
IEnumerator IEnumerable.GetEnumerator() => GetEnumerator();
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -6,6 +6,8 @@ public class BlogEssay : IComparable<BlogEssay>
|
|||||||
|
|
||||||
public required string FileName { get; init; }
|
public required string FileName { get; init; }
|
||||||
|
|
||||||
|
public required bool IsDraft { get; init; }
|
||||||
|
|
||||||
public required DateTime PublishTime { get; init; }
|
public required DateTime PublishTime { get; init; }
|
||||||
|
|
||||||
public required string Description { get; init; }
|
public required string Description { get; init; }
|
||||||
@@ -24,6 +26,7 @@ public class BlogEssay : IComparable<BlogEssay>
|
|||||||
{
|
{
|
||||||
Title = Title,
|
Title = Title,
|
||||||
FileName = FileName,
|
FileName = FileName,
|
||||||
|
IsDraft = IsDraft,
|
||||||
PublishTime = PublishTime,
|
PublishTime = PublishTime,
|
||||||
Description = Description,
|
Description = Description,
|
||||||
WordCount = WordCount,
|
WordCount = WordCount,
|
||||||
@@ -39,10 +42,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()
|
||||||
|
|||||||
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,3 +0,0 @@
|
|||||||
namespace YaeBlog.Models;
|
|
||||||
|
|
||||||
public record struct ImageScanResult(List<FileInfo> UnusedImages, List<FileInfo> NotFoundImages);
|
|
||||||
@@ -1,10 +0,0 @@
|
|||||||
namespace YaeBlog.Models;
|
|
||||||
|
|
||||||
public class TailwindOptions
|
|
||||||
{
|
|
||||||
public const string OptionName = "Tailwind";
|
|
||||||
|
|
||||||
public required string InputFile { get; set; }
|
|
||||||
|
|
||||||
public required string OutputFile { get; set; }
|
|
||||||
}
|
|
||||||
@@ -1,141 +1,74 @@
|
|||||||
@page "/blog/about"
|
@page "/about"
|
||||||
@using YaeBlog.Models
|
|
||||||
|
|
||||||
@inject BlogOptions Options
|
|
||||||
|
|
||||||
<PageTitle>
|
<PageTitle>
|
||||||
关于
|
关于
|
||||||
</PageTitle>
|
</PageTitle>
|
||||||
|
|
||||||
<div class="container">
|
<div class="flex flex-col">
|
||||||
<div class="row">
|
<div>
|
||||||
<div class="col">
|
<h1 class="text-4xl">关于</h1>
|
||||||
<h1>关于</h1>
|
|
||||||
</div>
|
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div class="row">
|
<div class="py-4">
|
||||||
<div class="col fst-italic py-2">
|
<span class="italic">把字刻在石头上!(・’ω’・)</span>
|
||||||
把字刻在石头上!(・’ω’・)
|
|
||||||
</div>
|
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div class="row p-2">
|
<div class="flex flex-col p-2">
|
||||||
<div class="col">
|
<div class="flex flex-col p-2">
|
||||||
<div class="row">
|
<div class="pb-2">
|
||||||
<div class="col">
|
<h3 class="text-2xl">关于我</h3>
|
||||||
<h3>关于我</h3>
|
|
||||||
</div>
|
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div class="row py-2">
|
<div class="py-2">
|
||||||
<div class="col">
|
计算机科学与技术在读大学生,明光村幼儿园附属大学所属。正处于读书和失业的叠加态。
|
||||||
计算机科学与技术在读大学生,明光村幼儿园附属大学所属。正处于读书和失业的叠加态。
|
一般在互联网上使用<span class="italic">初冬的朝阳</span>或者<span class="italic">jackfiled</span>的名字活动。
|
||||||
一般在互联网上使用<span class="fst-italic">初冬的朝阳</span>或者<span class="fst-italic">jackfiled</span>的名字活动。
|
<span class="line-through">都是ICP备案过的人了,网名似乎没有太大的用处(</span>
|
||||||
<span class="text-decoration-line-through">都是ICP备案过的人了,网名似乎没有太大的用处(</span>
|
|
||||||
</div>
|
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div class="row py-2">
|
<div class="py-2">
|
||||||
<div class="col">
|
主要是一个C#程序员,目前也在尝试写一点Rust。
|
||||||
主要是一个C#程序员,目前也在尝试写一点Rust。
|
总体上对于编程语言的态度是“<span>大家都是我的翅膀.jpg</span>”。
|
||||||
总体上对于编程语言的态度是“<span>大家都是我的翅膀.jpg</span>”。
|
前后端分离的项目本当上手。
|
||||||
前后端分离的项目本当上手。
|
常常因为现实的压力而写一些C/C++。
|
||||||
常常因为现实的压力而写一些C/C++。
|
<span class="line-through">对于Java和Go的评价很低。</span>
|
||||||
<span class="text-decoration-line-through">对于Java和Go的评价很低。</span>
|
日常使用ArchLinux。
|
||||||
日常使用ArchLinux。
|
|
||||||
</div>
|
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div class="row py-2">
|
<div class="py-2">
|
||||||
<div class="col">
|
100%社恐。日常生活是宅在电脑前面自言自语。
|
||||||
100%社恐。日常生活是宅在电脑前面自言自语。兴趣活动是读书和看番。
|
兴趣活动是读书和看番,目前在玩原神和三角洲。
|
||||||
</div>
|
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div class="row py-2">
|
<div class="py-4">
|
||||||
<div class="col">
|
常常被人批评没有梦想,这里就随便瞎编一下。
|
||||||
常常被人批评没有梦想,这里就随便瞎编一下。
|
成为嵌入式工程师,修好桌面上的<a href="https://www.bilibili.com/video/BV1VA411p7MD">HoloCubic</a>。
|
||||||
成为嵌入式工程师,修好桌面上的<a href="https://www.bilibili.com/video/BV1VA411p7MD">HoloCubic</a>。
|
完成第一个不是课程设计的个人开源项目。
|
||||||
完成第一个不是课程设计的个人开源项目。
|
遇到能够搭伙过日子的人也算是一大梦想,虽然社恐人根本不知道从何开始的说,
|
||||||
遇到能够搭伙过日子的人也算是一大梦想,虽然社恐人根本不知道从何开始的说,
|
<span class="line-through">什么时候天上才能掉美少女?</span>
|
||||||
<span class="text-decoration-line-through">什么时候天上才能掉美少女?</span>
|
|
||||||
</div>
|
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div class="row py-2">
|
<div class="py-2">
|
||||||
<div class="col">
|
公开的联系渠道是<a href="mailto:shicangjuner@outlook.com">电子邮件</a>。
|
||||||
公开的联系渠道是<a href="mailto:shicangjuner@outlook.com">电子邮件</a>。
|
也可以试试在各大平台搜索上面提到的名字。
|
||||||
也可以试试在各大平台搜索上面提到的名字。
|
|
||||||
</div>
|
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
|
||||||
|
|
||||||
<div class="row p-2">
|
<div class="flex flex-col p-2">
|
||||||
<div class="col">
|
<div class="pb-2">
|
||||||
<div class="row">
|
<h3 class="text-2xl">关于本站</h3>
|
||||||
<div class="col">
|
|
||||||
<h3>关于本站</h3>
|
|
||||||
</div>
|
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div class="row py-2">
|
<div class="py-2">
|
||||||
<div class="col">
|
本站肇始于2021年下半年,在开始的两年中个人网站和博客是分别的两个网站,个人网站是裸HTML写的,博客是用
|
||||||
本站肇始于2021年下半年,在开始的两年中个人网站和博客是分别的两个网站,个人网站是裸HTML写的,博客是用
|
<a href="https://hexo.io">Hexo</a>渲染的。
|
||||||
<a href="https://hexo.io">Hexo</a>渲染的。
|
|
||||||
</div>
|
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div class="row py-2">
|
<div class="py-2">
|
||||||
<div class="col">
|
2024年,我们决定使用.NET技术完全重构两个网站,合二为一。虽然目前这个版本还是一个半成品,但是我们一定会努力的~(确信。
|
||||||
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>
|
||||||
|
|
||||||
<div class="row py-2">
|
<div class="py-2">
|
||||||
<div class="col fst-italic">
|
2025年,我们将使用的样式库从Bootstrap迁移到Tailwind CSS,将现代的前端技术同Blazor结合起来。
|
||||||
欢迎所有人联系我添加友链!(´。✪ω✪。`)
|
|
||||||
</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>
|
||||||
</div>
|
</div>
|
||||||
|
|||||||
@@ -1,8 +0,0 @@
|
|||||||
.link-item {
|
|
||||||
padding: 1rem;
|
|
||||||
border-radius: 4px;
|
|
||||||
}
|
|
||||||
|
|
||||||
.link-item:hover {
|
|
||||||
background-color: var(--bs-secondary-bg);
|
|
||||||
}
|
|
||||||
@@ -8,68 +8,56 @@
|
|||||||
归档
|
归档
|
||||||
</PageTitle>
|
</PageTitle>
|
||||||
|
|
||||||
<div class="container">
|
<div class="flex flex-col">
|
||||||
<div class="row">
|
<div>
|
||||||
<div class="col">
|
<h1 class="text-4xl">归档</h1>
|
||||||
<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>
|
</div>
|
||||||
|
|
||||||
@foreach (IGrouping<DateTime, KeyValuePair<string, BlogEssay>> group in _essays)
|
<div class="py-4">
|
||||||
{
|
<span class="italic">
|
||||||
<div class="row">
|
时光图书馆,黑历史集散地。(๑◔‿◔๑)
|
||||||
<div class="col">
|
</span>
|
||||||
<div class="container">
|
</div>
|
||||||
<div class="row">
|
|
||||||
<div class="col">
|
|
||||||
<h3>@(group.Key.Year)</h3>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<div class="container px-3 py-2">
|
@foreach (IGrouping<DateTime, BlogEssay> group in _essays)
|
||||||
@foreach (KeyValuePair<string, BlogEssay> essay in group)
|
{
|
||||||
{
|
<div class="p-2">
|
||||||
<div class="row py-1">
|
<div class="flex flex-col">
|
||||||
<div class="col-auto">
|
<div>
|
||||||
@(essay.Value.PublishTime.ToString("MM-dd"))
|
<h3 class="text-xl">@(group.Key.Year)</h3>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div class="px-4 py-4 flex flex-col">
|
||||||
|
@foreach (BlogEssay essay in group)
|
||||||
|
{
|
||||||
|
<a target="_blank" 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>
|
||||||
|
|
||||||
<div class="col-auto">
|
<div>
|
||||||
<a href="/blog/essays/@(essay.Key)">
|
<span class="text-blue-600">
|
||||||
@(essay.Value.Title)
|
@(essay.Title)
|
||||||
</a>
|
</span>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
}
|
</a>
|
||||||
</div>
|
}
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
}
|
}
|
||||||
|
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
@code {
|
@code {
|
||||||
private readonly List<IGrouping<DateTime, KeyValuePair<string, BlogEssay>>> _essays = [];
|
private readonly List<IGrouping<DateTime, BlogEssay>> _essays = [];
|
||||||
|
|
||||||
protected override void OnInitialized()
|
protected override void OnInitialized()
|
||||||
{
|
{
|
||||||
base.OnInitialized();
|
base.OnInitialized();
|
||||||
|
|
||||||
_essays.AddRange(from essay in Contents.Essays
|
_essays.AddRange(from essay in Contents.Essays
|
||||||
orderby essay.Value.PublishTime descending
|
group essay by new DateTime(essay.PublishTime.Year, 1, 1));
|
||||||
group essay by new DateTime(essay.Value.PublishTime.Year, 1, 1));
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -9,79 +9,18 @@
|
|||||||
Ricardo's Blog
|
Ricardo's Blog
|
||||||
</PageTitle>
|
</PageTitle>
|
||||||
|
|
||||||
<div class="container">
|
<div>
|
||||||
<div class="row">
|
<div class="grid grid-cols-4">
|
||||||
<div class="col-sm-12 col-md-9">
|
<div class="col-span-4 md:col-span-3">
|
||||||
@foreach (KeyValuePair<string, BlogEssay> pair in _essays)
|
@foreach (BlogEssay essay in _essays)
|
||||||
{
|
{
|
||||||
<EssayCard Essay="@(pair.Value)"/>
|
<EssayCard Essay="@(essay)"/>
|
||||||
}
|
}
|
||||||
|
|
||||||
<div class="row align-items-center justify-content-center p-3">
|
<Pagination BaseUrl="/blog/" Page="_page" PageCount="_pageCount"/>
|
||||||
@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>
|
||||||
|
|
||||||
<div class="col-sm-12 col-md-3">
|
<div class="col-span-4 md:col-span-1">
|
||||||
<BlogInformationCard/>
|
<BlogInformationCard/>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
@@ -91,7 +30,7 @@
|
|||||||
|
|
||||||
[SupplyParameterFromQuery] private int? Page { get; set; }
|
[SupplyParameterFromQuery] private int? Page { get; set; }
|
||||||
|
|
||||||
private readonly List<KeyValuePair<string, BlogEssay>> _essays = [];
|
private readonly List<BlogEssay> _essays = [];
|
||||||
private const int EssaysPerPage = 8;
|
private const int EssaysPerPage = 8;
|
||||||
private int _pageCount = 1;
|
private int _pageCount = 1;
|
||||||
private int _page = 1;
|
private int _page = 1;
|
||||||
@@ -99,16 +38,20 @@
|
|||||||
protected override void OnInitialized()
|
protected override void OnInitialized()
|
||||||
{
|
{
|
||||||
_page = Page ?? 1;
|
_page = Page ?? 1;
|
||||||
_pageCount = Contents.Essays.Count / EssaysPerPage + 1;
|
_pageCount = Contents.Count / EssaysPerPage + 1;
|
||||||
|
(_pageCount, int reminder) = int.DivRem(Contents.Count, EssaysPerPage);
|
||||||
|
if (reminder > 0)
|
||||||
|
{
|
||||||
|
_pageCount += 1;
|
||||||
|
}
|
||||||
|
|
||||||
if (EssaysPerPage * _page > Contents.Essays.Count + EssaysPerPage)
|
if (EssaysPerPage * _page > Contents.Count + EssaysPerPage)
|
||||||
{
|
{
|
||||||
NavigationInstance.NavigateTo("/NotFount");
|
NavigationInstance.NavigateTo("/NotFount");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
_essays.AddRange(Contents.Essays
|
_essays.AddRange(Contents.Essays
|
||||||
.OrderByDescending(p => p.Value.PublishTime)
|
|
||||||
.Skip((_page - 1) * EssaysPerPage)
|
.Skip((_page - 1) * EssaysPerPage)
|
||||||
.Take(EssaysPerPage));
|
.Take(EssaysPerPage));
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,7 +0,0 @@
|
|||||||
.essay-title a {
|
|
||||||
color: var(--bs-body-color);
|
|
||||||
}
|
|
||||||
|
|
||||||
.read-more a {
|
|
||||||
color: var(--bs-body-color);
|
|
||||||
}
|
|
||||||
@@ -10,96 +10,87 @@
|
|||||||
@(_essay!.Title)
|
@(_essay!.Title)
|
||||||
</PageTitle>
|
</PageTitle>
|
||||||
|
|
||||||
<div class="container py-4">
|
<div class="flex flex-col py-8">
|
||||||
<div class="row">
|
<div>
|
||||||
|
<h1 id="title" class="text-4xl">@(_essay!.Title)</h1>
|
||||||
<div class="col-auto">
|
<div class="col-auto">
|
||||||
<h1 id="title">@(_essay!.Title)</h1>
|
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div class="row px-4 py-1">
|
<div class="px-6 pt-4 pb-2">
|
||||||
<div class="col-auto fw-light">
|
<div class="flex flex-row gap-4">
|
||||||
@(_essay!.PublishTime.ToString("yyyy-MM-dd"))
|
<div class="font-light">
|
||||||
</div>
|
@(_essay!.PublishTime.ToString("yyyy-MM-dd"))
|
||||||
|
|
||||||
@foreach (string tag in _essay!.Tags)
|
|
||||||
{
|
|
||||||
<div class="col-auto">
|
|
||||||
<a href="/blog/tags/?tagName=@(UrlEncoder.Default.Encode(tag))">
|
|
||||||
# @(tag)
|
|
||||||
</a>
|
|
||||||
</div>
|
</div>
|
||||||
}
|
|
||||||
|
@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>
|
</div>
|
||||||
|
|
||||||
<div class="row px-4 py-1">
|
<div class="px-6 pt-2 pb-4">
|
||||||
<div class="col-auto fw-light">
|
<div class="font-light">
|
||||||
总字数:@(_essay!.WordCount)字,预计阅读时间 @(_essay!.ReadTime)。
|
总字数:@(_essay!.WordCount)字,预计阅读时间 @(_essay!.ReadTime)。
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div class="row">
|
<div class="grid grid-cols-3">
|
||||||
<div class="col-lg-8 col-md-12">
|
<div class="col-span-3 md:col-span-2 flex flex-col gap-3">
|
||||||
@((MarkupString)_essay!.HtmlContent)
|
<div>
|
||||||
|
@((MarkupString)_essay!.HtmlContent)
|
||||||
|
</div>
|
||||||
|
|
||||||
<LicenseDisclaimer EssayAddress="@BlogKey"/>
|
<div>
|
||||||
|
<LicenseDisclaimer EssayFilename="@BlogKey"/>
|
||||||
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div class="col-lg-4 col-md-12">
|
<div class="col-span-3 md:col-span-1">
|
||||||
<div class="row sticky-lg-top justify-content-center">
|
<div class="flex flex-col sticky top-0 px-8">
|
||||||
<div class="col-auto">
|
<div>
|
||||||
<div class="row">
|
<h3 class="text-2xl">文章目录</h3>
|
||||||
<div class="col-auto">
|
</div>
|
||||||
<h3 style="margin-block-start: 1em; margin-block-end: 0.5em">
|
|
||||||
文章目录
|
|
||||||
</h3>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<div class="row" style="padding-left: 10px">
|
<div>
|
||||||
<div class="col-auto">
|
@foreach (BlogHeadline level2 in _headline!.Children)
|
||||||
@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="py-2 pl-3">
|
||||||
<div class="col fst-italic">
|
<Anchor Address="@(GenerateSelectorUrl(level2.SelectorId))"
|
||||||
坏了(* Ŏ∀Ŏ),没有在文章中识别到目录
|
Text="@(level2.Title)"/>
|
||||||
</div>
|
|
||||||
</div>
|
</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>
|
</div>
|
||||||
|
|
||||||
|
@if (_headline!.Children.Count == 0)
|
||||||
|
{
|
||||||
|
<div class="row">
|
||||||
|
<div class="col fst-italic">
|
||||||
|
坏了(* Ŏ∀Ŏ),没有在文章中识别到目录
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
}
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
@@ -123,7 +114,7 @@
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!Contents.Essays.TryGetValue(BlogKey, out _essay))
|
if (!Contents.TryGetEssay(BlogKey, out _essay))
|
||||||
{
|
{
|
||||||
NavigationInstance.NavigateTo("/NotFound");
|
NavigationInstance.NavigateTo("/NotFound");
|
||||||
}
|
}
|
||||||
|
|||||||
49
YaeBlog/Pages/Friends.razor
Normal file
49
YaeBlog/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 {
|
||||||
|
|
||||||
|
}
|
||||||
@@ -4,28 +4,28 @@
|
|||||||
Ricardo's Index
|
Ricardo's Index
|
||||||
</PageTitle>
|
</PageTitle>
|
||||||
|
|
||||||
<div class="container">
|
<div class="mx-20">
|
||||||
<div class="row py-4">
|
<div class="grid grid-cols-3 py-4">
|
||||||
<div class="col-lg-4 col-12 p-5 p-lg-0">
|
<div class="col-span-3 md:col-span-1 p-5 p-lg-0">
|
||||||
@* <Image Src="images/avatar.png" Alt="Ricardo's Avatar"/> *@
|
<img src="images/avatar.png" alt="Ricardo's Avatar" class="h-auto max-w-full">
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div class="col-lg-8 col-12">
|
<div class="col-span-3 md:col-span-2">
|
||||||
<div class="container px-3">
|
<div class="flex flex-col px-3 gap-y-3">
|
||||||
<div class="row">
|
<div class="">
|
||||||
<h4 class="fw-bold">初冬的朝阳 (Ricardo Ren)</h4>
|
<div class="text-3xl font-bold">初冬的朝阳 (Ricardo Ren)</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div class="row">
|
<div class="">
|
||||||
<p class="fs-5">a.k.a jackfiled</p>
|
<p class="text-lg">a.k.a jackfiled</p>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div class="row">
|
<div class="">
|
||||||
<p class="fs-5 fst-italic">世界很大,时间很长。</p>
|
<p class="text-lg italic">世界很大,时间很长。</p>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div class="row">
|
<div class="">
|
||||||
<p class="fs-5">
|
<p class="text-lg">
|
||||||
平平无奇的计算机科学与技术学徒,连微小的贡献都没做。
|
平平无奇的计算机科学与技术学徒,连微小的贡献都没做。
|
||||||
</p>
|
</p>
|
||||||
</div>
|
</div>
|
||||||
@@ -33,20 +33,22 @@
|
|||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div class="row" style="padding-top: 80px">
|
<div class="py-5">
|
||||||
<p class="fs-5">恕我不能亲自为您沏茶(?),还是非常欢迎您能够来到我的主页。</p>
|
<p class="text-lg">恕我不能亲自为您沏茶(?),还是非常欢迎您能够来到我的主页。</p>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div class="row">
|
<div>
|
||||||
<p class="fs-5">
|
<p class="text-lg py-1">
|
||||||
如果您想四处看看,了解一下屏幕对面的人,可以在我的 <a href="/blog/">博客</a> 看看。
|
如果您想四处看看,了解一下屏幕对面的人,可以在我的 <Anchor Address="/blog/" Text="博客"/> 看看。
|
||||||
如果您对于明光村幼儿园某附属技校的计算机教学感兴趣,您可以移步到
|
如果您对于明光村幼儿园某附属技校的计算机教学感兴趣,您可以移步到
|
||||||
<a href="https://jackfiled.github.io/wiki/">我的学习笔记</a>,
|
<Anchor Address="https://jackfiled.github.io/wiki/" Text="我的学习笔记"/>,
|
||||||
<span class="fs-5 text-decoration-line-through">虽然这笔记我自己也木有看过。</span>
|
<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> 都可以找到。
|
<Anchor Address="https://github.com/jackfiled/" Text="Github"/> 和
|
||||||
|
<Anchor Address="https://git.rrricardo.top/jackfiled/" Text="Gitea"/>
|
||||||
|
都可以找到。
|
||||||
</p>
|
</p>
|
||||||
<p class="fs-5">
|
<p class="text-lg py-1">
|
||||||
如果您真的很闲,也可以四处搜寻一下,也许存在着一些不为人知的彩蛋。
|
如果您真的很闲,也可以四处搜寻一下,也许存在着一些不为人知的彩蛋。
|
||||||
</p>
|
</p>
|
||||||
</div>
|
</div>
|
||||||
|
|||||||
@@ -4,8 +4,8 @@
|
|||||||
啊~ 页面走丢啦~
|
啊~ 页面走丢啦~
|
||||||
</PageTitle>
|
</PageTitle>
|
||||||
|
|
||||||
<div class="container">
|
<div>
|
||||||
<h3>NotFound!</h3>
|
<h3 class="text-3xl">NotFound!</h3>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
@code {
|
@code {
|
||||||
|
|||||||
@@ -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 class="text-4xl">标签</h1>
|
||||||
<h1>标签</h1>
|
}
|
||||||
}
|
else
|
||||||
else
|
{
|
||||||
{
|
<h2 class="text-2xl">@(TagName)</h2>
|
||||||
<h2>@(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">
|
||||||
<a href="/blog/tags/?tagName=@(pair.Key.UrlEncodedTagName)">
|
<div class="flex flex-row">
|
||||||
<div class="container fs-5">
|
<a href="/blog/tags/?tagName=@(pair.Key.UrlEncodedTagName)">
|
||||||
<div class="row">
|
<div class="text-sky-600 text-lg">
|
||||||
<div class="col-auto">
|
# @(pair.Key.TagName)
|
||||||
# @(pair.Key.TagName)
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<div class="col-auto tag-count">
|
|
||||||
@(pair.Value.Count)
|
|
||||||
</div>
|
|
||||||
</div>
|
</div>
|
||||||
|
</a>
|
||||||
|
|
||||||
|
<div class="mx-2 px-1 text-lg bg-gray-300 rounded-lg">
|
||||||
|
@(pair.Value.Count)
|
||||||
</div>
|
</div>
|
||||||
</a>
|
</div>
|
||||||
</li>
|
</li>
|
||||||
}
|
}
|
||||||
</ul>
|
</ul>
|
||||||
|
|||||||
@@ -1,6 +0,0 @@
|
|||||||
.tag-count {
|
|
||||||
background: var(--bs-secondary-bg);
|
|
||||||
border-radius: 5px;
|
|
||||||
padding: 0 6px;
|
|
||||||
}
|
|
||||||
|
|
||||||
@@ -1,29 +0,0 @@
|
|||||||
using AngleSharp;
|
|
||||||
using AngleSharp.Dom;
|
|
||||||
using YaeBlog.Abstraction;
|
|
||||||
using YaeBlog.Models;
|
|
||||||
|
|
||||||
namespace YaeBlog.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);
|
|
||||||
}
|
|
||||||
145
YaeBlog/Processors/EssayStylesPostRenderProcessor.cs
Normal file
145
YaeBlog/Processors/EssayStylesPostRenderProcessor.cs
Normal file
@@ -0,0 +1,145 @@
|
|||||||
|
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" },
|
||||||
|
};
|
||||||
|
|
||||||
|
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");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private static void BeatifyList(IDocument document)
|
||||||
|
{
|
||||||
|
foreach (IElement ulElement in from e in document.All
|
||||||
|
where e.LocalName == "ul"
|
||||||
|
select e)
|
||||||
|
{
|
||||||
|
// 首先给<ul>元素添加样式
|
||||||
|
ulElement.ClassList.Add("list-disc ml-10");
|
||||||
|
|
||||||
|
|
||||||
|
foreach (IElement liElement in from e in ulElement.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");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -7,17 +7,16 @@ using YaeBlog.Models;
|
|||||||
|
|
||||||
namespace YaeBlog.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 AngleSharp.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));
|
||||||
|
|
||||||
@@ -31,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,34 +0,0 @@
|
|||||||
using AngleSharp;
|
|
||||||
using AngleSharp.Dom;
|
|
||||||
using AngleSharp.Html.Dom;
|
|
||||||
using YaeBlog.Abstraction;
|
|
||||||
using YaeBlog.Models;
|
|
||||||
|
|
||||||
namespace YaeBlog.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);
|
|
||||||
}
|
|
||||||
@@ -6,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;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -10,24 +10,41 @@ public sealed class BlogHotReloadService(
|
|||||||
{
|
{
|
||||||
protected override async Task ExecuteAsync(CancellationToken stoppingToken)
|
protected override async Task ExecuteAsync(CancellationToken stoppingToken)
|
||||||
{
|
{
|
||||||
logger.LogInformation("BlogHotReloadService is starting.");
|
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();
|
await rendererService.RenderAsync(true);
|
||||||
|
|
||||||
while (!stoppingToken.IsCancellationRequested)
|
Task[] reloadTasks = [WatchFileAsync(stoppingToken)];
|
||||||
|
await Task.WhenAll(reloadTasks);
|
||||||
|
}
|
||||||
|
|
||||||
|
private async Task WatchFileAsync(CancellationToken token)
|
||||||
|
{
|
||||||
|
while (!token.IsCancellationRequested)
|
||||||
{
|
{
|
||||||
logger.LogDebug("Watching file changes...");
|
logger.LogInformation("Watching file changes...");
|
||||||
string? changFile = await watcher.WaitForChange(stoppingToken);
|
string? changeFile = await watcher.WaitForChange(token);
|
||||||
|
|
||||||
if (changFile is null)
|
if (changeFile is null)
|
||||||
{
|
{
|
||||||
logger.LogInformation("BlogHotReloadService is stopping.");
|
logger.LogInformation("File watcher is stopping.");
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
logger.LogInformation("{} changed, re-rendering.", changFile);
|
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();
|
essayContentService.Clear();
|
||||||
await rendererService.RenderAsync();
|
await rendererService.RenderAsync(true);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -9,15 +9,28 @@ 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;
|
||||||
|
|
||||||
|
|||||||
@@ -1,5 +1,7 @@
|
|||||||
using System.Collections.Concurrent;
|
using System.Collections.Concurrent;
|
||||||
using System.Text.RegularExpressions;
|
using System.Text.RegularExpressions;
|
||||||
|
using Imageflow.Bindings;
|
||||||
|
using Imageflow.Fluent;
|
||||||
using Microsoft.Extensions.Options;
|
using Microsoft.Extensions.Options;
|
||||||
using YaeBlog.Abstraction;
|
using YaeBlog.Abstraction;
|
||||||
using YaeBlog.Core.Exceptions;
|
using YaeBlog.Core.Exceptions;
|
||||||
@@ -9,100 +11,130 @@ using YamlDotNet.Serialization;
|
|||||||
|
|
||||||
namespace YaeBlog.Services;
|
namespace YaeBlog.Services;
|
||||||
|
|
||||||
public partial class EssayScanService(
|
public partial class EssayScanService : IEssayScanService
|
||||||
ISerializer yamlSerializer,
|
|
||||||
IDeserializer yamlDeserializer,
|
|
||||||
IOptions<BlogOptions> blogOptions,
|
|
||||||
ILogger<EssayScanService> logger) : IEssayScanService
|
|
||||||
{
|
{
|
||||||
private readonly BlogOptions _blogOptions = blogOptions.Value;
|
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()
|
public async Task<BlogContents> ScanContents()
|
||||||
{
|
{
|
||||||
ValidateDirectory(_blogOptions.Root, out DirectoryInfo drafts, out DirectoryInfo posts);
|
ValidateDirectory(out DirectoryInfo drafts, out DirectoryInfo posts);
|
||||||
|
|
||||||
return new BlogContents(
|
return new BlogContents(
|
||||||
await ScanContentsInternal(drafts),
|
await ScanContentsInternal(drafts, true),
|
||||||
await ScanContentsInternal(posts));
|
await ScanContentsInternal(posts, false));
|
||||||
}
|
}
|
||||||
|
|
||||||
public async Task SaveBlogContent(BlogContent content, bool isDraft = true)
|
public async Task SaveBlogContent(BlogContent content, bool isDraft = true)
|
||||||
{
|
{
|
||||||
ValidateDirectory(_blogOptions.Root, out DirectoryInfo drafts, out DirectoryInfo posts);
|
ValidateDirectory(out DirectoryInfo drafts, out DirectoryInfo posts);
|
||||||
|
|
||||||
FileInfo targetFile = isDraft
|
FileInfo targetFile = isDraft
|
||||||
? new FileInfo(Path.Combine(drafts.FullName, content.FileName + ".md"))
|
? new FileInfo(Path.Combine(drafts.FullName, content.BlogName + ".md"))
|
||||||
: new FileInfo(Path.Combine(posts.FullName, content.FileName + ".md"));
|
: new FileInfo(Path.Combine(posts.FullName, content.BlogName + ".md"));
|
||||||
|
|
||||||
if (!isDraft)
|
|
||||||
{
|
|
||||||
content.Metadata.Date = DateTime.Now;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (targetFile.Exists)
|
if (targetFile.Exists)
|
||||||
{
|
{
|
||||||
logger.LogWarning("Blog {} exists, overriding.", targetFile.Name);
|
_logger.LogWarning("Blog {} exists, overriding.", targetFile.Name);
|
||||||
}
|
}
|
||||||
|
|
||||||
await using StreamWriter writer = targetFile.CreateText();
|
await using StreamWriter writer = targetFile.CreateText();
|
||||||
|
|
||||||
await writer.WriteAsync("---\n");
|
await writer.WriteAsync("---\n");
|
||||||
await writer.WriteAsync(yamlSerializer.Serialize(content.Metadata));
|
await writer.WriteAsync(_yamlSerializer.Serialize(content.Metadata));
|
||||||
await writer.WriteAsync("---\n");
|
await writer.WriteAsync("---\n");
|
||||||
|
|
||||||
if (isDraft)
|
if (string.IsNullOrEmpty(content.Content) && isDraft)
|
||||||
{
|
{
|
||||||
|
// 如果博客为操作且内容为空
|
||||||
|
// 创建简介隔断符号
|
||||||
await writer.WriteLineAsync("<!--more-->");
|
await writer.WriteLineAsync("<!--more-->");
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
await writer.WriteAsync(content.FileContent);
|
await writer.WriteAsync(content.Content);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// 保存图片文件
|
||||||
|
await Task.WhenAll(from image in content.Images
|
||||||
|
select File.WriteAllBytesAsync(image.File.FullName, image.Content));
|
||||||
}
|
}
|
||||||
|
|
||||||
private async Task<ConcurrentBag<BlogContent>> ScanContentsInternal(DirectoryInfo directory)
|
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结果的但是不是隐藏文件的文件
|
// 扫描以md结尾且不是隐藏文件的文件
|
||||||
IEnumerable<FileInfo> markdownFiles = from file in directory.EnumerateFiles()
|
IEnumerable<FileInfo> markdownFiles = from file in directory.EnumerateFiles()
|
||||||
where file.Extension == ".md" && !file.Name.StartsWith('.')
|
where file.Extension == ".md" && !file.Name.StartsWith('.')
|
||||||
select file;
|
select file;
|
||||||
|
|
||||||
ConcurrentBag<(string, string)> fileContents = [];
|
ConcurrentBag<BlogResult> fileContents = [];
|
||||||
|
|
||||||
await Parallel.ForEachAsync(markdownFiles, async (file, token) =>
|
await Parallel.ForEachAsync(markdownFiles, async (file, token) =>
|
||||||
{
|
{
|
||||||
using StreamReader reader = file.OpenText();
|
using StreamReader reader = file.OpenText();
|
||||||
fileContents.Add((file.Name, await reader.ReadToEndAsync(token)));
|
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 = [];
|
ConcurrentBag<BlogContent> contents = [];
|
||||||
|
|
||||||
await Task.Run(() =>
|
await Task.Run(() =>
|
||||||
{
|
{
|
||||||
foreach ((string filename, string content) in fileContents)
|
foreach (BlogResult blog in fileContents)
|
||||||
{
|
{
|
||||||
int endPos = content.IndexOf("---", 4, StringComparison.Ordinal);
|
if (blog.BlogContent.Length < 4)
|
||||||
if (!content.StartsWith("---") || endPos is -1 or 0)
|
|
||||||
{
|
{
|
||||||
logger.LogWarning("Failed to parse metadata from {}, skipped.", filename);
|
// 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;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
string metadataString = content[4..endPos];
|
string metadataString = blog.BlogContent[4..endPos];
|
||||||
|
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
MarkdownMetadata metadata = yamlDeserializer.Deserialize<MarkdownMetadata>(metadataString);
|
MarkdownMetadata metadata = _yamlDeserializer.Deserialize<MarkdownMetadata>(metadataString);
|
||||||
logger.LogDebug("Scan metadata title: '{}' for {}.", metadata.Title, filename);
|
_logger.LogDebug("Scan metadata title: '{title}' for {name}.", metadata.Title, blog.BlogFile.Name);
|
||||||
|
|
||||||
contents.Add(new BlogContent
|
contents.Add(new BlogContent(blog.BlogFile, metadata, blog.BlogContent[(endPos + 3)..], isDraft,
|
||||||
{
|
blog.Images, blog.NotFoundImages));
|
||||||
FileName = filename[..^3], Metadata = metadata, FileContent = content[(endPos + 3)..]
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
catch (YamlException e)
|
catch (YamlException e)
|
||||||
{
|
{
|
||||||
logger.LogWarning("Failed to parser metadata from {} due to {}, skipping", filename, e);
|
_logger.LogWarning("Failed to parser metadata from {name} due to {exception}, skipping", blog.BlogFile.Name, e);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
@@ -110,99 +142,96 @@ public partial class EssayScanService(
|
|||||||
return contents;
|
return contents;
|
||||||
}
|
}
|
||||||
|
|
||||||
public async Task<ImageScanResult> ScanImages()
|
private record struct ImageResult(List<BlogImageInfo> Images, List<FileInfo> NotfoundImages);
|
||||||
|
|
||||||
|
private async Task<ImageResult> ScanImagePreBlog(DirectoryInfo directory, string blogName, string content)
|
||||||
{
|
{
|
||||||
BlogContents contents = await ScanContents();
|
MatchCollection matchResult = ImagePattern.Matches(content);
|
||||||
ValidateDirectory(_blogOptions.Root, out DirectoryInfo drafts, out DirectoryInfo posts);
|
DirectoryInfo imageDirectory = new(Path.Combine(directory.FullName, blogName));
|
||||||
|
|
||||||
List<FileInfo> unusedFiles = [];
|
Dictionary<string, bool> usedImages = imageDirectory.Exists
|
||||||
List<FileInfo> notFoundFiles = [];
|
? imageDirectory.EnumerateFiles().ToDictionary(file => file.FullName, _ => false)
|
||||||
|
: [];
|
||||||
|
List<FileInfo> notFoundImages = [];
|
||||||
|
|
||||||
ImageScanResult draftResult = await ScanUnusedImagesInternal(contents.Drafts, drafts);
|
foreach (Match match in matchResult)
|
||||||
ImageScanResult postResult = await ScanUnusedImagesInternal(contents.Posts, posts);
|
|
||||||
|
|
||||||
unusedFiles.AddRange(draftResult.UnusedImages);
|
|
||||||
notFoundFiles.AddRange(draftResult.NotFoundImages);
|
|
||||||
unusedFiles.AddRange(postResult.UnusedImages);
|
|
||||||
notFoundFiles.AddRange(postResult.NotFoundImages);
|
|
||||||
|
|
||||||
return new ImageScanResult(unusedFiles, notFoundFiles);
|
|
||||||
}
|
|
||||||
|
|
||||||
private static Task<ImageScanResult> ScanUnusedImagesInternal(IEnumerable<BlogContent> contents,
|
|
||||||
DirectoryInfo root)
|
|
||||||
{
|
|
||||||
ConcurrentBag<FileInfo> unusedImage = [];
|
|
||||||
ConcurrentBag<FileInfo> notFoundImage = [];
|
|
||||||
|
|
||||||
Parallel.ForEach(contents, content =>
|
|
||||||
{
|
{
|
||||||
MatchCollection result = ImagePattern.Matches(content.FileContent);
|
string imageName = match.Groups[1].Value;
|
||||||
DirectoryInfo imageDirectory = new(Path.Combine(root.FullName, content.FileName));
|
|
||||||
|
|
||||||
Dictionary<string, bool> usedDictionary;
|
// 判断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 (imageDirectory.Exists)
|
if (usedImages.TryGetValue(usedFile.FullName, out _))
|
||||||
{
|
{
|
||||||
usedDictionary = (from file in imageDirectory.EnumerateFiles()
|
usedImages[usedFile.FullName] = true;
|
||||||
select new KeyValuePair<string, bool>(file.FullName, false)).ToDictionary();
|
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
usedDictionary = [];
|
notFoundImages.Add(usedFile);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
foreach (Match match in result)
|
List<BlogImageInfo> images = (await Task.WhenAll((from pair in usedImages
|
||||||
{
|
select GetImageInfo(new FileInfo(pair.Key), pair.Value)).ToArray())).ToList();
|
||||||
string imageName = match.Groups[1].Value;
|
|
||||||
|
|
||||||
FileInfo usedFile = imageName.Contains(content.FileName)
|
return new ImageResult(images, notFoundImages);
|
||||||
? new FileInfo(Path.Combine(root.FullName, imageName))
|
}
|
||||||
: new FileInfo(Path.Combine(root.FullName, content.FileName, imageName));
|
|
||||||
|
|
||||||
if (usedDictionary.TryGetValue(usedFile.FullName, out _))
|
private static async Task<BlogImageInfo> GetImageInfo(FileInfo file, bool isUsed)
|
||||||
{
|
{
|
||||||
usedDictionary[usedFile.FullName] = true;
|
byte[] image = await File.ReadAllBytesAsync(file.FullName);
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
notFoundImage.Add(usedFile);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
foreach (KeyValuePair<string, bool> pair in usedDictionary.Where(p => !p.Value))
|
if (file.Extension is ".jpg" or ".jpeg" or ".png")
|
||||||
{
|
{
|
||||||
unusedImage.Add(new FileInfo(pair.Key));
|
ImageInfo imageInfo =
|
||||||
}
|
await ImageJob.GetImageInfoAsync(MemorySource.Borrow(image), SourceLifetime.NowOwnedAndDisposedByTask);
|
||||||
});
|
|
||||||
|
|
||||||
return Task.FromResult(new ImageScanResult(unusedImage.ToList(), notFoundImage.ToList()));
|
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(@"\!\[.*?\]\((.*?)\)")]
|
[GeneratedRegex(@"\!\[.*?\]\((.*?)\)")]
|
||||||
private static partial Regex ImagePattern { get; }
|
private static partial Regex ImagePattern { get; }
|
||||||
|
|
||||||
private void ValidateDirectory(string root, out DirectoryInfo drafts, out DirectoryInfo posts)
|
|
||||||
|
private DirectoryInfo ValidateRootDirectory()
|
||||||
{
|
{
|
||||||
root = Path.Combine(Environment.CurrentDirectory, root);
|
DirectoryInfo rootDirectory = new(Path.Combine(Environment.CurrentDirectory, _blogOptions.Root));
|
||||||
DirectoryInfo rootDirectory = new(root);
|
|
||||||
|
|
||||||
if (!rootDirectory.Exists)
|
if (!rootDirectory.Exists)
|
||||||
{
|
{
|
||||||
throw new BlogFileException($"'{root}' is not a directory.");
|
throw new BlogFileException($"'{_blogOptions.Root}' is not a directory.");
|
||||||
}
|
}
|
||||||
|
|
||||||
if (rootDirectory.EnumerateDirectories().All(dir => dir.Name != "drafts"))
|
return rootDirectory;
|
||||||
|
}
|
||||||
|
|
||||||
|
private void ValidateDirectory(out DirectoryInfo drafts, out DirectoryInfo posts)
|
||||||
|
{
|
||||||
|
if (RootDirectory.EnumerateDirectories().All(dir => dir.Name != "drafts"))
|
||||||
{
|
{
|
||||||
throw new BlogFileException($"'{root}/drafts' not exists.");
|
throw new BlogFileException($"'{_blogOptions.Root}/drafts' not exists.");
|
||||||
}
|
}
|
||||||
|
|
||||||
if (rootDirectory.EnumerateDirectories().All(dir => dir.Name != "posts"))
|
if (RootDirectory.EnumerateDirectories().All(dir => dir.Name != "posts"))
|
||||||
{
|
{
|
||||||
throw new BlogFileException($"'{root}/posts' not exists.");
|
throw new BlogFileException($"'{_blogOptions.Root}/posts' not exists.");
|
||||||
}
|
}
|
||||||
|
|
||||||
drafts = new DirectoryInfo(Path.Combine(root, "drafts"));
|
drafts = new DirectoryInfo(Path.Combine(_blogOptions.Root, "drafts"));
|
||||||
posts = new DirectoryInfo(Path.Combine(root, "posts"));
|
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.");
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -1,65 +0,0 @@
|
|||||||
using System.Diagnostics;
|
|
||||||
using System.Runtime.InteropServices;
|
|
||||||
using YaeBlog.Core.Exceptions;
|
|
||||||
|
|
||||||
namespace YaeBlog.Services;
|
|
||||||
|
|
||||||
public class ProcessInteropService(ILogger<ProcessInteropService> logger)
|
|
||||||
{
|
|
||||||
public Process StartProcess(string command, string arguments)
|
|
||||||
{
|
|
||||||
string commandName;
|
|
||||||
if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows) && !command.EndsWith(".exe"))
|
|
||||||
{
|
|
||||||
commandName = command + ".exe";
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
commandName = command;
|
|
||||||
}
|
|
||||||
|
|
||||||
try
|
|
||||||
{
|
|
||||||
ProcessStartInfo startInfo = new()
|
|
||||||
{
|
|
||||||
FileName = commandName,
|
|
||||||
Arguments = arguments,
|
|
||||||
RedirectStandardOutput = true,
|
|
||||||
RedirectStandardError = true,
|
|
||||||
UseShellExecute = false,
|
|
||||||
CreateNoWindow = true
|
|
||||||
};
|
|
||||||
|
|
||||||
Process? process = Process.Start(startInfo);
|
|
||||||
|
|
||||||
if (process is null)
|
|
||||||
{
|
|
||||||
throw new ProcessInteropException(
|
|
||||||
$"Failed to start process: {commandName}, the return process is null.");
|
|
||||||
}
|
|
||||||
|
|
||||||
process.OutputDataReceived += (_, data) =>
|
|
||||||
{
|
|
||||||
if (!string.IsNullOrEmpty(data.Data))
|
|
||||||
{
|
|
||||||
logger.LogInformation("Receive output from process '{}': '{}'", commandName, data.Data);
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
process.ErrorDataReceived += (_, data) =>
|
|
||||||
{
|
|
||||||
if (!string.IsNullOrEmpty(data.Data))
|
|
||||||
{
|
|
||||||
logger.LogWarning("Receive error from process '{}': '{}'", commandName, data.Data);
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
return process;
|
|
||||||
}
|
|
||||||
catch (Exception innerException)
|
|
||||||
{
|
|
||||||
throw new ProcessInteropException($"Failed to start process '{command}' with arguments '{arguments}",
|
|
||||||
innerException);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -21,40 +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);
|
||||||
|
BlogEssay essay = new()
|
||||||
{
|
{
|
||||||
uint wordCount = GetWordCount(content);
|
Title = content.Metadata.Title ?? content.BlogName,
|
||||||
BlogEssay essay = new()
|
FileName = content.BlogName,
|
||||||
{
|
IsDraft = content.IsDraft,
|
||||||
Title = content.Metadata.Title ?? content.FileName,
|
Description = GetDescription(content),
|
||||||
FileName = content.FileName,
|
WordCount = wordCount,
|
||||||
Description = GetDescription(content),
|
ReadTime = CalculateReadTime(wordCount),
|
||||||
WordCount = wordCount,
|
PublishTime = content.Metadata.Date ?? DateTime.Now,
|
||||||
ReadTime = CalculateReadTime(wordCount),
|
HtmlContent = content.Content
|
||||||
PublishTime = content.Metadata.Date ?? DateTime.Now,
|
};
|
||||||
HtmlContent = content.FileContent
|
|
||||||
};
|
|
||||||
|
|
||||||
if (content.Metadata.Tags is not null)
|
if (content.Metadata.Tags is not null)
|
||||||
{
|
{
|
||||||
essay.Tags.AddRange(content.Metadata.Tags);
|
essay.Tags.AddRange(content.Metadata.Tags);
|
||||||
}
|
|
||||||
|
|
||||||
essays.Add(essay);
|
|
||||||
}
|
}
|
||||||
});
|
|
||||||
|
essays.Add(essay);
|
||||||
|
}
|
||||||
|
|
||||||
ConcurrentBag<BlogEssay> postProcessEssays = [];
|
ConcurrentBag<BlogEssay> postProcessEssays = [];
|
||||||
Parallel.ForEach(essays, essay =>
|
Parallel.ForEach(essays, essay =>
|
||||||
@@ -66,7 +69,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();
|
||||||
@@ -117,8 +129,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)
|
||||||
@@ -126,12 +140,13 @@ 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(@"(?<!\\)[^\#\*_\-\+\`{}\[\]!~]+")]
|
||||||
@@ -141,17 +156,17 @@ public partial class RendererService(
|
|||||||
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();
|
||||||
@@ -167,18 +182,18 @@ public partial class RendererService(
|
|||||||
|
|
||||||
string description = builder.ToString();
|
string description = builder.ToString();
|
||||||
|
|
||||||
logger.LogDebug("Description of {} is {}.", content.FileName,
|
logger.LogDebug("Description of {} is {}.", content.BlogName,
|
||||||
description);
|
description);
|
||||||
return description;
|
return description;
|
||||||
}
|
}
|
||||||
|
|
||||||
private uint GetWordCount(BlogContent content)
|
private uint GetWordCount(BlogContent content)
|
||||||
{
|
{
|
||||||
int count = (from c in content.FileContent
|
int count = (from c in content.Content
|
||||||
where char.IsLetterOrDigit(c)
|
where char.IsLetterOrDigit(c)
|
||||||
select c).Count();
|
select c).Count();
|
||||||
|
|
||||||
logger.LogDebug("Word count of {} is {}", content.FileName,
|
logger.LogDebug("Word count of {} is {}", content.BlogName,
|
||||||
count);
|
count);
|
||||||
return (uint)count;
|
return (uint)count;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,46 +0,0 @@
|
|||||||
using System.Diagnostics;
|
|
||||||
using Microsoft.Extensions.Options;
|
|
||||||
using YaeBlog.Models;
|
|
||||||
|
|
||||||
namespace YaeBlog.Services;
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// 在应用程序运行的过程中启动Tailwind watch
|
|
||||||
/// 在程序退出时自动结束进程
|
|
||||||
/// 只在Development模式下启动
|
|
||||||
/// </summary>
|
|
||||||
public sealed class TailwindRefreshService(
|
|
||||||
IOptions<TailwindOptions> options,
|
|
||||||
ProcessInteropService processInteropService,
|
|
||||||
IHostEnvironment hostEnvironment,
|
|
||||||
ILogger<TailwindRefreshService> logger) : IHostedService, IDisposable
|
|
||||||
{
|
|
||||||
private Process? _tailwindProcess;
|
|
||||||
|
|
||||||
public Task StartAsync(CancellationToken cancellationToken)
|
|
||||||
{
|
|
||||||
if (!hostEnvironment.IsDevelopment())
|
|
||||||
{
|
|
||||||
return Task.CompletedTask;
|
|
||||||
}
|
|
||||||
|
|
||||||
logger.LogInformation("Try to start tailwind watcher with input {} and output {}", options.Value.InputFile,
|
|
||||||
options.Value.OutputFile);
|
|
||||||
|
|
||||||
_tailwindProcess = processInteropService.StartProcess("pnpm",
|
|
||||||
$"tailwind -i {options.Value.InputFile} -o {options.Value.OutputFile} --watch");
|
|
||||||
|
|
||||||
return Task.CompletedTask;
|
|
||||||
}
|
|
||||||
|
|
||||||
public Task StopAsync(CancellationToken cancellationToken)
|
|
||||||
{
|
|
||||||
_tailwindProcess?.Kill();
|
|
||||||
return Task.CompletedTask;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void Dispose()
|
|
||||||
{
|
|
||||||
_tailwindProcess?.Dispose();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,15 +1,14 @@
|
|||||||
<Project Sdk="Microsoft.NET.Sdk.Web">
|
<Project Sdk="Microsoft.NET.Sdk.Web">
|
||||||
|
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
|
<PackageReference Include="ImageFlow.NativeRuntime.ubuntu-x86_64" Version="2.1.0-rc11" Condition="$([MSBuild]::IsOsPlatform('Linux'))"/>
|
||||||
|
<PackageReference Include="ImageFlow.NativeRuntime.osx-arm64" Version="2.1.0-rc11" Condition="$([MSBuild]::IsOsPlatform('OSX'))"/>
|
||||||
|
<PackageReference Include="ImageFlow.Net" Version="0.13.2"/>
|
||||||
<PackageReference Include="System.CommandLine" Version="2.0.0-beta4.22272.1"/>
|
<PackageReference Include="System.CommandLine" Version="2.0.0-beta4.22272.1"/>
|
||||||
<PackageReference Include="AngleSharp" Version="1.1.0"/>
|
<PackageReference Include="AngleSharp" Version="1.1.0"/>
|
||||||
<PackageReference Include="Markdig" Version="0.38.0"/>
|
<PackageReference Include="Markdig" Version="0.38.0"/>
|
||||||
<PackageReference Include="YamlDotNet" Version="16.2.1"/>
|
<PackageReference Include="YamlDotNet" Version="16.2.1"/>
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
|
|
||||||
<ItemGroup>
|
|
||||||
<Watch Remove="**\*.razor~"/>
|
|
||||||
</ItemGroup>
|
|
||||||
|
|
||||||
<PropertyGroup>
|
<PropertyGroup>
|
||||||
<TargetFramework>net9.0</TargetFramework>
|
<TargetFramework>net9.0</TargetFramework>
|
||||||
@@ -17,12 +16,25 @@
|
|||||||
<ImplicitUsings>enable</ImplicitUsings>
|
<ImplicitUsings>enable</ImplicitUsings>
|
||||||
</PropertyGroup>
|
</PropertyGroup>
|
||||||
|
|
||||||
<Target Name="PnpmInstall">
|
<Target Name="EnsurePnpmInstalled" BeforeTargets="BeforeBuild">
|
||||||
|
<Message Importance="low" Text="Ensure pnpm is installed..."/>
|
||||||
|
<Exec Command="pnpm --version" ContinueOnError="true">
|
||||||
|
<Output TaskParameter="ExitCode" PropertyName="ErrorCode"/>
|
||||||
|
</Exec>
|
||||||
|
|
||||||
|
<Error Condition="$(ErrorCode) != 0" Text="Pnpm is not installed which is required for build."/>
|
||||||
|
|
||||||
|
<Message Importance="normal" Text="Installing pakages using pnpm..."/>
|
||||||
<Exec Command="pnpm install"/>
|
<Exec Command="pnpm install"/>
|
||||||
</Target>
|
</Target>
|
||||||
|
|
||||||
<Target Name="TailwindGenerate" DependsOnTargets="PnpmInstall" BeforeTargets="BeforeBuild">
|
<Target Name="TailwindGenerate" AfterTargets="EnsurePnpmInstalled" BeforeTargets="BeforeBuild" Condition="'$(_IsPublishing)' == 'yes'">
|
||||||
<Exec Command="pnpm tailwind -i wwwroot/input.css -o wwwroot/output.css"/>
|
<Message Importance="normal" Text="Generate css files using tailwind..."/>
|
||||||
|
<Exec Command="pnpm tailwindcss -i wwwroot/tailwind.css -o $(IntermediateOutputPath)tailwind.g.css"/>
|
||||||
|
|
||||||
|
<ItemGroup>
|
||||||
|
<Content Include="$(IntermediateOutputPath)tailwind.g.css" Visible="false" TargetPath="wwwroot/tailwind.g.css"/>
|
||||||
|
</ItemGroup>
|
||||||
</Target>
|
</Target>
|
||||||
|
|
||||||
</Project>
|
</Project>
|
||||||
|
|||||||
@@ -1,12 +1,15 @@
|
|||||||
{
|
{
|
||||||
"name": "YaeBlog",
|
"name": "yae-blog",
|
||||||
"version": "1.0.0",
|
"version": "1.0.0",
|
||||||
"description": "",
|
"description": "",
|
||||||
"scripts": {},
|
"scripts": {
|
||||||
"keywords": [],
|
"dev": "tailwindcss -i wwwroot/tailwind.css -o wwwroot/tailwind.g.css -w"
|
||||||
"author": "",
|
},
|
||||||
"license": "ISC",
|
"keywords": [],
|
||||||
"devDependencies": {
|
"author": "",
|
||||||
"tailwindcss": "^3.4.16"
|
"license": "ISC",
|
||||||
}
|
"devDependencies": {
|
||||||
|
"tailwindcss": "^4.0.0",
|
||||||
|
"@tailwindcss/cli": "^4.0.0"
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
1107
YaeBlog/pnpm-lock.yaml
generated
1107
YaeBlog/pnpm-lock.yaml
generated
File diff suppressed because it is too large
Load Diff
@@ -1,10 +1,12 @@
|
|||||||
---
|
---
|
||||||
title: 2021年终总结
|
title: 2021年终总结
|
||||||
date: 2022-01-12 16:27:19
|
date: 2022-01-12T16:27:19.0000000
|
||||||
tags:
|
tags:
|
||||||
- 随笔
|
- 杂谈
|
||||||
|
- 年终总结
|
||||||
---
|
---
|
||||||
|
|
||||||
|
|
||||||
2021年已经过去,2022年已经来临。每每一年开始的时候,我都会展开一张纸或者新建一个文档,思量着又是一年时光,也该同诸大杂志一般,写几句意味深长的话语,怀念过去的时光,也祝福未来的自己。可往往脑海中已是三万字的长篇,落在笔头却又是一个字都没有了。
|
2021年已经过去,2022年已经来临。每每一年开始的时候,我都会展开一张纸或者新建一个文档,思量着又是一年时光,也该同诸大杂志一般,写几句意味深长的话语,怀念过去的时光,也祝福未来的自己。可往往脑海中已是三万字的长篇,落在笔头却又是一个字都没有了。
|
||||||
如今跨年的时候已经过去,朋友圈中已经不见文案的踪影,我也该重新提笔,细说自己2021年中做过的种种。
|
如今跨年的时候已经过去,朋友圈中已经不见文案的踪影,我也该重新提笔,细说自己2021年中做过的种种。
|
||||||
|
|
||||||
@@ -22,7 +24,7 @@ tags:
|
|||||||
在前12年的学生生涯中,我们都在期待着这一次的暑假,以为在这个没有作业的假期里,我们就可以充分的享受人间的美好。可是,当时我们不知道,这人间的烦恼,可不止作业这一种,无论是突如其来的疫情导致开学延期,还是等待录取时的不安。
|
在前12年的学生生涯中,我们都在期待着这一次的暑假,以为在这个没有作业的假期里,我们就可以充分的享受人间的美好。可是,当时我们不知道,这人间的烦恼,可不止作业这一种,无论是突如其来的疫情导致开学延期,还是等待录取时的不安。
|
||||||
虽说在暑假时,拥有了自己的笔记本电脑,可是在高中三年屯下的游戏还是没有玩几个,看来我也是“喜加一”的受害者。虽然在高考后入坑了原神,但是假期间我并没有太过投入的玩。
|
虽说在暑假时,拥有了自己的笔记本电脑,可是在高中三年屯下的游戏还是没有玩几个,看来我也是“喜加一”的受害者。虽然在高考后入坑了原神,但是假期间我并没有太过投入的玩。
|
||||||
暑假下定决心要好好的学一学,可是看着我gitee上暑假期间那稀疏的提交,我就知道我又摸了一个暑假的鱼。
|
暑假下定决心要好好的学一学,可是看着我gitee上暑假期间那稀疏的提交,我就知道我又摸了一个暑假的鱼。
|
||||||

|

|
||||||
即使我想写的很多项目都没有被扎实的推进下来,但是学习的一些的C语言还是让我受益匪浅。
|
即使我想写的很多项目都没有被扎实的推进下来,但是学习的一些的C语言还是让我受益匪浅。
|
||||||
现在看来,这个假期真是,**学也没有学好,耍也没有耍好**的典型。
|
现在看来,这个假期真是,**学也没有学好,耍也没有耍好**的典型。
|
||||||
|
|
||||||
|
|||||||
BIN
YaeBlog/source/posts/2021-final/1.png
(Stored with Git LFS)
BIN
YaeBlog/source/posts/2021-final/1.png
(Stored with Git LFS)
Binary file not shown.
BIN
YaeBlog/source/posts/2021-final/1.webp
(Stored with Git LFS)
Normal file
BIN
YaeBlog/source/posts/2021-final/1.webp
(Stored with Git LFS)
Normal file
Binary file not shown.
@@ -1,11 +1,13 @@
|
|||||||
---
|
---
|
||||||
title: 2022年终总结
|
title: 2022年终总结
|
||||||
|
date: 2022-12-30T14:58:12.0000000
|
||||||
tags:
|
tags:
|
||||||
- 随笔
|
- 杂谈
|
||||||
date: 2022-12-30 14:58:12
|
- 年终总结
|
||||||
---
|
---
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
2022是困难的一年。我们需要为2023年做好准备。
|
2022是困难的一年。我们需要为2023年做好准备。
|
||||||
|
|
||||||
<!--more-->
|
<!--more-->
|
||||||
@@ -56,11 +58,11 @@ date: 2022-12-30 14:58:12
|
|||||||
|
|
||||||
小小的总结一下:2022年可以算得上是一事无成的一年,还搞砸了不少的事情。在写代码上进展有限,成绩上大幅倒退,说好的六级英语和大学物理竞赛都没有参加,在年末应对疫情进展的时候更是把“不知所措”这个成语诠释的淋漓尽致。
|
小小的总结一下:2022年可以算得上是一事无成的一年,还搞砸了不少的事情。在写代码上进展有限,成绩上大幅倒退,说好的六级英语和大学物理竞赛都没有参加,在年末应对疫情进展的时候更是把“不知所措”这个成语诠释的淋漓尽致。
|
||||||
|
|
||||||

|

|
||||||
|
|
||||||
关于今年的人际交往和社会关系,我愿意用QQ2022年年终总结中的一张截屏来总结,这张图片透漏出一种无可救药的悲伤。
|
关于今年的人际交往和社会关系,我愿意用QQ2022年年终总结中的一张截屏来总结,这张图片透漏出一种无可救药的悲伤。
|
||||||
|
|
||||||

|

|
||||||
|
|
||||||
## 展望
|
## 展望
|
||||||
|
|
||||||
|
|||||||
BIN
YaeBlog/source/posts/2022-final/2022-12-30-14-26-19-QQ_Image_1672381538441.jpg
(Stored with Git LFS)
BIN
YaeBlog/source/posts/2022-final/2022-12-30-14-26-19-QQ_Image_1672381538441.jpg
(Stored with Git LFS)
Binary file not shown.
BIN
YaeBlog/source/posts/2022-final/2022-12-30-14-26-19-QQ_Image_1672381538441.webp
(Stored with Git LFS)
Normal file
BIN
YaeBlog/source/posts/2022-final/2022-12-30-14-26-19-QQ_Image_1672381538441.webp
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
YaeBlog/source/posts/2022-final/2022-12-30-14-28-12-QQ_Image_1672381543836.jpg
(Stored with Git LFS)
BIN
YaeBlog/source/posts/2022-final/2022-12-30-14-28-12-QQ_Image_1672381543836.jpg
(Stored with Git LFS)
Binary file not shown.
BIN
YaeBlog/source/posts/2022-final/2022-12-30-14-28-12-QQ_Image_1672381543836.webp
(Stored with Git LFS)
Normal file
BIN
YaeBlog/source/posts/2022-final/2022-12-30-14-28-12-QQ_Image_1672381543836.webp
(Stored with Git LFS)
Normal file
Binary file not shown.
@@ -1,11 +1,11 @@
|
|||||||
---
|
---
|
||||||
title: 2022年暑假碎碎念
|
title: 2022年暑假碎碎念
|
||||||
|
date: 2022-08-22T15:39:13.0000000
|
||||||
tags:
|
tags:
|
||||||
- 随笔
|
- 杂谈
|
||||||
typora-root-url: 2022-summer-vacation
|
|
||||||
date: 2022-08-22 15:39:13
|
|
||||||
---
|
---
|
||||||
|
|
||||||
|
|
||||||
在8个月的漫长寒假的最后两个月,~~也就是俗称的暑假中~~,我都干了些什么?
|
在8个月的漫长寒假的最后两个月,~~也就是俗称的暑假中~~,我都干了些什么?
|
||||||
|
|
||||||
<!--more-->
|
<!--more-->
|
||||||
@@ -32,7 +32,7 @@ date: 2022-08-22 15:39:13
|
|||||||
- 下定决定要参加下一学期的物理竞赛,但是在听了讲座之后直接决定开学再开始学习,~~我知道我在家没法学习,俗称开摆~~
|
- 下定决定要参加下一学期的物理竞赛,但是在听了讲座之后直接决定开学再开始学习,~~我知道我在家没法学习,俗称开摆~~
|
||||||
- 又捡起了`Blender`,并在[Github](https://github.com/tanjian1998/bupt_minecraft)上找到了伟大的前辈们在`Minecraft`里复刻的老校区,希望能用`Blender`渲染几张图当作桌面。
|
- 又捡起了`Blender`,并在[Github](https://github.com/tanjian1998/bupt_minecraft)上找到了伟大的前辈们在`Minecraft`里复刻的老校区,希望能用`Blender`渲染几张图当作桌面。
|
||||||
|
|
||||||

|

|
||||||
|
|
||||||
> 在此感谢所有为此付出过汗水的前辈们,让我这个即将搬入老校区的萌新能提前一睹老校区的风采。
|
> 在此感谢所有为此付出过汗水的前辈们,让我这个即将搬入老校区的萌新能提前一睹老校区的风采。
|
||||||
|
|
||||||
|
|||||||
BIN
YaeBlog/source/posts/2022-summer-vacation/result1.png
(Stored with Git LFS)
BIN
YaeBlog/source/posts/2022-summer-vacation/result1.png
(Stored with Git LFS)
Binary file not shown.
BIN
YaeBlog/source/posts/2022-summer-vacation/result1.webp
(Stored with Git LFS)
Normal file
BIN
YaeBlog/source/posts/2022-summer-vacation/result1.webp
(Stored with Git LFS)
Normal file
Binary file not shown.
@@ -1,10 +1,12 @@
|
|||||||
---
|
---
|
||||||
title: 2023年年终总结
|
title: 2023年年终总结
|
||||||
|
date: 2024-02-29T20:18:19.0000000
|
||||||
tags:
|
tags:
|
||||||
- 随笔
|
- 杂谈
|
||||||
date: 2024-2-29 20:18:19
|
- 年终总结
|
||||||
---
|
---
|
||||||
|
|
||||||
|
|
||||||
虽然2023年已经过去了两个月,但是年终总结还是要发的。
|
虽然2023年已经过去了两个月,但是年终总结还是要发的。
|
||||||
|
|
||||||
<!--more-->
|
<!--more-->
|
||||||
@@ -43,7 +45,7 @@ date: 2024-2-29 20:18:19
|
|||||||
|
|
||||||
2023年最令我吃惊的事情是我刷B站的时长:
|
2023年最令我吃惊的事情是我刷B站的时长:
|
||||||
|
|
||||||

|

|
||||||
|
|
||||||
容易计算得出,我一共看了64天的B站,接近六分之一的时间都在看。虽然我确实有着在干活的时候黑听B站和把B站当作音乐播放器的习惯,但是这个时间未免有点太长了。下一年一定要在这个方面做出一定的改变,将更多的时间放在看书上面去,~~虽然写这句话的时候我就在黑听B站~~。
|
容易计算得出,我一共看了64天的B站,接近六分之一的时间都在看。虽然我确实有着在干活的时候黑听B站和把B站当作音乐播放器的习惯,但是这个时间未免有点太长了。下一年一定要在这个方面做出一定的改变,将更多的时间放在看书上面去,~~虽然写这句话的时候我就在黑听B站~~。
|
||||||
|
|
||||||
|
|||||||
BIN
YaeBlog/source/posts/2023-final/image-20240303165826486.png
(Stored with Git LFS)
BIN
YaeBlog/source/posts/2023-final/image-20240303165826486.png
(Stored with Git LFS)
Binary file not shown.
BIN
YaeBlog/source/posts/2023-final/image-20240303165826486.webp
(Stored with Git LFS)
Normal file
BIN
YaeBlog/source/posts/2023-final/image-20240303165826486.webp
(Stored with Git LFS)
Normal file
Binary file not shown.
90
YaeBlog/source/posts/2024-final.md
Normal file
90
YaeBlog/source/posts/2024-final.md
Normal file
@@ -0,0 +1,90 @@
|
|||||||
|
---
|
||||||
|
title: 2024年年终总结
|
||||||
|
date: 2025-01-16T17:15:05.8634370+08:00
|
||||||
|
tags:
|
||||||
|
- 杂谈
|
||||||
|
- 年终总结
|
||||||
|
---
|
||||||
|
|
||||||
|
|
||||||
|
欸,年终总结难道不是应该在新年当天发出吗,什么已经是新年第三天了?!
|
||||||
|
|
||||||
|
然而年末偶遇流感病毒,头疼脑热强如怪物,拼尽全力也无法战胜。
|
||||||
|
|
||||||
|
所以年终总结再次跳票,红豆泥私密马赛!
|
||||||
|
|
||||||
|
<!--more-->
|
||||||
|
|
||||||
|
### 压力
|
||||||
|
|
||||||
|
本年度的第一个关键词,我会选择压力。这一年总是被不同的压力笼罩着,先是有形的压力,然后是无形的压力,在不同的时间阶段有着不同的来源。
|
||||||
|
|
||||||
|
1月份起始的两周就是大三学年秋季学期的期末考试周,而鄙人在下不才我,在本学期面临着计算机科学四幻神的考验——老师不知所云之操作系统、抽象概念无法理解之编译原理、全英语授课之数据库系统原理和智商不够无法战胜之算法导论。挣扎在保研线上的我,刚刚被上一学期的离散数学(下)的~~75分~~74分和数据结构的79分拷打,面对着如此沉重的考试压力(加起来一共12学分呢),可耻的失眠了。
|
||||||
|
|
||||||
|
过完年回来的三月份,就是同论文奋斗的一个月。虽然只是一篇6页的EI检索论文,但对于一个**纯洁**的本科生来说还是有点太困难了。这个过程就像是你先拉了一坨大的,然后在上面细细的涂上巧克力,在最后发表的过程中,需要在众人的面前大嚼这一坨东西,并且称赞“真是一道美食啊”!还没有开始的学术生涯就已经留下永恒的污点力(悲)。
|
||||||
|
|
||||||
|
搞完论文的四月和五月则是和大作业搏斗的两个月。首先是无法战胜的“编译原理课程设计”,内容是设计一个Pascal-S到C语言的源到源编译器。这一大作业的主要压力来源是大作业本身的难度,直到最后提交的时候,全部95个测试点也没有能够完全通过,然而其他人在祖传代码上缝缝补补却过来,哭。虽然考虑到我们是全手写的编译器,没有使用任何的编译器构建工具,提出的解决方案也称不上是墨守成规,老师给了我一个还算是可以的分数,算是压力中的小小慰藉。
|
||||||
|
|
||||||
|
然后是风波不断的软件工程大作业,明明只是一个相对简单的Web前后端开发,但是我们前后进行了三次验收才通过,一直拖到了学期的第16周。老师设计的联合验收制度给我们结结实实的上了一课,要求联合验收小组的不同前后端需要能够任意组合使用,导致我们为了适配另外一组的逻辑,几乎是把核心代码写了两遍。虽然我不喜欢在背后攻击别人,但是我不得不说,这一年中最有压力的时刻,往往不是自己的事情搞不定时,而是看着别人搞砸事情你却无能为力的时候。
|
||||||
|
|
||||||
|
这两个月还夹杂这一个意义不明的专业实习,明明是计算机科学与技术专业的牛马,为什么会被中兴通讯的老师培训通信项目的项目管理?
|
||||||
|
|
||||||
|
应付完上面这些杂七杂八的内容,便是本科生生涯中的最后三场考试:人称计算机领域的政治之《软件工程》,通信领域科普课程之《现代交换原理》和永远的神之《计算机系统结构》。
|
||||||
|
|
||||||
|
不得不说《软件工程》,~~或者人们常说的肖概~~确实不愧于计算机领域的政治之称。毕竟政治的主要课题就是研究如何组织和动员人群以完成一个特定的目标,《软件工程》不过是将人员限制为了软件的开发人员,领域限制为了软件开发领域,基本的道理还是相通的。
|
||||||
|
|
||||||
|
《现代交换原理》则是一门在现有的课程体系下非常尴尬的一门课程,显然这门课的保留还是为了凸显“计算机+通信”的学科特色,但是大量前置知识的缺失和同其他课程的脱节使得这门课就显得非常的“脱节”。而且相对来说,通信技术的发展速度远远不如互联网的迭代技术,这门课也被同学们戏称为“古代交换原理”。令人最难受的,虽然知识古代,但是却一点都不简单,很多内容只能说是听了个概念,幸好最后的考试不难,靠死记硬背通过了考试。
|
||||||
|
|
||||||
|
《计算机系统结构》就是核心课中的核心课了。课程内容和《计算机组成原理》衔接的非常紧密,~~虽然我组成原理就学的很垃圾~~,主要围绕着如何最大限度的并行化运行程序进行,从指令级的并行一直到多机并行,可以说是压力最大的一门考试。在准备的过程中做了很多套往年题,博客上也发布了一部分的复习笔记,最终幸好低空飞过。唯一的吐槽是实验什么时候可以从MIPS改成为RISC-V呢。
|
||||||
|
|
||||||
|
三门课的考试一结束,这些死线明确的、有形的压力便消失了,但是无形的压力——对于是否能保研的焦虑——便笼罩下来。
|
||||||
|
|
||||||
|
7月和8月都是在这种不安和恐慌中度过,这种氛围在9月份保研名单出炉之前达到了顶峰。保研的流程开始之后则是通知推着人走,各种交材料,各种准备答辩,各种等待公示,直到最后的保研名单出炉。
|
||||||
|
|
||||||
|
不过现在回想起来,最后名单出炉,获得保研资格,复试通过之后,并没有一种如释重负的感觉,或者说终于实现了既定目标的快感。反而是一种“啊,结束了”的空落感,只想回去睡一觉。
|
||||||
|
|
||||||
|
然后新的~~风暴~~压力已经出现,在度过一个短短的国庆假期之后便正式进组,作为一个研究生的社畜生涯就此开始。
|
||||||
|
|
||||||
|
### 经历
|
||||||
|
|
||||||
|
虽然2024年的第一个关键词已经选择为“压力”,但是众所周知,高压锅里往往能压出好吃的。人也是这样。所以我将2024年的第二个关键词定为“经历”,人生如逆旅,我亦是行人,各式各样的经历便是风格迥异的景点。
|
||||||
|
|
||||||
|
人生第一篇学术论文的撰写和发表无疑是今年最难忘的经历。虽然我在前面称之为“学术生涯上的污点”,但是污点也好过一片空白不是,还非常的引人夺目。而且这是一个完整的撰写-发表流程,从开始的选题、实验、撰写、投稿,到最后的接受、提交、发表、报销等等数个环节我均参加。这个过程不仅让我对于学术论文的诞生流程有力较为清晰的认识,也对学校的各种发表和报销流程有了深入的了解。
|
||||||
|
|
||||||
|
两个大作业,编译原理课程设计和软件工程大作业,也是非常难忘的经历。这两个项目的代码都已经整理好开源在Github上了。前者代表了目前我软件开发的最高水平,而后者则是我本科阶段唯一一个差点失败的软件开发项目。这种冰火两重天的对比实在是很难令人忘记。
|
||||||
|
|
||||||
|
这两个项目中的收获有非常技术性的。相较于2023年面对各种大作业时的略显底气不足,这次我在各种技术栈的选择上更加游刃有余,选择了完全倒向.NET和React,摈弃了之前的Java和Vue。各类现代软件开发技术也得到了充分的应用,例如由Gitea Actions驱动的DevOps实践,完全基于合并请求的多人协作流程。事实证明,这些协作流程确实在一定程度上加速了项目的开发。
|
||||||
|
|
||||||
|
但是,“软件工程里没有银弹”,先进技术的堆叠并不能保证软件项目成功。虽然我这里~~自吹自擂~~有非常多新技术的帮助,软件工程大作业的差点失败的确说明了软件工程实际上还是人的工程,猪队友永远比凶恶的敌人更可怕。当然也不能将所有的锅都扔给别人,我在项目失控的过程中也没有能够采取有力的措施挽救整个项目,~~负有不可推卸的领导责任~~。
|
||||||
|
|
||||||
|
今年最后一个难忘的经历便是去横店镇参加CNCC 2024,也单独出过[博客](https://rrricardo.top/blog/essays/cncc-2024)。虽然之前学术论文发表的过程中也是在学术会议上做过口头报告,不过是线上参加的,并没有特别的实感。现在线下参加,也不需要自己上去发表,顿感旅游真好玩,~~也有可能是因为CNCC比较水~~。
|
||||||
|
|
||||||
|
### 匆匆
|
||||||
|
|
||||||
|
2024年的第三个关键词我想定为”匆匆“,虽然想找一个更加”有文化“的词汇,奈何自己的文化造纸实在不够,故定为”匆匆“。
|
||||||
|
|
||||||
|
可2024年确实是非常忙碌的一年,现在回想起来,几乎每一个月都是在为了某一件特定的事情而奔走着。还记得在新年伊始的时间里,我还制订了各种各样的读书计划和补番计划,现在看来,定计划的目的不是为了实现,而是为了安心。
|
||||||
|
|
||||||
|
不过匆匆之中还是读了几本书。首先是久负盛名的《置身事内——中国政府与经济发展》,这本书的开篇即言:“这本书是写给大学生和对经济话题感兴趣的读者”,细读下来也确实如此。然后是一本我从小便着迷的二战军史相关话题《美国陷阱:橙色计划始末》,其中若干的政治与军事细节之于我不过是走马观花,不过其中表达出的长期战略实在令人敬佩。
|
||||||
|
|
||||||
|
至于补番计划,我则是表现出了同电子ED一样的症状,对于新番没有兴趣,对于补早就下载安装好的老番更是兴趣缺缺。反倒是电视剧,由于12月韩国的惊天一变,我又重新下载了《第五共和国》,忠!诚!
|
||||||
|
|
||||||
|
不过我的B站观看时长再度增长30%,这好吗,这不好,~~有这么多时间刷B站,鬼知道你匆匆在哪了~~。
|
||||||
|
|
||||||
|

|
||||||
|
|
||||||
|
### 未来
|
||||||
|
|
||||||
|
> 定计划的目的不是为了实现,而是为了安心。
|
||||||
|
|
||||||
|
站在年关,已经可以预见到2025年将会是更为繁忙的一年,从一月份到十月份都已经有了或多或少的安排,现在无法多言,只能希望都能有良好的结果。
|
||||||
|
|
||||||
|
还是多说点可以说的罢。
|
||||||
|
|
||||||
|
首先是读书计划。《置身事内——中国政府与经济发展》的每章最后都有一个推荐书目,一整本上总结下来也能有超过50本,其中不乏超过一千页的大部头,说能够一年看完显然是痴人说梦。这里先列两本同我的工作关系密切的书籍:
|
||||||
|
|
||||||
|
- 陆风,《光变:一个企业及其工业史》
|
||||||
|
- 吴军,《浪潮之巅》
|
||||||
|
|
||||||
|
其次是补番计划,这一年刷到了不少押井守导演的《机动警察》系列,虽然我之前对于人形机器人并不热心,但剧中精细的作画和宏大的背景设定确实非常吸引人,遂决定今年找来看看。
|
||||||
|
|
||||||
BIN
YaeBlog/source/posts/2024-final/image-20250115171809775.webp
(Stored with Git LFS)
Normal file
BIN
YaeBlog/source/posts/2024-final/image-20250115171809775.webp
(Stored with Git LFS)
Normal file
Binary file not shown.
@@ -1,11 +1,11 @@
|
|||||||
---
|
---
|
||||||
title: 人生代码大作业初体验
|
title: 人生代码大作业初体验
|
||||||
|
date: 2022-07-27T11:34:49.0000000
|
||||||
tags:
|
tags:
|
||||||
- 随笔
|
- 杂谈
|
||||||
typora-root-url: big-homework
|
|
||||||
date: 2022-07-27 11:34:49
|
|
||||||
---
|
---
|
||||||
|
|
||||||
|
|
||||||
在大学也呆了一年了,终于遇上了第一个需要多人合作的写代码项目。从四月底分组完成,任务部署下来到七月初接近尾声,在这两个多月的时间里,也算是经历了不少,学到了不少。
|
在大学也呆了一年了,终于遇上了第一个需要多人合作的写代码项目。从四月底分组完成,任务部署下来到七月初接近尾声,在这两个多月的时间里,也算是经历了不少,学到了不少。
|
||||||
|
|
||||||
<!--more-->
|
<!--more-->
|
||||||
@@ -44,7 +44,7 @@ date: 2022-07-27 11:34:49
|
|||||||
|
|
||||||
而且采用 `Git`还有一个好处,采用 `Github`的 `Insight`功能可以轻松的看出大家的贡献值()。
|
而且采用 `Git`还有一个好处,采用 `Github`的 `Insight`功能可以轻松的看出大家的贡献值()。
|
||||||
|
|
||||||

|

|
||||||
|
|
||||||
## 一些技术上的收获
|
## 一些技术上的收获
|
||||||
|
|
||||||
|
|||||||
BIN
YaeBlog/source/posts/big-homework/1.png
(Stored with Git LFS)
BIN
YaeBlog/source/posts/big-homework/1.png
(Stored with Git LFS)
Binary file not shown.
BIN
YaeBlog/source/posts/big-homework/1.webp
(Stored with Git LFS)
Normal file
BIN
YaeBlog/source/posts/big-homework/1.webp
(Stored with Git LFS)
Normal file
Binary file not shown.
@@ -1,12 +1,12 @@
|
|||||||
---
|
---
|
||||||
title: 建立博客过程的记录
|
title: 建立博客过程的记录
|
||||||
typora-root-url: 建立博客过程的记录
|
date: 2022-04-08T11:52:32.0000000
|
||||||
date: 2022-04-08 11:52:32
|
|
||||||
tags:
|
tags:
|
||||||
- 技术笔记
|
- 技术笔记
|
||||||
---
|
---
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
当我已经在Python的浩瀚大海遨(zheng)游(zha)了半个暑假后,我决定尝试一下传说中程序员专用的学(zhuang)习(bi)手(fangfa)段(fa)——建立自己的个人博客。作为一个半懂不懂的Python程序员,心中冒出的第一个想法自然是采用Python的Django作为开发自己的个人博客的手段。然而,在阅读了[用Django搭建个人博客](https://www.dusaiphoto.com/article/2/)等的其他人搭建这类动态博客的过程记录之后,我便义无反顾的转向了采用javascript开发的博客框架[Hexo](https://hexo.io),<del>说好的Python信仰呢</del>。无他,唯简单尔。
|
当我已经在Python的浩瀚大海遨(zheng)游(zha)了半个暑假后,我决定尝试一下传说中程序员专用的学(zhuang)习(bi)手(fangfa)段(fa)——建立自己的个人博客。作为一个半懂不懂的Python程序员,心中冒出的第一个想法自然是采用Python的Django作为开发自己的个人博客的手段。然而,在阅读了[用Django搭建个人博客](https://www.dusaiphoto.com/article/2/)等的其他人搭建这类动态博客的过程记录之后,我便义无反顾的转向了采用javascript开发的博客框架[Hexo](https://hexo.io),<del>说好的Python信仰呢</del>。无他,唯简单尔。
|
||||||
|
|
||||||
<!--more-->
|
<!--more-->
|
||||||
@@ -131,7 +131,7 @@ Hexo init blog
|
|||||||
```
|
```
|
||||||
Hexo会以blog为名称创建一个博客文件夹,这个文件夹的内容为
|
Hexo会以blog为名称创建一个博客文件夹,这个文件夹的内容为
|
||||||
|
|
||||||

|

|
||||||
|
|
||||||
`node_modules`文件夹是Hexo需要用到的一些npm依赖包的存放地址,`public`文件夹下是由Hexo渲染产生的静态博客文件,`scaffolds`文件夹是博客用到的模板文件,在默认情况下应该有`draft.md`,`page.md`,`post.md`三个模板文件。`themes`是Hexo中可以使用的主题文件。主题也是Hexo一个非常方便的设计,我们可以方便使用其他人编写的Hexo Themes,让自己的博客在不同的风格之间变换。`source`文件夹就是存放我们写作的博客的地方。一般这里面会有两个子文件夹,`_draft`, `_posts`。我们在里面在创建一个`img`文件夹,把自己的头像图片和网站的图标文件都放在里面,在之后的设置的时候使用。
|
`node_modules`文件夹是Hexo需要用到的一些npm依赖包的存放地址,`public`文件夹下是由Hexo渲染产生的静态博客文件,`scaffolds`文件夹是博客用到的模板文件,在默认情况下应该有`draft.md`,`page.md`,`post.md`三个模板文件。`themes`是Hexo中可以使用的主题文件。主题也是Hexo一个非常方便的设计,我们可以方便使用其他人编写的Hexo Themes,让自己的博客在不同的风格之间变换。`source`文件夹就是存放我们写作的博客的地方。一般这里面会有两个子文件夹,`_draft`, `_posts`。我们在里面在创建一个`img`文件夹,把自己的头像图片和网站的图标文件都放在里面,在之后的设置的时候使用。
|
||||||
|
|
||||||
@@ -146,7 +146,7 @@ INFO Hexo is running at http://localhost:4000/ . Press Ctrl+C to stop.
|
|||||||
|
|
||||||
会在本地运行Hexo自带的一台静态博客服务器。我们用浏览器访问http://localhost:4000, 就可以看见Hexo博客的初始界面
|
会在本地运行Hexo自带的一台静态博客服务器。我们用浏览器访问http://localhost:4000, 就可以看见Hexo博客的初始界面
|
||||||
|
|
||||||

|

|
||||||
|
|
||||||
这便说明安装成功了,~~可以开香槟了~~
|
这便说明安装成功了,~~可以开香槟了~~
|
||||||
|
|
||||||
|
|||||||
BIN
YaeBlog/source/posts/build-blog-record/1.png
(Stored with Git LFS)
BIN
YaeBlog/source/posts/build-blog-record/1.png
(Stored with Git LFS)
Binary file not shown.
BIN
YaeBlog/source/posts/build-blog-record/1.webp
(Stored with Git LFS)
Normal file
BIN
YaeBlog/source/posts/build-blog-record/1.webp
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
YaeBlog/source/posts/build-blog-record/2.png
(Stored with Git LFS)
BIN
YaeBlog/source/posts/build-blog-record/2.png
(Stored with Git LFS)
Binary file not shown.
BIN
YaeBlog/source/posts/build-blog-record/2.webp
(Stored with Git LFS)
Normal file
BIN
YaeBlog/source/posts/build-blog-record/2.webp
(Stored with Git LFS)
Normal file
Binary file not shown.
@@ -7,6 +7,7 @@ tags:
|
|||||||
---
|
---
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
我们编译是这样的,在本平台上编译只要敲三条命令就好了,而交叉编译要考虑的就很多了。
|
我们编译是这样的,在本平台上编译只要敲三条命令就好了,而交叉编译要考虑的就很多了。
|
||||||
|
|
||||||
<!--more-->
|
<!--more-->
|
||||||
@@ -45,7 +46,7 @@ tags:
|
|||||||
|
|
||||||
通常一份GNU工具链只能针对一个平台进行编译,但是LLVM工具链是一套先天的交叉编译工具链,例如对于`llc`工具,使用`llc --version`命令可以看见该编译器可以生成多种目标平台上的汇编代码:
|
通常一份GNU工具链只能针对一个平台进行编译,但是LLVM工具链是一套先天的交叉编译工具链,例如对于`llc`工具,使用`llc --version`命令可以看见该编译器可以生成多种目标平台上的汇编代码:
|
||||||
|
|
||||||

|

|
||||||
|
|
||||||
在使用`clang++`时加上`--target=<triple>`指定目标三元组就可以进行交叉编译。
|
在使用`clang++`时加上`--target=<triple>`指定目标三元组就可以进行交叉编译。
|
||||||
|
|
||||||
@@ -62,7 +63,7 @@ int main()
|
|||||||
}
|
}
|
||||||
```
|
```
|
||||||
|
|
||||||

|

|
||||||
|
|
||||||
看样子交叉编译也不是开箱即用的。最开始我们猜想系统提供的LLVM工具链没有被配置为交叉编译,因此尝试在本地自行编译一套LLVM工具链。
|
看样子交叉编译也不是开箱即用的。最开始我们猜想系统提供的LLVM工具链没有被配置为交叉编译,因此尝试在本地自行编译一套LLVM工具链。
|
||||||
|
|
||||||
@@ -81,7 +82,7 @@ cmake ../llvm-project.src/llvm \
|
|||||||
|
|
||||||
编译之后的成果会安装到`/usr/local/`目录下,而在`$PATH`环境变量中`/usr/local`位置将在`/usr`目录之前,因此调用时将会优先调用我们自行编译的LLVM工具链,而不是系统中安装的LLVM工具链。
|
编译之后的成果会安装到`/usr/local/`目录下,而在`$PATH`环境变量中`/usr/local`位置将在`/usr`目录之前,因此调用时将会优先调用我们自行编译的LLVM工具链,而不是系统中安装的LLVM工具链。
|
||||||
|
|
||||||

|

|
||||||
|
|
||||||
但是使用这套编译工具链仍然会爆出和之前一样的问题。说明这并不是系统安装LLVM工具链的问题。仔细一想也确实,这里提示找不到对应的头文件应该是找不到RISC-V架构之下的头文件——这里的也是交叉编译的主要问题所在:虽然LLVM工具链宣称自己是原生支持交叉编译的,但是没人宣称说标准库和头文件是原生的。这里我们就需要一个根文件系统来提供这些头文件和各种库文件。
|
但是使用这套编译工具链仍然会爆出和之前一样的问题。说明这并不是系统安装LLVM工具链的问题。仔细一想也确实,这里提示找不到对应的头文件应该是找不到RISC-V架构之下的头文件——这里的也是交叉编译的主要问题所在:虽然LLVM工具链宣称自己是原生支持交叉编译的,但是没人宣称说标准库和头文件是原生的。这里我们就需要一个根文件系统来提供这些头文件和各种库文件。
|
||||||
|
|
||||||
@@ -198,7 +199,7 @@ clang++ --target=riscv64-linux-gnu --sysroot=$ROOTFS_DIR -fuse-ld=lld hello.cpp
|
|||||||
|
|
||||||
第一个问题的回答是Arch Linux安装的LLVM工具是可以交叉编译的。虽然在Arch Linux官方构建LLVM工具链的[构建脚本](https://gitlab.archlinux.org/archlinux/packaging/packages/clang/-/blob/main/PKGBUILD?ref_type=heads)中没有使用`LLVM_TARGETS_TO_BUILD`参数,但是这个参数的默认值是`all`。这一点我们也可以通过实验来验证。
|
第一个问题的回答是Arch Linux安装的LLVM工具是可以交叉编译的。虽然在Arch Linux官方构建LLVM工具链的[构建脚本](https://gitlab.archlinux.org/archlinux/packaging/packages/clang/-/blob/main/PKGBUILD?ref_type=heads)中没有使用`LLVM_TARGETS_TO_BUILD`参数,但是这个参数的默认值是`all`。这一点我们也可以通过实验来验证。
|
||||||
|
|
||||||
于是回到编译`llvm`的目录下执行`cat install_manifest.txt | sudo xargs rm`。
|
于是回到编译`llvm`的目录下执行`cat install_manifest.txt | sudo xargs rm`。
|
||||||
|
|
||||||
第二个问题的回答可以使用实验来验证,首先安装`riscv64-linux-gnu-gcc`,然后将根文件系统的位置设置为`/usr/riscv64-linux-gnu`,重新编译上面的你好世界样例。编译之后可以正常执行。
|
第二个问题的回答可以使用实验来验证,首先安装`riscv64-linux-gnu-gcc`,然后将根文件系统的位置设置为`/usr/riscv64-linux-gnu`,重新编译上面的你好世界样例。编译之后可以正常执行。
|
||||||
|
|
||||||
@@ -229,4 +230,4 @@ export ROOTFS_DIR=<rootfs>
|
|||||||
|
|
||||||
但是现在的.NET在RISC-V平台上还是废物一个,甚至连`dotnet new`都跑不过,下一步看看能不能运行一下运行时的测试集看看。
|
但是现在的.NET在RISC-V平台上还是废物一个,甚至连`dotnet new`都跑不过,下一步看看能不能运行一下运行时的测试集看看。
|
||||||
|
|
||||||

|

|
||||||
|
|||||||
BIN
YaeBlog/source/posts/build-dotnet-from-source/image-20240824120646587.png
(Stored with Git LFS)
BIN
YaeBlog/source/posts/build-dotnet-from-source/image-20240824120646587.png
(Stored with Git LFS)
Binary file not shown.
BIN
YaeBlog/source/posts/build-dotnet-from-source/image-20240824120646587.webp
(Stored with Git LFS)
Normal file
BIN
YaeBlog/source/posts/build-dotnet-from-source/image-20240824120646587.webp
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
YaeBlog/source/posts/build-dotnet-from-source/image-20240824121425007.png
(Stored with Git LFS)
BIN
YaeBlog/source/posts/build-dotnet-from-source/image-20240824121425007.png
(Stored with Git LFS)
Binary file not shown.
BIN
YaeBlog/source/posts/build-dotnet-from-source/image-20240824121425007.webp
(Stored with Git LFS)
Normal file
BIN
YaeBlog/source/posts/build-dotnet-from-source/image-20240824121425007.webp
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
YaeBlog/source/posts/build-dotnet-from-source/image-20240824134158262.png
(Stored with Git LFS)
BIN
YaeBlog/source/posts/build-dotnet-from-source/image-20240824134158262.png
(Stored with Git LFS)
Binary file not shown.
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user