Skip to content

Commit

Permalink
Merge pull request #804 from EdiWang/master
Browse files Browse the repository at this point in the history
v14.6.0
  • Loading branch information
EdiWang authored Jul 22, 2024
2 parents ae7d4ef + caa18de commit e7c14c5
Show file tree
Hide file tree
Showing 48 changed files with 254 additions and 237 deletions.
4 changes: 2 additions & 2 deletions Deployment/AzureQuickDeploy.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -139,10 +139,10 @@ $planCheck = az appservice plan list --query "[?name=='$aspName']" | ConvertFrom
$planExists = $planCheck.Length -gt 0
if (!$planExists) {
if ($useLinuxPlanWithDocker) {
$echo = az appservice plan create -n $aspName -g $rsgName --is-linux --sku S1 --location $regionName
$echo = az appservice plan create -n $aspName -g $rsgName --is-linux --sku P0V3 --location $regionName
}
else {
$echo = az appservice plan create -n $aspName -g $rsgName --sku S1 --location $regionName
$echo = az appservice plan create -n $aspName -g $rsgName --sku P0V3 --location $regionName
}
}

Expand Down
16 changes: 1 addition & 15 deletions Deployment/mssql-migration.sql
Original file line number Diff line number Diff line change
@@ -1,16 +1,2 @@
-- v14.4.1 - v14.5.x
-- v14.5.x - vNext

ALTER TABLE Post DROP COLUMN IsOriginal
GO

ALTER TABLE Post DROP COLUMN OriginLink
GO

EXEC sp_rename 'Pingback', 'Mention'
GO

ALTER TABLE Mention ADD Worker NVARCHAR(16)
GO

UPDATE Mention SET Worker = N'Pingback'
GO
6 changes: 3 additions & 3 deletions src/Directory.Build.props
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@
<Authors>Edi Wang</Authors>
<Company>edi.wang</Company>
<Copyright>(C) 2024 edi.wang@outlook.com</Copyright>
<AssemblyVersion>14.5.0.0</AssemblyVersion>
<FileVersion>14.5.0.0</FileVersion>
<Version>14.5.0</Version>
<AssemblyVersion>14.6.0.0</AssemblyVersion>
<FileVersion>14.6.0.0</FileVersion>
<Version>14.6.0</Version>
</PropertyGroup>
</Project>
2 changes: 1 addition & 1 deletion src/Moonglade.Auth/Moonglade.Auth.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
</ItemGroup>
<ItemGroup>
<FrameworkReference Include="Microsoft.AspNetCore.App" />
<PackageReference Include="Microsoft.Identity.Web" Version="2.20.0" />
<PackageReference Include="Microsoft.Identity.Web" Version="3.0.0" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\Moonglade.Configuration\Moonglade.Configuration.csproj" />
Expand Down
4 changes: 2 additions & 2 deletions src/Moonglade.Comments/Moonglade.Comments.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,12 @@
<ImplicitUsings>enable</ImplicitUsings>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Edi.Captcha" Version="3.22.0" />
<PackageReference Include="Edi.Captcha" Version="3.23.1" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\Moonglade.Configuration\Moonglade.Configuration.csproj" />
</ItemGroup>
<ItemGroup>
<PackageReference Include="Microsoft.Extensions.Http.Resilience" Version="8.6.0" />
<PackageReference Include="Microsoft.Extensions.Http.Resilience" Version="8.7.0" />
</ItemGroup>
</Project>
4 changes: 4 additions & 0 deletions src/Moonglade.Configuration/GeneralSettings.cs
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,10 @@ public class GeneralSettings : IBlogSettings
[MaxLength(256)]
public string Description { get; set; }

[Display(Name = "Your pronouns")]
[MaxLength(32)]
public string Pronouns { get; set; }

