Skip to content

Commit

Permalink
Merge pull request #774 from EdiWang/master
Browse files Browse the repository at this point in the history
Release v14.2.0
  • Loading branch information
EdiWang authored Jan 16, 2024
2 parents 14a2d53 + fef2dc2 commit fc90063
Show file tree
Hide file tree
Showing 75 changed files with 422 additions and 600 deletions.
1 change: 0 additions & 1 deletion azure-pipelines.yml → .azure/build-release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ jobs:
inputs:
packageType: 'sdk'
version: '8.0.x'
#includePreviewVersions: true

- task: DotNetCoreCLI@2
displayName: Build
Expand Down
4 changes: 3 additions & 1 deletion .github/workflows/azure-appservice-staging.yml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
name: Azure App Service (Staging)

env:
AZURE_WEBAPP_NAME: moonglade-ediwang-ea
AZURE_WEBAPP_NAME: moonglade-ediwang-us
SLOT_NAME: staging
AZURE_WEBAPP_PACKAGE_PATH: '.'
DOTNET_VERSION: '8.0.x'
Expand All @@ -16,6 +16,7 @@ permissions:

jobs:
build:
if: github.repository == 'EdiWang/Moonglade'
runs-on: ubuntu-latest

steps:
Expand Down Expand Up @@ -51,6 +52,7 @@ jobs:
path: ${{env.DOTNET_ROOT}}/moonglade

deploy:
if: github.repository == 'EdiWang/Moonglade'
permissions:
contents: none
runs-on: ubuntu-latest
Expand Down
1 change: 1 addition & 0 deletions .github/workflows/docker-preview.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ on:
jobs:

build:
if: github.repository == 'EdiWang/Moonglade'
runs-on: ubuntu-latest

steps:
Expand Down
1 change: 1 addition & 0 deletions .github/workflows/docker.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ on:
jobs:

build:
if: github.repository == 'EdiWang/Moonglade'
runs-on: ubuntu-latest

steps:
Expand Down
11 changes: 1 addition & 10 deletions Deployment/mssql-migration.sql
Original file line number Diff line number Diff line change
@@ -1,10 +1 @@
-- v14.1.0

ALTER TABLE FriendLink ADD [Rank] INT
GO

UPDATE FriendLink SET [Rank] = 0
GO

ALTER TABLE FriendLink ALTER COLUMN [Rank] INT NOT NULL
GO
--
4 changes: 2 additions & 2 deletions LICENSE
Original file line number Diff line number Diff line change
Expand Up @@ -632,7 +632,7 @@ state the exclusion of warranty; and each file should have at least
the "copyright" line and a pointer to where the full notice is found.

Moonglade, the blog system for https://edi.wang
Copyright (C) 2020-2023 Edi Wang
Copyright (C) 2020-2024 Edi Wang

This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
Expand All @@ -652,7 +652,7 @@ Also add information on how to contact you by electronic and paper mail.
If the program does terminal interaction, make it output a short
notice like this when it starts in an interactive mode:

Moonglade Copyright (C) 2020-2023 Edi Wang
Moonglade Copyright (C) 2020-2024 Edi Wang
This program comes with ABSOLUTELY NO WARRANTY; for details type `show w'.
This is free software, and you are welcome to redistribute it
under certain conditions; type `show c' for details.
Expand Down
8 changes: 4 additions & 4 deletions src/Directory.Build.props
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@
<PropertyGroup>
<Authors>Edi Wang</Authors>
<Company>edi.wang</Company>
<Copyright>(C) 2023 edi.wang@outlook.com</Copyright>
<AssemblyVersion>14.1.0.0</AssemblyVersion>
<FileVersion>14.1.0.0</FileVersion>
<Version>14.1.0</Version>
<Copyright>(C) 2024 edi.wang@outlook.com</Copyright>
<AssemblyVersion>14.2.0.0</AssemblyVersion>
<FileVersion>14.2.0.0</FileVersion>
<Version>14.2.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.16.0" />
<PackageReference Include="Microsoft.Identity.Web" Version="2.16.1" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\Moonglade.Data\Moonglade.Data.csproj" />
Expand Down
2 changes: 1 addition & 1 deletion src/Moonglade.Configuration/AdvancedSettings.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ public class AdvancedSettings : IBlogSettings

