-
Notifications
You must be signed in to change notification settings - Fork 137
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #835 from EdiWang/feature/social-links
Social link (preview)
- Loading branch information
Showing
6 changed files
with
79 additions
and
0 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
namespace Moonglade.Configuration; | ||
|
||
public class SocialLink | ||
{ | ||
public string Name { get; set; } | ||
|
||
public string Icon { get; set; } | ||
|
||
public string Url { get; set; } | ||
} |
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,22 @@ | ||
using Microsoft.Extensions.Configuration; | ||
using Moonglade.Configuration; | ||
|
||
namespace Moonglade.Core; | ||
|
||
public record GetAllSocialLinksQuery : IRequest<List<SocialLink>>; | ||
|
||
public class GetAllSocialLinksQueryHandler(IConfiguration configuration) : IRequestHandler<GetAllSocialLinksQuery, List<SocialLink>> | ||
{ | ||
public Task<List<SocialLink>> Handle(GetAllSocialLinksQuery request, CancellationToken ct) | ||
{ | ||
var section = configuration.GetSection("Experimental:SocialLinks"); | ||
|
||
if (!section.Exists()) | ||
{ | ||
return Task.FromResult(new List<SocialLink>()); | ||
} | ||
|
||
var links = section.Get<List<SocialLink>>(); | ||
return Task.FromResult(links ?? new List<SocialLink>()); | ||
} | ||
} |
19 changes: 19 additions & 0 deletions
19
src/Moonglade.Web/Pages/Components/SocialLink/Default.cshtml
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,19 @@ | ||
@using Moonglade.Utils | ||
@model List<SocialLink> | ||
|
||
@if (Model.Any()) | ||
{ | ||
<div class="aside-widget p-3 rounded-3 shadow-sm border"> | ||
<h6 class="card-subtitle mb-3 text-secondary">@SharedLocalizer["Social Links"]</h6> | ||
|
||
<div role="list"> | ||
@foreach (var item in Model.OrderBy(c => c.Name)) | ||
{ | ||
<a href="@Helper.SterilizeLink(item.Url)" target="_blank" class="d-block mb-3 mt-2" role="listitem"> | ||
<i class="@item.Icon me-1"></i> | ||
@item.Name | ||
</a> | ||
} | ||
</div> | ||
</div> | ||
} |
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
18 changes: 18 additions & 0 deletions
18
src/Moonglade.Web/ViewComponents/SocialLinkViewComponent.cs
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,18 @@ | ||
namespace Moonglade.Web.ViewComponents; | ||
|
||
public class SocialLinkViewComponent(ILogger<SocialLinkViewComponent> logger, IMediator mediator) : ViewComponent | ||
{ | ||
public async Task<IViewComponentResult> InvokeAsync() | ||
{ | ||
try | ||
{ | ||
var links = await mediator.Send(new GetAllSocialLinksQuery()); | ||
return View(links ?? []); | ||
} | ||
catch (Exception e) | ||
{ | ||
logger.LogError(e, "Error Reading SocialLink."); | ||
return Content("ERROR"); | ||
} | ||
} | ||
} |
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