[Display(Name = "Side bar HTML code")]
[DataType(DataType.MultilineText)]
[MaxLength(2048)]
Expand Down
18 changes: 13 additions & 5 deletions src/Moonglade.Core/PostFeature/CreatePostCommand.cs
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,18 @@ public class CreatePostCommandHandler(
{
public async Task<PostEntity> Handle(CreatePostCommand request, CancellationToken ct)
{
var abs = ContentProcessor.GetPostAbstract(
string.IsNullOrEmpty(request.Payload.Abstract) ? request.Payload.EditorContent : request.Payload.Abstract.Trim(),
blogConfig.ContentSettings.PostAbstractWords,
configuration.GetSection("Editor").Get<EditorChoice>() == EditorChoice.Markdown);
string abs;
if (string.IsNullOrEmpty(request.Payload.Abstract))
{
abs = ContentProcessor.GetPostAbstract(
request.Payload.EditorContent,
blogConfig.ContentSettings.PostAbstractWords,
configuration.GetSection("Editor").Get<EditorChoice>() == EditorChoice.Markdown);
}
else
{
abs = request.Payload.Abstract.Trim();
}

var post = new PostEntity
{
Expand Down Expand Up @@ -74,7 +82,7 @@ public async Task<PostEntity> Handle(CreatePostCommand request, CancellationToke

// add tags
var tags = string.IsNullOrWhiteSpace(request.Payload.Tags) ?
Array.Empty<string>() :
[] :
request.Payload.Tags.Split(',').ToArray();

if (tags is { Length: > 0 })
Expand Down
2 changes: 1 addition & 1 deletion src/Moonglade.Core/PostFeature/PostEditModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ public class PostEditModel
public string LanguageCode { get; set; }

[DataType(DataType.MultilineText)]
[MaxLength(400)]
[MaxLength(1024)]
public string Abstract { get; set; }

[Display(Name = "Publish Date")]
Expand Down
2 changes: 2 additions & 0 deletions src/Moonglade.Core/PostFeature/PostSegment.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ public struct PostSegment
public bool IsPublished { get; set; }
public bool IsFeatured { get; set; }
public bool IsDeleted { get; set; }
public bool IsOutdated { get; set; }

public static readonly Expression<Func<PostEntity, PostSegment>> EntitySelector = p => new()
{
Expand All @@ -24,6 +25,7 @@ public struct PostSegment
IsPublished = p.IsPublished,
IsFeatured = p.IsFeatured,
IsDeleted = p.IsDeleted,
IsOutdated = p.IsOutdated,
CreateTimeUtc = p.CreateTimeUtc,
LastModifiedUtc = p.LastModifiedUtc,
ContentAbstract = p.ContentAbstract
Expand Down
2 changes: 1 addition & 1 deletion src/Moonglade.Core/PostFeature/UpdatePostCommand.cs
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ public async Task<PostEntity> Handle(UpdatePostCommand request, CancellationToke

// 1. Add new tags to tag lib
var tags = string.IsNullOrWhiteSpace(postEditModel.Tags) ?
Array.Empty<string>() :
[] :
postEditModel.Tags.Split(',').ToArray();

foreach (var item in tags)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
<Nullable>enable</Nullable>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Microsoft.EntityFrameworkCore.SqlServer" Version="8.0.6" />
<PackageReference Include="Microsoft.EntityFrameworkCore.SqlServer" Version="8.0.7" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\Moonglade.Data\Moonglade.Data.csproj" />
Expand Down
2 changes: 1 addition & 1 deletion src/Moonglade.Data/Moonglade.Data.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
<PackageReference Include="Ardalis.Specification" Version="8.0.0" />
<PackageReference Include="Ardalis.Specification.EntityFrameworkCore" Version="8.0.0" />
<PackageReference Include="MediatR" Version="12.3.0" />
<PackageReference Include="Microsoft.EntityFrameworkCore.Proxies" Version="8.0.6" />
<PackageReference Include="Microsoft.EntityFrameworkCore.Proxies" Version="8.0.7" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\Moonglade.Utils\Moonglade.Utils.csproj" />
Expand Down
2 changes: 1 addition & 1 deletion src/Moonglade.Email.Client/Moonglade.Email.Client.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
<FrameworkReference Include="Microsoft.AspNetCore.App" />
</ItemGroup>
<ItemGroup>
<PackageReference Include="Microsoft.Extensions.Http.Resilience" Version="8.6.0" />
<PackageReference Include="Microsoft.Extensions.Http.Resilience" Version="8.7.0" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\Moonglade.Configuration\Moonglade.Configuration.csproj" />
Expand Down
2 changes: 1 addition & 1 deletion src/Moonglade.ImageStorage/Moonglade.ImageStorage.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
</PropertyGroup>
<ItemGroup>
<FrameworkReference Include="Microsoft.AspNetCore.App" />
<PackageReference Include="Azure.Storage.Blobs" Version="12.20.0" />
<PackageReference Include="Azure.Storage.Blobs" Version="12.21.0" />
<PackageReference Include="Minio" Version="6.0.3" />
</ItemGroup>
</Project>
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,6 @@
<ProjectReference Include="..\Moonglade.Utils\Moonglade.Utils.csproj" />
</ItemGroup>
<ItemGroup>
<PackageReference Include="Microsoft.Extensions.Http.Resilience" Version="8.6.0" />
<PackageReference Include="Microsoft.Extensions.Http.Resilience" Version="8.7.0" />
</ItemGroup>
</Project>
4 changes: 1 addition & 3 deletions src/Moonglade.Syndication/GetAtomStringQuery.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,7 @@ public class GetAtomStringQueryHandler : IRequestHandler<GetAtomStringQuery, str
public GetAtomStringQueryHandler(IBlogConfig blogConfig, ISyndicationDataSource sdds, IHttpContextAccessor httpContextAccessor)
{
_sdds = sdds;

var acc = httpContextAccessor;
var baseUrl = $"{acc.HttpContext.Request.Scheme}://{acc.HttpContext.Request.Host}";
var baseUrl = $"{httpContextAccessor.HttpContext!.Request.Scheme}://{httpContextAccessor.HttpContext.Request.Host}";

_feedGenerator = new(
baseUrl,
Expand Down
3 changes: 1 addition & 2 deletions src/Moonglade.Syndication/GetRssStringQuery.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,7 @@ public GetRssStringQueryHandler(IBlogConfig blogConfig, ISyndicationDataSource s
{
_sdds = sdds;

var acc = httpContextAccessor;
var baseUrl = $"{acc.HttpContext.Request.Scheme}://{acc.HttpContext.Request.Host}";
var baseUrl = $"{httpContextAccessor.HttpContext!.Request.Scheme}://{httpContextAccessor.HttpContext.Request.Host}";

_feedGenerator = new(
baseUrl,
Expand Down
48 changes: 17 additions & 31 deletions src/Moonglade.Syndication/SyndicationDataSource.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,36 +13,22 @@ public interface ISyndicationDataSource
Task<List<FeedEntry>> GetFeedDataAsync(string catSlug = null);
}

public class SyndicationDataSource : ISyndicationDataSource
public class SyndicationDataSource(
IBlogConfig blogConfig,
IHttpContextAccessor httpContextAccessor,
MoongladeRepository<CategoryEntity> catRepo,
MoongladeRepository<PostEntity> postRepo,
IConfiguration configuration)
: ISyndicationDataSource
{
private readonly string _baseUrl;
private readonly IBlogConfig _blogConfig;
private readonly MoongladeRepository<CategoryEntity> _catRepo;
private readonly MoongladeRepository<PostEntity> _postRepo;
private readonly IConfiguration _configuration;

public SyndicationDataSource(
IBlogConfig blogConfig,
IHttpContextAccessor httpContextAccessor,
MoongladeRepository<CategoryEntity> catRepo,
MoongladeRepository<PostEntity> postRepo,
IConfiguration configuration)
{
_blogConfig = blogConfig;
_catRepo = catRepo;
_postRepo = postRepo;
_configuration = configuration;

var acc = httpContextAccessor;
_baseUrl = $"{acc.HttpContext.Request.Scheme}://{acc.HttpContext.Request.Host}";
}
private readonly string _baseUrl = $"{httpContextAccessor.HttpContext!.Request.Scheme}://{httpContextAccessor.HttpContext.Request.Host}";

public async Task<List<FeedEntry>> GetFeedDataAsync(string catSlug = null)
{
List<FeedEntry> itemCollection;
if (!string.IsNullOrWhiteSpace(catSlug))
{
var cat = await _catRepo.FirstOrDefaultAsync(new CategoryBySlugSpec(catSlug));
var cat = await catRepo.FirstOrDefaultAsync(new CategoryBySlugSpec(catSlug));
if (cat is null) return null;

itemCollection = await GetFeedEntriesAsync(cat.Id);
Expand All @@ -58,27 +44,27 @@ public async Task<List<FeedEntry>> GetFeedDataAsync(string catSlug = null)
private async Task<List<FeedEntry>> GetFeedEntriesAsync(Guid? catId = null)
{
int? top = null;
if (_blogConfig.FeedSettings.FeedItemCount != 0)
if (blogConfig.FeedSettings.FeedItemCount != 0)
{
top = _blogConfig.FeedSettings.FeedItemCount;
top = blogConfig.FeedSettings.FeedItemCount;
}

var postSpec = new PostByCatSpec(catId, top);
var list = await _postRepo.SelectAsync(postSpec, p => p.PubDateUtc != null ? new FeedEntry
var list = await postRepo.SelectAsync(postSpec, p => p.PubDateUtc != null ? new FeedEntry
{
Id = p.Id.ToString(),
Title = p.Title,
PubDateUtc = p.PubDateUtc.Value,
Description = _blogConfig.FeedSettings.UseFullContent ? p.PostContent : p.ContentAbstract,
Description = blogConfig.FeedSettings.UseFullContent ? p.PostContent : p.ContentAbstract,
Link = $"{_baseUrl}/post/{p.PubDateUtc.Value.Year}/{p.PubDateUtc.Value.Month}/{p.PubDateUtc.Value.Day}/{p.Slug}",
Author = _blogConfig.GeneralSettings.OwnerName,
AuthorEmail = _blogConfig.GeneralSettings.OwnerEmail,
Author = blogConfig.GeneralSettings.OwnerName,
AuthorEmail = blogConfig.GeneralSettings.OwnerEmail,
Categories = p.PostCategory.Select(pc => pc.Category.DisplayName).ToArray()
} : null);

// Workaround EF limitation
// Man, this is super ugly
if (_blogConfig.FeedSettings.UseFullContent && list.Any())
if (blogConfig.FeedSettings.UseFullContent && list.Any())
{
foreach (var simpleFeedItem in list)
{
Expand All @@ -91,7 +77,7 @@ private async Task<List<FeedEntry>> GetFeedEntriesAsync(Guid? catId = null)

private string FormatPostContent(string rawContent)
{
return _configuration.GetSection("Editor").Get<EditorChoice>() == EditorChoice.Markdown ?
return configuration.GetSection("Editor").Get<EditorChoice>() == EditorChoice.Markdown ?
ContentProcessor.MarkdownToContent(rawContent, ContentProcessor.MarkdownConvertType.Html, false) :
rawContent;
}
Expand Down
2 changes: 1 addition & 1 deletion src/Moonglade.Web/Controllers/PostController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ public async Task<IActionResult> CreateOrEdit(PostEditModel model, LinkGenerator
{
if (!ModelState.IsValid) return Conflict(ModelState.CombineErrorMessages());

var tzDate = timeZoneResolver.NowOfTimeZone;
var tzDate = timeZoneResolver.NowInTimeZone;
if (model.ChangePublishDate &&
model.PublishDate.HasValue &&
model.PublishDate <= tzDate &&
Expand Down
2 changes: 1 addition & 1 deletion src/Moonglade.Web/Moonglade.Web.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@
<PackageReference Include="Edi.ImageWatermark" Version="2.12.0" />
<PackageReference Include="Edi.PasswordGenerator" Version="1.2.0" />
<PackageReference Include="Microsoft.ApplicationInsights.AspNetCore" Version="2.22.0" />
<PackageReference Include="Microsoft.Extensions.Logging.AzureAppServices" Version="8.0.6" />
<PackageReference Include="Microsoft.Extensions.Logging.AzureAppServices" Version="8.0.7" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\Moonglade.Auth\Moonglade.Auth.csproj" />
Expand Down
9 changes: 5 additions & 4 deletions src/Moonglade.Web/Pages/Admin/EditPost.cshtml
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,10 @@
switch (ec)
{
case EditorChoice.Html:
<script src="https://cdnjs.cloudflare.com/ajax/libs/tinymce/7.1.2/tinymce.min.js"
integrity="sha512-2T0G/zn88pKqnmUStXKW0BSPIW3Y2sky5Bl6HER5TwPGqCsLTVzAQRZMum/ptf5mRwYylP1lcvnLkgn6chASuA=="
crossorigin="anonymous" referrerpolicy="no-referrer"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/tinymce/7.2.1/tinymce.min.js"
integrity="sha512-zmlLhIesl+uwwzjoUz/izUsSjAMVb/7fH2ffCbJvYLepAvdvAq1T6ev9edZR8jwRKfM0OTaUyFVO1D7wAwXCEw=="
crossorigin="anonymous"
referrerpolicy="no-referrer"></script>
break;
case EditorChoice.Markdown:
<partial name="_MonacoLoaderScript" />
Expand Down Expand Up @@ -267,7 +268,7 @@
class="form-control form-control-sm"
data-bs-toggle="tooltip"
data-placement="top"
maxlength="400"
maxlength="1024"
title="@SharedLocalizer["The first {0} character(s) will be used as abstract if you leave this field blank.", BlogConfig.ContentSettings.PostAbstractWords]"
style="height: 90px"></textarea>
<label for="ViewModel_Abstract">@SharedLocalizer["Abstract"]</label>
Expand Down
15 changes: 12 additions & 3 deletions src/Moonglade.Web/Pages/Admin/Post.cshtml
Original file line number Diff line number Diff line change
Expand Up @@ -52,13 +52,14 @@
foreach (var item in Model.PostSegments)
{
<div id="post-@item.Id" class="p-3 mb-2 rounded-3 shadow-sm border bg-white">
<div class="d-flex">
<div class="flex-grow-1">
<div class="row">
<div class="col">
<a asp-page="/Post"
asp-route-year="@item.PubDateUtc.GetValueOrDefault().Year"
asp-route-month="@item.PubDateUtc.GetValueOrDefault().Month"
asp-route-day="@item.PubDateUtc.GetValueOrDefault().Day"
asp-route-slug="@item.Slug"
class="d-inline-block"
title="@item.Slug"
target="_blank">
<h6>
Expand All @@ -67,8 +68,16 @@
{
<i class="bi-star-fill text-warning"></i>
}

@if (item.IsOutdated)
{
<span class="badge rounded-pill text-bg-secondary ms-2">Outdated</span>
}
</h6>
</a>
<div class="mb-2">
@item.ContentAbstract
</div>
<div>
<i class="bi-calendar-event"></i>
<span class="text-muted me-2">
Expand All @@ -77,7 +86,7 @@
</div>
</div>

<div>
<div class="col-auto">
<a class="btn btn-outline-accent btn-sm btn-edit" asp-page="./EditPost" asp-route-id="@item.Id"><i class="bi-pen"></i></a>
<button class="btn btn-outline-danger btn-sm btn-delete" onclick="window.deleteConfirm('@item.Id')"><i class="bi-trash"></i></button>
</div>
Expand Down
2 changes: 1 addition & 1 deletion src/Moonglade.Web/Pages/Admin/Post.cshtml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ namespace Moonglade.Web.Pages.Admin;

public class PostModel(IMediator mediator) : PageModel
{
private const int PageSize = 7;
private const int PageSize = 4;

[BindProperty]
[MaxLength(32)]
Expand Down
Loading

0 comments on commit e7c14c5

Please sign in to comment.