From b66c26394dff64e22205278b2b3621ddbf8ed5a3 Mon Sep 17 00:00:00 2001 From: Mia Winter Date: Wed, 7 Feb 2024 13:52:18 +0100 Subject: [PATCH] Added OpenGraph to Home, addded Customization for page description --- Wave/Components/Pages/Home.razor | 175 +++++++++++++++++-------------- Wave/Data/Customization.cs | 1 + 2 files changed, 98 insertions(+), 78 deletions(-) diff --git a/Wave/Components/Pages/Home.razor b/Wave/Components/Pages/Home.razor index 6bba5ad..b0815b4 100644 --- a/Wave/Components/Pages/Home.razor +++ b/Wave/Components/Pages/Home.razor @@ -1,14 +1,33 @@ @page "/" @using Microsoft.Extensions.Localization @using Microsoft.EntityFrameworkCore +@using Microsoft.Extensions.Options @using Wave.Data @using Wave.Utilities @rendermode InteractiveServer @attribute [StreamRendering] +@inject IOptions Customizations +@inject NavigationManager Navigation @inject IDbContextFactory ContextFactory; @inject IStringLocalizer Localizer + + + + + + @if (!string.IsNullOrWhiteSpace(Customizations.Value.LogoLink)) { + + } else { + + } + @if (!string.IsNullOrWhiteSpace(Customizations.Value.AppDescription)) { + + + } + + @(TitlePrefix + Localizer["Title"])

@Localizer["Title"]

@@ -16,97 +35,97 @@ @if (Busy) { -
- -
+
+ +
} else { - @if (Articles.FirstOrDefault() is {} featured) { -
- -
-
-
-

- @featured.Title -

- @foreach (var category in featured.Categories.OrderBy(c => c.Color)) { - - @category.Name - - } -

-

-

- @featured.PublishDate.ToString("g")
- @featured.Body[..Math.Min(1000, featured.Body.Length)] -

-
- -
-
-
+ @if (Articles.FirstOrDefault() is {} featured) { +
+ +
+
+
+

+ @featured.Title +

+ @foreach (var category in featured.Categories.OrderBy(c => c.Color)) { + + @category.Name + + } +

+

+

+ @featured.PublishDate.ToString("g")
+ @featured.Body[..Math.Min(1000, featured.Body.Length)] +

+
+ +
+
+
-
-
- } else { -

@Localizer["NoArticles_Title"]

-

@Localizer["NoArticles_Message"]

- } + +
+ } else { +

@Localizer["NoArticles_Title"]

+

@Localizer["NoArticles_Message"]

+ } - - @foreach (var article in Articles.Skip(1)) { - - } - + + @foreach (var article in Articles.Skip(1)) { + + } + } @if (HasMore) { -
- -
+
+ +
} @code { - [CascadingParameter(Name = "TitlePrefix")] - private string TitlePrefix { get; set; } = default!; + [CascadingParameter(Name = "TitlePrefix")] + private string TitlePrefix { get; set; } = default!; - private List
Articles { get; } = []; - private bool HasMore { get; set; } - private bool Busy { get; set; } = true; + private List
Articles { get; } = []; + private bool HasMore { get; set; } + private bool Busy { get; set; } = true; - protected override async Task OnAfterRenderAsync(bool firstRender) { - if (firstRender) { - try { - await using var context = await ContextFactory.CreateDbContextAsync(); + protected override async Task OnAfterRenderAsync(bool firstRender) { + if (firstRender) { + try { + await using var context = await ContextFactory.CreateDbContextAsync(); - var query = context.Set
() - .Include(a => a.Author).Include(a => a.Categories) - .OrderByDescending(a => a.PublishDate); - var articles = await query.Take(11).ToListAsync(); - HasMore = (await query.CountAsync()) > 11; - Articles.AddRange(articles); - } finally { - Busy = false; - await InvokeAsync(StateHasChanged); - } - } - } + var query = context.Set
() + .Include(a => a.Author).Include(a => a.Categories) + .OrderByDescending(a => a.PublishDate); + var articles = await query.Take(11).ToListAsync(); + HasMore = (await query.CountAsync()) > 11; + Articles.AddRange(articles); + } finally { + Busy = false; + await InvokeAsync(StateHasChanged); + } + } + } - private async Task More() { - try { - Busy = HasMore = true; - await using var context = await ContextFactory.CreateDbContextAsync(); + private async Task More() { + try { + Busy = HasMore = true; + await using var context = await ContextFactory.CreateDbContextAsync(); - var query = context.Set
() - .Include(a => a.Author).Include(a => a.Categories) - .OrderByDescending(a => a.PublishDate) - .Skip(Articles.Count); - var articles = await query.Take(10).ToListAsync(); - Articles.AddRange(articles); - HasMore = (await query.CountAsync()) > 10; - } finally { - Busy = false; - } - } + var query = context.Set
() + .Include(a => a.Author).Include(a => a.Categories) + .OrderByDescending(a => a.PublishDate) + .Skip(Articles.Count); + var articles = await query.Take(10).ToListAsync(); + Articles.AddRange(articles); + HasMore = (await query.CountAsync()) > 10; + } finally { + Busy = false; + } + } } \ No newline at end of file diff --git a/Wave/Data/Customization.cs b/Wave/Data/Customization.cs index 8ea7f38..e1c277a 100644 --- a/Wave/Data/Customization.cs +++ b/Wave/Data/Customization.cs @@ -2,6 +2,7 @@ public class Customization { public string AppName { get; set; } = "Wave"; + public string AppDescription { get; set; } = ""; public string DefaultTheme { get; set; } = ""; public string LogoLink { get; set; } = ""; public string Footer { get; set; } = "";