@@ -52,6 +52,7 @@ public void Configure(IWebHostBuilder builder) => builder
52
52
pages . LoadFrom ( "_pages" ) ;
53
53
videos . LoadFrom ( "_videos" ) ;
54
54
AppConfig . Instance . GitPagesBaseUrl ??= ResolveGitBlobBaseUrl ( appHost . ContentRootDirectory ) ;
55
+ AppConfig . Instance . GitPagesRawBaseUrl ??= ResolveGitRawBlobBaseUrl ( appHost . ContentRootDirectory ) ;
55
56
} ,
56
57
afterAppHostInit : appHost =>
57
58
{
@@ -95,14 +96,34 @@ public void Configure(IWebHostBuilder builder) => builder
95
96
}
96
97
return null ;
97
98
}
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
+ }
98
117
}
99
118
100
119
public class AppConfig
101
120
{
102
121
public static AppConfig Instance { get ; } = new ( ) ;
122
+ public string Title { get ; set ; }
103
123
public string LocalBaseUrl { get ; set ; }
104
124
public string PublicBaseUrl { get ; set ; }
105
125
public string ? GitPagesBaseUrl { get ; set ; }
126
+ public string ? GitPagesRawBaseUrl { get ; set ; }
106
127
}
107
128
108
129
// Add additional frontmatter info to include
0 commit comments