Compare commits
2 Commits
master
...
4fd464fd34
| Author | SHA1 | Date | |
|---|---|---|---|
| 4fd464fd34 | |||
| d9c17720dc |
@@ -12,10 +12,7 @@ indent_style = space
|
|||||||
indent_size = 4
|
indent_size = 4
|
||||||
trim_trailing_whitespace = true
|
trim_trailing_whitespace = true
|
||||||
|
|
||||||
[{project.json,appsettings.json,appsettings.*.json}]
|
[project.json]
|
||||||
indent_size = 2
|
|
||||||
|
|
||||||
[*.{yaml,yml}]
|
|
||||||
indent_size = 2
|
indent_size = 2
|
||||||
|
|
||||||
# C# and Visual Basic files
|
# C# and Visual Basic files
|
||||||
|
|||||||
3
.gitattributes
vendored
3
.gitattributes
vendored
@@ -1,5 +1,2 @@
|
|||||||
*.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,30 +1,29 @@
|
|||||||
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:
|
||||||
- name: Check out code.
|
- uses: https://git.rrricardo.top/actions/checkout@v4
|
||||||
uses: http://github-mirrors.infra.svc.cluster.local/actions/checkout.git@v4
|
name: Check out code
|
||||||
with:
|
with:
|
||||||
lfs: true
|
lfs: true
|
||||||
- name: Build project.
|
- name: Build project
|
||||||
run: |
|
run: |
|
||||||
git submodule update --init
|
cd YaeBlog
|
||||||
podman pull mcr.azure.cn/dotnet/aspnet:10.0
|
dotnet publish
|
||||||
pwsh build.ps1 build
|
- name: Build docker image
|
||||||
- name: Workaround to make sure podman-login working.
|
run: |
|
||||||
run: |
|
cd YaeBlog
|
||||||
mkdir -p /root/.docker
|
docker build . -t registry.cn-beijing.aliyuncs.com/jackfiled/blog:latest
|
||||||
- name: Login tencent cloud docker registry.
|
- name: Login aliyun docker registry
|
||||||
uses: http://github-mirrors.infra.svc.cluster.local/actions/podman-login.git@v1
|
uses: https://git.rrricardo.top/actions/login-action@v3
|
||||||
with:
|
with:
|
||||||
registry: ccr.ccs.tencentyun.com
|
registry: registry.cn-beijing.aliyuncs.com
|
||||||
username: 100044380877
|
username: 初冬的朝阳
|
||||||
password: ${{ secrets.TENCENT_REGISTRY_PASSWORD }}
|
password: ${{ secrets.ALIYUN_PASSWORD }}
|
||||||
auth_file_path: /etc/containers/auth.json
|
- name: Push docker image
|
||||||
- name: Push docker image.
|
run: docker push registry.cn-beijing.aliyuncs.com/jackfiled/blog:latest
|
||||||
run: podman push ccr.ccs.tencentyun.com/jackfiled/blog:latest
|
|
||||||
|
|||||||
4
.gitignore
vendored
4
.gitignore
vendored
@@ -184,7 +184,6 @@ DocProject/Help/html
|
|||||||
|
|
||||||
# Click-Once directory
|
# Click-Once directory
|
||||||
publish/
|
publish/
|
||||||
out/
|
|
||||||
|
|
||||||
# Publish Web Output
|
# Publish Web Output
|
||||||
*.[Pp]ublish.xml
|
*.[Pp]ublish.xml
|
||||||
@@ -483,6 +482,3 @@ $RECYCLE.BIN/
|
|||||||
|
|
||||||
# Vim temporary swap files
|
# Vim temporary swap files
|
||||||
*.swp
|
*.swp
|
||||||
|
|
||||||
# Tailwind auto-generated stylesheet
|
|
||||||
*.g.css
|
|
||||||
|
|||||||
3
.gitmodules
vendored
3
.gitmodules
vendored
@@ -1,3 +0,0 @@
|
|||||||
[submodule "third-party/BlazorSvgComponents"]
|
|
||||||
path = third-party/BlazorSvgComponents
|
|
||||||
url = https://git.rrricardo.top/jackfiled/BlazorSvgComponents.git
|
|
||||||
@@ -1,13 +1,11 @@
|
|||||||
using System.Diagnostics.CodeAnalysis;
|
using System.Diagnostics.CodeAnalysis;
|
||||||
using YaeBlog.Models;
|
using YaeBlog.Core.Models;
|
||||||
|
|
||||||
namespace YaeBlog.Abstraction;
|
namespace YaeBlog.Core.Abstractions;
|
||||||
|
|
||||||
public interface IEssayContentService
|
public interface IEssayContentService
|
||||||
{
|
{
|
||||||
public IEnumerable<BlogEssay> Essays { get; }
|
public IReadOnlyDictionary<string, BlogEssay> Essays { get; }
|
||||||
|
|
||||||
public int Count { get; }
|
|
||||||
|
|
||||||
public IReadOnlyDictionary<EssayTag, List<BlogEssay>> Tags { get; }
|
public IReadOnlyDictionary<EssayTag, List<BlogEssay>> Tags { get; }
|
||||||
|
|
||||||
@@ -18,8 +16,6 @@ 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();
|
||||||
12
YaeBlog.Core/Abstractions/IEssayScanService.cs
Normal file
12
YaeBlog.Core/Abstractions/IEssayScanService.cs
Normal file
@@ -0,0 +1,12 @@
|
|||||||
|
using YaeBlog.Core.Models;
|
||||||
|
|
||||||
|
namespace YaeBlog.Core.Abstractions;
|
||||||
|
|
||||||
|
public interface IEssayScanService
|
||||||
|
{
|
||||||
|
public Task<BlogContents> ScanContents();
|
||||||
|
|
||||||
|
public Task SaveBlogContent(BlogContent content, bool isDraft = true);
|
||||||
|
|
||||||
|
public Task<ImageScanResult> ScanImages();
|
||||||
|
}
|
||||||
@@ -1,6 +1,6 @@
|
|||||||
using YaeBlog.Models;
|
using YaeBlog.Core.Models;
|
||||||
|
|
||||||
namespace YaeBlog.Abstraction;
|
namespace YaeBlog.Core.Abstractions;
|
||||||
|
|
||||||
public interface IPostRenderProcessor
|
public interface IPostRenderProcessor
|
||||||
{
|
{
|
||||||
@@ -1,6 +1,6 @@
|
|||||||
using YaeBlog.Models;
|
using YaeBlog.Core.Models;
|
||||||
|
|
||||||
namespace YaeBlog.Abstraction;
|
namespace YaeBlog.Core.Abstractions;
|
||||||
|
|
||||||
public interface IPreRenderProcessor
|
public interface IPreRenderProcessor
|
||||||
{
|
{
|
||||||
8
YaeBlog.Core/Components/_Imports.razor
Normal file
8
YaeBlog.Core/Components/_Imports.razor
Normal file
@@ -0,0 +1,8 @@
|
|||||||
|
@using System.Net.Http
|
||||||
|
@using System.Net.Http.Json
|
||||||
|
@using Microsoft.AspNetCore.Components.Forms
|
||||||
|
@using Microsoft.AspNetCore.Components.Routing
|
||||||
|
@using Microsoft.AspNetCore.Components.Web
|
||||||
|
@using static Microsoft.AspNetCore.Components.Web.RenderMode
|
||||||
|
@using Microsoft.AspNetCore.Components.Web.Virtualization
|
||||||
|
@using Microsoft.JSInterop
|
||||||
34
YaeBlog.Core/Extensions/ServiceCollectionExtensions.cs
Normal file
34
YaeBlog.Core/Extensions/ServiceCollectionExtensions.cs
Normal file
@@ -0,0 +1,34 @@
|
|||||||
|
using Markdig;
|
||||||
|
using Microsoft.Extensions.DependencyInjection;
|
||||||
|
using YamlDotNet.Serialization;
|
||||||
|
using YamlDotNet.Serialization.NamingConventions;
|
||||||
|
|
||||||
|
namespace YaeBlog.Core.Extensions;
|
||||||
|
|
||||||
|
public static class ServiceCollectionExtensions
|
||||||
|
{
|
||||||
|
public static IServiceCollection AddMarkdig(this IServiceCollection collection)
|
||||||
|
{
|
||||||
|
MarkdownPipelineBuilder builder = new();
|
||||||
|
|
||||||
|
builder.UseAdvancedExtensions();
|
||||||
|
|
||||||
|
collection.AddSingleton<MarkdownPipeline>(_ => builder.Build());
|
||||||
|
|
||||||
|
return collection;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static IServiceCollection AddYamlParser(this IServiceCollection collection)
|
||||||
|
{
|
||||||
|
DeserializerBuilder deserializerBuilder = new();
|
||||||
|
deserializerBuilder.WithNamingConvention(CamelCaseNamingConvention.Instance);
|
||||||
|
deserializerBuilder.IgnoreUnmatchedProperties();
|
||||||
|
collection.AddSingleton(deserializerBuilder.Build());
|
||||||
|
|
||||||
|
SerializerBuilder serializerBuilder = new();
|
||||||
|
serializerBuilder.WithNamingConvention(CamelCaseNamingConvention.Instance);
|
||||||
|
collection.AddSingleton(serializerBuilder.Build());
|
||||||
|
|
||||||
|
return collection;
|
||||||
|
}
|
||||||
|
}
|
||||||
50
YaeBlog.Core/Extensions/WebApplicationBuilderExtensions.cs
Normal file
50
YaeBlog.Core/Extensions/WebApplicationBuilderExtensions.cs
Normal file
@@ -0,0 +1,50 @@
|
|||||||
|
using AngleSharp;
|
||||||
|
using Microsoft.AspNetCore.Builder;
|
||||||
|
using Microsoft.Extensions.DependencyInjection;
|
||||||
|
using Microsoft.Extensions.Options;
|
||||||
|
using YaeBlog.Core.Abstractions;
|
||||||
|
using YaeBlog.Core.Models;
|
||||||
|
using YaeBlog.Core.Processors;
|
||||||
|
using YaeBlog.Core.Services;
|
||||||
|
|
||||||
|
namespace YaeBlog.Core.Extensions;
|
||||||
|
|
||||||
|
public static class WebApplicationBuilderExtensions
|
||||||
|
{
|
||||||
|
public static WebApplicationBuilder AddYaeBlog(this WebApplicationBuilder builder)
|
||||||
|
{
|
||||||
|
builder.Services.Configure<BlogOptions>(builder.Configuration.GetSection(BlogOptions.OptionName));
|
||||||
|
|
||||||
|
builder.Services.AddHttpClient();
|
||||||
|
|
||||||
|
builder.Services.AddMarkdig();
|
||||||
|
builder.Services.AddYamlParser();
|
||||||
|
builder.Services.AddSingleton<IConfiguration>(_ => Configuration.Default);
|
||||||
|
builder.Services.AddSingleton<IEssayScanService, EssayScanService>();
|
||||||
|
builder.Services.AddSingleton<RendererService>();
|
||||||
|
builder.Services.AddSingleton<IEssayContentService, EssayContentService>();
|
||||||
|
builder.Services.AddTransient<ImagePostRenderProcessor>();
|
||||||
|
builder.Services.AddTransient<CodeBlockPostRenderProcessor>();
|
||||||
|
builder.Services.AddTransient<TablePostRenderProcessor>();
|
||||||
|
builder.Services.AddTransient<HeadlinePostRenderProcessor>();
|
||||||
|
builder.Services.AddTransient<BlogOptions>(provider =>
|
||||||
|
provider.GetRequiredService<IOptions<BlogOptions>>().Value);
|
||||||
|
|
||||||
|
return builder;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static WebApplicationBuilder AddServer(this WebApplicationBuilder builder)
|
||||||
|
{
|
||||||
|
builder.Services.AddHostedService<BlogHostedService>();
|
||||||
|
|
||||||
|
return builder;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static WebApplicationBuilder AddWatcher(this WebApplicationBuilder builder)
|
||||||
|
{
|
||||||
|
builder.Services.AddTransient<BlogChangeWatcher>();
|
||||||
|
builder.Services.AddHostedService<BlogHotReloadService>();
|
||||||
|
|
||||||
|
return builder;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -1,16 +1,19 @@
|
|||||||
using YaeBlog.Abstraction;
|
using Microsoft.AspNetCore.Builder;
|
||||||
using YaeBlog.Processors;
|
using Microsoft.Extensions.DependencyInjection;
|
||||||
using YaeBlog.Services;
|
using YaeBlog.Core.Abstractions;
|
||||||
|
using YaeBlog.Core.Processors;
|
||||||
|
using YaeBlog.Core.Services;
|
||||||
|
|
||||||
namespace YaeBlog.Extensions;
|
namespace YaeBlog.Core.Extensions;
|
||||||
|
|
||||||
public static class WebApplicationExtensions
|
public static class WebApplicationExtensions
|
||||||
{
|
{
|
||||||
public static void UseYaeBlog(this WebApplication application)
|
public static void UseYaeBlog(this WebApplication application)
|
||||||
{
|
{
|
||||||
application.UsePostRenderProcessor<ImagePostRenderProcessor>();
|
application.UsePostRenderProcessor<ImagePostRenderProcessor>();
|
||||||
|
application.UsePostRenderProcessor<CodeBlockPostRenderProcessor>();
|
||||||
|
application.UsePostRenderProcessor<TablePostRenderProcessor>();
|
||||||
application.UsePostRenderProcessor<HeadlinePostRenderProcessor>();
|
application.UsePostRenderProcessor<HeadlinePostRenderProcessor>();
|
||||||
application.UsePostRenderProcessor<EssayStylesPostRenderProcessor>();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private static void UsePreRenderProcessor<T>(this WebApplication application) where T : IPreRenderProcessor
|
private static void UsePreRenderProcessor<T>(this WebApplication application) where T : IPreRenderProcessor
|
||||||
10
YaeBlog.Core/Models/AboutInfo.cs
Normal file
10
YaeBlog.Core/Models/AboutInfo.cs
Normal file
@@ -0,0 +1,10 @@
|
|||||||
|
namespace YaeBlog.Core.Models;
|
||||||
|
|
||||||
|
public class AboutInfo
|
||||||
|
{
|
||||||
|
public required string Introduction { get; set; }
|
||||||
|
|
||||||
|
public required string Description { get; set; }
|
||||||
|
|
||||||
|
public required string AvatarImage { get; set; }
|
||||||
|
}
|
||||||
10
YaeBlog.Core/Models/BlogContent.cs
Normal file
10
YaeBlog.Core/Models/BlogContent.cs
Normal file
@@ -0,0 +1,10 @@
|
|||||||
|
namespace YaeBlog.Core.Models;
|
||||||
|
|
||||||
|
public class BlogContent
|
||||||
|
{
|
||||||
|
public required string FileName { get; init; }
|
||||||
|
|
||||||
|
public required MarkdownMetadata Metadata { get; init; }
|
||||||
|
|
||||||
|
public required string FileContent { get; set; }
|
||||||
|
}
|
||||||
10
YaeBlog.Core/Models/BlogContents.cs
Normal file
10
YaeBlog.Core/Models/BlogContents.cs
Normal file
@@ -0,0 +1,10 @@
|
|||||||
|
using System.Collections.Concurrent;
|
||||||
|
|
||||||
|
namespace YaeBlog.Core.Models;
|
||||||
|
|
||||||
|
public sealed class BlogContents(ConcurrentBag<BlogContent> drafts, ConcurrentBag<BlogContent> posts)
|
||||||
|
{
|
||||||
|
public ConcurrentBag<BlogContent> Drafts { get; } = drafts;
|
||||||
|
|
||||||
|
public ConcurrentBag<BlogContent> Posts { get; } = posts;
|
||||||
|
}
|
||||||
52
YaeBlog.Core/Models/BlogEssay.cs
Normal file
52
YaeBlog.Core/Models/BlogEssay.cs
Normal file
@@ -0,0 +1,52 @@
|
|||||||
|
namespace YaeBlog.Core.Models;
|
||||||
|
|
||||||
|
public class BlogEssay : IComparable<BlogEssay>
|
||||||
|
{
|
||||||
|
public required string Title { get; init; }
|
||||||
|
|
||||||
|
public required string FileName { get; init; }
|
||||||
|
|
||||||
|
public required DateTime PublishTime { get; init; }
|
||||||
|
|
||||||
|
public required string Description { get; init; }
|
||||||
|
|
||||||
|
public required uint WordCount { get; init; }
|
||||||
|
|
||||||
|
public required string ReadTime { get; init; }
|
||||||
|
|
||||||
|
public List<string> Tags { get; } = [];
|
||||||
|
|
||||||
|
public required string HtmlContent { get; init; }
|
||||||
|
|
||||||
|
public BlogEssay WithNewHtmlContent(string newHtmlContent)
|
||||||
|
{
|
||||||
|
var essay = new BlogEssay
|
||||||
|
{
|
||||||
|
Title = Title,
|
||||||
|
FileName = FileName,
|
||||||
|
PublishTime = PublishTime,
|
||||||
|
Description = Description,
|
||||||
|
WordCount = WordCount,
|
||||||
|
ReadTime = ReadTime,
|
||||||
|
HtmlContent = newHtmlContent
|
||||||
|
};
|
||||||
|
essay.Tags.AddRange(Tags);
|
||||||
|
|
||||||
|
return essay;
|
||||||
|
}
|
||||||
|
|
||||||
|
public int CompareTo(BlogEssay? other)
|
||||||
|
{
|
||||||
|
if (other is null)
|
||||||
|
{
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
return PublishTime.CompareTo(other.PublishTime);
|
||||||
|
}
|
||||||
|
|
||||||
|
public override string ToString()
|
||||||
|
{
|
||||||
|
return $"{Title}-{PublishTime}";
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -1,4 +1,4 @@
|
|||||||
namespace YaeBlog.Models;
|
namespace YaeBlog.Core.Models;
|
||||||
|
|
||||||
public class BlogHeadline(string title, string selectorId)
|
public class BlogHeadline(string title, string selectorId)
|
||||||
{
|
{
|
||||||
26
YaeBlog.Core/Models/BlogOptions.cs
Normal file
26
YaeBlog.Core/Models/BlogOptions.cs
Normal file
@@ -0,0 +1,26 @@
|
|||||||
|
namespace YaeBlog.Core.Models;
|
||||||
|
|
||||||
|
public class BlogOptions
|
||||||
|
{
|
||||||
|
public const string OptionName = "Blog";
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 博客markdown文件的根目录
|
||||||
|
/// </summary>
|
||||||
|
public required string Root { get; set; }
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 博客正文的广而告之
|
||||||
|
/// </summary>
|
||||||
|
public required string Announcement { get; set; }
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 博客的起始年份
|
||||||
|
/// </summary>
|
||||||
|
public required int StartYear { get; set; }
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 博客的友链
|
||||||
|
/// </summary>
|
||||||
|
public required List<FriendLink> Links { get; set; }
|
||||||
|
}
|
||||||
@@ -1,6 +1,6 @@
|
|||||||
using System.Text.Encodings.Web;
|
using System.Text.Encodings.Web;
|
||||||
|
|
||||||
namespace YaeBlog.Models;
|
namespace YaeBlog.Core.Models;
|
||||||
|
|
||||||
public class EssayTag(string tagName) : IEquatable<EssayTag>
|
public class EssayTag(string tagName) : IEquatable<EssayTag>
|
||||||
{
|
{
|
||||||
27
YaeBlog.Core/Models/FriendLink.cs
Normal file
27
YaeBlog.Core/Models/FriendLink.cs
Normal file
@@ -0,0 +1,27 @@
|
|||||||
|
namespace YaeBlog.Core.Models;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 友链模型类
|
||||||
|
/// </summary>
|
||||||
|
public class FriendLink
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// 友链名称
|
||||||
|
/// </summary>
|
||||||
|
public required string Name { get; set; }
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 友链的简单介绍
|
||||||
|
/// </summary>
|
||||||
|
public required string Description { get; set; }
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 友链地址
|
||||||
|
/// </summary>
|
||||||
|
public required string Link { get; set; }
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 头像地址
|
||||||
|
/// </summary>
|
||||||
|
public required string AvatarImage { get; set; }
|
||||||
|
}
|
||||||
3
YaeBlog.Core/Models/ImageScanResult.cs
Normal file
3
YaeBlog.Core/Models/ImageScanResult.cs
Normal file
@@ -0,0 +1,3 @@
|
|||||||
|
namespace YaeBlog.Core.Models;
|
||||||
|
|
||||||
|
public record struct ImageScanResult(List<FileInfo> UnusedImages, List<FileInfo> NotFoundImages);
|
||||||
@@ -1,12 +1,10 @@
|
|||||||
namespace YaeBlog.Models;
|
namespace YaeBlog.Core.Models;
|
||||||
|
|
||||||
public class MarkdownMetadata
|
public class MarkdownMetadata
|
||||||
{
|
{
|
||||||
public string? Title { get; set; }
|
public string? Title { get; set; }
|
||||||
|
|
||||||
public string? Date { get; set; }
|
public DateTime? Date { get; set; }
|
||||||
|
|
||||||
public string? UpdateTime { get; set; }
|
|
||||||
|
|
||||||
public List<string>? Tags { get; set; }
|
public List<string>? Tags { get; set; }
|
||||||
}
|
}
|
||||||
54
YaeBlog.Core/Processors/CodeBlockPostRenderProcessor.cs
Normal file
54
YaeBlog.Core/Processors/CodeBlockPostRenderProcessor.cs
Normal file
@@ -0,0 +1,54 @@
|
|||||||
|
using AngleSharp;
|
||||||
|
using AngleSharp.Dom;
|
||||||
|
using Microsoft.Extensions.Logging;
|
||||||
|
using YaeBlog.Core.Abstractions;
|
||||||
|
using YaeBlog.Core.Models;
|
||||||
|
|
||||||
|
namespace YaeBlog.Core.Processors;
|
||||||
|
|
||||||
|
public class CodeBlockPostRenderProcessor(ILogger<CodeBlockPostRenderProcessor> logger) : 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");
|
||||||
|
|
||||||
|
IEnumerable<IElement> codeElements = from e in element.Children
|
||||||
|
where e.LocalName == "code"
|
||||||
|
select e;
|
||||||
|
|
||||||
|
foreach (IElement code in codeElements)
|
||||||
|
{
|
||||||
|
string? language = (from c in code.ClassList
|
||||||
|
where c.StartsWith("language-")
|
||||||
|
select c[9..].ToLower()).FirstOrDefault();
|
||||||
|
|
||||||
|
if (language is null)
|
||||||
|
{
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
logger.LogDebug("Detect code block of language {}.", language);
|
||||||
|
code.InnerHtml = HighLightCode(code.InnerHtml, language);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return essay.WithNewHtmlContent(document.DocumentElement.OuterHtml);
|
||||||
|
}
|
||||||
|
|
||||||
|
public string Name => nameof(CodeBlockPostRenderProcessor);
|
||||||
|
|
||||||
|
private static string HighLightCode(string code, string language)
|
||||||
|
{
|
||||||
|
return code;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -1,12 +1,13 @@
|
|||||||
using AngleSharp;
|
using AngleSharp;
|
||||||
using AngleSharp.Dom;
|
using AngleSharp.Dom;
|
||||||
using YaeBlog.Abstraction;
|
using Microsoft.Extensions.Logging;
|
||||||
using YaeBlog.Models;
|
using YaeBlog.Core.Abstractions;
|
||||||
|
using YaeBlog.Core.Models;
|
||||||
|
|
||||||
namespace YaeBlog.Processors;
|
namespace YaeBlog.Core.Processors;
|
||||||
|
|
||||||
public class HeadlinePostRenderProcessor(
|
public class HeadlinePostRenderProcessor(
|
||||||
AngleSharp.IConfiguration angleConfiguration,
|
IConfiguration angleConfiguration,
|
||||||
IEssayContentService essayContentService,
|
IEssayContentService essayContentService,
|
||||||
ILogger<HeadlinePostRenderProcessor> logger) : IPostRenderProcessor
|
ILogger<HeadlinePostRenderProcessor> logger) : IPostRenderProcessor
|
||||||
{
|
{
|
||||||
@@ -67,7 +68,7 @@ public class HeadlinePostRenderProcessor(
|
|||||||
logger.LogWarning("Failed to add headline of {}.", essay.FileName);
|
logger.LogWarning("Failed to add headline of {}.", essay.FileName);
|
||||||
}
|
}
|
||||||
|
|
||||||
return essay with { HtmlContent = document.DocumentElement.OuterHtml };
|
return essay.WithNewHtmlContent(document.DocumentElement.OuterHtml);
|
||||||
}
|
}
|
||||||
|
|
||||||
private static BlogHeadline ParserHeadlineElement(IElement element)
|
private static BlogHeadline ParserHeadlineElement(IElement element)
|
||||||
@@ -1,28 +1,24 @@
|
|||||||
using AngleSharp;
|
using AngleSharp;
|
||||||
using AngleSharp.Dom;
|
using AngleSharp.Dom;
|
||||||
|
using Microsoft.Extensions.Logging;
|
||||||
using Microsoft.Extensions.Options;
|
using Microsoft.Extensions.Options;
|
||||||
using YaeBlog.Abstraction;
|
using YaeBlog.Core.Abstractions;
|
||||||
using YaeBlog.Core.Exceptions;
|
using YaeBlog.Core.Exceptions;
|
||||||
using YaeBlog.Models;
|
using YaeBlog.Core.Models;
|
||||||
|
|
||||||
namespace YaeBlog.Processors;
|
namespace YaeBlog.Core.Processors;
|
||||||
|
|
||||||
/// <summary>
|
public class ImagePostRenderProcessor(ILogger<ImagePostRenderProcessor> logger,
|
||||||
/// 图片地址路径后处理器
|
|
||||||
/// 将本地图片地址修改为图片API地址
|
|
||||||
/// </summary>
|
|
||||||
/// <param name="logger"></param>
|
|
||||||
/// <param name="options"></param>
|
|
||||||
public class ImagePostRenderProcessor(
|
|
||||||
ILogger<ImagePostRenderProcessor> logger,
|
|
||||||
IOptions<BlogOptions> options)
|
IOptions<BlogOptions> options)
|
||||||
: IPostRenderProcessor
|
: IPostRenderProcessor
|
||||||
{
|
{
|
||||||
|
private static readonly IConfiguration s_configuration = Configuration.Default;
|
||||||
|
|
||||||
private readonly BlogOptions _options = options.Value;
|
private readonly BlogOptions _options = options.Value;
|
||||||
|
|
||||||
public async Task<BlogEssay> ProcessAsync(BlogEssay essay)
|
public async Task<BlogEssay> ProcessAsync(BlogEssay essay)
|
||||||
{
|
{
|
||||||
BrowsingContext context = new(Configuration.Default);
|
BrowsingContext context = new(s_configuration);
|
||||||
IDocument html = await context.OpenAsync(
|
IDocument html = await context.OpenAsync(
|
||||||
req => req.Content(essay.HtmlContent));
|
req => req.Content(essay.HtmlContent));
|
||||||
|
|
||||||
@@ -36,27 +32,23 @@ public class ImagePostRenderProcessor(
|
|||||||
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, essay.IsDraft);
|
attr.Value = GenerateImageLink(attr.Value, essay.FileName);
|
||||||
}
|
}
|
||||||
|
element.ClassList.Add("essay-image");
|
||||||
}
|
}
|
||||||
|
return essay.WithNewHtmlContent(html.DocumentElement.OuterHtml);
|
||||||
return essay with { HtmlContent = html.DocumentElement.OuterHtml };
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public string Name => nameof(ImagePostRenderProcessor);
|
public string Name => nameof(ImagePostRenderProcessor);
|
||||||
|
|
||||||
private string GenerateImageLink(string filename, string essayFilename, bool isDraft)
|
private string GenerateImageLink(string filename, string essayFilename)
|
||||||
{
|
{
|
||||||
// 如果图片路径中没有包含文件名
|
|
||||||
// 则添加文件名
|
|
||||||
if (!filename.Contains(essayFilename))
|
if (!filename.Contains(essayFilename))
|
||||||
{
|
{
|
||||||
filename = Path.Combine(essayFilename, filename);
|
filename = Path.Combine(essayFilename, filename);
|
||||||
}
|
}
|
||||||
|
|
||||||
filename = isDraft
|
filename = Path.Combine(_options.Root, "posts", filename);
|
||||||
? Path.Combine(_options.Root, "drafts", filename)
|
|
||||||
: Path.Combine(_options.Root, "posts", filename);
|
|
||||||
|
|
||||||
if (!Path.Exists(filename))
|
if (!Path.Exists(filename))
|
||||||
{
|
{
|
||||||
@@ -65,7 +57,7 @@ public class ImagePostRenderProcessor(
|
|||||||
}
|
}
|
||||||
|
|
||||||
string imageLink = "api/files/" + filename;
|
string imageLink = "api/files/" + filename;
|
||||||
logger.LogDebug("Generate image link '{link}' for image file '{filename}'.",
|
logger.LogDebug("Generate image link '{}' for image file '{}'.",
|
||||||
imageLink, filename);
|
imageLink, filename);
|
||||||
|
|
||||||
return imageLink;
|
return imageLink;
|
||||||
9
YaeBlog.Core/Processors/Scanners/CSharpScanner.cs
Normal file
9
YaeBlog.Core/Processors/Scanners/CSharpScanner.cs
Normal file
@@ -0,0 +1,9 @@
|
|||||||
|
using static LanguageExt.Prelude;
|
||||||
|
|
||||||
|
|
||||||
|
namespace YaeBlog.Core.Processors.Scanners;
|
||||||
|
|
||||||
|
public class CSharpScanner
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
||||||
34
YaeBlog.Core/Processors/TablePostRenderProcessor.cs
Normal file
34
YaeBlog.Core/Processors/TablePostRenderProcessor.cs
Normal file
@@ -0,0 +1,34 @@
|
|||||||
|
using AngleSharp;
|
||||||
|
using AngleSharp.Dom;
|
||||||
|
using AngleSharp.Html.Dom;
|
||||||
|
using YaeBlog.Core.Abstractions;
|
||||||
|
using YaeBlog.Core.Models;
|
||||||
|
|
||||||
|
namespace YaeBlog.Core.Processors;
|
||||||
|
|
||||||
|
public class TablePostRenderProcessor: IPostRenderProcessor
|
||||||
|
{
|
||||||
|
public async Task<BlogEssay> ProcessAsync(BlogEssay essay)
|
||||||
|
{
|
||||||
|
BrowsingContext browsingContext = new(Configuration.Default);
|
||||||
|
IDocument document = await browsingContext.OpenAsync(
|
||||||
|
req => req.Content(essay.HtmlContent));
|
||||||
|
|
||||||
|
IEnumerable<IHtmlTableElement> tableElements = from item in document.All
|
||||||
|
where item.LocalName == "table"
|
||||||
|
select item as IHtmlTableElement;
|
||||||
|
|
||||||
|
foreach (IHtmlTableElement element in tableElements)
|
||||||
|
{
|
||||||
|
IHtmlDivElement divElement = document.CreateElement<IHtmlDivElement>();
|
||||||
|
divElement.InnerHtml = element.OuterHtml;
|
||||||
|
divElement.ClassList.Add("py-2", "table-wrapper");
|
||||||
|
|
||||||
|
element.Replace(divElement);
|
||||||
|
}
|
||||||
|
|
||||||
|
return essay.WithNewHtmlContent(document.DocumentElement.OuterHtml);
|
||||||
|
}
|
||||||
|
|
||||||
|
public string Name => nameof(TablePostRenderProcessor);
|
||||||
|
}
|
||||||
@@ -1,7 +1,8 @@
|
|||||||
using Microsoft.Extensions.Options;
|
using Microsoft.Extensions.Logging;
|
||||||
using YaeBlog.Models;
|
using Microsoft.Extensions.Options;
|
||||||
|
using YaeBlog.Core.Models;
|
||||||
|
|
||||||
namespace YaeBlog.Services;
|
namespace YaeBlog.Core.Services;
|
||||||
|
|
||||||
public sealed class BlogChangeWatcher : IDisposable
|
public sealed class BlogChangeWatcher : IDisposable
|
||||||
{
|
{
|
||||||
@@ -1,4 +1,7 @@
|
|||||||
namespace YaeBlog.Services;
|
using Microsoft.Extensions.Hosting;
|
||||||
|
using Microsoft.Extensions.Logging;
|
||||||
|
|
||||||
|
namespace YaeBlog.Core.Services;
|
||||||
|
|
||||||
public class BlogHostedService(
|
public class BlogHostedService(
|
||||||
ILogger<BlogHostedService> logger,
|
ILogger<BlogHostedService> logger,
|
||||||
@@ -6,12 +9,14 @@ public class BlogHostedService(
|
|||||||
{
|
{
|
||||||
public async Task StartAsync(CancellationToken cancellationToken)
|
public async Task StartAsync(CancellationToken cancellationToken)
|
||||||
{
|
{
|
||||||
logger.LogInformation("Failed to load cache, render essays.");
|
logger.LogInformation("Welcome to YaeBlog!");
|
||||||
|
|
||||||
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;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
35
YaeBlog.Core/Services/BlogHotReloadService.cs
Normal file
35
YaeBlog.Core/Services/BlogHotReloadService.cs
Normal file
@@ -0,0 +1,35 @@
|
|||||||
|
using Microsoft.Extensions.Hosting;
|
||||||
|
using Microsoft.Extensions.Logging;
|
||||||
|
using YaeBlog.Core.Abstractions;
|
||||||
|
|
||||||
|
namespace YaeBlog.Core.Services;
|
||||||
|
|
||||||
|
public sealed class BlogHotReloadService(
|
||||||
|
RendererService rendererService,
|
||||||
|
IEssayContentService essayContentService,
|
||||||
|
BlogChangeWatcher watcher,
|
||||||
|
ILogger<BlogHotReloadService> logger) : BackgroundService
|
||||||
|
{
|
||||||
|
protected override async Task ExecuteAsync(CancellationToken stoppingToken)
|
||||||
|
{
|
||||||
|
logger.LogInformation("BlogHotReloadService is starting.");
|
||||||
|
|
||||||
|
await rendererService.RenderAsync();
|
||||||
|
|
||||||
|
while (!stoppingToken.IsCancellationRequested)
|
||||||
|
{
|
||||||
|
logger.LogDebug("Watching file changes...");
|
||||||
|
string? changFile = await watcher.WaitForChange(stoppingToken);
|
||||||
|
|
||||||
|
if (changFile is null)
|
||||||
|
{
|
||||||
|
logger.LogInformation("BlogHotReloadService is stopping.");
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
logger.LogInformation("{} changed, re-rendering.", changFile);
|
||||||
|
essayContentService.Clear();
|
||||||
|
await rendererService.RenderAsync();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -1,36 +1,23 @@
|
|||||||
using System.Collections.Concurrent;
|
using System.Collections.Concurrent;
|
||||||
using System.Diagnostics.CodeAnalysis;
|
using System.Diagnostics.CodeAnalysis;
|
||||||
using YaeBlog.Abstraction;
|
using YaeBlog.Core.Abstractions;
|
||||||
using YaeBlog.Models;
|
using YaeBlog.Core.Models;
|
||||||
|
|
||||||
namespace YaeBlog.Services;
|
namespace YaeBlog.Core.Services;
|
||||||
|
|
||||||
public class EssayContentService : IEssayContentService
|
public class EssayContentService : IEssayContentService
|
||||||
{
|
{
|
||||||
private readonly ConcurrentDictionary<string, BlogEssay> _essays = new();
|
private readonly ConcurrentDictionary<string, BlogEssay> _essays = new();
|
||||||
|
|
||||||
private readonly List<BlogEssay> _sortedEssays = [];
|
|
||||||
|
|
||||||
private readonly Dictionary<EssayTag, List<BlogEssay>> _tags = [];
|
private readonly Dictionary<EssayTag, List<BlogEssay>> _tags = [];
|
||||||
|
|
||||||
private readonly ConcurrentDictionary<string, BlogHeadline> _headlines = new();
|
private readonly ConcurrentDictionary<string, BlogHeadline> _headlines = new();
|
||||||
|
|
||||||
public bool TryAdd(BlogEssay essay)
|
public bool TryAdd(BlogEssay essay) => _essays.TryAdd(essay.FileName, 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 IEnumerable<BlogEssay> Essays => _sortedEssays;
|
public IReadOnlyDictionary<string, BlogEssay> Essays => _essays;
|
||||||
|
|
||||||
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;
|
||||||
|
|
||||||
210
YaeBlog.Core/Services/EssayScanService.cs
Normal file
210
YaeBlog.Core/Services/EssayScanService.cs
Normal file
@@ -0,0 +1,210 @@
|
|||||||
|
using System.Collections.Concurrent;
|
||||||
|
using System.Text.RegularExpressions;
|
||||||
|
using Microsoft.Extensions.Logging;
|
||||||
|
using Microsoft.Extensions.Options;
|
||||||
|
using YaeBlog.Core.Abstractions;
|
||||||
|
using YaeBlog.Core.Exceptions;
|
||||||
|
using YaeBlog.Core.Models;
|
||||||
|
using YamlDotNet.Core;
|
||||||
|
using YamlDotNet.Serialization;
|
||||||
|
|
||||||
|
namespace YaeBlog.Core.Services;
|
||||||
|
|
||||||
|
public partial class EssayScanService(
|
||||||
|
ISerializer yamlSerializer,
|
||||||
|
IDeserializer yamlDeserializer,
|
||||||
|
IOptions<BlogOptions> blogOptions,
|
||||||
|
ILogger<EssayScanService> logger) : IEssayScanService
|
||||||
|
{
|
||||||
|
private readonly BlogOptions _blogOptions = blogOptions.Value;
|
||||||
|
|
||||||
|
public async Task<BlogContents> ScanContents()
|
||||||
|
{
|
||||||
|
ValidateDirectory(_blogOptions.Root, out DirectoryInfo drafts, out DirectoryInfo posts);
|
||||||
|
|
||||||
|
return new BlogContents(
|
||||||
|
await ScanContentsInternal(drafts),
|
||||||
|
await ScanContentsInternal(posts));
|
||||||
|
}
|
||||||
|
|
||||||
|
public async Task SaveBlogContent(BlogContent content, bool isDraft = true)
|
||||||
|
{
|
||||||
|
ValidateDirectory(_blogOptions.Root, out DirectoryInfo drafts, out DirectoryInfo posts);
|
||||||
|
|
||||||
|
FileInfo targetFile = isDraft
|
||||||
|
? new FileInfo(Path.Combine(drafts.FullName, content.FileName + ".md"))
|
||||||
|
: new FileInfo(Path.Combine(posts.FullName, content.FileName + ".md"));
|
||||||
|
|
||||||
|
if (!isDraft)
|
||||||
|
{
|
||||||
|
content.Metadata.Date = DateTime.Now;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (targetFile.Exists)
|
||||||
|
{
|
||||||
|
logger.LogWarning("Blog {} exists, overriding.", targetFile.Name);
|
||||||
|
}
|
||||||
|
|
||||||
|
await using StreamWriter writer = targetFile.CreateText();
|
||||||
|
|
||||||
|
await writer.WriteAsync("---\n");
|
||||||
|
await writer.WriteAsync(yamlSerializer.Serialize(content.Metadata));
|
||||||
|
await writer.WriteAsync("---\n");
|
||||||
|
|
||||||
|
if (isDraft)
|
||||||
|
{
|
||||||
|
await writer.WriteLineAsync("<!--more-->");
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
await writer.WriteAsync(content.FileContent);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private async Task<ConcurrentBag<BlogContent>> ScanContentsInternal(DirectoryInfo directory)
|
||||||
|
{
|
||||||
|
// 扫描以md结果的但是不是隐藏文件的文件
|
||||||
|
IEnumerable<FileInfo> markdownFiles = from file in directory.EnumerateFiles()
|
||||||
|
where file.Extension == ".md" && !file.Name.StartsWith('.')
|
||||||
|
select file;
|
||||||
|
|
||||||
|
ConcurrentBag<(string, string)> fileContents = [];
|
||||||
|
|
||||||
|
await Parallel.ForEachAsync(markdownFiles, async (file, token) =>
|
||||||
|
{
|
||||||
|
using StreamReader reader = file.OpenText();
|
||||||
|
fileContents.Add((file.Name, await reader.ReadToEndAsync(token)));
|
||||||
|
});
|
||||||
|
|
||||||
|
ConcurrentBag<BlogContent> contents = [];
|
||||||
|
|
||||||
|
await Task.Run(() =>
|
||||||
|
{
|
||||||
|
foreach ((string filename, string content) in fileContents)
|
||||||
|
{
|
||||||
|
int endPos = content.IndexOf("---", 4, StringComparison.Ordinal);
|
||||||
|
if (!content.StartsWith("---") || endPos is -1 or 0)
|
||||||
|
{
|
||||||
|
logger.LogWarning("Failed to parse metadata from {}, skipped.", filename);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
string metadataString = content[4..endPos];
|
||||||
|
|
||||||
|
try
|
||||||
|
{
|
||||||
|
MarkdownMetadata metadata = yamlDeserializer.Deserialize<MarkdownMetadata>(metadataString);
|
||||||
|
logger.LogDebug("Scan metadata title: '{}' for {}.", metadata.Title, filename);
|
||||||
|
|
||||||
|
contents.Add(new BlogContent
|
||||||
|
{
|
||||||
|
FileName = filename[..^3], Metadata = metadata, FileContent = content[(endPos + 3)..]
|
||||||
|
});
|
||||||
|
}
|
||||||
|
catch (YamlException e)
|
||||||
|
{
|
||||||
|
logger.LogWarning("Failed to parser metadata from {} due to {}, skipping", filename, e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
return contents;
|
||||||
|
}
|
||||||
|
|
||||||
|
public async Task<ImageScanResult> ScanImages()
|
||||||
|
{
|
||||||
|
BlogContents contents = await ScanContents();
|
||||||
|
ValidateDirectory(_blogOptions.Root, out DirectoryInfo drafts, out DirectoryInfo posts);
|
||||||
|
|
||||||
|
List<FileInfo> unusedFiles = [];
|
||||||
|
List<FileInfo> notFoundFiles = [];
|
||||||
|
|
||||||
|
ImageScanResult draftResult = await ScanUnusedImagesInternal(contents.Drafts, drafts);
|
||||||
|
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)
|
||||||
|
{
|
||||||
|
Regex imageRegex = ImageRegex();
|
||||||
|
ConcurrentBag<FileInfo> unusedImage = [];
|
||||||
|
ConcurrentBag<FileInfo> notFoundImage = [];
|
||||||
|
|
||||||
|
Parallel.ForEach(contents, content =>
|
||||||
|
{
|
||||||
|
MatchCollection result = imageRegex.Matches(content.FileContent);
|
||||||
|
DirectoryInfo imageDirectory = new(Path.Combine(root.FullName, content.FileName));
|
||||||
|
|
||||||
|
Dictionary<string, bool> usedDictionary;
|
||||||
|
|
||||||
|
if (imageDirectory.Exists)
|
||||||
|
{
|
||||||
|
usedDictionary = (from file in imageDirectory.EnumerateFiles()
|
||||||
|
select new KeyValuePair<string, bool>(file.FullName, false)).ToDictionary();
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
usedDictionary = [];
|
||||||
|
}
|
||||||
|
|
||||||
|
foreach (Match match in result)
|
||||||
|
{
|
||||||
|
string imageName = match.Groups[1].Value;
|
||||||
|
|
||||||
|
FileInfo usedFile = imageName.Contains(content.FileName)
|
||||||
|
? new FileInfo(Path.Combine(root.FullName, imageName))
|
||||||
|
: new FileInfo(Path.Combine(root.FullName, content.FileName, imageName));
|
||||||
|
|
||||||
|
if (usedDictionary.TryGetValue(usedFile.FullName, out _))
|
||||||
|
{
|
||||||
|
usedDictionary[usedFile.FullName] = true;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
notFoundImage.Add(usedFile);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
foreach (KeyValuePair<string, bool> pair in usedDictionary.Where(p => !p.Value))
|
||||||
|
{
|
||||||
|
unusedImage.Add(new FileInfo(pair.Key));
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
return Task.FromResult(new ImageScanResult(unusedImage.ToList(), notFoundImage.ToList()));
|
||||||
|
}
|
||||||
|
|
||||||
|
[GeneratedRegex(@"\!\[.*?\]\((.*?)\)")]
|
||||||
|
private static partial Regex ImageRegex();
|
||||||
|
|
||||||
|
private void ValidateDirectory(string root, out DirectoryInfo drafts, out DirectoryInfo posts)
|
||||||
|
{
|
||||||
|
root = Path.Combine(Environment.CurrentDirectory, root);
|
||||||
|
DirectoryInfo rootDirectory = new(root);
|
||||||
|
|
||||||
|
if (!rootDirectory.Exists)
|
||||||
|
{
|
||||||
|
throw new BlogFileException($"'{root}' is not a directory.");
|
||||||
|
}
|
||||||
|
|
||||||
|
if (rootDirectory.EnumerateDirectories().All(dir => dir.Name != "drafts"))
|
||||||
|
{
|
||||||
|
throw new BlogFileException($"'{root}/drafts' not exists.");
|
||||||
|
}
|
||||||
|
|
||||||
|
if (rootDirectory.EnumerateDirectories().All(dir => dir.Name != "posts"))
|
||||||
|
{
|
||||||
|
throw new BlogFileException($"'{root}/posts' not exists.");
|
||||||
|
}
|
||||||
|
|
||||||
|
drafts = new DirectoryInfo(Path.Combine(root, "drafts"));
|
||||||
|
posts = new DirectoryInfo(Path.Combine(root, "posts"));
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -3,13 +3,14 @@ using System.Diagnostics;
|
|||||||
using System.Text;
|
using System.Text;
|
||||||
using System.Text.RegularExpressions;
|
using System.Text.RegularExpressions;
|
||||||
using Markdig;
|
using Markdig;
|
||||||
using YaeBlog.Abstraction;
|
using Microsoft.Extensions.Logging;
|
||||||
|
using YaeBlog.Core.Abstractions;
|
||||||
using YaeBlog.Core.Exceptions;
|
using YaeBlog.Core.Exceptions;
|
||||||
using YaeBlog.Models;
|
using YaeBlog.Core.Models;
|
||||||
|
|
||||||
namespace YaeBlog.Services;
|
namespace YaeBlog.Core.Services;
|
||||||
|
|
||||||
public sealed partial class RendererService(
|
public partial class RendererService(
|
||||||
ILogger<RendererService> logger,
|
ILogger<RendererService> logger,
|
||||||
IEssayScanService essayScanService,
|
IEssayScanService essayScanService,
|
||||||
MarkdownPipeline markdownPipeline,
|
MarkdownPipeline markdownPipeline,
|
||||||
@@ -21,54 +22,52 @@ public sealed partial class RendererService(
|
|||||||
|
|
||||||
private readonly List<IPostRenderProcessor> _postRenderProcessors = [];
|
private readonly List<IPostRenderProcessor> _postRenderProcessors = [];
|
||||||
|
|
||||||
public async Task RenderAsync(bool includeDrafts = false)
|
public async Task RenderAsync()
|
||||||
{
|
{
|
||||||
_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);
|
||||||
ConcurrentBag<BlogEssay> essays = [];
|
|
||||||
|
|
||||||
Parallel.ForEach(preProcessedContents, content =>
|
List<BlogEssay> essays = [];
|
||||||
|
await Task.Run(() =>
|
||||||
{
|
{
|
||||||
(uint wordCount, string readTime) = GetWordCount(content);
|
foreach (BlogContent content in preProcessedContents)
|
||||||
DateTimeOffset publishDate = content.Metadata.Date is null
|
{
|
||||||
? DateTimeOffset.Now
|
uint wordCount = GetWordCount(content);
|
||||||
: DateTimeOffset.Parse(content.Metadata.Date);
|
BlogEssay essay = new()
|
||||||
// 如果不存在最后的更新时间,就把更新时间设置为发布时间
|
{
|
||||||
DateTimeOffset updateTime = content.Metadata.UpdateTime is null
|
Title = content.Metadata.Title ?? content.FileName,
|
||||||
? publishDate
|
FileName = content.FileName,
|
||||||
: DateTimeOffset.Parse(content.Metadata.UpdateTime);
|
Description = GetDescription(content),
|
||||||
string description = GetDescription(content);
|
WordCount = wordCount,
|
||||||
List<string> tags = content.Metadata.Tags ?? [];
|
ReadTime = CalculateReadTime(wordCount),
|
||||||
|
PublishTime = content.Metadata.Date ?? DateTime.Now,
|
||||||
|
HtmlContent = content.FileContent
|
||||||
|
};
|
||||||
|
|
||||||
string originalHtml = Markdown.ToHtml(content.Content, markdownPipeline);
|
if (content.Metadata.Tags is not null)
|
||||||
|
{
|
||||||
|
essay.Tags.AddRange(content.Metadata.Tags);
|
||||||
|
}
|
||||||
|
|
||||||
BlogEssay essay = new(
|
essays.Add(essay);
|
||||||
content.Metadata.Title ?? content.BlogName, content.BlogName, content.IsDraft, publishDate, updateTime,
|
}
|
||||||
description, wordCount, readTime, tags, originalHtml);
|
|
||||||
logger.LogDebug("Render essay: {}", essay);
|
|
||||||
|
|
||||||
essays.Add(essay);
|
|
||||||
});
|
});
|
||||||
|
|
||||||
IEnumerable<BlogEssay> postProcessedEssays = await PostProcess(essays);
|
ConcurrentBag<BlogEssay> postProcessEssays = [];
|
||||||
|
Parallel.ForEach(essays, essay =>
|
||||||
foreach (BlogEssay essay in postProcessedEssays)
|
|
||||||
{
|
{
|
||||||
if (!essayContentService.TryAdd(essay))
|
BlogEssay newEssay =
|
||||||
{
|
essay.WithNewHtmlContent(Markdown.ToHtml(essay.HtmlContent, markdownPipeline));
|
||||||
throw new BlogFileException($"There are at least two essays with filename '{essay.FileName}'.");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
postProcessEssays.Add(newEssay);
|
||||||
|
logger.LogDebug("Render markdown file {}.", newEssay);
|
||||||
|
});
|
||||||
|
|
||||||
|
await PostProcess(postProcessEssays);
|
||||||
essayContentService.RefreshTags();
|
essayContentService.RefreshTags();
|
||||||
|
|
||||||
_stopwatch.Stop();
|
_stopwatch.Stop();
|
||||||
@@ -119,10 +118,8 @@ public sealed partial class RendererService(
|
|||||||
return processedContents;
|
return processedContents;
|
||||||
}
|
}
|
||||||
|
|
||||||
private async Task<IEnumerable<BlogEssay>> PostProcess(IEnumerable<BlogEssay> essays)
|
private async Task 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)
|
||||||
@@ -130,34 +127,32 @@ public sealed partial class RendererService(
|
|||||||
essay = await processor.ProcessAsync(essay);
|
essay = await processor.ProcessAsync(essay);
|
||||||
}
|
}
|
||||||
|
|
||||||
processedContents.Add(essay);
|
if (!essayContentService.TryAdd(essay))
|
||||||
|
{
|
||||||
|
throw new BlogFileException(
|
||||||
|
$"There are two essays with the same name: '{essay.FileName}'.");
|
||||||
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
List<BlogEssay> result = processedContents.ToList();
|
|
||||||
result.Sort();
|
|
||||||
|
|
||||||
return result;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
[GeneratedRegex(@"(?<!\\)[^\#\*_\-\+\`{}\[\]!~]+")]
|
[GeneratedRegex(@"(?<!\\)[^\#\*_\-\+\`{}\[\]!~]+")]
|
||||||
// private static partial Regex DescriptionPattern();
|
private static partial Regex DescriptionPattern();
|
||||||
private static partial Regex DescriptionPattern { get; }
|
|
||||||
|
|
||||||
private string GetDescription(BlogContent content)
|
private string GetDescription(BlogContent content)
|
||||||
{
|
{
|
||||||
const string delimiter = "<!--more-->";
|
const string delimiter = "<!--more-->";
|
||||||
int pos = content.Content.IndexOf(delimiter, StringComparison.Ordinal);
|
int pos = content.FileContent.IndexOf(delimiter, StringComparison.Ordinal);
|
||||||
bool breakSentence = false;
|
bool breakSentence = false;
|
||||||
|
|
||||||
if (pos == -1)
|
if (pos == -1)
|
||||||
{
|
{
|
||||||
// 自动截取前50个字符
|
// 自动截取前50个字符
|
||||||
pos = content.Content.Length < 50 ? content.Content.Length : 50;
|
pos = content.FileContent.Length < 50 ? content.FileContent.Length : 50;
|
||||||
breakSentence = true;
|
breakSentence = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
string rawContent = content.Content[..pos];
|
string rawContent = content.FileContent[..pos];
|
||||||
MatchCollection matches = DescriptionPattern.Matches(rawContent);
|
MatchCollection matches = DescriptionPattern().Matches(rawContent);
|
||||||
|
|
||||||
StringBuilder builder = new();
|
StringBuilder builder = new();
|
||||||
foreach (Match match in matches)
|
foreach (Match match in matches)
|
||||||
@@ -172,21 +167,28 @@ public sealed partial class RendererService(
|
|||||||
|
|
||||||
string description = builder.ToString();
|
string description = builder.ToString();
|
||||||
|
|
||||||
logger.LogDebug("Description of {name} is {desc}.", content.BlogName,
|
logger.LogDebug("Description of {} is {}.", content.FileName,
|
||||||
description);
|
description);
|
||||||
return description;
|
return description;
|
||||||
}
|
}
|
||||||
|
|
||||||
private (uint, string) GetWordCount(BlogContent content)
|
private uint GetWordCount(BlogContent content)
|
||||||
{
|
{
|
||||||
uint count = MarkdownWordCounter.CountWord(content);
|
int count = (from c in content.FileContent
|
||||||
|
where char.IsLetterOrDigit(c)
|
||||||
|
select c).Count();
|
||||||
|
|
||||||
logger.LogDebug("Word count of {blog} is {count}", content.BlogName,
|
logger.LogDebug("Word count of {} is {}", content.FileName,
|
||||||
count);
|
count);
|
||||||
// 据说语文教学大纲规定,中国高中生阅读现代文的速度是600字每分钟
|
return (uint)count;
|
||||||
uint second = count / 10;
|
}
|
||||||
TimeSpan span = new(0, 0, (int)second);
|
|
||||||
|
|
||||||
return (count, span.ToString("mm'分'ss'秒'"));
|
private static string CalculateReadTime(uint wordCount)
|
||||||
|
{
|
||||||
|
// 据说语文教学大纲规定,中国高中生阅读现代文的速度是600字每分钟
|
||||||
|
int second = (int)wordCount / 10;
|
||||||
|
TimeSpan span = new(0, 0, second);
|
||||||
|
|
||||||
|
return span.ToString("mm'分 'ss'秒'");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
27
YaeBlog.Core/YaeBlog.Core.csproj
Normal file
27
YaeBlog.Core/YaeBlog.Core.csproj
Normal file
@@ -0,0 +1,27 @@
|
|||||||
|
<Project Sdk="Microsoft.NET.Sdk.Razor">
|
||||||
|
|
||||||
|
<PropertyGroup>
|
||||||
|
<TargetFramework>net8.0</TargetFramework>
|
||||||
|
<Nullable>enable</Nullable>
|
||||||
|
<ImplicitUsings>enable</ImplicitUsings>
|
||||||
|
</PropertyGroup>
|
||||||
|
|
||||||
|
<ItemGroup>
|
||||||
|
<FrameworkReference Include="Microsoft.AspNetCore.App" />
|
||||||
|
</ItemGroup>
|
||||||
|
|
||||||
|
<ItemGroup>
|
||||||
|
<PackageReference Include="AngleSharp" Version="1.1.0" />
|
||||||
|
<PackageReference Include="LanguageExt.Core" Version="4.4.9" />
|
||||||
|
<PackageReference Include="LanguageExt.Parsec" Version="4.4.9" />
|
||||||
|
<PackageReference Include="Markdig" Version="0.34.0" />
|
||||||
|
<PackageReference Include="Microsoft.AspNetCore.Components.Web" Version="8.0.6" />
|
||||||
|
<PackageReference Include="Microsoft.Extensions.Hosting" Version="8.0.0" />
|
||||||
|
<PackageReference Include="YamlDotNet" Version="13.7.1" />
|
||||||
|
</ItemGroup>
|
||||||
|
|
||||||
|
<ItemGroup>
|
||||||
|
<Folder Include="wwwroot\" />
|
||||||
|
</ItemGroup>
|
||||||
|
|
||||||
|
</Project>
|
||||||
47
YaeBlog.sln
Normal file
47
YaeBlog.sln
Normal file
@@ -0,0 +1,47 @@
|
|||||||
|
|
||||||
|
Microsoft Visual Studio Solution File, Format Version 12.00
|
||||||
|
# Visual Studio Version 17
|
||||||
|
VisualStudioVersion = 17.0.31903.59
|
||||||
|
MinimumVisualStudioVersion = 10.0.40219.1
|
||||||
|
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "YaeBlog.Core", "YaeBlog.Core\YaeBlog.Core.csproj", "{1671A8AE-78F6-4641-B97D-D8ABA5E9CBEF}"
|
||||||
|
EndProject
|
||||||
|
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "YaeBlog", "YaeBlog\YaeBlog.csproj", "{20438EFD-8DDE-43AF-92E2-76495C29233C}"
|
||||||
|
EndProject
|
||||||
|
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = ".gitea", ".gitea", "{9B5AAA29-37D8-454A-8D8F-3E6B6BCF38E6}"
|
||||||
|
EndProject
|
||||||
|
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "workflows", "workflows", "{ADBC3DA8-F65C-4B5D-A97A-DC351F8E6592}"
|
||||||
|
ProjectSection(SolutionItems) = preProject
|
||||||
|
.gitea\workflows\build.yaml = .gitea\workflows\build.yaml
|
||||||
|
EndProjectSection
|
||||||
|
EndProject
|
||||||
|
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution Items", "{753B998C-1B9E-498F-B949-845CE86C4075}"
|
||||||
|
ProjectSection(SolutionItems) = preProject
|
||||||
|
.editorconfig = .editorconfig
|
||||||
|
.gitattributes = .gitattributes
|
||||||
|
.gitignore = .gitignore
|
||||||
|
README.md = README.md
|
||||||
|
LICENSE = LICENSE
|
||||||
|
EndProjectSection
|
||||||
|
EndProject
|
||||||
|
Global
|
||||||
|
GlobalSection(SolutionConfigurationPlatforms) = preSolution
|
||||||
|
Debug|Any CPU = Debug|Any CPU
|
||||||
|
Release|Any CPU = Release|Any CPU
|
||||||
|
EndGlobalSection
|
||||||
|
GlobalSection(ProjectConfigurationPlatforms) = postSolution
|
||||||
|
{1671A8AE-78F6-4641-B97D-D8ABA5E9CBEF}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
||||||
|
{1671A8AE-78F6-4641-B97D-D8ABA5E9CBEF}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||||
|
{1671A8AE-78F6-4641-B97D-D8ABA5E9CBEF}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||||
|
{1671A8AE-78F6-4641-B97D-D8ABA5E9CBEF}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||||
|
{20438EFD-8DDE-43AF-92E2-76495C29233C}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
||||||
|
{20438EFD-8DDE-43AF-92E2-76495C29233C}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||||
|
{20438EFD-8DDE-43AF-92E2-76495C29233C}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||||
|
{20438EFD-8DDE-43AF-92E2-76495C29233C}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||||
|
EndGlobalSection
|
||||||
|
GlobalSection(SolutionProperties) = preSolution
|
||||||
|
HideSolutionNode = FALSE
|
||||||
|
EndGlobalSection
|
||||||
|
GlobalSection(NestedProjects) = preSolution
|
||||||
|
{ADBC3DA8-F65C-4B5D-A97A-DC351F8E6592} = {9B5AAA29-37D8-454A-8D8F-3E6B6BCF38E6}
|
||||||
|
EndGlobalSection
|
||||||
|
EndGlobal
|
||||||
23
YaeBlog.slnx
23
YaeBlog.slnx
@@ -1,23 +0,0 @@
|
|||||||
<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="build.ps1" />
|
|
||||||
<File Path="LICENSE" />
|
|
||||||
<File Path="README.md" />
|
|
||||||
</Folder>
|
|
||||||
<Folder Name="/src/">
|
|
||||||
<Project Path="src/YaeBlog.Tests/YaeBlog.Tests.csproj" />
|
|
||||||
<Project Path="src/YaeBlog/YaeBlog.csproj" />
|
|
||||||
</Folder>
|
|
||||||
<Folder Name="/third-party/" />
|
|
||||||
<Folder Name="/third-party/BlazorSvgComponents/" />
|
|
||||||
<Folder Name="/third-party/BlazorSvgComponents/src/">
|
|
||||||
<Project Path="third-party/BlazorSvgComponents/src/BlazorSvgComponents/BlazorSvgComponents.csproj" />
|
|
||||||
</Folder>
|
|
||||||
</Solution>
|
|
||||||
36
YaeBlog/Commands/Binders/BlogOptionsBinder.cs
Normal file
36
YaeBlog/Commands/Binders/BlogOptionsBinder.cs
Normal file
@@ -0,0 +1,36 @@
|
|||||||
|
using System.CommandLine.Binding;
|
||||||
|
using System.Text.Json;
|
||||||
|
using Microsoft.Extensions.Options;
|
||||||
|
using YaeBlog.Core.Models;
|
||||||
|
|
||||||
|
namespace YaeBlog.Commands.Binders;
|
||||||
|
|
||||||
|
public sealed class BlogOptionsBinder : BinderBase<IOptions<BlogOptions>>
|
||||||
|
{
|
||||||
|
protected override IOptions<BlogOptions> GetBoundValue(BindingContext bindingContext)
|
||||||
|
{
|
||||||
|
bindingContext.AddService<IOptions<BlogOptions>>(_ =>
|
||||||
|
{
|
||||||
|
FileInfo settings = new(Path.Combine(Environment.CurrentDirectory, "appsettings.json"));
|
||||||
|
if (!settings.Exists)
|
||||||
|
{
|
||||||
|
throw new InvalidOperationException("Failed to load YaeBlog configurations.");
|
||||||
|
}
|
||||||
|
|
||||||
|
using StreamReader reader = settings.OpenText();
|
||||||
|
using JsonDocument document = JsonDocument.Parse(reader.ReadToEnd());
|
||||||
|
JsonElement root = document.RootElement;
|
||||||
|
JsonElement optionSection = root.GetProperty(BlogOptions.OptionName);
|
||||||
|
|
||||||
|
BlogOptions? result = optionSection.Deserialize<BlogOptions>();
|
||||||
|
if (result is null)
|
||||||
|
{
|
||||||
|
throw new InvalidOperationException("Failed to load YaeBlog configuration in appsettings.json.");
|
||||||
|
}
|
||||||
|
|
||||||
|
return new OptionsWrapper<BlogOptions>(result);
|
||||||
|
});
|
||||||
|
|
||||||
|
return bindingContext.GetRequiredService<IOptions<BlogOptions>>();
|
||||||
|
}
|
||||||
|
}
|
||||||
32
YaeBlog/Commands/Binders/EssayScanServiceBinder.cs
Normal file
32
YaeBlog/Commands/Binders/EssayScanServiceBinder.cs
Normal file
@@ -0,0 +1,32 @@
|
|||||||
|
using System.CommandLine.Binding;
|
||||||
|
using Microsoft.Extensions.Options;
|
||||||
|
using YaeBlog.Core.Abstractions;
|
||||||
|
using YaeBlog.Core.Models;
|
||||||
|
using YaeBlog.Core.Services;
|
||||||
|
using YamlDotNet.Serialization;
|
||||||
|
using YamlDotNet.Serialization.NamingConventions;
|
||||||
|
|
||||||
|
namespace YaeBlog.Commands.Binders;
|
||||||
|
|
||||||
|
public sealed class EssayScanServiceBinder : BinderBase<IEssayScanService>
|
||||||
|
{
|
||||||
|
protected override IEssayScanService GetBoundValue(BindingContext bindingContext)
|
||||||
|
{
|
||||||
|
bindingContext.AddService<IEssayScanService>(provider =>
|
||||||
|
{
|
||||||
|
DeserializerBuilder deserializerBuilder = new();
|
||||||
|
deserializerBuilder.WithNamingConvention(CamelCaseNamingConvention.Instance);
|
||||||
|
deserializerBuilder.IgnoreUnmatchedProperties();
|
||||||
|
|
||||||
|
SerializerBuilder serializerBuilder = new();
|
||||||
|
serializerBuilder.WithNamingConvention(CamelCaseNamingConvention.Instance);
|
||||||
|
|
||||||
|
IOptions<BlogOptions> options = provider.GetRequiredService<IOptions<BlogOptions>>();
|
||||||
|
ILogger<EssayScanService> logger = provider.GetRequiredService<ILogger<EssayScanService>>();
|
||||||
|
|
||||||
|
return new EssayScanService(serializerBuilder.Build(), deserializerBuilder.Build(), options, logger);
|
||||||
|
});
|
||||||
|
|
||||||
|
return bindingContext.GetRequiredService<IEssayScanService>();
|
||||||
|
}
|
||||||
|
}
|
||||||
18
YaeBlog/Commands/Binders/LoggerBinder.cs
Normal file
18
YaeBlog/Commands/Binders/LoggerBinder.cs
Normal file
@@ -0,0 +1,18 @@
|
|||||||
|
using System.CommandLine.Binding;
|
||||||
|
|
||||||
|
namespace YaeBlog.Commands.Binders;
|
||||||
|
|
||||||
|
public sealed class LoggerBinder<T> : BinderBase<ILogger<T>>
|
||||||
|
{
|
||||||
|
protected override ILogger<T> GetBoundValue(BindingContext bindingContext)
|
||||||
|
{
|
||||||
|
bindingContext.AddService(_ => LoggerFactory.Create(builder => builder.AddConsole()));
|
||||||
|
bindingContext.AddService<ILogger<T>>(provider =>
|
||||||
|
{
|
||||||
|
ILoggerFactory factory = provider.GetRequiredService<ILoggerFactory>();
|
||||||
|
return factory.CreateLogger<T>();
|
||||||
|
});
|
||||||
|
|
||||||
|
return bindingContext.GetRequiredService<ILogger<T>>();
|
||||||
|
}
|
||||||
|
}
|
||||||
216
YaeBlog/Commands/CommandExtensions.cs
Normal file
216
YaeBlog/Commands/CommandExtensions.cs
Normal file
@@ -0,0 +1,216 @@
|
|||||||
|
using System.CommandLine;
|
||||||
|
using YaeBlog.Commands.Binders;
|
||||||
|
using YaeBlog.Components;
|
||||||
|
using YaeBlog.Core.Extensions;
|
||||||
|
using YaeBlog.Core.Models;
|
||||||
|
using YaeBlog.Core.Services;
|
||||||
|
|
||||||
|
namespace YaeBlog.Commands;
|
||||||
|
|
||||||
|
public static class CommandExtensions
|
||||||
|
{
|
||||||
|
public static void AddServeCommand(this RootCommand rootCommand)
|
||||||
|
{
|
||||||
|
Command serveCommand = new("serve", "Start http server.");
|
||||||
|
rootCommand.AddCommand(serveCommand);
|
||||||
|
|
||||||
|
serveCommand.SetHandler(async context =>
|
||||||
|
{
|
||||||
|
WebApplicationBuilder builder = WebApplication.CreateBuilder();
|
||||||
|
|
||||||
|
builder.Services.AddRazorComponents()
|
||||||
|
.AddInteractiveServerComponents();
|
||||||
|
builder.Services.AddControllers();
|
||||||
|
builder.Services.AddBlazorBootstrap();
|
||||||
|
builder.AddYaeBlog();
|
||||||
|
builder.AddServer();
|
||||||
|
|
||||||
|
WebApplication application = builder.Build();
|
||||||
|
|
||||||
|
application.UseStaticFiles();
|
||||||
|
application.UseAntiforgery();
|
||||||
|
application.UseYaeBlog();
|
||||||
|
|
||||||
|
application.MapRazorComponents<App>()
|
||||||
|
.AddInteractiveServerRenderMode();
|
||||||
|
application.MapControllers();
|
||||||
|
|
||||||
|
CancellationToken token = context.GetCancellationToken();
|
||||||
|
await application.RunAsync(token);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void AddWatchCommand(this RootCommand rootCommand)
|
||||||
|
{
|
||||||
|
Command command = new("watch", "Start a blog watcher that re-render when file changes.");
|
||||||
|
rootCommand.AddCommand(command);
|
||||||
|
|
||||||
|
command.SetHandler(async context =>
|
||||||
|
{
|
||||||
|
WebApplicationBuilder builder = WebApplication.CreateBuilder();
|
||||||
|
|
||||||
|
builder.Services.AddRazorComponents()
|
||||||
|
.AddInteractiveServerComponents();
|
||||||
|
builder.Services.AddControllers();
|
||||||
|
builder.Services.AddBlazorBootstrap();
|
||||||
|
builder.AddYaeBlog();
|
||||||
|
builder.AddWatcher();
|
||||||
|
|
||||||
|
WebApplication application = builder.Build();
|
||||||
|
|
||||||
|
application.UseStaticFiles();
|
||||||
|
application.UseAntiforgery();
|
||||||
|
application.UseYaeBlog();
|
||||||
|
|
||||||
|
application.MapRazorComponents<App>()
|
||||||
|
.AddInteractiveServerRenderMode();
|
||||||
|
application.MapControllers();
|
||||||
|
|
||||||
|
CancellationToken token = context.GetCancellationToken();
|
||||||
|
await application.RunAsync(token);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void AddNewCommand(this RootCommand rootCommand)
|
||||||
|
{
|
||||||
|
Command newCommand = new("new", "Create a new blog file and image directory.");
|
||||||
|
rootCommand.AddCommand(newCommand);
|
||||||
|
|
||||||
|
Argument<string> filenameArgument = new(name: "blog name", description: "The created blog filename.");
|
||||||
|
newCommand.AddArgument(filenameArgument);
|
||||||
|
|
||||||
|
newCommand.SetHandler(async (file, _, _, essayScanService) =>
|
||||||
|
{
|
||||||
|
BlogContents contents = await essayScanService.ScanContents();
|
||||||
|
|
||||||
|
if (contents.Posts.Any(content => content.FileName == file))
|
||||||
|
{
|
||||||
|
Console.WriteLine("There exists the same title blog in posts.");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
await essayScanService.SaveBlogContent(new BlogContent
|
||||||
|
{
|
||||||
|
FileName = file,
|
||||||
|
FileContent = string.Empty,
|
||||||
|
Metadata = new MarkdownMetadata { Title = file, Date = DateTime.Now }
|
||||||
|
});
|
||||||
|
|
||||||
|
Console.WriteLine($"Created new blog '{file}.");
|
||||||
|
}, filenameArgument, new BlogOptionsBinder(), new LoggerBinder<EssayScanService>(),
|
||||||
|
new EssayScanServiceBinder());
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void AddListCommand(this RootCommand rootCommand)
|
||||||
|
{
|
||||||
|
Command command = new("list", "List all blogs");
|
||||||
|
rootCommand.AddCommand(command);
|
||||||
|
|
||||||
|
command.SetHandler(async (_, _, essyScanService) =>
|
||||||
|
{
|
||||||
|
BlogContents contents = await essyScanService.ScanContents();
|
||||||
|
|
||||||
|
Console.WriteLine($"All {contents.Posts.Count} Posts:");
|
||||||
|
foreach (BlogContent content in contents.Posts.OrderBy(x => x.FileName))
|
||||||
|
{
|
||||||
|
Console.WriteLine($" - {content.FileName}");
|
||||||
|
}
|
||||||
|
|
||||||
|
Console.WriteLine($"All {contents.Drafts.Count} Drafts:");
|
||||||
|
foreach (BlogContent content in contents.Drafts.OrderBy(x => x.FileName))
|
||||||
|
{
|
||||||
|
Console.WriteLine($" - {content.FileName}");
|
||||||
|
}
|
||||||
|
}, new BlogOptionsBinder(), new LoggerBinder<EssayScanService>(), new EssayScanServiceBinder());
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void AddScanCommand(this RootCommand rootCommand)
|
||||||
|
{
|
||||||
|
Command command = new("scan", "Scan unused and not found images.");
|
||||||
|
rootCommand.AddCommand(command);
|
||||||
|
|
||||||
|
Option<bool> removeOption =
|
||||||
|
new(name: "--rm", description: "Remove unused images.", getDefaultValue: () => false);
|
||||||
|
command.AddOption(removeOption);
|
||||||
|
|
||||||
|
command.SetHandler(async (_, _, essayScanService, removeOptionValue) =>
|
||||||
|
{
|
||||||
|
ImageScanResult result = await essayScanService.ScanImages();
|
||||||
|
|
||||||
|
if (result.UnusedImages.Count != 0)
|
||||||
|
{
|
||||||
|
Console.WriteLine("Found unused images:");
|
||||||
|
Console.WriteLine("HINT: use '--rm' to remove unused images.");
|
||||||
|
}
|
||||||
|
|
||||||
|
foreach (FileInfo image in result.UnusedImages)
|
||||||
|
{
|
||||||
|
Console.WriteLine($" - {image.FullName}");
|
||||||
|
}
|
||||||
|
|
||||||
|
if (removeOptionValue)
|
||||||
|
{
|
||||||
|
foreach (FileInfo image in result.UnusedImages)
|
||||||
|
{
|
||||||
|
image.Delete();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
Console.WriteLine("Used not existed images:");
|
||||||
|
|
||||||
|
foreach (FileInfo image in result.NotFoundImages)
|
||||||
|
{
|
||||||
|
Console.WriteLine($" - {image.FullName}");
|
||||||
|
}
|
||||||
|
}, new BlogOptionsBinder(), new LoggerBinder<EssayScanService>(), new EssayScanServiceBinder(), removeOption);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void AddPublishCommand(this RootCommand rootCommand)
|
||||||
|
{
|
||||||
|
Command command = new("publish", "Publish a new blog file.");
|
||||||
|
rootCommand.AddCommand(command);
|
||||||
|
|
||||||
|
Argument<string> filenameArgument = new(name: "blog name", description: "The published blog filename.");
|
||||||
|
command.AddArgument(filenameArgument);
|
||||||
|
|
||||||
|
command.SetHandler(async (blogOptions, _, essayScanService, filename) =>
|
||||||
|
{
|
||||||
|
BlogContents contents = await essayScanService.ScanContents();
|
||||||
|
|
||||||
|
BlogContent? content = (from blog in contents.Drafts
|
||||||
|
where blog.FileName == filename
|
||||||
|
select blog).FirstOrDefault();
|
||||||
|
|
||||||
|
if (content is null)
|
||||||
|
{
|
||||||
|
Console.WriteLine("Target blog does not exist.");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
// 将选中的博客文件复制到posts
|
||||||
|
await essayScanService.SaveBlogContent(content, isDraft: false);
|
||||||
|
|
||||||
|
// 复制图片文件夹
|
||||||
|
DirectoryInfo sourceImageDirectory =
|
||||||
|
new(Path.Combine(blogOptions.Value.Root, "drafts", content.FileName));
|
||||||
|
DirectoryInfo targetImageDirectory =
|
||||||
|
new(Path.Combine(blogOptions.Value.Root, "posts", content.FileName));
|
||||||
|
|
||||||
|
if (sourceImageDirectory.Exists)
|
||||||
|
{
|
||||||
|
targetImageDirectory.Create();
|
||||||
|
foreach (FileInfo file in sourceImageDirectory.EnumerateFiles())
|
||||||
|
{
|
||||||
|
file.CopyTo(Path.Combine(targetImageDirectory.FullName, file.Name), true);
|
||||||
|
}
|
||||||
|
|
||||||
|
sourceImageDirectory.Delete(true);
|
||||||
|
}
|
||||||
|
|
||||||
|
// 删除原始的文件
|
||||||
|
FileInfo sourceBlogFile = new(Path.Combine(blogOptions.Value.Root, "drafts", content.FileName + ".md"));
|
||||||
|
sourceBlogFile.Delete();
|
||||||
|
}, new BlogOptionsBinder(),
|
||||||
|
new LoggerBinder<EssayScanService>(), new EssayScanServiceBinder(), filenameArgument);
|
||||||
|
}
|
||||||
|
}
|
||||||
28
YaeBlog/Components/App.razor
Normal file
28
YaeBlog/Components/App.razor
Normal file
@@ -0,0 +1,28 @@
|
|||||||
|
<!DOCTYPE html>
|
||||||
|
<html lang="en">
|
||||||
|
|
||||||
|
<head>
|
||||||
|
<meta charset="utf-8"/>
|
||||||
|
<meta name="viewport" content="width=device-width, initial-scale=1.0"/>
|
||||||
|
<base href="/"/>
|
||||||
|
<link rel="stylesheet" href="YaeBlog.styles.css"/>
|
||||||
|
<link rel="icon" href="images/favicon.ico"/>
|
||||||
|
<link rel="stylesheet" href="bootstrap.min.css"/>
|
||||||
|
<link rel="stylesheet" href="bootstrap-icons.min.css"/>
|
||||||
|
<link rel="stylesheet" href="_content/Blazor.Bootstrap/blazor.bootstrap.css"/>
|
||||||
|
<link rel="stylesheet" href="globals.css"/>
|
||||||
|
<HeadOutlet/>
|
||||||
|
</head>
|
||||||
|
|
||||||
|
<body>
|
||||||
|
<Routes/>
|
||||||
|
|
||||||
|
<script src="_framework/blazor.web.js"></script>
|
||||||
|
<script src="bootstrap.bundle.min.js"></script>
|
||||||
|
<script src="clipboard.min.js"></script>
|
||||||
|
<script>
|
||||||
|
const clipboard = new ClipboardJS('.btn');
|
||||||
|
</script>
|
||||||
|
</body>
|
||||||
|
|
||||||
|
</html>
|
||||||
57
YaeBlog/Components/BlogInformationCard.razor
Normal file
57
YaeBlog/Components/BlogInformationCard.razor
Normal file
@@ -0,0 +1,57 @@
|
|||||||
|
@using YaeBlog.Core.Abstractions
|
||||||
|
@using YaeBlog.Core.Models
|
||||||
|
|
||||||
|
@inject IEssayContentService Contents
|
||||||
|
@inject BlogOptions Options
|
||||||
|
|
||||||
|
<div class="container">
|
||||||
|
<div class="row justify-content-center">
|
||||||
|
<div class="col-auto p-4">
|
||||||
|
<Image Src="images/avatar.png" Alt="Ricardo's avatar"/>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div class="row justify-content-center p-3">
|
||||||
|
<div class="col-auto fs-4">
|
||||||
|
“奇奇怪怪东西的聚合地”
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div class="row justify-content-between px-2 py-1 fs-5">
|
||||||
|
<div class="col-auto">
|
||||||
|
文章
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div class="col-auto">
|
||||||
|
<a href="/blog/archives">
|
||||||
|
@(Contents.Essays.Count)
|
||||||
|
</a>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div class="row justify-content-between px-2 py-1 fs-5">
|
||||||
|
<div class="col-auto">
|
||||||
|
标签
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div class="col-auto">
|
||||||
|
<a href="/blog/tags">
|
||||||
|
@(Contents.Tags.Count)
|
||||||
|
</a>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div class="row justify-content-start fs-5" style="padding-top: 2em">
|
||||||
|
<div class="col-auto">
|
||||||
|
广而告之
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div class="row">
|
||||||
|
<div class="col">
|
||||||
|
<p style="text-indent: 2em">
|
||||||
|
@(Options.Announcement)
|
||||||
|
</p>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
40
YaeBlog/Components/EssayCard.razor
Normal file
40
YaeBlog/Components/EssayCard.razor
Normal file
@@ -0,0 +1,40 @@
|
|||||||
|
@using System.Text.Encodings.Web
|
||||||
|
@using YaeBlog.Core.Models
|
||||||
|
|
||||||
|
<div class="container p-3">
|
||||||
|
<div class="row fs-2 fw-bold py-2 essay-title">
|
||||||
|
<a href="/blog/essays/@(Essay.FileName)" target="_blank">@(Essay.Title)</a>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div class="row p-2 justify-content-start">
|
||||||
|
<div class="col-auto fw-light">
|
||||||
|
@(Essay.PublishTime.ToString("yyyy-MM-dd"))
|
||||||
|
</div>
|
||||||
|
|
||||||
|
@foreach (string key in Essay.Tags)
|
||||||
|
{
|
||||||
|
<div class="col-auto">
|
||||||
|
<a href="/blog/tags/?tagName=@(UrlEncoder.Default.Encode(key))">
|
||||||
|
# @key
|
||||||
|
</a>
|
||||||
|
</div>
|
||||||
|
}
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div class="row p-2">
|
||||||
|
<div class="col">
|
||||||
|
@(Essay.Description)
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div class="row">
|
||||||
|
<div class="col border-bottom">
|
||||||
|
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
@code {
|
||||||
|
[Parameter]
|
||||||
|
public required BlogEssay Essay { get; set; }
|
||||||
|
}
|
||||||
3
YaeBlog/Components/EssayCard.razor.css
Normal file
3
YaeBlog/Components/EssayCard.razor.css
Normal file
@@ -0,0 +1,3 @@
|
|||||||
|
.essay-title a {
|
||||||
|
color: var(--bs-body-color);
|
||||||
|
}
|
||||||
14
YaeBlog/Components/Foonter.razor
Normal file
14
YaeBlog/Components/Foonter.razor
Normal file
@@ -0,0 +1,14 @@
|
|||||||
|
<div class="row align-items-end text-center">
|
||||||
|
<div class="row">
|
||||||
|
<p class="fs-6">
|
||||||
|
2021 - @(DateTimeOffset.Now.Year) © <a href="https://rrricardo.top" target="_blank">Ricardo Ren</a>,
|
||||||
|
由 <a href="https://dotnet.microsoft.com/zh-cn/" target="_blank">.NET @(Environment.Version)</a> 驱动。
|
||||||
|
</p>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div class="row">
|
||||||
|
<p class="fs-6">
|
||||||
|
<a href="https://beian.miit.gov.cn" target="_blank">蜀ICP备2022004429号-1</a>
|
||||||
|
</p>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
36
YaeBlog/Components/LicenseDisclaimer.razor
Normal file
36
YaeBlog/Components/LicenseDisclaimer.razor
Normal file
@@ -0,0 +1,36 @@
|
|||||||
|
@using YaeBlog.Core.Models
|
||||||
|
|
||||||
|
@inject BlogOptions Options
|
||||||
|
|
||||||
|
<div class="row px-2 py-4 copyright border border-primary rounded-1 bg-primary-subtle">
|
||||||
|
<div class="col">
|
||||||
|
<div class="row p-1">
|
||||||
|
<div class="col">
|
||||||
|
文章作者:<a href="https://rrricardo.top" target="_blank">Ricardo Ren</a>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div 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>
|
||||||
|
|
||||||
|
@code
|
||||||
|
{
|
||||||
|
[Parameter] public string? EssayAddress { get; set; }
|
||||||
|
}
|
||||||
2
YaeBlog/Components/LicenseDisclaimer.razor.css
Normal file
2
YaeBlog/Components/LicenseDisclaimer.razor.css
Normal file
@@ -0,0 +1,2 @@
|
|||||||
|
.copyright {
|
||||||
|
}
|
||||||
@@ -9,6 +9,6 @@
|
|||||||
<RouteView RouteData="@routeData" DefaultLayout="@typeof(Layout.MainLayout)"></RouteView>
|
<RouteView RouteData="@routeData" DefaultLayout="@typeof(Layout.MainLayout)"></RouteView>
|
||||||
}
|
}
|
||||||
|
|
||||||
<FocusOnNavigate RouteData="routeData" Selector="page-starter"/>
|
<FocusOnNavigate RouteData="routeData" Selector="h1"/>
|
||||||
</Found>
|
</Found>
|
||||||
</Router>
|
</Router>
|
||||||
8
YaeBlog/Dockerfile
Normal file
8
YaeBlog/Dockerfile
Normal file
@@ -0,0 +1,8 @@
|
|||||||
|
FROM mcr.microsoft.com/dotnet/aspnet:8.0
|
||||||
|
|
||||||
|
WORKDIR /app
|
||||||
|
COPY bin/Release/net8.0/publish/ ./
|
||||||
|
COPY source/ ./source/
|
||||||
|
COPY appsettings.json .
|
||||||
|
|
||||||
|
ENTRYPOINT ["dotnet", "YaeBlog.dll", "serve"]
|
||||||
63
YaeBlog/Layout/BlogLayout.razor
Normal file
63
YaeBlog/Layout/BlogLayout.razor
Normal file
@@ -0,0 +1,63 @@
|
|||||||
|
@inherits LayoutComponentBase
|
||||||
|
|
||||||
|
@attribute [StreamRendering]
|
||||||
|
|
||||||
|
<main class="container">
|
||||||
|
<div class="row d-none d-xl-flex" style="height: 80px">
|
||||||
|
<div class="px-2 col-9">
|
||||||
|
<a href="/blog/" class="p-2">
|
||||||
|
<h4>Ricardo's Blog</h4>
|
||||||
|
</a>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div class="col-3 d-flex justify-content-around align-items-center">
|
||||||
|
<a href="/blog/" class="p-2">
|
||||||
|
<h5>首页</h5>
|
||||||
|
</a>
|
||||||
|
|
||||||
|
<a href="/blog/archives/" class="p-2">
|
||||||
|
<h5>归档</h5>
|
||||||
|
</a>
|
||||||
|
|
||||||
|
<a href="/blog/tags/" class="p-2">
|
||||||
|
<h5>标签</h5>
|
||||||
|
</a>
|
||||||
|
|
||||||
|
<a href="/blog/about/" class="p-2">
|
||||||
|
<h5>关于</h5>
|
||||||
|
</a>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div class="row d-xl-none">
|
||||||
|
<div class="px-2 col-12">
|
||||||
|
<a href="/blog/" class="p-2">
|
||||||
|
<h4>Ricardo's Blog</h4>
|
||||||
|
</a>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div class="px-2 col-12 justify-content-end d-flex">
|
||||||
|
<a href="/blog/" class="p-2">
|
||||||
|
<h5>首页</h5>
|
||||||
|
</a>
|
||||||
|
|
||||||
|
<a href="/blog/archives/" class="p-2">
|
||||||
|
<h5>归档</h5>
|
||||||
|
</a>
|
||||||
|
|
||||||
|
<a href="/blog/tags/" class="p-2">
|
||||||
|
<h5>标签</h5>
|
||||||
|
</a>
|
||||||
|
|
||||||
|
<a href="/blog/about/" class="p-2">
|
||||||
|
<h5>关于</h5>
|
||||||
|
</a>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div class="row px-4 py-2">
|
||||||
|
@Body
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<Foonter/>
|
||||||
|
</main>
|
||||||
0
YaeBlog/Layout/BlogLayout.razor.css
Normal file
0
YaeBlog/Layout/BlogLayout.razor.css
Normal file
25
YaeBlog/Layout/MainLayout.razor
Normal file
25
YaeBlog/Layout/MainLayout.razor
Normal file
@@ -0,0 +1,25 @@
|
|||||||
|
@inherits LayoutComponentBase
|
||||||
|
|
||||||
|
<main class="container">
|
||||||
|
<div class="row" style="height: 80px">
|
||||||
|
<div class="px-2 col-8">
|
||||||
|
<a href="/" class="p-2">
|
||||||
|
<h4>Ricardo's Index</h4>
|
||||||
|
</a>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div class="col-4 d-flex justify-content-around align-items-center">
|
||||||
|
<a href="mailto://shicangjuner@outlook.com" class="p-2" target="_blank">
|
||||||
|
<h5>E-mail</h5>
|
||||||
|
</a>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div class="row px-4 center">
|
||||||
|
<div class="py-2">
|
||||||
|
@Body
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<Foonter/>
|
||||||
|
</main>
|
||||||
8
YaeBlog/Layout/MainLayout.razor.css
Normal file
8
YaeBlog/Layout/MainLayout.razor.css
Normal file
@@ -0,0 +1,8 @@
|
|||||||
|
.center {
|
||||||
|
margin: 0 auto;
|
||||||
|
max-width: 48em;
|
||||||
|
min-height: calc(100vh - 80px);
|
||||||
|
position: relative;
|
||||||
|
display: flex;
|
||||||
|
flex-direction: column;
|
||||||
|
}
|
||||||
146
YaeBlog/Pages/About.razor
Normal file
146
YaeBlog/Pages/About.razor
Normal file
@@ -0,0 +1,146 @@
|
|||||||
|
@page "/blog/about"
|
||||||
|
@using YaeBlog.Core.Models
|
||||||
|
|
||||||
|
@inject BlogOptions Options
|
||||||
|
|
||||||
|
<PageTitle>
|
||||||
|
关于
|
||||||
|
</PageTitle>
|
||||||
|
|
||||||
|
<div class="container">
|
||||||
|
<div class="row">
|
||||||
|
<div class="col">
|
||||||
|
<h1>关于</h1>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div class="row">
|
||||||
|
<div class="col fst-italic py-2">
|
||||||
|
把字刻在石头上!(・’ω’・)
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div class="row p-2">
|
||||||
|
<div class="col">
|
||||||
|
<div class="row">
|
||||||
|
<div class="col">
|
||||||
|
<h3>关于我</h3>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div class="row py-2">
|
||||||
|
<div class="col">
|
||||||
|
计算机科学与技术在读大学生,明光村幼儿园附属大学所属。正处于读书和失业的叠加态。
|
||||||
|
一般在互联网上使用<span class="fst-italic">初冬的朝阳</span>或者<span class="fst-italic">jackfiled</span>的名字活动。
|
||||||
|
<span class="text-decoration-line-through">都是ICP备案过的人了,网名似乎没有太大的用处(</span>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div class="row py-2">
|
||||||
|
<div class="col">
|
||||||
|
主要是一个C#程序员,目前也在尝试写一点Rust。
|
||||||
|
总体上对于编程语言的态度是“<span>大家都是我的翅膀.jpg</span>”。
|
||||||
|
前后端分离的项目本当上手。
|
||||||
|
常常因为现实的压力而写一些C/C++。
|
||||||
|
<span class="text-decoration-line-through">对于Java和Go的评价很低。</span>
|
||||||
|
日常使用ArchLinux。
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div class="row py-2">
|
||||||
|
<div class="col">
|
||||||
|
100%社恐。日常生活是宅在电脑前面自言自语。兴趣活动是读书和看番。
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div class="row py-2">
|
||||||
|
<div class="col">
|
||||||
|
常常被人批评没有梦想,这里就随便瞎编一下。
|
||||||
|
成为嵌入式工程师,修好桌面上的<a href="https://www.bilibili.com/video/BV1VA411p7MD">HoloCubic</a>。
|
||||||
|
完成第一个不是课程设计的个人开源项目。
|
||||||
|
遇到能够搭伙过日子的人也算是一大梦想,虽然社恐人根本不知道从何开始的说,
|
||||||
|
<span class="text-decoration-line-through">什么时候天上才能掉美少女?</span>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div class="row py-2">
|
||||||
|
<div class="col">
|
||||||
|
公开的联系渠道是<a href="mailto:shicangjuner@outlook.com">电子邮件</a>。
|
||||||
|
也可以试试在各大平台搜索上面提到的名字。
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div class="row p-2">
|
||||||
|
<div class="col">
|
||||||
|
<div class="row">
|
||||||
|
<div class="col">
|
||||||
|
<h3>关于本站</h3>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div class="row py-2">
|
||||||
|
<div class="col">
|
||||||
|
本站肇始于2021年下半年,在开始的两年中个人网站和博客是分别的两个网站,个人网站是裸HTML写的,博客是用
|
||||||
|
<a href="https://hexo.io">Hexo</a>渲染的。
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div class="row py-2">
|
||||||
|
<div class="col">
|
||||||
|
2024年,我们决定使用.NET技术完全重构两个网站,合二为一。虽然目前这个版本还是一个半成品,但是我们一定会努力的~(确信。
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div class="row p-2">
|
||||||
|
<div class="col">
|
||||||
|
<div class="row">
|
||||||
|
<div class="col">
|
||||||
|
<h3>友链</h3>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div class="row py-2">
|
||||||
|
<div class="col fst-italic">
|
||||||
|
欢迎所有人联系我添加友链!(´。✪ω✪。`)
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div class="row py-2">
|
||||||
|
@foreach (FriendLink link in Options.Links)
|
||||||
|
{
|
||||||
|
<div class="col-sm-12 col-md-4 col-lg-3">
|
||||||
|
<a href="@(link.Link)" target="_blank" class="m-3">
|
||||||
|
<div class="row link-item">
|
||||||
|
<div class="col-4">
|
||||||
|
<Image Src="@(link.AvatarImage)" Alt="@(link.Name)" Style="border-radius: 50%"/>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div class="col-8">
|
||||||
|
<div class="row">
|
||||||
|
<div class="col-auto fs-5">
|
||||||
|
@(link.Name)
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div class="row">
|
||||||
|
<div class="col-auto fst-italic">
|
||||||
|
@(link.Description)
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</a>
|
||||||
|
</div>
|
||||||
|
}
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
@code {
|
||||||
|
|
||||||
|
}
|
||||||
8
YaeBlog/Pages/About.razor.css
Normal file
8
YaeBlog/Pages/About.razor.css
Normal file
@@ -0,0 +1,8 @@
|
|||||||
|
.link-item {
|
||||||
|
padding: 1rem;
|
||||||
|
border-radius: 4px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.link-item:hover {
|
||||||
|
background-color: var(--bs-secondary-bg);
|
||||||
|
}
|
||||||
75
YaeBlog/Pages/Archives.razor
Normal file
75
YaeBlog/Pages/Archives.razor
Normal file
@@ -0,0 +1,75 @@
|
|||||||
|
@page "/blog/archives"
|
||||||
|
@using YaeBlog.Core.Abstractions
|
||||||
|
@using YaeBlog.Core.Models
|
||||||
|
|
||||||
|
@inject IEssayContentService Contents
|
||||||
|
|
||||||
|
<PageTitle>
|
||||||
|
归档
|
||||||
|
</PageTitle>
|
||||||
|
|
||||||
|
<div class="container">
|
||||||
|
<div class="row">
|
||||||
|
<div class="col">
|
||||||
|
<div class="container">
|
||||||
|
<div class="row">
|
||||||
|
<div class="col">
|
||||||
|
<h1>归档</h1>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div class="row">
|
||||||
|
<div class="col fst-italic py-4">
|
||||||
|
时光图书馆,黑历史集散地。(๑◔‿◔๑)
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
@foreach (IGrouping<DateTime, KeyValuePair<string, BlogEssay>> group in _essays)
|
||||||
|
{
|
||||||
|
<div class="row">
|
||||||
|
<div class="col">
|
||||||
|
<div class="container">
|
||||||
|
<div class="row">
|
||||||
|
<div class="col">
|
||||||
|
<h3>@(group.Key.Year)</h3>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div class="container px-3 py-2">
|
||||||
|
@foreach (KeyValuePair<string, BlogEssay> essay in group)
|
||||||
|
{
|
||||||
|
<div class="row py-1">
|
||||||
|
<div class="col-auto">
|
||||||
|
@(essay.Value.PublishTime.ToString("MM-dd"))
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div class="col-auto">
|
||||||
|
<a href="/blog/essays/@(essay.Key)">
|
||||||
|
@(essay.Value.Title)
|
||||||
|
</a>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
}
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
}
|
||||||
|
|
||||||
|
</div>
|
||||||
|
|
||||||
|
@code {
|
||||||
|
private readonly List<IGrouping<DateTime, KeyValuePair<string, BlogEssay>>> _essays = [];
|
||||||
|
|
||||||
|
protected override void OnInitialized()
|
||||||
|
{
|
||||||
|
base.OnInitialized();
|
||||||
|
|
||||||
|
_essays.AddRange(from essay in Contents.Essays
|
||||||
|
orderby essay.Value.PublishTime descending
|
||||||
|
group essay by new DateTime(essay.Value.PublishTime.Year, 1, 1));
|
||||||
|
}
|
||||||
|
}
|
||||||
0
YaeBlog/Pages/Archives.razor.css
Normal file
0
YaeBlog/Pages/Archives.razor.css
Normal file
116
YaeBlog/Pages/BlogIndex.razor
Normal file
116
YaeBlog/Pages/BlogIndex.razor
Normal file
@@ -0,0 +1,116 @@
|
|||||||
|
@page "/blog"
|
||||||
|
@using YaeBlog.Core.Abstractions
|
||||||
|
@using YaeBlog.Core.Models
|
||||||
|
|
||||||
|
@inject IEssayContentService Contents
|
||||||
|
@inject NavigationManager NavigationInstance
|
||||||
|
|
||||||
|
<PageTitle>
|
||||||
|
Ricardo's Blog
|
||||||
|
</PageTitle>
|
||||||
|
|
||||||
|
<div class="container">
|
||||||
|
<div class="row">
|
||||||
|
<div class="col-sm-12 col-md-9">
|
||||||
|
@foreach (KeyValuePair<string, BlogEssay> pair in _essays)
|
||||||
|
{
|
||||||
|
<EssayCard Essay="@(pair.Value)"/>
|
||||||
|
}
|
||||||
|
|
||||||
|
<div class="row align-items-center justify-content-center p-3">
|
||||||
|
@if (_page == 1)
|
||||||
|
{
|
||||||
|
<div class="col-auto fw-light">上一页</div>
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
<div class="col-auto">
|
||||||
|
<a href="/blog/?page=@(_page - 1)">上一页</a>
|
||||||
|
</div>
|
||||||
|
}
|
||||||
|
|
||||||
|
@if (_page == 1)
|
||||||
|
{
|
||||||
|
<div class="col-auto">
|
||||||
|
1
|
||||||
|
</div>
|
||||||
|
<div class="col-auto">
|
||||||
|
<a href="/blog/?page=2">2</a>
|
||||||
|
</div>
|
||||||
|
<div class="col-auto">
|
||||||
|
<a href="/blog/?page=3">3</a>
|
||||||
|
</div>
|
||||||
|
}
|
||||||
|
else if (_page == _pageCount)
|
||||||
|
{
|
||||||
|
<div class="col-auto">
|
||||||
|
<a href="/blog/?page=@(_pageCount - 2)">@(_pageCount - 2)</a>
|
||||||
|
</div>
|
||||||
|
<div class="col-auto">
|
||||||
|
<a href="/blog/?page=@(_pageCount - 1)">@(_pageCount - 1)</a>
|
||||||
|
</div>
|
||||||
|
<div class="col-auto">
|
||||||
|
@(_pageCount)
|
||||||
|
</div>
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
<div class="col-auto">
|
||||||
|
<a href="/blog/?page=@(_page - 1)">@(_page - 1)</a>
|
||||||
|
</div>
|
||||||
|
<div class="col-auto">
|
||||||
|
@(_page)
|
||||||
|
</div>
|
||||||
|
<div class="col-auto">
|
||||||
|
<a href="/blog/?page=@(_page + 1)">@(_page + 1)</a>
|
||||||
|
</div>
|
||||||
|
}
|
||||||
|
|
||||||
|
@if (_page == _pageCount)
|
||||||
|
{
|
||||||
|
<div class="col-auto fw-light">
|
||||||
|
下一页
|
||||||
|
</div>
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
<div class="col-auto">
|
||||||
|
<a href="/blog/?page=@(_page + 1)">下一页</a>
|
||||||
|
</div>
|
||||||
|
}
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div class="col-sm-12 col-md-3">
|
||||||
|
<BlogInformationCard/>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
@code {
|
||||||
|
|
||||||
|
[SupplyParameterFromQuery] private int? Page { get; set; }
|
||||||
|
|
||||||
|
private readonly List<KeyValuePair<string, BlogEssay>> _essays = [];
|
||||||
|
private const int EssaysPerPage = 8;
|
||||||
|
private int _pageCount = 1;
|
||||||
|
private int _page = 1;
|
||||||
|
|
||||||
|
protected override void OnInitialized()
|
||||||
|
{
|
||||||
|
_page = Page ?? 1;
|
||||||
|
_pageCount = Contents.Essays.Count / EssaysPerPage + 1;
|
||||||
|
|
||||||
|
if (EssaysPerPage * _page > Contents.Essays.Count + EssaysPerPage)
|
||||||
|
{
|
||||||
|
NavigationInstance.NavigateTo("/NotFount");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
_essays.AddRange(Contents.Essays
|
||||||
|
.OrderByDescending(p => p.Value.PublishTime)
|
||||||
|
.Skip((_page - 1) * EssaysPerPage)
|
||||||
|
.Take(EssaysPerPage));
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
7
YaeBlog/Pages/BlogIndex.razor.css
Normal file
7
YaeBlog/Pages/BlogIndex.razor.css
Normal file
@@ -0,0 +1,7 @@
|
|||||||
|
.essay-title a {
|
||||||
|
color: var(--bs-body-color);
|
||||||
|
}
|
||||||
|
|
||||||
|
.read-more a {
|
||||||
|
color: var(--bs-body-color);
|
||||||
|
}
|
||||||
137
YaeBlog/Pages/Essays.razor
Normal file
137
YaeBlog/Pages/Essays.razor
Normal file
@@ -0,0 +1,137 @@
|
|||||||
|
@page "/blog/essays/{BlogKey}"
|
||||||
|
@using System.Text.Encodings.Web
|
||||||
|
@using YaeBlog.Core.Abstractions
|
||||||
|
@using YaeBlog.Core.Models
|
||||||
|
|
||||||
|
@inject IEssayContentService Contents
|
||||||
|
@inject NavigationManager NavigationInstance
|
||||||
|
|
||||||
|
<PageTitle>
|
||||||
|
@(_essay!.Title)
|
||||||
|
</PageTitle>
|
||||||
|
|
||||||
|
<div class="container py-4">
|
||||||
|
<div class="row">
|
||||||
|
<div class="col-auto">
|
||||||
|
<h1 id="title">@(_essay!.Title)</h1>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div class="row px-4 py-1">
|
||||||
|
<div class="col-auto fw-light">
|
||||||
|
@(_essay!.PublishTime.ToString("yyyy-MM-dd"))
|
||||||
|
</div>
|
||||||
|
|
||||||
|
@foreach (string tag in _essay!.Tags)
|
||||||
|
{
|
||||||
|
<div class="col-auto">
|
||||||
|
<a href="/blog/tags/?tagName=@(UrlEncoder.Default.Encode(tag))">
|
||||||
|
# @(tag)
|
||||||
|
</a>
|
||||||
|
</div>
|
||||||
|
}
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div class="row px-4 py-1">
|
||||||
|
<div class="col-auto fw-light">
|
||||||
|
总字数:@(_essay!.WordCount)字,预计阅读时间 @(_essay!.ReadTime)。
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div class="row">
|
||||||
|
<div class="col-lg-8 col-md-12">
|
||||||
|
@((MarkupString)_essay!.HtmlContent)
|
||||||
|
|
||||||
|
<LicenseDisclaimer EssayAddress="@BlogKey"/>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div class="col-lg-4 col-md-12">
|
||||||
|
<div class="row sticky-lg-top justify-content-center">
|
||||||
|
<div class="col-auto">
|
||||||
|
<div class="row">
|
||||||
|
<div class="col-auto">
|
||||||
|
<h3 style="margin-block-start: 1em; margin-block-end: 0.5em">
|
||||||
|
文章目录
|
||||||
|
</h3>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div class="row" style="padding-left: 10px">
|
||||||
|
<div class="col-auto">
|
||||||
|
@foreach (BlogHeadline level2 in _headline!.Children)
|
||||||
|
{
|
||||||
|
<div class="row py-1">
|
||||||
|
<div class="col-auto">
|
||||||
|
<a href="@(GenerateSelectorUrl(level2.SelectorId))">@(level2.Title)</a>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
@foreach (BlogHeadline level3 in level2.Children)
|
||||||
|
{
|
||||||
|
<div class="row py-1">
|
||||||
|
<div class="col-auto">
|
||||||
|
<a style="padding-left: 20px" href="@GenerateSelectorUrl(level3.SelectorId)">
|
||||||
|
@(level3.Title)
|
||||||
|
</a>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
@foreach (BlogHeadline level4 in level3.Children)
|
||||||
|
{
|
||||||
|
<div class="row py-1">
|
||||||
|
<div class="col-auto">
|
||||||
|
<a style="padding-left: 40px" href="@(GenerateSelectorUrl(level4.SelectorId))">
|
||||||
|
@(level4.Title)
|
||||||
|
</a>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
@if (_headline!.Children.Count == 0)
|
||||||
|
{
|
||||||
|
<div class="row">
|
||||||
|
<div class="col fst-italic">
|
||||||
|
坏了(* Ŏ∀Ŏ),没有在文章中识别到目录
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
}
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
</div>
|
||||||
|
|
||||||
|
@code {
|
||||||
|
[Parameter] public string? BlogKey { get; set; }
|
||||||
|
|
||||||
|
private BlogEssay? _essay;
|
||||||
|
|
||||||
|
private BlogHeadline? _headline;
|
||||||
|
|
||||||
|
protected override void OnInitialized()
|
||||||
|
{
|
||||||
|
base.OnInitialized();
|
||||||
|
|
||||||
|
if (string.IsNullOrWhiteSpace(BlogKey))
|
||||||
|
{
|
||||||
|
NavigationInstance.NavigateTo("/NotFound");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!Contents.Essays.TryGetValue(BlogKey, out _essay))
|
||||||
|
{
|
||||||
|
NavigationInstance.NavigateTo("/NotFound");
|
||||||
|
}
|
||||||
|
|
||||||
|
_headline = Contents.Headlines[BlogKey];
|
||||||
|
}
|
||||||
|
|
||||||
|
private string GenerateSelectorUrl(string selectorId)
|
||||||
|
=> $"/blog/essays/{BlogKey!}#{selectorId}";
|
||||||
|
|
||||||
|
}
|
||||||
0
YaeBlog/Pages/Essays.razor.css
Normal file
0
YaeBlog/Pages/Essays.razor.css
Normal file
57
YaeBlog/Pages/Index.razor
Normal file
57
YaeBlog/Pages/Index.razor
Normal file
@@ -0,0 +1,57 @@
|
|||||||
|
@page "/"
|
||||||
|
|
||||||
|
<PageTitle>
|
||||||
|
Ricardo's Index
|
||||||
|
</PageTitle>
|
||||||
|
|
||||||
|
<div class="container">
|
||||||
|
<div class="row py-4">
|
||||||
|
<div class="col-lg-4 col-12 p-5 p-lg-0">
|
||||||
|
<Image Src="images/avatar.png" Alt="Ricardo's Avatar"/>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div class="col-lg-8 col-12">
|
||||||
|
<div class="container px-3">
|
||||||
|
<div class="row">
|
||||||
|
<h4 class="fw-bold">初冬的朝阳 (Ricardo Ren)</h4>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div class="row">
|
||||||
|
<p class="fs-5">a.k.a jackfiled</p>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div class="row">
|
||||||
|
<p class="fs-5 fst-italic">世界很大,时间很长。</p>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div class="row">
|
||||||
|
<p class="fs-5">
|
||||||
|
平平无奇的计算机科学与技术学徒,连微小的贡献都没做。
|
||||||
|
</p>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div class="row" style="padding-top: 80px">
|
||||||
|
<p class="fs-5">恕我不能亲自为您沏茶(?),还是非常欢迎您能够来到我的主页。</p>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div class="row">
|
||||||
|
<p class="fs-5">
|
||||||
|
如果您想四处看看,了解一下屏幕对面的人,可以在我的 <a href="/blog/">博客</a> 看看。
|
||||||
|
如果您对于明光村幼儿园某附属技校的计算机教学感兴趣,您可以移步到
|
||||||
|
<a href="https://jackfiled.github.io/wiki/">我的学习笔记</a>,
|
||||||
|
<span class="fs-5 text-decoration-line-through">虽然这笔记我自己也木有看过。</span>
|
||||||
|
如果您想批判一下我的代码,在 <a href="https://github.com/jackfiled" target="_blank">Github</a> 和
|
||||||
|
<a href="https://git.rrricardo.top/jackfiled/" target="_blank">Gitea</a> 都可以找到。
|
||||||
|
</p>
|
||||||
|
<p class="fs-5">
|
||||||
|
如果您真的很闲,也可以四处搜寻一下,也许存在着一些不为人知的彩蛋。
|
||||||
|
</p>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
@code {
|
||||||
|
|
||||||
|
}
|
||||||
0
YaeBlog/Pages/Index.razor.css
Normal file
0
YaeBlog/Pages/Index.razor.css
Normal file
@@ -4,8 +4,8 @@
|
|||||||
啊~ 页面走丢啦~
|
啊~ 页面走丢啦~
|
||||||
</PageTitle>
|
</PageTitle>
|
||||||
|
|
||||||
<div>
|
<div class="container">
|
||||||
<h3 class="text-3xl page-starter">NotFound!</h3>
|
<h3>NotFound!</h3>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
@code {
|
@code {
|
||||||
0
YaeBlog/Pages/NotFound.razor.css
Normal file
0
YaeBlog/Pages/NotFound.razor.css
Normal file
@@ -1,7 +1,7 @@
|
|||||||
@page "/blog/tags/"
|
@page "/blog/tags/"
|
||||||
@using System.Text.Encodings.Web
|
@using System.Text.Encodings.Web
|
||||||
@using YaeBlog.Abstraction
|
@using YaeBlog.Core.Abstractions
|
||||||
@using YaeBlog.Models
|
@using YaeBlog.Core.Models
|
||||||
|
|
||||||
@inject IEssayContentService Contents
|
@inject IEssayContentService Contents
|
||||||
@inject NavigationManager NavigationInstance
|
@inject NavigationManager NavigationInstance
|
||||||
@@ -10,22 +10,24 @@
|
|||||||
@(TagName ?? "标签")
|
@(TagName ?? "标签")
|
||||||
</PageTitle>
|
</PageTitle>
|
||||||
|
|
||||||
<div class="flex flex-col">
|
<div class="container">
|
||||||
<div class="page-starter">
|
<div class="row">
|
||||||
@if (TagName is null)
|
<div class="col">
|
||||||
{
|
@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="py-4">
|
<div class="row">
|
||||||
<span class="italic">
|
<div class="col fst-italic py-4">
|
||||||
在野外游荡的指针,走向未知的方向。٩(๑˃̵ᴗ˂̵๑)۶
|
在野外游荡的指针,走向未知的方向。٩(๑˃̵ᴗ˂̵๑)۶
|
||||||
</span>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
@if (TagName is null)
|
@if (TagName is null)
|
||||||
@@ -36,17 +38,19 @@
|
|||||||
Contents.Tags.OrderByDescending(pair => pair.Value.Count))
|
Contents.Tags.OrderByDescending(pair => pair.Value.Count))
|
||||||
{
|
{
|
||||||
<li class="p-2">
|
<li class="p-2">
|
||||||
<div class="flex flex-row">
|
<a href="/blog/tags/?tagName=@(pair.Key.UrlEncodedTagName)">
|
||||||
<a href="/blog/tags/?tagName=@(pair.Key.UrlEncodedTagName)">
|
<div class="container fs-5">
|
||||||
<div class="text-sky-600 text-lg">
|
<div class="row">
|
||||||
# @(pair.Key.TagName)
|
<div class="col-auto">
|
||||||
</div>
|
# @(pair.Key.TagName)
|
||||||
</a>
|
</div>
|
||||||
|
|
||||||
<div class="mx-2 px-1 text-lg bg-gray-300 rounded-lg">
|
<div class="col-auto tag-count">
|
||||||
@(pair.Value.Count)
|
@(pair.Value.Count)
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</a>
|
||||||
</li>
|
</li>
|
||||||
}
|
}
|
||||||
</ul>
|
</ul>
|
||||||
6
YaeBlog/Pages/Tags.razor.css
Normal file
6
YaeBlog/Pages/Tags.razor.css
Normal file
@@ -0,0 +1,6 @@
|
|||||||
|
.tag-count {
|
||||||
|
background: var(--bs-secondary-bg);
|
||||||
|
border-radius: 5px;
|
||||||
|
padding: 0 6px;
|
||||||
|
}
|
||||||
|
|
||||||
13
YaeBlog/Program.cs
Normal file
13
YaeBlog/Program.cs
Normal file
@@ -0,0 +1,13 @@
|
|||||||
|
using System.CommandLine;
|
||||||
|
using YaeBlog.Commands;
|
||||||
|
|
||||||
|
RootCommand rootCommand = new("YaeBlog CLI");
|
||||||
|
|
||||||
|
rootCommand.AddServeCommand();
|
||||||
|
rootCommand.AddNewCommand();
|
||||||
|
rootCommand.AddListCommand();
|
||||||
|
rootCommand.AddWatchCommand();
|
||||||
|
rootCommand.AddScanCommand();
|
||||||
|
rootCommand.AddPublishCommand();
|
||||||
|
|
||||||
|
await rootCommand.InvokeAsync(args);
|
||||||
18
YaeBlog/YaeBlog.csproj
Normal file
18
YaeBlog/YaeBlog.csproj
Normal file
@@ -0,0 +1,18 @@
|
|||||||
|
<Project Sdk="Microsoft.NET.Sdk.Web">
|
||||||
|
|
||||||
|
<ItemGroup>
|
||||||
|
<ProjectReference Include="..\YaeBlog.Core\YaeBlog.Core.csproj" />
|
||||||
|
</ItemGroup>
|
||||||
|
|
||||||
|
<ItemGroup>
|
||||||
|
<PackageReference Include="Blazor.Bootstrap" Version="3.0.0-preview.2" />
|
||||||
|
<PackageReference Include="System.CommandLine" Version="2.0.0-beta4.22272.1" />
|
||||||
|
</ItemGroup>
|
||||||
|
|
||||||
|
<PropertyGroup>
|
||||||
|
<TargetFramework>net8.0</TargetFramework>
|
||||||
|
<Nullable>enable</Nullable>
|
||||||
|
<ImplicitUsings>enable</ImplicitUsings>
|
||||||
|
</PropertyGroup>
|
||||||
|
|
||||||
|
</Project>
|
||||||
@@ -6,6 +6,6 @@
|
|||||||
@using static Microsoft.AspNetCore.Components.Web.RenderMode
|
@using static Microsoft.AspNetCore.Components.Web.RenderMode
|
||||||
@using Microsoft.AspNetCore.Components.Web.Virtualization
|
@using Microsoft.AspNetCore.Components.Web.Virtualization
|
||||||
@using Microsoft.JSInterop
|
@using Microsoft.JSInterop
|
||||||
|
@using BlazorBootstrap
|
||||||
|
@using YaeBlog
|
||||||
@using YaeBlog.Components
|
@using YaeBlog.Components
|
||||||
@using BlazorSvgComponents
|
|
||||||
@using BlazorSvgComponents.Models
|
|
||||||
40
YaeBlog/appsettings.json
Normal file
40
YaeBlog/appsettings.json
Normal file
@@ -0,0 +1,40 @@
|
|||||||
|
{
|
||||||
|
"Logging": {
|
||||||
|
"LogLevel": {
|
||||||
|
"Default": "Information",
|
||||||
|
"Microsoft.AspNetCore": "Warning"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"AllowedHosts": "*",
|
||||||
|
"Blog": {
|
||||||
|
"Root": "source",
|
||||||
|
"Announcement": "博客锐意装修中,敬请期待!测试阶段如有问题还请海涵。",
|
||||||
|
"StartYear": 2021,
|
||||||
|
"Links": [
|
||||||
|
{
|
||||||
|
"Name": "Ichirinko",
|
||||||
|
"Description": "这是个大哥",
|
||||||
|
"Link": "https://ichirinko.top",
|
||||||
|
"AvatarImage": "https://ichirinko-blog-img-1.oss-cn-shenzhen.aliyuncs.com/Pic_res/img/202209122110798.png"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"Name": "志田千陽",
|
||||||
|
"Description": "日出多值得",
|
||||||
|
"Link": "https://zzachary.top/",
|
||||||
|
"AvatarImage": "https://zzachary.top/img/ztqy_hub928259802d192ff5718c06370f0f2c4_48203_300x0_resize_q75_box.jpg"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"Name": "不会写程序的晨旭",
|
||||||
|
"Description": "一个普通大学生",
|
||||||
|
"Link": "https://chenxutalk.top",
|
||||||
|
"AvatarImage": "https://www.chenxutalk.top/img/photo.png"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"Name": "万木长风",
|
||||||
|
"Description": "世界渲染中...",
|
||||||
|
"Link": "https://ryohai.fun",
|
||||||
|
"AvatarImage": "https://ryohai.fun/icon.jpg"
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
|
}
|
||||||
13
YaeBlog/docker-compose.yaml
Normal file
13
YaeBlog/docker-compose.yaml
Normal file
@@ -0,0 +1,13 @@
|
|||||||
|
version: '3.8'
|
||||||
|
|
||||||
|
services:
|
||||||
|
blog:
|
||||||
|
image: registry.cn-beijing.aliyuncs.com/jackfiled/blog:latest
|
||||||
|
restart: unless-stopped
|
||||||
|
labels:
|
||||||
|
- "traefik.enable=true"
|
||||||
|
- "traefik.http.routers.blog.rule=Host(`rrricardo.top`) || Host(`www.rrricardo.top`)"
|
||||||
|
- "traefik.http.services.blog.loadbalancer.server.port=8080"
|
||||||
|
- "traefik.http.routers.blog.tls=true"
|
||||||
|
- "traefik.http.routers.blog.tls.certresolver=myresolver"
|
||||||
|
- "com.centurylinklabs.watchtower.enable=true"
|
||||||
0
YaeBlog/source/drafts/.gitkeep
Normal file
0
YaeBlog/source/drafts/.gitkeep
Normal file
0
YaeBlog/source/posts/.gitkeep
Normal file
0
YaeBlog/source/posts/.gitkeep
Normal file
@@ -1,12 +1,10 @@
|
|||||||
---
|
---
|
||||||
title: 2021年终总结
|
title: 2021年终总结
|
||||||
date: 2022-01-12T16:27:19.0000000
|
date: 2022-01-12 16:27:19
|
||||||
tags:
|
tags:
|
||||||
- 杂谈
|
- 随笔
|
||||||
- 年终总结
|
|
||||||
---
|
---
|
||||||
|
|
||||||
|
|
||||||
2021年已经过去,2022年已经来临。每每一年开始的时候,我都会展开一张纸或者新建一个文档,思量着又是一年时光,也该同诸大杂志一般,写几句意味深长的话语,怀念过去的时光,也祝福未来的自己。可往往脑海中已是三万字的长篇,落在笔头却又是一个字都没有了。
|
2021年已经过去,2022年已经来临。每每一年开始的时候,我都会展开一张纸或者新建一个文档,思量着又是一年时光,也该同诸大杂志一般,写几句意味深长的话语,怀念过去的时光,也祝福未来的自己。可往往脑海中已是三万字的长篇,落在笔头却又是一个字都没有了。
|
||||||
如今跨年的时候已经过去,朋友圈中已经不见文案的踪影,我也该重新提笔,细说自己2021年中做过的种种。
|
如今跨年的时候已经过去,朋友圈中已经不见文案的踪影,我也该重新提笔,细说自己2021年中做过的种种。
|
||||||
|
|
||||||
@@ -24,7 +22,7 @@ tags:
|
|||||||
在前12年的学生生涯中,我们都在期待着这一次的暑假,以为在这个没有作业的假期里,我们就可以充分的享受人间的美好。可是,当时我们不知道,这人间的烦恼,可不止作业这一种,无论是突如其来的疫情导致开学延期,还是等待录取时的不安。
|
在前12年的学生生涯中,我们都在期待着这一次的暑假,以为在这个没有作业的假期里,我们就可以充分的享受人间的美好。可是,当时我们不知道,这人间的烦恼,可不止作业这一种,无论是突如其来的疫情导致开学延期,还是等待录取时的不安。
|
||||||
虽说在暑假时,拥有了自己的笔记本电脑,可是在高中三年屯下的游戏还是没有玩几个,看来我也是“喜加一”的受害者。虽然在高考后入坑了原神,但是假期间我并没有太过投入的玩。
|
虽说在暑假时,拥有了自己的笔记本电脑,可是在高中三年屯下的游戏还是没有玩几个,看来我也是“喜加一”的受害者。虽然在高考后入坑了原神,但是假期间我并没有太过投入的玩。
|
||||||
暑假下定决心要好好的学一学,可是看着我gitee上暑假期间那稀疏的提交,我就知道我又摸了一个暑假的鱼。
|
暑假下定决心要好好的学一学,可是看着我gitee上暑假期间那稀疏的提交,我就知道我又摸了一个暑假的鱼。
|
||||||

|

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

|

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

|

|
||||||
|
|
||||||
## 展望
|
## 展望
|
||||||
|
|
||||||
BIN
YaeBlog/source/posts/2022-final/2022-12-30-14-26-19-QQ_Image_1672381538441.jpg
LFS
Normal file
BIN
YaeBlog/source/posts/2022-final/2022-12-30-14-26-19-QQ_Image_1672381538441.jpg
LFS
Normal file
Binary file not shown.
BIN
YaeBlog/source/posts/2022-final/2022-12-30-14-28-12-QQ_Image_1672381543836.jpg
LFS
Normal file
BIN
YaeBlog/source/posts/2022-final/2022-12-30-14-28-12-QQ_Image_1672381543836.jpg
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 @@ tags:
|
|||||||
- 下定决定要参加下一学期的物理竞赛,但是在听了讲座之后直接决定开学再开始学习,~~我知道我在家没法学习,俗称开摆~~
|
- 下定决定要参加下一学期的物理竞赛,但是在听了讲座之后直接决定开学再开始学习,~~我知道我在家没法学习,俗称开摆~~
|
||||||
- 又捡起了`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
LFS
Normal file
BIN
YaeBlog/source/posts/2022-summer-vacation/result1.png
LFS
Normal file
Binary file not shown.
@@ -1,12 +1,10 @@
|
|||||||
---
|
---
|
||||||
title: 2023年年终总结
|
title: 2023年年终总结
|
||||||
date: 2024-02-29T20:18:19.0000000
|
|
||||||
tags:
|
tags:
|
||||||
- 杂谈
|
- 随笔
|
||||||
- 年终总结
|
date: 2024-2-29 20:18:19
|
||||||
---
|
---
|
||||||
|
|
||||||
|
|
||||||
虽然2023年已经过去了两个月,但是年终总结还是要发的。
|
虽然2023年已经过去了两个月,但是年终总结还是要发的。
|
||||||
|
|
||||||
<!--more-->
|
<!--more-->
|
||||||
@@ -45,7 +43,7 @@ tags:
|
|||||||
|
|
||||||
2023年最令我吃惊的事情是我刷B站的时长:
|
2023年最令我吃惊的事情是我刷B站的时长:
|
||||||
|
|
||||||

|

|
||||||
|
|
||||||
容易计算得出,我一共看了64天的B站,接近六分之一的时间都在看。虽然我确实有着在干活的时候黑听B站和把B站当作音乐播放器的习惯,但是这个时间未免有点太长了。下一年一定要在这个方面做出一定的改变,将更多的时间放在看书上面去,~~虽然写这句话的时候我就在黑听B站~~。
|
容易计算得出,我一共看了64天的B站,接近六分之一的时间都在看。虽然我确实有着在干活的时候黑听B站和把B站当作音乐播放器的习惯,但是这个时间未免有点太长了。下一年一定要在这个方面做出一定的改变,将更多的时间放在看书上面去,~~虽然写这句话的时候我就在黑听B站~~。
|
||||||
|
|
||||||
BIN
YaeBlog/source/posts/2023-final/image-20240303165826486.png
LFS
Normal file
BIN
YaeBlog/source/posts/2023-final/image-20240303165826486.png
LFS
Normal file
Binary file not shown.
|
Before Width: | Height: | Size: 55 KiB After Width: | Height: | Size: 55 KiB |
@@ -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 @@ tags:
|
|||||||
|
|
||||||
而且采用 `Git`还有一个好处,采用 `Github`的 `Insight`功能可以轻松的看出大家的贡献值()。
|
而且采用 `Git`还有一个好处,采用 `Github`的 `Insight`功能可以轻松的看出大家的贡献值()。
|
||||||
|
|
||||||

|

|
||||||
|
|
||||||
## 一些技术上的收获
|
## 一些技术上的收获
|
||||||
|
|
||||||
BIN
YaeBlog/source/posts/big-homework/1.png
LFS
Normal file
BIN
YaeBlog/source/posts/big-homework/1.png
LFS
Normal file
Binary file not shown.
@@ -1,12 +1,12 @@
|
|||||||
---
|
---
|
||||||
title: 建立博客过程的记录
|
title: 建立博客过程的记录
|
||||||
date: 2022-04-08T11:52:32.0000000
|
typora-root-url: 建立博客过程的记录
|
||||||
|
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
LFS
Normal file
BIN
YaeBlog/source/posts/build-blog-record/1.png
LFS
Normal file
Binary file not shown.
BIN
YaeBlog/source/posts/build-blog-record/2.png
LFS
Normal file
BIN
YaeBlog/source/posts/build-blog-record/2.png
LFS
Normal file
Binary file not shown.
@@ -7,7 +7,6 @@ tags:
|
|||||||
---
|
---
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
我们编译是这样的,在本平台上编译只要敲三条命令就好了,而交叉编译要考虑的就很多了。
|
我们编译是这样的,在本平台上编译只要敲三条命令就好了,而交叉编译要考虑的就很多了。
|
||||||
|
|
||||||
<!--more-->
|
<!--more-->
|
||||||
@@ -46,7 +45,7 @@ tags:
|
|||||||
|
|
||||||
通常一份GNU工具链只能针对一个平台进行编译,但是LLVM工具链是一套先天的交叉编译工具链,例如对于`llc`工具,使用`llc --version`命令可以看见该编译器可以生成多种目标平台上的汇编代码:
|
通常一份GNU工具链只能针对一个平台进行编译,但是LLVM工具链是一套先天的交叉编译工具链,例如对于`llc`工具,使用`llc --version`命令可以看见该编译器可以生成多种目标平台上的汇编代码:
|
||||||
|
|
||||||

|

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

|

|
||||||
|
|
||||||
看样子交叉编译也不是开箱即用的。最开始我们猜想系统提供的LLVM工具链没有被配置为交叉编译,因此尝试在本地自行编译一套LLVM工具链。
|
看样子交叉编译也不是开箱即用的。最开始我们猜想系统提供的LLVM工具链没有被配置为交叉编译,因此尝试在本地自行编译一套LLVM工具链。
|
||||||
|
|
||||||
@@ -82,7 +81,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工具链宣称自己是原生支持交叉编译的,但是没人宣称说标准库和头文件是原生的。这里我们就需要一个根文件系统来提供这些头文件和各种库文件。
|
||||||
|
|
||||||
@@ -199,7 +198,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`,重新编译上面的你好世界样例。编译之后可以正常执行。
|
||||||
|
|
||||||
@@ -230,4 +229,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
LFS
Normal file
BIN
YaeBlog/source/posts/build-dotnet-from-source/image-20240824120646587.png
LFS
Normal file
Binary file not shown.
BIN
YaeBlog/source/posts/build-dotnet-from-source/image-20240824121425007.png
LFS
Normal file
BIN
YaeBlog/source/posts/build-dotnet-from-source/image-20240824121425007.png
LFS
Normal file
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