Skip to content

Commit

Permalink
Merge branch 'dev'
Browse files Browse the repository at this point in the history
  • Loading branch information
niltor committed Apr 11, 2024
2 parents 14b64b9 + ae6f692 commit b3dfee9
Show file tree
Hide file tree
Showing 5 changed files with 50 additions and 63 deletions.
13 changes: 2 additions & 11 deletions WebApp/data/blogs.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,18 +6,9 @@
"Title": "introduction",
"Path": "/introduction.html",
"FileName": "introduction.md",
"PublishTime": "2024-04-01T10:48:51+08:00",
"PublishTime": "2024-04-07T14:07:45+08:00",
"CreatedTime": "2024-03-20T11:51:35+08:00",
"UpdatedTime": "2024-04-01T10:48:51+08:00",
"Catalog": null
},
{
"Title": "Markdown支持示例",
"Path": "/Markdown%E6%94%AF%E6%8C%81%E7%A4%BA%E4%BE%8B.html",
"FileName": "Markdown支持示例.md",
"PublishTime": "2024-04-01T16:49:23+08:00",
"CreatedTime": "2024-04-01T14:45:14+08:00",
"UpdatedTime": "2024-04-01T16:49:23+08:00",
"UpdatedTime": "2024-04-07T14:07:45+08:00",
"Catalog": null
}
],
Expand Down
20 changes: 4 additions & 16 deletions WebApp/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -34,26 +34,14 @@
<div class="px-3 bg-white dark:bg-neutral-900" id="blogList">
<!-- 博客卡片内容 -->
<div class="w-100 rounded overflow-hidden shadow-lg dark:bg-neutral-800 my-2">
<div class="px-6 py-3">
<div class="font-bold text-xl mb-2">
<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>
</div>
<p class="text-neutral-700 text-base dark:text-neutral-300">
👨‍💻 NilTor
&nbsp;&nbsp;
⏱️ <span class="publish-time" data-time="2024-04-01T16:49:23+08:00"></span>
</p>
</div>
</div>
<div class="w-100 rounded overflow-hidden shadow-lg dark:bg-neutral-800 my-2">
<div class="px-6 py-3">
<div class="font-bold text-xl mb-2">
<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>
</div>
<p class="text-neutral-700 text-base dark:text-neutral-300">
👨‍💻 NilTor
&nbsp;&nbsp;
⏱️ <span class="publish-time" data-time="2024-04-01T10:48:51+08:00"></span>
⏱️ <span class="publish-time" data-time="2024-04-07T14:07:45+08:00"></span>
</p>
</div>
</div>
Expand All @@ -66,16 +54,16 @@
<div id="catalog-list" class="rounded-lg shadow-md p-4 dark:bg-neutral-800">
<div class="text-xl font-semibold dark:text-neutral-300">分类</div>
<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">
全部 [2]
全部 [1]
</span>
</div>
<div id="date-list" class="rounded-lg shadow-md p-4 dark:bg-neutral-800 mt-2">
<div class="text-xl font-semibold dark:text-neutral-300">存档</div>
<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">
全部 [2]
全部 [1]
</span>
<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">
2024-04 [2]
2024-04 [1]
</span>
</div>

Expand Down
8 changes: 1 addition & 7 deletions WebApp/sitemap.xml
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,7 @@
<urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9">
<url>
<loc>https://aterdev.github.io/EasyBlog/blogs/introduction.html</loc>
<lastmod>2024-04-01</lastmod>
<changefreq>daily</changefreq>
<priority>0.9</priority>
</url>
<url>
<loc>https://aterdev.github.io/EasyBlog/blogs/Markdown%E6%94%AF%E6%8C%81%E7%A4%BA%E4%BE%8B.html</loc>
<lastmod>2024-04-01</lastmod>
<lastmod>2024-04-07</lastmod>
<changefreq>daily</changefreq>
<priority>0.9</priority>
</url>
Expand Down
40 changes: 22 additions & 18 deletions src/BuildSite/HtmlBuilder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -82,11 +82,13 @@ public void BuildBlogs()
List<string> otherFiles = Directory.EnumerateFiles(ContentPath, "*", SearchOption.AllDirectories)
.Where(f => !f.EndsWith(".md"))
.ToList();
try

