@@ -30,8 +30,8 @@ public sealed class StaticSiteGenerator(
3030 IPluginRunner pluginRunner ,
3131 IThemeService themeService ,
3232 IComponentRenderer renderer ,
33- IAppPaths paths ,
34- IFileSystem fileSystem ,
33+ IAppPaths paths ,
34+ IFileSystem fileSystem ,
3535 SiteManifest options ,
3636 ILogger < StaticSiteGenerator > logger ) : IStaticSiteGenerator
3737{
@@ -69,39 +69,9 @@ public async Task BuildAsync<TMainLayout, TIndexView, TPostView, TPageView, TNot
6969 var notFoundDocument = documents . SingleOrDefault ( d => d . Kind == ContentKind . Page && string . Equals ( d . Metadata . Slug , PAGE_NOT_FOUND_SLUG , StringComparison . OrdinalIgnoreCase ) ) ;
7070 await RenderNotFoundAsync < TNotFoundView > ( notFoundDocument , plugins , theme , destination , layoutType , cancellationToken ) ;
7171
72- foreach ( var document in documents )
72+ foreach ( var document in documents . Where ( d => IsNotFoundPage ( d ) == false ) )
7373 {
74- cancellationToken . ThrowIfCancellationRequested ( ) ;
75-
76- if ( document . Kind == ContentKind . Page && string . Equals ( document . Metadata . Slug , PAGE_NOT_FOUND_SLUG , StringComparison . OrdinalIgnoreCase ) )
77- {
78- continue ;
79- }
80-
81- var preProcessed = await _pluginRunner . RunPreMarkdownAsync ( document , cancellationToken ) ;
82- var html = await _markdownService . ToHtmlAsync ( preProcessed . Markdown , cancellationToken : cancellationToken ) ;
83- preProcessed . Html = html ;
84- var postMarkdown = await _pluginRunner . RunPostMarkdownAsync ( preProcessed , cancellationToken ) ;
85-
86- var parameters = new Dictionary < string , object ? >
87- {
88- [ "Document" ] = postMarkdown ,
89- [ "Plugins" ] = plugins ,
90- [ "Theme" ] = theme ,
91- [ "Site" ] = _options
92- } ;
93-
94- var rendered = postMarkdown . Kind switch
95- {
96- ContentKind . Page => await _renderer . RenderAsync < TPageView > ( layoutType , parameters , cancellationToken ) ,
97- _ => await _renderer . RenderAsync < TPostView > ( layoutType , parameters , cancellationToken )
98- } ;
99-
100- var finalHtml = await _pluginRunner . RunPostHtmlAsync ( rendered , postMarkdown , cancellationToken ) ;
101- var outputPath = ResolveOutputPath ( destination , postMarkdown . Metadata . Slug ) ;
102- _fileSystem . Directory . CreateDirectory ( _fileSystem . Path . GetDirectoryName ( outputPath ) ! ) ;
103- await _fileSystem . File . WriteAllTextAsync ( outputPath , finalHtml , Encoding . UTF8 , cancellationToken ) ;
104- _logger . LogInformation ( "Wrote {OutputPath}" , outputPath ) ;
74+ await RenderDocumentAsync < TPostView , TPageView > ( document , plugins , theme , destination , layoutType , cancellationToken ) ;
10575 }
10676
10777 CopyContentAssets ( destination ) ;
@@ -190,6 +160,44 @@ private async Task RenderNotFoundAsync<TNotFoundView>(ContentDocument? notFoundD
190160 _logger . LogInformation ( "Wrote {OutputPath}" , outputPath ) ;
191161 }
192162
163+ private async Task RenderDocumentAsync < TPostView , TPageView > ( ContentDocument document , IEnumerable < PluginManifest > plugins , ThemeManifest theme , string destination , Type layoutType , CancellationToken cancellationToken )
164+ where TPostView : ScissorHands . Theme . PostViewBase
165+ where TPageView : ScissorHands . Theme . PageViewBase
166+ {
167+ cancellationToken . ThrowIfCancellationRequested ( ) ;
168+
169+ var preProcessed = await _pluginRunner . RunPreMarkdownAsync ( document , cancellationToken ) ;
170+ var html = await _markdownService . ToHtmlAsync ( preProcessed . Markdown , cancellationToken : cancellationToken ) ;
171+ preProcessed . Html = html ;
172+ var postMarkdown = await _pluginRunner . RunPostMarkdownAsync ( preProcessed , cancellationToken ) ;
173+
174+ var parameters = new Dictionary < string , object ? >
175+ {
176+ [ "Document" ] = postMarkdown ,
177+ [ "Plugins" ] = plugins ,
178+ [ "Theme" ] = theme ,
179+ [ "Site" ] = _options
180+ } ;
181+
182+ var rendered = postMarkdown . Kind switch
183+ {
184+ ContentKind . Page => await _renderer . RenderAsync < TPageView > ( layoutType , parameters , cancellationToken ) ,
185+ _ => await _renderer . RenderAsync < TPostView > ( layoutType , parameters , cancellationToken )
186+ } ;
187+
188+ var finalHtml = await _pluginRunner . RunPostHtmlAsync ( rendered , postMarkdown , cancellationToken ) ;
189+ var outputPath = ResolveOutputPath ( destination , postMarkdown . Metadata . Slug ) ;
190+ _fileSystem . Directory . CreateDirectory ( _fileSystem . Path . GetDirectoryName ( outputPath ) ! ) ;
191+ await _fileSystem . File . WriteAllTextAsync ( outputPath , finalHtml , Encoding . UTF8 , cancellationToken ) ;
192+ _logger . LogInformation ( "Wrote {OutputPath}" , outputPath ) ;
193+ }
194+
195+ private static bool IsNotFoundPage ( ContentDocument document )
196+ {
197+ return document . Kind == ContentKind . Page &&
198+ string . Equals ( document . Metadata . Slug , PAGE_NOT_FOUND_SLUG , StringComparison . OrdinalIgnoreCase ) == true ;
199+ }
200+
193201 private static string ResolveOutputPath ( string root , string slug )
194202 {
195203 if ( string . IsNullOrWhiteSpace ( slug ) )
0 commit comments