Skip to content

Commit b3dfee9

Browse files
committed
Merge branch 'dev'
2 parents 14b64b9 + ae6f692 commit b3dfee9

File tree

5 files changed

+50
-63
lines changed

5 files changed

+50
-63
lines changed

WebApp/data/blogs.json

Lines changed: 2 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -6,18 +6,9 @@
66
"Title": "introduction",
77
"Path": "/introduction.html",
88
"FileName": "introduction.md",
9-
"PublishTime": "2024-04-01T10:48:51+08:00",
9+
"PublishTime": "2024-04-07T14:07:45+08:00",
1010
"CreatedTime": "2024-03-20T11:51:35+08:00",
11-
"UpdatedTime": "2024-04-01T10:48:51+08:00",
12-
"Catalog": null
13-
},
14-
{
15-
"Title": "Markdown支持示例",
16-
"Path": "/Markdown%E6%94%AF%E6%8C%81%E7%A4%BA%E4%BE%8B.html",
17-
"FileName": "Markdown支持示例.md",
18-
"PublishTime": "2024-04-01T16:49:23+08:00",
19-
"CreatedTime": "2024-04-01T14:45:14+08:00",
20-
"UpdatedTime": "2024-04-01T16:49:23+08:00",
11+
"UpdatedTime": "2024-04-07T14:07:45+08:00",
2112
"Catalog": null
2213
}
2314
],

WebApp/index.html

Lines changed: 4 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -34,26 +34,14 @@
3434
<div class="px-3 bg-white dark:bg-neutral-900" id="blogList">
3535
<!-- 博客卡片内容 -->
3636
<div class="w-100 rounded overflow-hidden shadow-lg dark:bg-neutral-800 my-2">
37-
<div class="px-6 py-3">
38-
<div class="font-bold text-xl mb-2">
39-
<a href = "/blogs/Markdown%E6%94%AF%E6%8C%81%E7%A4%BA%E4%BE%8B.html" target="_blank" class="block text-lg py-2 text-neutral-600 hover:text-neutral-800 dark:text-neutral-300 dark:hover:text-neutral-100">📑 Markdown支持示例</a>
40-
</div>
41-
<p class="text-neutral-700 text-base dark:text-neutral-300">
42-
👨‍💻 NilTor
43-
&nbsp;&nbsp;
44-
⏱️ <span class="publish-time" data-time="2024-04-01T16:49:23+08:00"></span>
45-
</p>
46-
</div>
47-
</div>
48-
<div class="w-100 rounded overflow-hidden shadow-lg dark:bg-neutral-800 my-2">
4937
<div class="px-6 py-3">
5038
<div class="font-bold text-xl mb-2">
5139
<a href = "/blogs/introduction.html" target="_blank" class="block text-lg py-2 text-neutral-600 hover:text-neutral-800 dark:text-neutral-300 dark:hover:text-neutral-100">📑 introduction</a>
5240
</div>
5341
<p class="text-neutral-700 text-base dark:text-neutral-300">
5442
👨‍💻 NilTor
5543
&nbsp;&nbsp;
56-
⏱️ <span class="publish-time" data-time="2024-04-01T10:48:51+08:00"></span>
44+
⏱️ <span class="publish-time" data-time="2024-04-07T14:07:45+08:00"></span>
5745
</p>
5846
</div>
5947
</div>
@@ -66,16 +54,16 @@
6654
<div id="catalog-list" class="rounded-lg shadow-md p-4 dark:bg-neutral-800">
6755
<div class="text-xl font-semibold dark:text-neutral-300">分类</div>
6856
<span data-catalog="all" class="filter-item text-lg block py-2 text-neutral-600 hover:text-neutral-800 dark:text-neutral-300 dark:hover:text-neutral-100">
69-
全部 [2]
57+
全部 [1]
7058
</span>
7159
</div>
7260
<div id="date-list" class="rounded-lg shadow-md p-4 dark:bg-neutral-800 mt-2">
7361
<div class="text-xl font-semibold dark:text-neutral-300">存档</div>
7462
<span data-date="all" class="filter-item text-lg block py-2 text-neutral-600 hover:text-neutral-800 dark:text-neutral-300 dark:hover:text-neutral-100">
75-
全部 [2]
63+
全部 [1]
7664
</span>
7765
<span data-date="2024-04" class="filter-item text-lg block py-2 text-neutral-600 hover:text-neutral-800 dark:text-neutral-300 dark:hover:text-neutral-100">
78-
2024-04 [2]
66+
2024-04 [1]
7967
</span>
8068
</div>
8169