[Display(Name = "Foot JavaScript")]
[DataType(DataType.MultilineText)]
[MaxLength(256)]
[MaxLength(1024)]
public string FootScripts { get; set; }

[Display(Name = "Enable Pingback")]
Expand Down
6 changes: 0 additions & 6 deletions src/Moonglade.Configuration/ContentSettings.cs
Original file line number Diff line number Diff line change
Expand Up @@ -39,11 +39,6 @@ public class ContentSettings : IBlogSettings
[Range(5, 30)]
public int PostListPageSize { get; set; } = 10;

[Required]
[Display(Name = "How many tags show on sidebar")]
[Range(5, 20)]
public int HotTagAmount { get; set; } = 10;

[Display(Name = "Enable Gravatar in comment list")]
public bool EnableGravatar { get; set; }

Expand Down Expand Up @@ -78,7 +73,6 @@ public class ContentSettings : IBlogSettings
EnableGravatar = true,
EnableWordFilter = false,
PostListPageSize = 10,
HotTagAmount = 10,
CalloutSectionHtmlPitch = string.Empty
};
}
Expand Down
13 changes: 8 additions & 5 deletions src/Moonglade.Configuration/GeneralSettings.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ public class GeneralSettings : IBlogSettings
{
[Required]
[Display(Name = "Meta keyword")]
[MaxLength(1024)]
[MaxLength(256)]
public string MetaKeyword { get; set; }

[Display(Name = "Canonical URL prefix")]
Expand Down Expand Up @@ -77,6 +77,11 @@ public class GeneralSettings : IBlogSettings
[Display(Name = "Tags")]
public bool WidgetsTags { get; set; } = true;

[Required]
[Display(Name = "How many tags to show on sidebar")]
[Range(5, 20)]
public int HotTagAmount { get; set; } = 10;

[Display(Name = "Categories")]
public bool WidgetsCategoryList { get; set; } = true;

Expand All @@ -86,9 +91,6 @@ public class GeneralSettings : IBlogSettings
[Display(Name = "Subscription buttons")]
public bool WidgetsSubscriptionButtons { get; set; } = true;

[Display(Name = "Admin login button")]
public bool ShowAdminLoginButton { get; set; }

[MaxLength(64)]
public string AvatarUrl { get; set; }

Expand Down Expand Up @@ -117,7 +119,8 @@ public class GeneralSettings : IBlogSettings
Copyright = $"[c] {DateTime.UtcNow.Year}",
TimeZoneId = "China Standard Time",
TimeZoneUtcOffset = TimeSpan.FromHours(8),
ThemeId = 1
ThemeId = 1,
HotTagAmount = 10
};
}

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.0" />
<PackageReference Include="Microsoft.EntityFrameworkCore.SqlServer" Version="8.0.1" />
</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 @@ -12,6 +12,6 @@
<Using Include="Microsoft.EntityFrameworkCore" />
<PackageReference Include="MediatR" Version="12.2.0" />
<FrameworkReference Include="Microsoft.AspNetCore.App" />
<PackageReference Include="Microsoft.EntityFrameworkCore.Proxies" Version="8.0.0" />
<PackageReference Include="Microsoft.EntityFrameworkCore.Proxies" Version="8.0.1" />
</ItemGroup>
</Project>
20 changes: 20 additions & 0 deletions src/Moonglade.Utils/Helper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -417,4 +417,24 @@ public static void ValidatePagingParameters(int pageSize, int pageIndex)
{ " ", "-" },
{ "+", "-plus" }
};

public static bool IsValidHeaderName(string headerName)
{
if (string.IsNullOrEmpty(headerName))
{
return false;
}

// Check if header name conforms to the standard which allows:
// - Any ASCII character from 'a' to 'z' and 'A' to 'Z'
// - Digits from '0' to '9'
// - Special characters: '!', '#', '$', '%', '&', ''', '*', '+', '-', '.', '^', '_', '`', '|', '~'
return headerName.All(c =>
c is >= 'a' and <= 'z' ||
c is >= 'A' and <= 'Z' ||
c is >= '0' and <= '9' ||
c == '!' || c == '#' || c == '$' || c == '%' || c == '&' || c == '\'' ||
c == '*' || c == '+' || c == '-' || c == '.' || c == '^' || c == '_' ||
c == '`' || c == '|' || c == '~');
}
}
7 changes: 4 additions & 3 deletions src/Moonglade.Web/Controllers/ImageController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
using Microsoft.Extensions.Caching.Memory;
using Microsoft.Extensions.Options;
using SixLabors.ImageSharp;
using System.ComponentModel.DataAnnotations;

