-
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.
- Loading branch information
Showing
69 changed files
with
1,235 additions
and
453 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
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
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
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,36 @@ | ||
using Microsoft.AspNetCore.Http; | ||
using Microsoft.AspNetCore.Http.Features; | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
using System.Security.Claims; | ||
using System.Text; | ||
using System.Threading.Tasks; | ||
|
||
namespace BlazeKit.Static | ||
{ | ||
internal class FkHttpContext : HttpContext | ||
{ | ||
public override IFeatureCollection Features => throw new NotImplementedException(); | ||
|
||
public override HttpRequest Request => throw new NotImplementedException(); | ||
|
||
public override HttpResponse Response => new FkHttpResponse(this); | ||
|
||
public override ConnectionInfo Connection => throw new NotImplementedException(); | ||
|
||
public override WebSocketManager WebSockets => throw new NotImplementedException(); | ||
|
||
public override ClaimsPrincipal User { get => throw new NotImplementedException(); set => throw new NotImplementedException(); } | ||
public override IDictionary<object, object?> Items { get => throw new NotImplementedException(); set => throw new NotImplementedException(); } | ||
public override IServiceProvider RequestServices { get => throw new NotImplementedException(); set => throw new NotImplementedException(); } | ||
public override CancellationToken RequestAborted { get => throw new NotImplementedException(); set => throw new NotImplementedException(); } | ||
public override string TraceIdentifier { get => throw new NotImplementedException(); set => throw new NotImplementedException(); } | ||
public override ISession Session { get => throw new NotImplementedException(); set => throw new NotImplementedException(); } | ||
|
||
public override void Abort() | ||
{ | ||
throw new NotImplementedException(); | ||
} | ||
} | ||
} |
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,55 @@ | ||
using Microsoft.AspNetCore.Http; | ||
using Microsoft.AspNetCore.Http.Features; | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Diagnostics; | ||
using System.Diagnostics.CodeAnalysis; | ||
using System.Linq; | ||
using System.Text; | ||
using System.Threading.Tasks; | ||
|
||
namespace BlazeKit.Static; | ||
|
||
/// <summary> | ||
/// A <see cref="HttpResponse"/> implementation for static site generation purposes"/> | ||
/// </summary> | ||
internal class FkHttpResponse : HttpResponse | ||
{ | ||
private readonly HttpContext ctx; | ||
|
||
/// <summary> | ||
/// A <see cref="HttpResponse"/> implementation for static site generation purposes"/> | ||
/// </summary> | ||
public FkHttpResponse(HttpContext ctx) | ||
{ | ||
this.ctx = ctx; | ||
} | ||
public override HttpContext HttpContext => this.ctx; | ||
|
||
public override int StatusCode { get; set; } | ||
|
||
public override IHeaderDictionary Headers => new HeaderDictionary(); | ||
|
||
public override Stream Body { get => throw new NotImplementedException(); set => throw new NotImplementedException(); } | ||
public override long? ContentLength { get => throw new NotImplementedException(); set => throw new NotImplementedException(); } | ||
public override string? ContentType { get => throw new NotImplementedException(); set => throw new NotImplementedException(); } | ||
|
||
public override IResponseCookies Cookies => new FkResponseCookies(); | ||
|
||
public override bool HasStarted => throw new NotImplementedException(); | ||
|
||
public override void OnCompleted(Func<object, Task> callback, object state) | ||
{ | ||
throw new NotSupportedException(); | ||
} | ||
|
||
public override void OnStarting(Func<object, Task> callback, object state) | ||
{ | ||
throw new NotSupportedException(); | ||
} | ||
|
||
public override void Redirect([StringSyntax("Uri")] string location, bool permanent) | ||
{ | ||
throw new NotSupportedException("'Redirect' is not supported 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,28 @@ | ||
using Microsoft.AspNetCore.Http; | ||
|
||
namespace BlazeKit.Static; | ||
/// <summary> | ||
/// A <see cref="IResponseCookies"/> implementation for static site generation purposes"/> | ||
/// </summary> | ||
internal class FkResponseCookies : IResponseCookies | ||
{ | ||
public void Append(string key, string value) | ||
{ | ||
// do nothing | ||
} | ||
|
||
public void Append(string key, string value, CookieOptions options) | ||
{ | ||
// do nothing | ||
} | ||
|
||
public void Delete(string key) | ||
{ | ||
// do nothing | ||
} | ||
|
||
public void Delete(string key, CookieOptions options) | ||
{ | ||
// do nothing | ||
} | ||
} |
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,61 @@ | ||
using Microsoft.AspNetCore.Components; | ||
using Microsoft.AspNetCore.Components.Routing; | ||
using Microsoft.AspNetCore.Components.Web; | ||
using Microsoft.AspNetCore.Identity; | ||
using Microsoft.AspNetCore.Routing; | ||
using Microsoft.Extensions.DependencyInjection; | ||
using Microsoft.Extensions.Hosting; | ||
using Microsoft.Extensions.Logging; | ||
using Microsoft.JSInterop; | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
using System.Text; | ||
using System.Threading.Tasks; | ||
|
||
namespace BlazeKit.Static | ||
{ | ||
public class PageRenderer | ||
{ | ||
private readonly Type rootComponent; | ||
private readonly IServiceCollection serviceCollection; | ||
|
||
public PageRenderer(Type rootComponent,IServiceCollection serviceCollection) | ||
{ | ||
this.rootComponent = rootComponent; | ||
this.serviceCollection = serviceCollection; | ||
} | ||
public async Task<string> Render(string route) | ||
{ | ||
var routeManager = new StaticNavigationManager(); | ||
|
||
serviceCollection.AddLogging(); | ||
serviceCollection.AddSingleton<IHostEnvironment>(new BKitHostEnvironment("Production")); | ||
serviceCollection.AddSingleton<NavigationManager>(routeManager); | ||
serviceCollection.AddSingleton<IJSRuntime>(new FkJsRuntime()); | ||
serviceCollection.AddSingleton<INavigationInterception>(new FkNavigationInterception()); | ||
serviceCollection.AddSingleton<IScrollToLocationHash>(new FkScrollToLocationHash()); | ||
serviceCollection.AddSingleton<IErrorBoundaryLogger>(new StaticErrorBoundaryLogger()); | ||
|
||
var spv = serviceCollection.BuildServiceProvider(); | ||
var scoped = spv.CreateScope(); | ||
var serviceProvider = scoped.ServiceProvider; | ||
|
||
routeManager.NavigateTo(route, forceLoad: true); | ||
var renderer = | ||
new BlazorRenderer( | ||
new HtmlRenderer( | ||
serviceProvider, | ||
serviceProvider | ||
.GetRequiredService<ILoggerFactory>() | ||
), | ||
serviceProvider | ||
); | ||
var html = | ||
await renderer.RenderComponent(this.rootComponent); | ||
|
||
return html; | ||
|
||
} | ||
} | ||
} |
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
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
Oops, something went wrong.