fix: not watching hidden files when triggering hot reload.
All checks were successful
Build blog docker image / Build-Blog-Image (push) Successful in 1m37s
All checks were successful
Build blog docker image / Build-Blog-Image (push) Successful in 1m37s
Fix incorrect page count calculation.
This commit is contained in:
@@ -39,6 +39,11 @@
|
||||
{
|
||||
_page = Page ?? 1;
|
||||
_pageCount = Contents.Count / EssaysPerPage + 1;
|
||||
(_pageCount, int reminder) = int.DivRem(Contents.Count, EssaysPerPage);
|
||||
if (reminder > 0)
|
||||
{
|
||||
_pageCount += 1;
|
||||
}
|
||||
|
||||
if (EssaysPerPage * _page > Contents.Count + EssaysPerPage)
|
||||
{
|
||||
|
@@ -16,11 +16,11 @@ public sealed class BlogHotReloadService(
|
||||
|
||||
await rendererService.RenderAsync(true);
|
||||
|
||||
Task[] reloadTasks = [FileWatchTask(stoppingToken)];
|
||||
Task[] reloadTasks = [WatchFileAsync(stoppingToken)];
|
||||
await Task.WhenAll(reloadTasks);
|
||||
}
|
||||
|
||||
private async Task FileWatchTask(CancellationToken token)
|
||||
private async Task WatchFileAsync(CancellationToken token)
|
||||
{
|
||||
while (!token.IsCancellationRequested)
|
||||
{
|
||||
@@ -33,6 +33,15 @@ public sealed class BlogHotReloadService(
|
||||
break;
|
||||
}
|
||||
|
||||
FileInfo changeFileInfo = new(changeFile);
|
||||
|
||||
if (changeFileInfo.Name.StartsWith('.'))
|
||||
{
|
||||
// Ignore dot-started file and directory.
|
||||
logger.LogDebug("Ignore hidden file: {}.", changeFile);
|
||||
continue;
|
||||
}
|
||||
|
||||
logger.LogInformation("{} changed, re-rendering.", changeFile);
|
||||
essayContentService.Clear();
|
||||
await rendererService.RenderAsync(true);
|
||||
|
@@ -109,6 +109,12 @@ public partial class EssayScanService : IEssayScanService
|
||||
{
|
||||
foreach (BlogResult blog in fileContents)
|
||||
{
|
||||
if (blog.BlogContent.Length < 4)
|
||||
{
|
||||
// Even not contains a legal header.
|
||||
continue;
|
||||
}
|
||||
|
||||
int endPos = blog.BlogContent.IndexOf("---", 4, StringComparison.Ordinal);
|
||||
if (!blog.BlogContent.StartsWith("---") || endPos is -1 or 0)
|
||||
{
|
||||
@@ -121,14 +127,14 @@ public partial class EssayScanService : IEssayScanService
|
||||
try
|
||||
{
|
||||
MarkdownMetadata metadata = _yamlDeserializer.Deserialize<MarkdownMetadata>(metadataString);
|
||||
_logger.LogDebug("Scan metadata title: '{}' for {}.", metadata.Title, blog.BlogFile.Name);
|
||||
_logger.LogDebug("Scan metadata title: '{title}' for {name}.", metadata.Title, blog.BlogFile.Name);
|
||||
|
||||
contents.Add(new BlogContent(blog.BlogFile, metadata, blog.BlogContent[(endPos + 3)..], isDraft,
|
||||
blog.Images, blog.NotFoundImages));
|
||||
}
|
||||
catch (YamlException e)
|
||||
{
|
||||
_logger.LogWarning("Failed to parser metadata from {} due to {}, skipping", blog.BlogFile.Name, e);
|
||||
_logger.LogWarning("Failed to parser metadata from {name} due to {exception}, skipping", blog.BlogFile.Name, e);
|
||||
}
|
||||
}
|
||||
});
|
||||
|
Reference in New Issue
Block a user