@@ -52,6 +52,7 @@ public void Configure(IWebHostBuilder builder) => builder
5252 pages . LoadFrom ( "_pages" ) ;
5353 videos . LoadFrom ( "_videos" ) ;
5454 AppConfig . Instance . GitPagesBaseUrl ??= ResolveGitBlobBaseUrl ( appHost . ContentRootDirectory ) ;
55+ AppConfig . Instance . GitPagesRawBaseUrl ??= ResolveGitRawBlobBaseUrl ( appHost . ContentRootDirectory ) ;
5556 } ,
5657 afterAppHostInit : appHost =>
5758 {
@@ -95,14 +96,34 @@ public void Configure(IWebHostBuilder builder) => builder
9596 }
9697 return null ;
9798 }
99+
100+ private string ? ResolveGitRawBlobBaseUrl ( IVirtualDirectory contentDir )
101+ {
102+ var srcDir = new DirectoryInfo ( contentDir . RealPath ) ;
103+ var gitConfig = new FileInfo ( Path . Combine ( srcDir . Parent ! . FullName , ".git" , "config" ) ) ;
104+ if ( gitConfig . Exists )
105+ {
106+ var txt = gitConfig . ReadAllText ( ) ;
107+ var pos = txt . IndexOf ( "url = " , StringComparison . Ordinal ) ;
108+ if ( pos >= 0 )
109+ {
110+ var url = txt [ ( pos + "url = " . Length ) ..] . LeftPart ( ".git" ) . LeftPart ( '\n ' ) . Trim ( ) ;
111+ var gitBaseUrl = url . Replace ( "github.com" , "raw.githubusercontent.com" ) . CombineWith ( $ "refs/heads/main/{ srcDir . Name } ") ;
112+ return gitBaseUrl ;
113+ }
114+ }
115+ return null ;
116+ }
98117}
99118
100119public class AppConfig
101120{
102121 public static AppConfig Instance { get ; } = new ( ) ;
122+ public string Title { get ; set ; }
103123 public string LocalBaseUrl { get ; set ; }
104124 public string PublicBaseUrl { get ; set ; }
105125 public string ? GitPagesBaseUrl { get ; set ; }
126+ public string ? GitPagesRawBaseUrl { get ; set ; }
106127}
107128
108129// Add additional frontmatter info to include
0 commit comments