@@ -7,11 +7,10 @@ namespace MyApp;
77public class ConfigureSsg : IHostingStartup
88{
99 public void Configure ( IWebHostBuilder builder ) => builder
10- . ConfigureServices ( ( context , services ) =>
10+ . ConfigureServices ( services =>
1111 {
12- context . Configuration . GetSection ( nameof ( AppConfig ) ) . Bind ( AppConfig . Instance ) ;
13- services . AddSingleton ( AppConfig . Instance ) ;
1412 services . AddSingleton < RazorPagesEngine > ( ) ;
13+ services . AddSingleton < MarkdownIncludes > ( ) ;
1514 services . AddSingleton < MarkdownPages > ( ) ;
1615 services . AddSingleton < MarkdownVideos > ( ) ;
1716 services . AddSingleton < MarkdownBlog > ( ) ;
@@ -21,58 +20,60 @@ public void Configure(IWebHostBuilder builder) => builder
2120 appHost => appHost . Plugins . Add ( new CleanUrlsFeature ( ) ) ,
2221 afterPluginsLoaded : appHost =>
2322 {
23+ MarkdigConfig . Set ( new MarkdigConfig
24+ {
25+ ConfigurePipeline = pipeline =>
26+ {
27+ // Extend Markdig Pipeline
28+ } ,
29+ ConfigureContainers = config =>
30+ {
31+ config . AddBuiltInContainers ( ) ;
32+ // Add Custom Block or Inline containers
33+ }
34+ } ) ;
35+
36+ var includes = appHost . Resolve < MarkdownIncludes > ( ) ;
2437 var pages = appHost . Resolve < MarkdownPages > ( ) ;
2538 var videos = appHost . Resolve < MarkdownVideos > ( ) ;
2639 var blogPosts = appHost . Resolve < MarkdownBlog > ( ) ;
2740 var meta = appHost . Resolve < MarkdownMeta > ( ) ;
28-
29- meta . Features = new ( ) { pages , videos , blogPosts } ;
30- meta . Features . ForEach ( x => x . VirtualFiles = appHost . VirtualFiles ) ;
31-
32- blogPosts . Authors = AppConfig . Instance . Authors ;
3341
42+ //blogPosts.Authors = BlogConfig.Instance.Authors;
43+ meta . Features = [ pages , videos , blogPosts ] ;
44+
45+ includes . LoadFrom ( "_includes" ) ;
3446 pages . LoadFrom ( "_pages" ) ;
3547 videos . LoadFrom ( "_videos" ) ;
3648 blogPosts . LoadFrom ( "_posts" ) ;
49+ AppConfig . Instance . Init ( appHost . ContentRootDirectory ) ;
3750 } ,
3851 afterAppHostInit : appHost =>
3952 {
4053 // prerender with: `$ npm run prerender`
4154 AppTasks . Register ( "prerender" , args =>
4255 {
43- var baseUrl = RazorSsg . GetBaseUrl ( ) ?? "https://localhost:5002" ;
4456 appHost . Resolve < MarkdownMeta > ( ) . RenderToAsync (
4557 metaDir : appHost . ContentRootDirectory . RealPath . CombineWith ( "wwwroot/meta" ) ,
46- baseUrl : baseUrl ) . GetAwaiter ( ) . GetResult ( ) ;
58+ baseUrl : HtmlHelpers . ToAbsoluteContentUrl ( "" ) ) . GetAwaiter ( ) . GetResult ( ) ;
4759
4860 var distDir = appHost . ContentRootDirectory . RealPath . CombineWith ( "dist" ) ;
4961 if ( Directory . Exists ( distDir ) )
5062 FileSystemVirtualFiles . DeleteDirectory ( distDir ) ;
5163 FileSystemVirtualFiles . CopyAll (
5264 new DirectoryInfo ( appHost . ContentRootDirectory . RealPath . CombineWith ( "wwwroot" ) ) ,
5365 new DirectoryInfo ( distDir ) ) ;
66+
67+ // Render .html redirect files
68+ RazorSsg . PrerenderRedirectsAsync ( appHost . ContentRootDirectory . GetFile ( "redirects.json" ) , distDir )
69+ . GetAwaiter ( ) . GetResult ( ) ;
70+
5471 var razorFiles = appHost . VirtualFiles . GetAllMatchingFiles ( "*.cshtml" ) ;
5572 RazorSsg . PrerenderAsync ( appHost , razorFiles , distDir ) . GetAwaiter ( ) . GetResult ( ) ;
5673 } ) ;
5774 } ) ;
5875}
5976
60- public class AppConfig
61- {
62- public static AppConfig Instance { get ; } = new ( ) ;
63- public string LocalBaseUrl { get ; set ; }
64- public string PublicBaseUrl { get ; set ; }
65- public string ? GitPagesBaseUrl { get ; set ; }
66- public string ? SiteTwitter { get ; set ; }
67- public List < AuthorInfo > Authors { get ; set ; } = new ( ) ;
68- public string ? BlogTitle { get ; set ; }
69- public string ? BlogDescription { get ; set ; }
70- public string ? BlogEmail { get ; set ; }
71- public string ? CopyrightOwner { get ; set ; }
72- public string ? BlogImageUrl { get ; set ; }
73- }
74-
75-
7677// Add additional frontmatter info to include
7778public class MarkdownFileInfo : MarkdownFileBase
7879{
0 commit comments