Skip to content

Commit 341a543

Browse files
committed
Upgrade to latest .NET 10 razor-ssg + latest posts/templates
1 parent 7e62c0d commit 341a543

134 files changed

Lines changed: 34405 additions & 20013 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

.github/workflows/build.yml

Lines changed: 16 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -10,19 +10,21 @@ on:
1010

1111
jobs:
1212
build:
13-
runs-on: ubuntu-22.04
13+
runs-on: ubuntu-latest
1414
steps:
1515
- name: checkout
16-
uses: actions/checkout@v2.0.0
16+
uses: actions/checkout@v5
1717

1818
- name: setup .net core
19-
uses: actions/setup-dotnet@v1.7.2
19+
uses: actions/setup-dotnet@v5
2020
with:
21-
dotnet-version: 6.0.100
21+
dotnet-version: 10.0.x
2222

2323
- name: build
2424
working-directory: ./MyApp
25-
run: dotnet build .
25+
run: |
26+
dotnet --info
27+
dotnet build .
2628
2729
- name: Assign default GitHub URL base path
2830
env:
@@ -45,6 +47,12 @@ jobs:
4547
fi
4648
fi
4749
50+
- name: Install tailwindcss
51+
run: |
52+
mkdir -p /home/runner/.local/bin
53+
curl -o "/home/runner/.local/bin/tailwindcss" -L "https://github.com/tailwindlabs/tailwindcss/releases/latest/download/tailwindcss-linux-x64"
54+
chmod +x /home/runner/.local/bin/tailwindcss
55+
4856
- name: Build tailwind
4957
working-directory: ./MyApp
5058
run: |
@@ -54,14 +62,13 @@ jobs:
5462
working-directory: ./MyApp
5563
run: |
5664
site_base_href=${{ env.ssg_base_href }}
57-
site_base_url="https://${{ env.custom_domain }}"
5865
if [ ! -z "$site_base_href" ]
5966
then
6067
echo "Prerendering for deployment to $site_base_href"
61-
dotnet run --AppTasks=prerender --environment Production --BaseHref "$site_base_href"
68+
dotnet run --no-launch-profile --AppTasks=prerender --configuration Release --environment Production --BaseHref "$site_base_href"
6269
else
63-
echo "Prerendering for deployment to $custom_domain"
64-
dotnet run --AppTasks=prerender --environment Production --BaseUrl "$site_base_url"
70+
echo "Prerendering for deployment to $(cat ./wwwroot/CNAME)"
71+
dotnet run --no-launch-profile --AppTasks=prerender --configuration Release --environment Production
6572
fi
6673
6774
# Deploy UI to GitHub Pages

MyApp.sln

Lines changed: 0 additions & 25 deletions
This file was deleted.

MyApp.slnx

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
<Solution>
2+
<Project Path="MyApp/MyApp.csproj" />
3+
</Solution>

MyApp/Configure.AppHost.cs

Lines changed: 50 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,66 @@
1-
[assembly: HostingStartup(typeof(MyApp.AppHost))]
1+
using Microsoft.AspNetCore.Mvc.Rendering;
2+
using ServiceStack.IO;
3+
4+
[assembly: HostingStartup(typeof(MyApp.AppHost))]
25

36
namespace MyApp;
47

5-
public class AppHost : AppHostBase, IHostingStartup
8+
public class AppHost() : AppHostBase("MyApp"), IHostingStartup
69
{
710
public void Configure(IWebHostBuilder builder) => builder
8-
.ConfigureServices(services => {
11+
.ConfigureServices((context,services) => {
912
// Configure ASP.NET Core IOC Dependencies
13+
context.Configuration.GetSection(nameof(AppConfig)).Bind(AppConfig.Instance);
14+
services.AddSingleton(AppConfig.Instance);
1015
});
16+
}
1117

12-
public AppHost() : base("MyApp", typeof(MyServices).Assembly) {}
18+
public class AppConfig
19+
{
20+
public static AppConfig Instance { get; } = new();
21+
public string Title { get; set; }
22+
public string LocalBaseUrl { get; set; }
23+
public string PublicBaseUrl { get; set; }
24+
public string? GitPagesBaseUrl { get; set; }
25+
public string? GitPagesRawBaseUrl { get; set; }
26+
27+
public void Init(IVirtualDirectory contentDir)
28+
{
29+
ResolveGitBlobBaseUrls(contentDir);
30+
}
1331

14-
public override void Configure(Funq.Container container)
32+
public void ResolveGitBlobBaseUrls(IVirtualDirectory contentDir)
1533
{
34+
var srcDir = new DirectoryInfo(contentDir.RealPath);
35+
var gitConfig = new FileInfo(Path.Combine(srcDir.Parent!.FullName, ".git", "config"));
36+
if (gitConfig.Exists)
37+
{
38+
var txt = gitConfig.ReadAllText();
39+
var pos = txt.IndexOf("url = ", StringComparison.Ordinal);
40+
if (pos >= 0)
41+
{
42+
var url = txt[(pos + "url = ".Length)..].LeftPart(".git").LeftPart('\n').Trim();
43+
GitPagesBaseUrl = url.CombineWith($"blob/main/{srcDir.Name}");
44+
GitPagesRawBaseUrl = url.Replace("github.com","raw.githubusercontent.com").CombineWith($"refs/heads/main/{srcDir.Name}");
45+
}
46+
}
1647
}
1748
}
1849

19-
public class Hello : IReturn<StringResponse> {}
50+
public static class HtmlHelpers
51+
{
52+
public static string ToAbsoluteContentUrl(string? relativePath) => HostContext.DebugMode
53+
? AppConfig.Instance.LocalBaseUrl.CombineWith(relativePath)
54+
: AppConfig.Instance.PublicBaseUrl.CombineWith(relativePath);
55+
public static string ToAbsoluteApiUrl(string? relativePath) => HostContext.DebugMode
56+
? AppConfig.Instance.LocalBaseUrl.CombineWith(relativePath)
57+
: AppConfig.Instance.PublicBaseUrl.CombineWith(relativePath);
58+
59+
public static string ContentUrl(this IHtmlHelper html, string? relativePath) => ToAbsoluteContentUrl(relativePath);
60+
public static string ApiUrl(this IHtmlHelper html, string? relativePath) => ToAbsoluteApiUrl(relativePath);
61+
}
62+
63+
public class Hello : IGet, IReturn<StringResponse> {}
2064
public class MyServices : Service
2165
{
2266
public object Any(Hello request) => new StringResponse { Result = $"Hello, World!" };

MyApp/Configure.Ssg.cs

Lines changed: 27 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,10 @@ namespace MyApp;
77
public 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
7778
public class MarkdownFileInfo : MarkdownFileBase
7879
{

0 commit comments

Comments
 (0)