foreach (var file in files)
{
foreach (var file in files)
try
{
string markdown = File.ReadAllText(file);

string html = Markdown.ToHtml(markdown, pipeline);
string relativePath = file.Replace(ContentPath, Path.Combine(Output, "blogs")).Replace(".md", ".html");

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

File.WriteAllText(relativePath, html, Encoding.UTF8);
}
Console.WriteLine("✅ generate blog html!");

foreach (var file in otherFiles)
catch (Exception e)
{
string relativePath = file.Replace(ContentPath, Path.Combine(Output, "blogs"));
string? dir = Path.GetDirectoryName(relativePath);

if (!Directory.Exists(dir))
{
Directory.CreateDirectory(dir!);
}

File.Copy(file, relativePath, true);
Console.WriteLine($"❌ parse markdown error: {file}" + e.Message + e.StackTrace);
}
Console.WriteLine("✅ copy blog other files!");

}
catch (Exception e)
Console.WriteLine("✅ generate blog html!");

foreach (var file in otherFiles)
{
Console.WriteLine("HtmlBuilder:BuildBlogs:" + e.Message);
throw;
string relativePath = file.Replace(ContentPath, Path.Combine(Output, "blogs"));
string? dir = Path.GetDirectoryName(relativePath);

if (!Directory.Exists(dir))
{
Directory.CreateDirectory(dir!);
}

File.Copy(file, relativePath, true);
}
Console.WriteLine("✅ copy blog other files!");


}

/// <summary>
Expand Down
32 changes: 21 additions & 11 deletions src/BuildSite/MarkdownExtension/BetterCodeBlockRenderer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ public BetterCodeBlockRenderer(CodeBlockRenderer underlyingRenderer)

protected override void Write(HtmlRenderer renderer, CodeBlock obj)
{
if (obj is not FencedCodeBlock fencedCodeBlock || obj.Parser is not FencedCodeBlockParser parser)
if (obj is not FencedCodeBlock fencedCodeBlock || obj.Parser is not FencedCodeBlockParser parser || obj is null)
{
_underlyingRenderer.Write(renderer, obj);

Check warning on line 21 in src/BuildSite/MarkdownExtension/BetterCodeBlockRenderer.cs

View workflow job for this annotation

GitHub Actions / deploy

Possible null reference argument for parameter 'obj' in 'void MarkdownObjectRenderer<HtmlRenderer, CodeBlock>.Write(RendererBase renderer, MarkdownObject obj)'.
return;
Expand All @@ -29,22 +29,32 @@ protected override void Write(HtmlRenderer renderer, CodeBlock obj)
return;
}

var code = GetCode(obj).Trim();
var code = GetCode(obj)?.Trim();

var formatter = new HtmlClassFormatter();

var html = formatter.GetHtmlString(code, language);
renderer.WriteLine(html);
if (code != null)
{
var formatter = new HtmlClassFormatter();
var html = formatter.GetHtmlString(code, language);
renderer.WriteLine(html);
return;
}
_underlyingRenderer.Write(renderer, obj);
return;
}

private static string GetCode(LeafBlock obj)

private static string? GetCode(LeafBlock obj)
{
var str = new StringBuilder();
foreach (var line in obj.Lines.Lines)
if (obj.Lines.Count > 0)
{
if (!string.IsNullOrWhiteSpace(line.Slice.ToString().Trim()))
str.AppendLine(line.Slice.ToString());
foreach (var line in obj.Lines.Lines)
{
if (!string.IsNullOrWhiteSpace(line.Slice.ToString().Trim()))
str.AppendLine(line.Slice.ToString());
}
return str.ToString();
}
return str.ToString();
return null;
}
}

0 comments on commit b3dfee9

Please sign in to comment.