WebApp/sitemap.xml

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,7 @@
22
<urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9">
33
<url>
44
<loc>https://aterdev.github.io/EasyBlog/blogs/introduction.html</loc>
5-
<lastmod>2024-04-01</lastmod>
6-
<changefreq>daily</changefreq>
7-
<priority>0.9</priority>
8-
</url>
9-
<url>
10-
<loc>https://aterdev.github.io/EasyBlog/blogs/Markdown%E6%94%AF%E6%8C%81%E7%A4%BA%E4%BE%8B.html</loc>
11-
<lastmod>2024-04-01</lastmod>
5+
<lastmod>2024-04-07</lastmod>
126
<changefreq>daily</changefreq>
137
<priority>0.9</priority>
148
</url>

src/BuildSite/HtmlBuilder.cs

Lines changed: 22 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -82,11 +82,13 @@ public void BuildBlogs()
8282
List<string> otherFiles = Directory.EnumerateFiles(ContentPath, "*", SearchOption.AllDirectories)
8383
.Where(f => !f.EndsWith(".md"))
8484
.ToList();
85-
try
85+
86+
foreach (var file in files)
8687
{
87-
foreach (var file in files)
88+
try
8889
{
8990
string markdown = File.ReadAllText(file);
91+
9092
string html = Markdown.ToHtml(markdown, pipeline);
9193
string relativePath = file.Replace(ContentPath, Path.Combine(Output, "blogs")).Replace(".md", ".html");
9294

@@ -102,27 +104,29 @@ public void BuildBlogs()
102104

103105
File.WriteAllText(relativePath, html, Encoding.UTF8);
104106
}
105-
Console.WriteLine("✅ generate blog html!");
106-
107-
foreach (var file in otherFiles)
107+
catch (Exception e)
108108
{
109-
string relativePath = file.Replace(ContentPath, Path.Combine(Output, "blogs"));
110-
string? dir = Path.GetDirectoryName(relativePath);
111-
112-
if (!Directory.Exists(dir))
113-
{
114-
Directory.CreateDirectory(dir!);
115-
}
116-
117-
File.Copy(file, relativePath, true);
109+
Console.WriteLine($"❌ parse markdown error: {file}" + e.Message + e.StackTrace);
118110
}
119-
Console.WriteLine("✅ copy blog other files!");
111+
120112
}
121-
catch (Exception e)
113+
Console.WriteLine("✅ generate blog html!");
114+
115+
foreach (var file in otherFiles)
122116
{
123-
Console.WriteLine("HtmlBuilder:BuildBlogs:" + e.Message);
124-
throw;
117+
string relativePath = file.Replace(ContentPath, Path.Combine(Output, "blogs"));
118+
string? dir = Path.GetDirectoryName(relativePath);
119+
120+
if (!Directory.Exists(dir))
121+
{
122+
Directory.CreateDirectory(dir!);
123+
}
124+
125+
File.Copy(file, relativePath, true);
125126
}
127+
Console.WriteLine("✅ copy blog other files!");
128+
129+
126130
}
127131

128132
/// <summary>

src/BuildSite/MarkdownExtension/BetterCodeBlockRenderer.cs

Lines changed: 21 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ public BetterCodeBlockRenderer(CodeBlockRenderer underlyingRenderer)
1616

1717
protected override void Write(HtmlRenderer renderer, CodeBlock obj)
1818
{
19-
if (obj is not FencedCodeBlock fencedCodeBlock || obj.Parser is not FencedCodeBlockParser parser)
19+
if (obj is not FencedCodeBlock fencedCodeBlock || obj.Parser is not FencedCodeBlockParser parser || obj is null)
2020
{
2121
_underlyingRenderer.Write(renderer, obj);
2222
return;
@@ -29,22 +29,32 @@ protected override void Write(HtmlRenderer renderer, CodeBlock obj)
2929
return;
3030
}
3131

32-
var code = GetCode(obj).Trim();
32+
var code = GetCode(obj)?.Trim();
3333

34-
var formatter = new HtmlClassFormatter();
35-
36-
var html = formatter.GetHtmlString(code, language);
37-
renderer.WriteLine(html);
34+
if (code != null)
35+
{
36+
var formatter = new HtmlClassFormatter();
37+
var html = formatter.GetHtmlString(code, language);
38+
renderer.WriteLine(html);
39+
return;
40+
}
41+
_underlyingRenderer.Write(renderer, obj);
42+
return;
3843
}
3944

40-
private static string GetCode(LeafBlock obj)
45+
46+
private static string? GetCode(LeafBlock obj)
4147
{
4248
var str = new StringBuilder();
43-
foreach (var line in obj.Lines.Lines)
49+
if (obj.Lines.Count > 0)
4450
{
45-
if (!string.IsNullOrWhiteSpace(line.Slice.ToString().Trim()))
46-
str.AppendLine(line.Slice.ToString());
51+
foreach (var line in obj.Lines.Lines)
52+
{
53+
if (!string.IsNullOrWhiteSpace(line.Slice.ToString().Trim()))
54+
str.AppendLine(line.Slice.ToString());
55+
}
56+
return str.ToString();
4757
}
48-
return str.ToString();
58+
return null;
4959
}
5060
}

0 commit comments

Comments
 (0)