namespace Moonglade.Web.Controllers;

Expand All @@ -23,7 +24,7 @@ public class ImageController(IBlogImageStorage imageStorage,
[ProducesResponseType(StatusCodes.Status302Found)]
[ProducesResponseType(StatusCodes.Status400BadRequest)]
[ProducesResponseType(StatusCodes.Status404NotFound)]
public async Task<IActionResult> Image(string filename)
public async Task<IActionResult> Image([MaxLength(256)] string filename)
{
var invalidChars = Path.GetInvalidFileNameChars();
if (filename.IndexOfAny(invalidChars) >= 0)
Expand All @@ -35,7 +36,7 @@ public async Task<IActionResult> Image(string filename)
if (blogConfig.ImageSettings.EnableCDNRedirect)
{
var imageUrl = blogConfig.ImageSettings.CDNEndpoint.CombineUrl(filename);
return Redirect(imageUrl);
return RedirectPermanent(imageUrl);
}

var image = await cache.GetOrCreateAsync(filename, async entry =>
Expand Down Expand Up @@ -67,7 +68,7 @@ public async Task<IActionResult> Image(IFormFile file, [FromQuery] bool skipWate
var ext = Path.GetExtension(name).ToLower();
var allowedExts = _imageStorageSettings.AllowedExtensions;

if (null == allowedExts || !allowedExts.Any())
if (null == allowedExts || allowedExts.Length == 0)
{
throw new InvalidDataException($"{nameof(ImageStorageSettings.AllowedExtensions)} is empty.");
}
Expand Down
1 change: 1 addition & 0 deletions src/Moonglade.Web/IconGenerator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ public static void GenerateIcons(string base64Data, string webRootPath, ILogger
{
logger.LogWarning("SiteIconBase64 is empty or not valid, fall back to default image.");

// Credit: Vector Market (siteicon-default.png)
var defaultIconImage = Path.Join($"{webRootPath}", "images", "siteicon-default.png");
if (!File.Exists(defaultIconImage))
{
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 @@ -41,7 +41,7 @@
<PackageReference Include="UAParser" Version="3.1.47" />
<PackageReference Include="WilderMinds.MetaWeblog" Version="5.1.1" />
<PackageReference Include="Microsoft.ApplicationInsights.AspNetCore" Version="2.22.0" />
<PackageReference Include="Microsoft.Extensions.Logging.AzureAppServices" Version="8.0.0" />
<PackageReference Include="Microsoft.Extensions.Logging.AzureAppServices" Version="8.0.1" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\Moonglade.Auth\Moonglade.Auth.csproj" />
Expand Down
7 changes: 5 additions & 2 deletions src/Moonglade.Web/PagedList/BasePagedList.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ namespace Moonglade.Web.PagedList;
/// <typeparam name = "T">The type of object the collection should contain.</typeparam>
/// <seealso cref = "IPagedList{T}" />
/// <seealso cref = "List{T}" />
public abstract class BasePagedList<T> : PagedListMetaData, IPagedList<T>
public class BasePagedList<T> : PagedListMetaData, IPagedList<T>
{
protected readonly List<T> Subset = new();

Expand All @@ -28,10 +28,11 @@ protected internal BasePagedList()
/// Initializes a new instance of a type deriving from <see cref = "BasePagedList{T}" /> and sets properties
/// needed to calculate position and size data on the subset and superset.
/// </summary>
/// <param name="subset">The single subset this collection should represent.</param>
/// <param name = "pageNumber">The one-based index of the subset of objects contained by this instance.</param>
/// <param name = "pageSize">The maximum size of any individual subset.</param>
/// <param name = "totalItemCount">The size of the superset.</param>
protected internal BasePagedList(int pageNumber, int pageSize, int totalItemCount)
public BasePagedList(IEnumerable<T> subset, int pageNumber, int pageSize, int totalItemCount)
{
if (pageNumber < 1)
{
Expand Down Expand Up @@ -75,6 +76,8 @@ protected internal BasePagedList(int pageNumber, int pageSize, int totalItemCoun
? TotalItemCount
: numberOfLastItemOnPage
: 0;

Subset.AddRange(subset);
}

#region IPagedList<T> Members
Expand Down
36 changes: 8 additions & 28 deletions src/Moonglade.Web/PagedList/HtmlHelper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -73,12 +73,12 @@ private TagBuilder First(IPagedList list, Func<int, string> generatePageUrl, Pag

if (list.IsFirstPage)
{
return WrapInListItem(first, options, "PagedList-skipToFirst", "disabled");
return WrapInListItem(first, options, "paged-list-skip-to-first", "disabled");
}

first.Attributes.Add("href", generatePageUrl(targetPageNumber));

return WrapInListItem(first, options, "PagedList-skipToFirst");
return WrapInListItem(first, options, "paged-list-skip-to-first");
}

private TagBuilder Previous(IPagedList list, Func<int, string> generatePageUrl, PagedListRenderOptions options)
Expand Down Expand Up @@ -174,12 +174,12 @@ private TagBuilder Last(IPagedList list, Func<int, string> generatePageUrl, Page

if (list.IsLastPage)
{
return WrapInListItem(last, options, "PagedList-skipToLast", "disabled");
return WrapInListItem(last, options, "paged-list-skip-to-last", "disabled");
}

last.Attributes.Add("href", generatePageUrl(targetPageNumber));

return WrapInListItem(last, options, "PagedList-skipToLast");
return WrapInListItem(last, options, "paged-list-skip-to-last");
}

private TagBuilder PageCountAndLocationText(IPagedList list, PagedListRenderOptions options)
Expand Down Expand Up @@ -210,7 +210,7 @@ private TagBuilder PreviousEllipsis(IPagedList list, Func<int, string> generateP
AppendHtml(previous, options.EllipsesFormat);

previous.Attributes.Add("rel", "prev");
previous.AddCssClass("PagedList-skipToPrevious");
previous.AddCssClass("paged-list-skip-to-previous");

foreach (var c in options.PageClasses ?? Enumerable.Empty<string>())
{
Expand All @@ -237,7 +237,7 @@ private TagBuilder NextEllipsis(IPagedList list, Func<int, string> generatePageU
AppendHtml(next, options.EllipsesFormat);

next.Attributes.Add("rel", "next");
next.AddCssClass("PagedList-skipToNext");
next.AddCssClass("paged-list-skip-to-next");

foreach (var c in options.PageClasses ?? Enumerable.Empty<string>())
{
Expand All @@ -260,9 +260,9 @@ private TagBuilder NextEllipsis(IPagedList list, Func<int, string> generatePageU

public string PagedListPager(IPagedList pagedList, Func<int, string> generatePageUrl, PagedListRenderOptions options)
{
var list = pagedList ?? new StaticPagedList<int>(ImmutableList<int>.Empty, 1, 10, 0);
var list = pagedList ?? new BasePagedList<int>(ImmutableList<int>.Empty, 1, 10, 0);

if (options.Display == PagedListDisplayMode.Never || (options.Display == PagedListDisplayMode.IfNeeded && list.PageCount <= 1))
if (options.Display == PagedListDisplayMode.IfNeeded && list.PageCount <= 1)
{
return null;
}
Expand Down Expand Up @@ -372,18 +372,6 @@ public string PagedListPager(IPagedList pagedList, Func<int, string> generatePag

if (listItemLinks.Any())
{
//append class to first item in list?
if (!string.IsNullOrWhiteSpace(options.ClassToApplyToFirstListItemInPager))
{
listItemLinks.First().AddCssClass(options.ClassToApplyToFirstListItemInPager);
}

//append class to last item in list?
if (!string.IsNullOrWhiteSpace(options.ClassToApplyToLastListItemInPager))
{
listItemLinks.Last().AddCssClass(options.ClassToApplyToLastListItemInPager);
}

//append classes to all list item links
foreach (var li in listItemLinks)
{
Expand All @@ -410,14 +398,6 @@ public string PagedListPager(IPagedList pagedList, Func<int, string> generatePag
ul.AddCssClass(c);
}

if (options.UlElementattributes != null)
{
foreach (var c in options.UlElementattributes)
{
ul.MergeAttribute(c.Key, c.Value);
}
}

var outerDiv = tagBuilderFactory
.Create("div");

Expand Down
Loading

0 comments on commit fc90063

Please sign in to comment.