fix: styles of title and subtitles.

This commit is contained in:
2024-07-28 14:03:54 +08:00
parent d1fa453952
commit 56a0cc2e9b
32 changed files with 45 additions and 186 deletions

View File

@@ -1,6 +1,7 @@
using System.Collections.Concurrent;
using System.Diagnostics;
using System.Text;
using System.Text.RegularExpressions;
using Markdig;
using Microsoft.Extensions.Logging;
using YaeBlog.Core.Abstractions;
@@ -11,7 +12,7 @@ using YamlDotNet.Serialization;
namespace YaeBlog.Core.Services;
public class RendererService(ILogger<RendererService> logger,
public partial class RendererService(ILogger<RendererService> logger,
EssayScanService essayScanService,
MarkdownPipeline markdownPipeline,
IDeserializer yamlDeserializer,
@@ -172,30 +173,34 @@ public class RendererService(ILogger<RendererService> logger,
}
}
[GeneratedRegex(@"(?<!\\)[^\#\*_\-\+\`{}\[\]!~]+")]
private static partial Regex DescriptionPattern();
private string GetDescription(BlogContent content)
{
const string delimiter = "<!--more-->";
int pos = content.FileContent.IndexOf(delimiter, StringComparison.Ordinal);
StringBuilder builder = new();
bool breakSentence = false;
if (pos == -1)
{
// 自动截取前50个字符
pos = content.FileContent.Length < 50 ? content.FileContent.Length : 50;
breakSentence = true;
}
for (int i = 0; i < pos; i++)
string rawContent = content.FileContent[..pos];
MatchCollection matches = DescriptionPattern().Matches(rawContent);
StringBuilder builder = new();
foreach (Match match in matches)
{
char c = content.FileContent[i];
builder.Append(match.Value);
}
if (char.IsControl(c) || char.IsSymbol(c) ||
char.IsSeparator(c) || char.IsPunctuation(c) ||
char.IsAsciiLetter(c))
{
continue;
}
builder.Append(c);
if (breakSentence)
{
builder.Append("……");
}
string description = builder.ToString();