-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
The website uses BlazeKit's SSG capabilities
- Loading branch information
Showing
64 changed files
with
9,493 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
{ | ||
// Use IntelliSense to learn about possible attributes. | ||
// Hover to view descriptions of existing attributes. | ||
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387 | ||
"version": "0.2.0", | ||
"configurations": [] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
<Project Sdk="Microsoft.NET.Sdk"> | ||
|
||
<PropertyGroup> | ||
<TargetFramework>net8.0</TargetFramework> | ||
<ImplicitUsings>enable</ImplicitUsings> | ||
<Nullable>enable</Nullable> | ||
</PropertyGroup> | ||
|
||
</Project> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,84 @@ | ||
using System.Text.Json; | ||
|
||
namespace BlazeKit.Hydration; | ||
public class DataHydrationContext | ||
{ | ||
private bool initalized = false; | ||
public DataHydrationContext(Func<Task<string>> loadData = null) | ||
{ | ||
_hydrationData = new Dictionary<string, object>(); | ||
this.loadData = loadData; | ||
} | ||
|
||
private Dictionary<string, object> _hydrationData; | ||
private readonly Func<Task<string>> loadData; | ||
|
||
public void Add(string key, object value) | ||
{ | ||
if(_hydrationData.ContainsKey(key)) { | ||
_hydrationData[key] = value; | ||
} else { | ||
_hydrationData.Add(key, value); | ||
} | ||
} | ||
|
||
public async Task<T> GetAsync<T>(string key, T defaultValue) | ||
{ | ||
var result = defaultValue; | ||
if(OperatingSystem.IsBrowser()) { | ||
await LoadData(); | ||
} | ||
|
||
if(_hydrationData.TryGetValue(key, out var tmpValue)) { | ||
var deserialzed = JsonSerializer.Deserialize<T>(((JsonElement)tmpValue).GetRawText()); | ||
result = deserialzed; | ||
} | ||
return result; | ||
} | ||
|
||
public bool TryGet<T>(string key, out T value) | ||
{ | ||
if(OperatingSystem.IsBrowser() && !initalized) { | ||
LoadData(); | ||
} | ||
value = default; | ||
if(_hydrationData.TryGetValue(key, out var tmpValue)) { | ||
// check if tmpValue is of type T | ||
if(tmpValue is T) { | ||
value = (T)tmpValue; | ||
return true; | ||
} else { | ||
value = default; | ||
return false; | ||
} | ||
} else { | ||
return false; | ||
} | ||
} | ||
|
||
public string Serialized() { | ||
return System.Text.Json.JsonSerializer.Serialize(_hydrationData); | ||
} | ||
|
||
private async Task<bool> LoadData() { | ||
// check if initalized if not hydrate data from dom | ||
Console.WriteLine("Loading page data"); | ||
var data = System.Text.Json.JsonSerializer.Deserialize<Dictionary<string,object>>(await loadData()); | ||
foreach(var item in data) { | ||
if(_hydrationData.ContainsKey(item.Key)) { | ||
_hydrationData[item.Key] = item.Value; | ||
} else { | ||
_hydrationData.Add(item.Key, item.Value); | ||
} | ||
} | ||
// if(!initalized) { | ||
// var data = System.Text.Json.JsonSerializer.Deserialize<Dictionary<string,object>>(await loadData()); | ||
// foreach(var item in data) { | ||
// _hydrationData.Add(item.Key, item.Value); | ||
// } | ||
// initalized = true; | ||
// } | ||
|
||
return true; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
<Project Sdk="Microsoft.NET.Sdk.Web"> | ||
<PropertyGroup> | ||
<OutputType>Exe</OutputType> | ||
<TargetFramework>net8.0</TargetFramework> | ||
<ImplicitUsings>enable</ImplicitUsings> | ||
<Nullable>enable</Nullable> | ||
<EmitCompilerGeneratedFiles>true</EmitCompilerGeneratedFiles> | ||
<CompilerGeneratedFilesOutputPath>.blazekit</CompilerGeneratedFilesOutputPath> | ||
<!-- <PublishDir>.blazekit/build/tmp</PublishDir> --> | ||
</PropertyGroup> | ||
|
||
<ItemGroup> | ||
<PackageReference Include="Microsoft.AspNetCore.Components.WebAssembly.Server" Version="8.0.1" /> | ||
<!-- <ProjectReference Include="..\BlazeKit.Site\BlazeKit.Site.csproj" PrivateAssets="all" /> --> | ||
<ProjectReference Include="..\BlazeKit.Static\BlazeKit.Static.csproj" /> | ||
<ProjectReference Include="..\BlazeKit.Website\BlazeKit.Website.csproj" /> | ||
<!-- <ProjectReference Include="..\BlazeKit\BlazeKit.csproj" OutputItemType="Analyzer" ReferenceOutputAssembly="false" /> --> | ||
</ItemGroup> | ||
|
||
<Target Name="CustomActionsAfterPublish" AfterTargets="AfterPublish"> | ||
<PropertyGroup> | ||
<SourceFolder>$(PublishDir)wwwroot</SourceFolder> | ||
<DestinationFolder>$(PublishDir)..\ssg</DestinationFolder> | ||
</PropertyGroup> | ||
<ItemGroup> | ||
<FilesToCopy Include="$([MSBuild]::EnsureTrailingSlash('$(SourceFolder)'))**\*.*"/> | ||
</ItemGroup> | ||
<MakeDir Directories="$(PublishDir)..\ssg" /> | ||
<Message Text="Copying files from $(SourceFolder) to $(DestinationFolder)" Importance="high" /> | ||
<Copy SourceFiles="@(FilesToCopy)" DestinationFolder="$([MSBuild]::EnsureTrailingSlash('$(DestinationFolder)'))%(RecursiveDir)"/> | ||
|
||
<Exec Command="$(PublishDir)$(AssemblyName).$(OutputType) ssg" /> | ||
</Target> | ||
|
||
</Project> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
// See https://aka.ms/new-console-template for more information | ||
|
||
using BlazeKit.Website; | ||
|
||
if (args.Count() > 0 && args[0] == "ssg") { | ||
Console.WriteLine("Building Static Site"); | ||
new BlazeKit.Static.StaticSiteGenerator( | ||
".blazekit/build/ssg", | ||
".blazekit/build/tmp/wwwroot", | ||
typeof(BlazeKit.Website.Index).Assembly | ||
).Build(); | ||
Console.WriteLine("Static Site Built"); | ||
return; | ||
} | ||
|
||
var builder = WebApplication.CreateBuilder(args); | ||
|
||
// Add services to the container. | ||
builder.Services.AddRazorComponents().AddInteractiveWebAssemblyComponents(); | ||
|
||
var app = builder.Build(); | ||
app.UseRouting(); | ||
// Configure the HTTP request pipeline. | ||
if (!app.Environment.IsDevelopment()) | ||
{ | ||
app.UseExceptionHandler("/Error", createScopeForErrors: true); | ||
// The default HSTS value is 30 days. You may want to change this for production scenarios, see https://aka.ms/aspnetcore-hsts. | ||
app.UseHsts(); | ||
} else { | ||
// app.UseWebAssemblyDebugging(); | ||
} | ||
// app.UseBlazorFrameworkFiles(); | ||
|
||
app.UseHttpsRedirection(); | ||
|
||
app.UseStaticFiles(); | ||
app.UseAntiforgery(); | ||
|
||
app.MapRazorComponents<BlazeKit.Website.Index>().AddInteractiveWebAssemblyRenderMode(); | ||
|
||
app.Run(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
<Project Sdk="Microsoft.NET.Sdk"> | ||
|
||
<PropertyGroup> | ||
<TargetFramework>net8.0</TargetFramework> | ||
<ImplicitUsings>enable</ImplicitUsings> | ||
<Nullable>enable</Nullable> | ||
</PropertyGroup> | ||
<ItemGroup> | ||
<PackageReference Include="Microsoft.AspNetCore.Components" Version="8.0.0" /> | ||
<PackageReference Include="Microsoft.AspNetCore.Components.Web" Version="8.0.0" /> | ||
<PackageReference Include="Microsoft.Extensions.Logging" Version="8.0.0" /> | ||
</ItemGroup> | ||
<ItemGroup> | ||
<ProjectReference Include="..\BlazeKit.Hydration\BlazeKit.Hydration.csproj" /> | ||
</ItemGroup> | ||
</Project> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,105 @@ | ||
using Microsoft.AspNetCore.Components; | ||
using Microsoft.AspNetCore.Components.RenderTree; | ||
using Microsoft.AspNetCore.Components.Web; | ||
using Microsoft.AspNetCore.Components.Web.HtmlRendering; | ||
using Microsoft.Extensions.DependencyInjection; | ||
using Microsoft.Extensions.Logging; | ||
|
||
namespace BlazeKit.Static; | ||
#pragma warning disable BL0006 // Do not use RenderTree types | ||
|
||
public sealed class BlazorRenderer : Renderer | ||
{ | ||
private readonly Lazy<HtmlRenderer> htmlRenderer; | ||
|
||
public BlazorRenderer(ServiceProvider serviceProvider) : this( | ||
() => | ||
new HtmlRenderer( | ||
serviceProvider, | ||
serviceProvider.GetRequiredService<ILoggerFactory>() | ||
), | ||
serviceProvider | ||
) | ||
{ } | ||
|
||
public BlazorRenderer(HtmlRenderer htmlRenderer,ServiceProvider serviceProvider) :this( | ||
() => htmlRenderer, | ||
serviceProvider | ||
) | ||
{ } | ||
|
||
public BlazorRenderer(Func<HtmlRenderer> htmlRenderer,ServiceProvider serviceProvider) : base(serviceProvider, serviceProvider.GetRequiredService<ILoggerFactory>()) | ||
{ | ||
this.htmlRenderer = new Lazy<HtmlRenderer>(htmlRenderer); | ||
} | ||
|
||
public override Dispatcher Dispatcher => this.htmlRenderer.Value.Dispatcher; | ||
|
||
|
||
/// <summary> | ||
/// Renders a component T which doesn't require any parameters | ||
/// </summary> | ||
/// <typeparam name="T"></typeparam> | ||
public Task<string> RenderComponent<T>() where T : IComponent | ||
=> RenderComponent<T>(ParameterView.Empty); | ||
|
||
/// <summary> | ||
/// Renders a component T using the provided dictionary of parameters | ||
/// </summary> | ||
/// <typeparam name="T"></typeparam> | ||
/// <param name="dictionary"></param> | ||
public Task<string> RenderComponent<T>(Dictionary<string, object?> dictionary) where T : IComponent | ||
=> RenderComponent<T>(ParameterView.FromDictionary(dictionary)); | ||
|
||
/// <summary> | ||
/// Renders a component T using the provided parameters | ||
/// </summary> | ||
/// <param name="componentType"></param> | ||
public Task<string> RenderComponent(Type componentType) | ||
=> RenderComponent(componentType, ParameterView.Empty); | ||
|
||
/// <summary> | ||
/// Renders a component T using the provided dictionary of parameters | ||
/// </summary> | ||
/// <param name="componentType"></param> | ||
/// <param name="dictionary"></param> | ||
public Task<string> RenderComponent(Type componentType, Dictionary<string, object?> dictionary) | ||
=> RenderComponent(componentType, ParameterView.FromDictionary(dictionary)); | ||
|
||
protected override void HandleException(Exception exception) | ||
{ | ||
throw new NotImplementedException(); | ||
} | ||
|
||
protected override Task UpdateDisplayAsync(in RenderBatch renderBatch) | ||
{ | ||
throw new NotImplementedException(); | ||
} | ||
|
||
|
||
private Task<string> RenderComponent<T>(ParameterView parameters) where T : IComponent | ||
{ | ||
// Use the default dispatcher to invoke actions in the context of the | ||
// static HTML renderer and return as a string | ||
return htmlRenderer.Value.Dispatcher.InvokeAsync(async () => | ||
{ | ||
HtmlRootComponent output = await htmlRenderer.Value.RenderComponentAsync<T>(parameters); | ||
return output.ToHtmlString(); | ||
}); | ||
} | ||
|
||
private Task<string> RenderComponent(Type componentType, ParameterView parameters) | ||
{ | ||
// Use the default dispatcher to invoke actions in the context of the | ||
// static HTML renderer and return as a string | ||
return htmlRenderer.Value.Dispatcher.InvokeAsync(async () => | ||
{ | ||
HtmlRootComponent output = await htmlRenderer.Value.RenderComponentAsync(componentType, parameters); | ||
return output.ToHtmlString(); | ||
}); | ||
} | ||
|
||
|
||
} | ||
#pragma warning restore BL0006 // Do not use RenderTree types | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
using System.Diagnostics.CodeAnalysis; | ||
using Microsoft.JSInterop; | ||
|
||
namespace BlazeKit.Static; | ||
public sealed class FkJsRuntime : IJSRuntime | ||
{ | ||
public ValueTask<TValue> InvokeAsync<[DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.PublicConstructors | DynamicallyAccessedMemberTypes.PublicFields | DynamicallyAccessedMemberTypes.PublicProperties)] TValue>(string identifier, object?[]? args) | ||
{ | ||
throw new NotSupportedException("Javascript Runtime is not valid in Static Site Generation"); | ||
} | ||
|
||
public ValueTask<TValue> InvokeAsync<[DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.PublicConstructors | DynamicallyAccessedMemberTypes.PublicFields | DynamicallyAccessedMemberTypes.PublicProperties)] TValue>(string identifier, CancellationToken cancellationToken, object?[]? args) | ||
{ | ||
throw new NotSupportedException("Javascript Runtime is not valid in Static Site Generation"); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
using Microsoft.AspNetCore.Components.Routing; | ||
|
||
namespace BlazeKit.Static; | ||
|
||
public sealed class FkNavigationInterception : INavigationInterception | ||
{ | ||
public Task EnableNavigationInterceptionAsync() | ||
{ | ||
return Task.CompletedTask; | ||
} | ||
} | ||
|
||
public class FkScrollToLocationHash : IScrollToLocationHash | ||
{ | ||
public Task RefreshScrollPositionForHash(string locationAbsolute) | ||
{ | ||
return Task.CompletedTask; | ||
} | ||
} |
Oops, something went wrong.