Skip to content

Commit fb9109d

Browse files
committed
feat: Enhance PostPageGenerator to use relative path resolution for asset copying
1 parent 1cb1c85 commit fb9109d

File tree

2 files changed

+20
-10
lines changed

2 files changed

+20
-10
lines changed

src/Blog/PostPage/PostPageGenerator.Template.cs

Lines changed: 16 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ private async Task<IFile> ResolveTemplateFileAsync(
5555
/// <summary>
5656
/// Recursively copy all assets from template folder to output folder.
5757
/// Excludes template file itself to avoid duplication.
58-
/// Preserves folder structure using OwlCore.Storage recursive operations.
58+
/// Preserves folder structure using relative path resolution.
5959
/// </summary>
6060
/// <param name="templateFolder">Source template folder</param>
6161
/// <param name="outputFolder">Destination output folder</param>
@@ -71,18 +71,26 @@ private async Task CopyTemplateAssetsAsync(
7171
// Gap #7 resolution: Filter files and exclude template file by ID comparison
7272
await foreach (var item in recursiveFolder.GetItemsAsync(StorableType.File))
7373
{
74-
if (item is not IFile file)
74+
if (item is not IChildFile file)
7575
continue;
7676

7777
// Exclude the template file itself
7878
if (file.Id == templateFile.Id)
7979
continue;
8080

81-
// Copy asset to output folder (overwrite silently per Gap #6)
82-
if (outputFolder is IModifiableFolder modifiableOutput)
83-
{
84-
await modifiableOutput.CreateCopyOfAsync(file, overwrite: true);
85-
}
81+
// Get relative path from template folder to file (preserves folder structure)
82+
var relativePath = await templateFolder.GetRelativePathToAsync(file);
83+
84+
// Create file at relative path in output folder (creates necessary parent folders)
85+
var targetStorable = await outputFolder.CreateByRelativePathAsync(relativePath, StorableType.File, overwrite: true);
86+
87+
if (targetStorable is not IFile targetFile)
88+
throw new InvalidOperationException($"Created item at '{relativePath}' is not a file.");
89+
90+
// Copy file content
91+
using var sourceStream = await file.OpenReadAsync();
92+
using var targetStream = await targetFile.OpenStreamAsync(FileAccess.Write);
93+
await sourceStream.CopyToAsync(targetStream);
8694
}
8795
}
8896

@@ -116,4 +124,4 @@ private async Task<string> RenderTemplateAsync(
116124
return html;
117125
}
118126
}
119-
}
127+
}

src/Program.cs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
using OwlCore.Diagnostics;
1+
using OwlCore.Diagnostics;
22
using WindowsAppCommunity.CommandLine;
33
using System.CommandLine;
44
using OwlCore.Nomad.Kubo;
@@ -8,6 +8,7 @@
88
using WindowsAppCommunity.CommandLine.User;
99
using WindowsAppCommunity.CommandLine.Project;
1010
using WindowsAppCommunity.CommandLine.Publisher;
11+
using WindowsAppCommunity.CommandLine.Blog;
1112

1213
// Logging
1314
var startTime = DateTime.Now;
@@ -85,5 +86,6 @@ void Logger_MessageReceived(object? sender, LoggerMessageEventArgs e)
8586
rootCommand.AddCommand(new WacsdkUserCommands(config, repoOption));
8687
rootCommand.AddCommand(new WacsdkProjectCommands(config, repoOption));
8788
rootCommand.AddCommand(new WacsdkPublisherCommands(config, repoOption));
89+
rootCommand.AddCommand(new WacsdkBlogCommands());
8890

89-
await rootCommand.InvokeAsync(args);
91+
await rootCommand.InvokeAsync(args);

0 commit comments

Comments
 (0)