61 lines
2.0 KiB
Plaintext
61 lines
2.0 KiB
Plaintext
@page "/admin/homepageeditor"
|
|
|
|
@layout AdminControlPanelLayout
|
|
|
|
@using Microsoft.Extensions.Options
|
|
@using MudExRichTextEditor
|
|
@using MudBlazor
|
|
@using OpenArchival.Blazor
|
|
@using OpenArchival.Blazor.AdminPages.Shared
|
|
@using OpenArchival.Blazor.Config
|
|
|
|
<MudText Typo="Typo.h6">Home Page Editor</MudText>
|
|
<MudDivider></MudDivider>
|
|
<MudText Typo="Typo.body2">This is the content that will be displayed on the site's home page</MudText>
|
|
<MudExRichTextEdit @ref="@_editor"
|
|
ReadOnly="false"
|
|
Height="444"
|
|
Class="m-2 mt-4"
|
|
Placeholder="Edit html"
|
|
ValueHtmlBehavior="MudExRichTextEditor.Types.GetHtmlBehavior.SemanticHtml"
|
|
@bind-Value="_editorContent"
|
|
>
|
|
@((MarkupString)_editorContent)
|
|
</MudExRichTextEdit>
|
|
|
|
<MudButton Variant="Variant.Filled" Color="Color.Primary" OnClick="OnSaveHomePage" Class="mt-4">Save</MudButton>
|
|
|
|
@inject ISnackbar Snackbar;
|
|
@inject IOptions<ApplicationOptions> AppOptions;
|
|
@code {
|
|
private MudExRichTextEdit _editor = default!;
|
|
|
|
private bool _hasLoaded = false;
|
|
|
|
private string _editorContent = "";
|
|
|
|
protected override void OnInitialized()
|
|
{
|
|
string html = "";
|
|
|
|
if (File.Exists(AppOptions.Value.HomepageContentLocation)) {
|
|
using var reader = new StreamReader(AppOptions.Value.HomepageContentLocation);
|
|
html = reader.ReadToEnd();
|
|
} else
|
|
{
|
|
Snackbar.Add("Homepage file not found, will create one on save!", Severity.Warning);
|
|
}
|
|
|
|
_editorContent = html;
|
|
}
|
|
|
|
private async Task OnSaveHomePage(Microsoft.AspNetCore.Components.Web.MouseEventArgs args)
|
|
{
|
|
using var writer = new StreamWriter(AppOptions.Value.HomepageContentLocation);
|
|
|
|
await writer.WriteLineAsync(_editorContent);
|
|
|
|
Snackbar.Add($"Wrote homepage to {AppOptions.Value.HomepageContentLocation}!", Severity.Success);
|
|
}
|
|
}
|