This commit is contained in:
2026-05-17 20:54:09 -04:00
parent 6da2183583
commit 74c21ee5cc
3000 changed files with 11794 additions and 15301 deletions

View File

@@ -1,35 +1,120 @@
@using Microsoft.Extensions.Options
@using Microsoft.EntityFrameworkCore
@using Microsoft.Extensions.Caching.Memory
@using Microsoft.Extensions.Options
@using OpenArchival.Blazor.Components.CustomComponents
@using OpenArchival.Blazor.Config;
@using OpenArchival.Blazor.Blog
@using OpenArchival.Blazor.ArchiveDisplay
@page "/"
<PageTitle>Home</PageTitle>
@if (string.IsNullOrEmpty(_htmlContent))
<style>
.banner-container {
position: relative;
width: calc(100% + 32px);
margin-left: -16px;
margin-right: -16px;
margin-top: -16px;
overflow: hidden;
}
.banner-container img {
width: 100% !important;
height: auto !important;
display: block;
}
.floating-buttons {
position: absolute;
bottom: 24px;
left: 0;
right: 0;
z-index: 10;
}
@@media (max-width: 600px) {
.floating-buttons {
position: static;
padding-top: 16px;
padding-bottom: 16px;
}
}
</style>
@if (_homePageConfig is null)
{
<p>Loading content...</p>
}
else
{
@((MarkupString)_htmlContent)
@if (_homePageConfig.HomePageBanner is not null)
{
<div class="banner-container">
<MudImage
ObjectPosition=ObjectPosition.Center
Src=@($"/api/files/{_homePageConfig.HomePageBanner.Id}/large")></MudImage>
<div class="floating-buttons">
<HomePageButtons></HomePageButtons>
</div>
</div>
<MudDivider></MudDivider>
}
else
{
<HomePageButtons></HomePageButtons>
}
@if (!string.IsNullOrEmpty(_homePageConfig.Content)) {
// Uses a custom CSS class to force the content to the width of the page regardless of what is in it
// ql-editor class tells the quill css that it should apply its classes in this div. Quill is used by the rich text editor this
// project uses
<div class="dynamic-content-container ql-editor">
@((MarkupString)_homePageConfig.Content)
</div>
}
<LatestBlogPostsSlider />
@if (_homePageConfig.SliderEntries != null)
{
@foreach (var sliderEntry in _homePageConfig.SliderEntries)
{
<SearchPageSlider SliderEntry="sliderEntry" />
}
}
}
@inject IOptions<ApplicationOptions> AppOptions;
@inject IMemoryCache MemoryCache;
@inject IDbContextFactory<ApplicationDbContext> ContextFactory;
@code {
private string _htmlContent = $"<h1>HTML file not found for homepage. Create one at /admin/homepageeditor</h1>";
private HomePageConfiguration? _homePageConfig = null;
protected override async void OnInitialized()
protected override async Task OnInitializedAsync()
{
try
_homePageConfig = await MemoryCache.GetOrCreateAsync(OpenArchivalConstants.HomePageConfigurationCacheKey, async entry =>
{
using var reader = new StreamReader(AppOptions.Value.HomepageContentLocation);
_htmlContent = await reader.ReadToEndAsync();
}
catch (Exception ex)
{
_htmlContent = $"<h1>HTML file not found for homepage. Create one at /admin/homepageeditor</h1>";
}
await using var context = await ContextFactory.CreateDbContextAsync();
HomePageConfiguration? config = await context.HomePageConfiguration
.Include(conf=>conf.HomePageBanner)
.Include(conf=>conf.SliderEntries)
.ThenInclude(se => se.FilterTags)
.FirstOrDefaultAsync();
if (config is null)
{
return new HomePageConfiguration() { Content = "Failed to load HomePageConfiguration from the database!" };
}
return config;
});
StateHasChanged();
}
}