File tree Expand file tree Collapse file tree 5 files changed +114
-0
lines changed
Expand file tree Collapse file tree 5 files changed +114
-0
lines changed Original file line number Diff line number Diff line change @@ -48,9 +48,33 @@ public override void Configure()
4848public class AppConfig
4949{
5050 public static AppConfig Instance { get ; } = new ( ) ;
51+ public string Title { get ; set ; }
5152 public string LocalBaseUrl { get ; set ; }
5253 public string PublicBaseUrl { get ; set ; }
5354 public string ? GitPagesBaseUrl { get ; set ; }
55+ public string ? GitPagesRawBaseUrl { get ; set ; }
56+
57+ public void Init ( IVirtualDirectory contentDir )
58+ {
59+ ResolveGitBlobBaseUrls ( contentDir ) ;
60+ }
61+
62+ public void ResolveGitBlobBaseUrls ( IVirtualDirectory contentDir )
63+ {
64+ var srcDir = new DirectoryInfo ( contentDir . RealPath ) ;
65+ var gitConfig = new FileInfo ( Path . Combine ( srcDir . Parent ! . FullName , ".git" , "config" ) ) ;
66+ if ( gitConfig . Exists )
67+ {
68+ var txt = gitConfig . ReadAllText ( ) ;
69+ var pos = txt . IndexOf ( "url = " , StringComparison . Ordinal ) ;
70+ if ( pos >= 0 )
71+ {
72+ var url = txt [ ( pos + "url = " . Length ) ..] . LeftPart ( ".git" ) . LeftPart ( '\n ' ) . Trim ( ) ;
73+ GitPagesBaseUrl = url . CombineWith ( $ "blob/main/{ srcDir . Name } ") ;
74+ GitPagesRawBaseUrl = url . Replace ( "github.com" , "raw.githubusercontent.com" ) . CombineWith ( $ "refs/heads/main/{ srcDir . Name } ") ;
75+ }
76+ }
77+ }
5478}
5579
5680public static class HtmlHelpers
Original file line number Diff line number Diff line change @@ -51,6 +51,7 @@ public void Configure(IWebHostBuilder builder) => builder
5151 videos . LoadFrom ( "_videos" ) ;
5252 blogPosts . LoadFrom ( "_posts" ) ;
5353 podcasts . LoadFrom ( "_podcasts" ) ;
54+ AppConfig . Instance . Init ( appHost . ContentRootDirectory ) ;
5455 } ,
5556 afterAppHostInit : appHost =>
5657 {
Original file line number Diff line number Diff line change 1+ @page " /llms.txt"
2+ @inject MarkdownPages Markdown
3+ @inject MarkdownBlog Blog
4+ @inject AppConfig Config
5+ @attribute [RenderStatic]
6+ @{
7+ Layout = " " ;
8+ Response .ContentType = " text/plain" ;
9+ }
10+ # @Config.Title
11+
12+ ## Docs
13+ @if (Blog .VisiblePosts .Count > 0 )
14+ {
15+ <text >
16+ Blog posts :
17+ </text >
18+ foreach (var post in Blog .VisiblePosts )
19+ {
20+ <text > - [@Html .Raw (post .Title )](@(Config .GitPagesRawBaseUrl .CombineWith ($" _posts/" ).CombineWith (post .FileName )))
21+ </text >
22+ }
23+ }
24+ @foreach ( var entry in Markdown .Sidebars .OrderBy (x => x .Key ))
25+ {
26+ @foreach ( var sidebar in entry .Value )
27+ {
28+ <text >
29+ @( sidebar .Text )
30+ </text >
31+ foreach (var item in sidebar .Children .Safe ().Where (x => x .Text != null && x .Link != null ))
32+ {
33+ var page = Markdown ! .GetBySlug (item .Link );
34+ var suffix = ! string .IsNullOrEmpty (page ? .Title ) && item .Text != page .Title ? $" : {page .Title }" : " " ;
35+ <text > - [@item .Text ](@(Config .GitPagesRawBaseUrl .CombineWith ($" _pages/" ).CombineWith (item .Link .LeftPart ('#' ) + " .md" )))@Html.Raw(suffix)
36+ </text >
37+ }
38+ }
39+ }
Original file line number Diff line number Diff line change 1+ @page " /llms-full.txt"
2+ @inject MarkdownPages Markdown
3+ @inject MarkdownBlog Blog
4+ @inject AppConfig Config
5+ @attribute [RenderStatic]
6+ @{
7+ Layout = " " ;
8+ Response .ContentType = " text/plain" ;
9+ }
10+ @foreach ( var post in Blog .VisiblePosts .OrderByDescending (x => x .Date ))
11+ {
12+ if (post ? .Content == null ) continue ;
13+ var content = post .Content .Trim ();
14+ if (content .StartsWith (" ---" ))
15+ {
16+ content = content .Substring (3 ).RightPart (" ---" ).Trim ();
17+ }
18+ <text ># @Html.Raw(post.Title)
19+ Source : @Config.PublicBaseUrl.CombineWith( $" posts/{post .Slug }" )
20+
21+ @( Html .Raw (content ))
22+
23+
24+ </text >
25+ }
26+ @foreach ( var entry in Markdown .Sidebars .OrderBy (x => x .Key ))
27+ {
28+ @foreach ( var sidebar in entry .Value )
29+ {
30+ foreach (var item in sidebar .Children .Safe ().Where (x => x .Text != null && x .Link != null ))
31+ {
32+ var page = Markdown ! .GetBySlug (item .Link );
33+ if (page ? .Content == null ) continue ;
34+ var content = page .Content .Trim ();
35+ if (content .StartsWith (" ---" ))
36+ {
37+ content = content .Substring (3 ).RightPart (" ---" ).Trim ();
38+ }
39+
40+ <text ># @( page .Title )
41+ Source : @Config.PublicBaseUrl.CombineWith(item.Link)
42+
43+ @( Html .Raw (content ))
44+
45+
46+ </text >
47+ }
48+ }
49+ }
Original file line number Diff line number Diff line change 77 },
88 "AllowedHosts" : " *" ,
99 "AppConfig" : {
10+ "Title" : " ServiceStack" ,
1011 "LocalBaseUrl" : " https://localhost:5002" ,
1112 "PublicBaseUrl" : " https://servicestack.net"
1213 }
You can’t perform that action at this time.
0 commit comments