✨ Managed page rendering
This commit is contained in:
@@ -8,12 +8,15 @@
|
||||
<div class="h-screen flex justify-center items-center">
|
||||
<div class="text-center max-w-96">
|
||||
<img src="~/favicon.png" width="80" height="80" alt="Logo" class="mb-1 mx-auto"/>
|
||||
<h1 class="text-2xl">Hello, World 👋</h1>
|
||||
<h1 class="text-2xl">404 Not Found</h1>
|
||||
<p>Here are the Solar Network Pages</p>
|
||||
<p>And you're accessing the site <b>@ViewData["SiteName"]</b></p>
|
||||
<p>And you're accessing the site <b>@(Model.SiteName ?? "main")</b></p>
|
||||
<p class="text-sm opacity-80 mt-1">
|
||||
The reason you're seeing this is the author of the site
|
||||
haven't configure anything that match this route.
|
||||
</p>
|
||||
<div class="text-xs opacity-70 mt-1">
|
||||
<p>Path: <b>@Model.CurrentPath</b> Site ID: <b>@(Model.Site?.Id.ToString() ?? "none")</b></p>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
@@ -2,17 +2,22 @@ using DysonNetwork.Shared.Models;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using Microsoft.AspNetCore.Mvc.RazorPages;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using System.IO;
|
||||
using System.Text.Json;
|
||||
|
||||
namespace DysonNetwork.Zone.Pages;
|
||||
|
||||
public class IndexModel(AppDatabase db) : PageModel
|
||||
{
|
||||
public SnPublicationSite? Site { get; set; }
|
||||
public string? SiteName { get; set; }
|
||||
public string? CurrentPath { get; set; }
|
||||
|
||||
public async Task<IActionResult> OnGet(string? path = null)
|
||||
{
|
||||
var siteNameValue = Request.Headers["X-SiteName"].ToString();
|
||||
SiteName = siteNameValue;
|
||||
CurrentPath = Path.Combine("/", path ?? "");
|
||||
if (string.IsNullOrEmpty(siteNameValue))
|
||||
{
|
||||
SiteName = null;
|
||||
@@ -20,36 +25,21 @@ public class IndexModel(AppDatabase db) : PageModel
|
||||
else
|
||||
{
|
||||
var capturedName = siteNameValue;
|
||||
var site = await db.PublicationSites.FirstOrDefaultAsync(s =>
|
||||
s.Name == capturedName && s.Mode == PublicationSiteMode.FullyManaged);
|
||||
if (site != null)
|
||||
{
|
||||
var pagePath = "/" + (path ?? "");
|
||||
if (pagePath == "/") pagePath = "/";
|
||||
Site = await db.PublicationSites.FirstOrDefaultAsync(s => s.Slug == capturedName);
|
||||
if (Site == null) return Page();
|
||||
var pagePath = CurrentPath;
|
||||
|
||||
var page = await db.PublicationPages.FirstOrDefaultAsync(p =>
|
||||
p.SiteId == site.Id && p.Path == pagePath);
|
||||
if (page != null)
|
||||
{
|
||||
if (page.Type == PublicationPageType.HtmlPage)
|
||||
{
|
||||
if (page.Config.TryGetValue("html", out var html) && html is string content)
|
||||
{
|
||||
return Content(content, "text/html");
|
||||
}
|
||||
}
|
||||
else if (page.Type == PublicationPageType.Redirect)
|
||||
{
|
||||
if (page.Config.TryGetValue("url", out var url) && url is string redirectUrl)
|
||||
{
|
||||
return Redirect(redirectUrl);
|
||||
}
|
||||
}
|
||||
}
|
||||
var page = await db.PublicationPages.FirstOrDefaultAsync(p => p.SiteId == Site.Id && p.Path == pagePath);
|
||||
if (page == null) return Page();
|
||||
switch (page.Type)
|
||||
{
|
||||
case PublicationPageType.HtmlPage when page.Config.TryGetValue("html", out var html) && html is JsonElement content:
|
||||
return Content(content.ToString(), "text/html");
|
||||
case PublicationPageType.Redirect when page.Config.TryGetValue("url", out var url) && url is JsonElement redirectUrl:
|
||||
return Redirect(redirectUrl.ToString());
|
||||
}
|
||||
}
|
||||
|
||||
return Page();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user