Skip to content

Commit

Permalink
feat(SSG): Update debug output and file writing logic
Browse files Browse the repository at this point in the history
- Updated the debug output in the GenerateStaticSiteCommand.cs file to use Markdown syntax for better readability.
- Modified the logic for writing files in the GenerateStaticSiteCommand.cs file to truncate existing files rather than byte-level overwrites.
  • Loading branch information
SakuraIsayeki committed Aug 5, 2023
1 parent 6602e7e commit 7b906fd
Showing 1 changed file with 6 additions and 13 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -96,12 +96,12 @@ await AnsiConsole.Status().StartAsync("Generating static assets.", async ctx =>
if (settings.DebugMode)
{
AnsiConsole.Console.MarkupLine(/*lang=markdown*/$"[grey]Ignoring folders:[/] {string.Join("[grey], [/]", settings.IgnoredFolders ?? new[] { "*None*" })}");
AnsiConsole.Console.MarkupLine(/*lang=markdown*/$"[grey]Ignoring files:[/] {string.Join("[grey], [/]", settings.IgnoredFiles ?? new[] { "*None*" })}");
AnsiConsole.Console.MarkupLine(/*lang=md*/$"[grey]Ignoring folders:[/] {string.Join("[grey], [/]", settings.IgnoredFolders ?? new[] { "*None*" })}");
AnsiConsole.Console.MarkupLine(/*lang=md*/$"[grey]Ignoring files:[/] {string.Join("[grey], [/]", settings.IgnoredFiles ?? new[] { "*None*" })}");
AnsiConsole.Console.MarkupLine(settings.OutputPath is null
? /*lang=markdown*/$"[grey]Output path defaulted to current directory: [/]{Environment.CurrentDirectory}"
: /*lang=markdown*/$"[grey]Output path set: [/]{settings.OutputPath}"
? /*lang=md*/$"[grey]Output path defaulted to current directory: [/]{Environment.CurrentDirectory}"
: /*lang=md*/$"[grey]Output path set: [/]{settings.OutputPath}"
);
}
Expand All @@ -116,19 +116,12 @@ await AnsiConsole.Status().StartAsync("Generating static assets.", async ctx =>
}
List<InfoDataPair> fileData = await StaticSiteGenerator.CreateOutputFilesAsync(settings.OutputPath!.ToString(), pathFilePair);
// foreach((FileInfo file, byte[] data) in fileData)
// {
// await WriteDataAsync(file, data);
// }
await Task.WhenAll(fileData.Select(WriteDataAsync));
}
AnsiConsole.Console.MarkupLine(/*lang=markdown*/$"Wrote manifest to [green link]{settings.OutputPath}[/].");
AnsiConsole.Console.MarkupLine(/*lang=md*/$"Wrote static files to [green link]{settings.OutputPath}[/].");
});


return 0;
}

Expand All @@ -138,7 +131,7 @@ private static async Task WriteDataAsync(InfoDataPair pair)
{
pair.FileInfo.Directory.Create();
}
await using FileStream stream = pair.FileInfo.Open(FileMode.OpenOrCreate, FileAccess.Write);
await using FileStream stream = pair.FileInfo.Open(FileMode.Create, FileAccess.Write);
await stream.WriteAsync(pair.FileData);
await stream.FlushAsync();

Expand Down

0 comments on commit 7b906fd

Please sign in to comment.