From d6ddf5deb9448286f879dc0f14e739753e51e1fa Mon Sep 17 00:00:00 2001 From: Edi Wang Date: Tue, 24 Sep 2024 07:35:03 +0800 Subject: [PATCH 001/112] Add Worker property display to Mention.cshtml Enhanced the mention details display by including the Worker property of the item object. This change ensures that the worker associated with each mention is now visible in the user interface, providing more context to the users. --- src/Moonglade.Web/Pages/Admin/Mention.cshtml | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/Moonglade.Web/Pages/Admin/Mention.cshtml b/src/Moonglade.Web/Pages/Admin/Mention.cshtml index 1b30cd7a4..56922eecd 100644 --- a/src/Moonglade.Web/Pages/Admin/Mention.cshtml +++ b/src/Moonglade.Web/Pages/Admin/Mention.cshtml @@ -93,7 +93,8 @@
@item.Domain, @item.SourceIp, - + , + @item.Worker
From c199036addcda24e5839ab48e1ed3c15ec16057d Mon Sep 17 00:00:00 2001 From: Edi Wang Date: Wed, 25 Sep 2024 10:35:20 +0800 Subject: [PATCH 002/112] Update Microsoft.Identity.Web to 3.2.0 Upgraded the Microsoft.Identity.Web package from version 3.1.0 to 3.2.0 in the Moonglade.Auth.csproj file to incorporate the latest features and bug fixes. --- src/Moonglade.Auth/Moonglade.Auth.csproj | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Moonglade.Auth/Moonglade.Auth.csproj b/src/Moonglade.Auth/Moonglade.Auth.csproj index 88c967c62..07fa0083c 100644 --- a/src/Moonglade.Auth/Moonglade.Auth.csproj +++ b/src/Moonglade.Auth/Moonglade.Auth.csproj @@ -16,7 +16,7 @@ - + From f7c14769c3c21ac14cf2855bcf67efe99e835511 Mon Sep 17 00:00:00 2001 From: Edi Wang Date: Wed, 25 Sep 2024 10:35:34 +0800 Subject: [PATCH 003/112] Update version tag to 14.10.0-rc.1 Updated the version tag in the `Directory.Build.props` file from `14.10.0-beta.1` to `14.10.0-rc.1`. This change marks the transition from the beta phase to the release candidate phase, indicating increased stability and readiness for final release. --- src/Directory.Build.props | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Directory.Build.props b/src/Directory.Build.props index 777ed256d..4eb252a5e 100644 --- a/src/Directory.Build.props +++ b/src/Directory.Build.props @@ -5,6 +5,6 @@ (C) 2024 edi.wang@outlook.com 14.10.0.0 14.10.0.0 - 14.10.0-beta.1 + 14.10.0-rc.1 \ No newline at end of file From b3ad80c1cbb362bc18c32b9a586375223639d0d2 Mon Sep 17 00:00:00 2001 From: Edi Wang Date: Wed, 25 Sep 2024 13:36:18 +0800 Subject: [PATCH 004/112] Update IndexNow key handling and error messages - Updated `IndexNowClient` to add comments on key file location options, comment out `KeyLocation`, and use square brackets for `UrlList`. - Changed `IndexNowMapHandler` error message to "No IndexNow API Key is present." - Modified `Program.cs` to dynamically map IndexNow key file route based on API key from configuration. --- src/Moonglade.IndexNow.Client/IndexNowClient.cs | 8 +++++--- src/Moonglade.IndexNow.Client/IndexNowMapHandler.cs | 2 +- src/Moonglade.Web/Program.cs | 7 ++++++- 3 files changed, 12 insertions(+), 5 deletions(-) diff --git a/src/Moonglade.IndexNow.Client/IndexNowClient.cs b/src/Moonglade.IndexNow.Client/IndexNowClient.cs index d4bd03c86..1b6976869 100644 --- a/src/Moonglade.IndexNow.Client/IndexNowClient.cs +++ b/src/Moonglade.IndexNow.Client/IndexNowClient.cs @@ -45,12 +45,14 @@ public async Task SendRequestAsync(Uri uri) private IndexNowRequest CreateRequestBody(Uri uri) { // https://www.indexnow.org/documentation - return new IndexNowRequest + // "In this option 2, the location of a key file determines the set of URLs that can be included with this key. A key file located at http://example.com/catalog/key12457EDd.txt can include any URLs starting with http://example.com/catalog/ but cannot include URLs starting with http://example.com/help/." + // "URLs that are not considered valid in option 2 may not be considered for indexing. It is strongly recommended that you use Option 1 and place your file key at the root directory of your web server." + return new() { Host = uri.Host, Key = _apiKey, - KeyLocation = $"https://{uri.Host}/indexnowkey.txt", - UrlList = new[] { uri.ToString() } + // KeyLocation = $"https://{uri.Host}/indexnowkey.txt", + UrlList = [uri.ToString()] }; } diff --git a/src/Moonglade.IndexNow.Client/IndexNowMapHandler.cs b/src/Moonglade.IndexNow.Client/IndexNowMapHandler.cs index 114481211..e0e0ffeb9 100644 --- a/src/Moonglade.IndexNow.Client/IndexNowMapHandler.cs +++ b/src/Moonglade.IndexNow.Client/IndexNowMapHandler.cs @@ -17,7 +17,7 @@ public static async Task Handle(HttpContext httpContext, IConfiguration configur if (string.IsNullOrWhiteSpace(apiKey)) { httpContext.Response.StatusCode = StatusCodes.Status404NotFound; - await httpContext.Response.WriteAsync("No indexnowkey.txt is present.", httpContext.RequestAborted); + await httpContext.Response.WriteAsync("No IndexNow API Key is present.", httpContext.RequestAborted); } else { diff --git a/src/Moonglade.Web/Program.cs b/src/Moonglade.Web/Program.cs index d8cb54495..f319f6733 100644 --- a/src/Moonglade.Web/Program.cs +++ b/src/Moonglade.Web/Program.cs @@ -220,7 +220,12 @@ app.MapRazorPages(); app.MapGet("/robots.txt", RobotsTxtMapHandler.Handler); -app.MapGet("/indexnowkey.txt", IndexNowMapHandler.Handler); + +if (!string.IsNullOrWhiteSpace(app.Configuration["IndexNow:ApiKey"])) +{ + app.MapGet($"/{app.Configuration["IndexNow:ApiKey"]}.txt", IndexNowMapHandler.Handler); +} + app.MapGet("/manifest.webmanifest", WebManifestMapHandler.Handler); var bc = app.Services.GetRequiredService(); From f7fbfb6449080d6b97aacc06dfdf7a681c2286f1 Mon Sep 17 00:00:00 2001 From: Edi Wang Date: Wed, 25 Sep 2024 16:14:56 +0800 Subject: [PATCH 005/112] Improve error handling in DiscoverWebmentionEndpoint Modified DiscoverWebmentionEndpoint to check HTTP response status before reading HTML content. This ensures the method handles unsuccessful HTTP requests gracefully by returning null, enhancing robustness and preventing further processing of failed responses. --- src/Moonglade.Webmention/WebmentionSender.cs | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/src/Moonglade.Webmention/WebmentionSender.cs b/src/Moonglade.Webmention/WebmentionSender.cs index 90add2e61..97d8ffd65 100644 --- a/src/Moonglade.Webmention/WebmentionSender.cs +++ b/src/Moonglade.Webmention/WebmentionSender.cs @@ -99,7 +99,10 @@ private async Task SendAsync(Uri sourceUrl, Uri targetUrl) private async Task DiscoverWebmentionEndpoint(string targetUrl) { - string html = await httpClient.GetStringAsync(targetUrl); + var response = await httpClient.GetAsync(targetUrl); + if (!response.IsSuccessStatusCode) return null; + + var html = await response.Content.ReadAsStringAsync(); // Regex to find the Webmention endpoint in the HTML Regex regex = new Regex(" DiscoverWebmentionEndpoint(string targetUrl) { return match.Groups[1].Value; } + return null; } } \ No newline at end of file From 4300ef3acddff36a1a0d4692287076ae5ae17755 Mon Sep 17 00:00:00 2001 From: Edi Wang Date: Wed, 25 Sep 2024 16:16:19 +0800 Subject: [PATCH 006/112] code clean up --- src/Moonglade.Core/PostFeature/CreatePostCommand.cs | 4 ++-- src/Moonglade.Webmention/WebmentionSender.cs | 4 +--- 2 files changed, 3 insertions(+), 5 deletions(-) diff --git a/src/Moonglade.Core/PostFeature/CreatePostCommand.cs b/src/Moonglade.Core/PostFeature/CreatePostCommand.cs index 18aa8afd7..164b12f30 100644 --- a/src/Moonglade.Core/PostFeature/CreatePostCommand.cs +++ b/src/Moonglade.Core/PostFeature/CreatePostCommand.cs @@ -1,10 +1,10 @@ -using System.Globalization; -using Microsoft.Extensions.Configuration; +using Microsoft.Extensions.Configuration; using Microsoft.Extensions.Logging; using Moonglade.Configuration; using Moonglade.Data; using Moonglade.Data.Specifications; using Moonglade.Utils; +using System.Globalization; namespace Moonglade.Core.PostFeature; diff --git a/src/Moonglade.Webmention/WebmentionSender.cs b/src/Moonglade.Webmention/WebmentionSender.cs index 97d8ffd65..3cff7ede2 100644 --- a/src/Moonglade.Webmention/WebmentionSender.cs +++ b/src/Moonglade.Webmention/WebmentionSender.cs @@ -1,5 +1,4 @@ -using Microsoft.Extensions.Configuration; -using Microsoft.Extensions.Logging; +using Microsoft.Extensions.Logging; using Moonglade.Utils; using System.Text.RegularExpressions; @@ -8,7 +7,6 @@ namespace Moonglade.Webmention; public class WebmentionSender( HttpClient httpClient, IWebmentionRequestor requestor, - IConfiguration configuration, ILogger logger) : IWebmentionSender { public async Task SendWebmentionAsync(string postUrl, string postContent) From 30a195820b6d64e1ba514c43e4a6e24271875671 Mon Sep 17 00:00:00 2001 From: Edi Wang Date: Wed, 25 Sep 2024 16:18:03 +0800 Subject: [PATCH 007/112] Enhance log message for missing Webmention endpoint Updated the log message to include the `targetUrl` when a Webmention endpoint is not found. This provides more context in the log output, making it easier to identify which target URL did not have a Webmention endpoint, thereby aiding in debugging and monitoring. --- src/Moonglade.Webmention/WebmentionSender.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Moonglade.Webmention/WebmentionSender.cs b/src/Moonglade.Webmention/WebmentionSender.cs index 3cff7ede2..f56331dd0 100644 --- a/src/Moonglade.Webmention/WebmentionSender.cs +++ b/src/Moonglade.Webmention/WebmentionSender.cs @@ -64,7 +64,7 @@ private async Task SendAsync(Uri sourceUrl, Uri targetUrl) string endpoint = await DiscoverWebmentionEndpoint(targetUrl.ToString()); if (endpoint is null) { - logger.LogWarning("Webmention endpoint not found."); + logger.LogWarning($"Webmention endpoint not found for '{targetUrl}'."); return; } From 7b242277b7844c792e992c967c5510186de35376 Mon Sep 17 00:00:00 2001 From: Edi Wang Date: Wed, 25 Sep 2024 16:20:01 +0800 Subject: [PATCH 008/112] Update IndexNowClient.cs --- src/Moonglade.IndexNow.Client/IndexNowClient.cs | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/Moonglade.IndexNow.Client/IndexNowClient.cs b/src/Moonglade.IndexNow.Client/IndexNowClient.cs index 1b6976869..f7eefff04 100644 --- a/src/Moonglade.IndexNow.Client/IndexNowClient.cs +++ b/src/Moonglade.IndexNow.Client/IndexNowClient.cs @@ -32,6 +32,9 @@ public async Task SendRequestAsync(Uri uri) try { + // TODO: Fix error + // 1. search.seznam.cz, 422 UnprocessableEntity: The host parameter is missing in the request. + // 2. yandex.com, 422 UnprocessableEntity: { "success":false, "message":"No key provided" } var response = await client.PostAsync("/indexnow", content); await HandleResponseAsync(pingTarget, response); } From ae2afd477cef999e7cb679369b9126c62fd75d67 Mon Sep 17 00:00:00 2001 From: Edi Wang Date: Wed, 25 Sep 2024 16:31:56 +0800 Subject: [PATCH 009/112] Fix JSON serialization and clean up IndexNowClient Updated IndexNowClient to use JsonSerializerOptions with JsonNamingPolicy.CamelCase to address 422 errors from case sensitivity in search engines. Removed commented-out code causing issues with search.seznam.cz and yandex.com. Removed KeyLocation property from IndexNowRequest class and its assignment in CreateRequestBody method. --- src/Moonglade.IndexNow.Client/IndexNowClient.cs | 16 +++++++++++----- src/Moonglade.IndexNow.Client/IndexNowRequest.cs | 1 - 2 files changed, 11 insertions(+), 6 deletions(-) diff --git a/src/Moonglade.IndexNow.Client/IndexNowClient.cs b/src/Moonglade.IndexNow.Client/IndexNowClient.cs index f7eefff04..7dbecaa12 100644 --- a/src/Moonglade.IndexNow.Client/IndexNowClient.cs +++ b/src/Moonglade.IndexNow.Client/IndexNowClient.cs @@ -2,6 +2,7 @@ using Microsoft.Extensions.Logging; using System.Net; using System.Text; +using System.Text.Json; namespace Moonglade.IndexNow.Client; @@ -28,13 +29,17 @@ public async Task SendRequestAsync(Uri uri) var client = httpClientFactory.CreateClient(pingTarget); var requestBody = CreateRequestBody(uri); - var content = new StringContent(System.Text.Json.JsonSerializer.Serialize(requestBody), Encoding.UTF8, "application/json"); + + var jso = new JsonSerializerOptions + { + // Fix 422 issue, some search engines is fracking case sensitive! + PropertyNamingPolicy = JsonNamingPolicy.CamelCase + }; + + var content = new StringContent(JsonSerializer.Serialize(requestBody, jso), Encoding.UTF8, "application/json"); try { - // TODO: Fix error - // 1. search.seznam.cz, 422 UnprocessableEntity: The host parameter is missing in the request. - // 2. yandex.com, 422 UnprocessableEntity: { "success":false, "message":"No key provided" } var response = await client.PostAsync("/indexnow", content); await HandleResponseAsync(pingTarget, response); } @@ -50,11 +55,12 @@ private IndexNowRequest CreateRequestBody(Uri uri) // https://www.indexnow.org/documentation // "In this option 2, the location of a key file determines the set of URLs that can be included with this key. A key file located at http://example.com/catalog/key12457EDd.txt can include any URLs starting with http://example.com/catalog/ but cannot include URLs starting with http://example.com/help/." // "URLs that are not considered valid in option 2 may not be considered for indexing. It is strongly recommended that you use Option 1 and place your file key at the root directory of your web server." + // This is why we should not set KeyLocation = $"https://{uri.Host}/xxxx.txt", + return new() { Host = uri.Host, Key = _apiKey, - // KeyLocation = $"https://{uri.Host}/indexnowkey.txt", UrlList = [uri.ToString()] }; } diff --git a/src/Moonglade.IndexNow.Client/IndexNowRequest.cs b/src/Moonglade.IndexNow.Client/IndexNowRequest.cs index 63f90c789..9cce4bf78 100644 --- a/src/Moonglade.IndexNow.Client/IndexNowRequest.cs +++ b/src/Moonglade.IndexNow.Client/IndexNowRequest.cs @@ -4,6 +4,5 @@ public class IndexNowRequest { public string Host { get; set; } public string Key { get; set; } - public string KeyLocation { get; set; } public string[] UrlList { get; set; } } \ No newline at end of file From 2c4097dd9ddd6c9df4a1f08114ffde92400fb641 Mon Sep 17 00:00:00 2001 From: Edi Wang Date: Wed, 25 Sep 2024 16:32:11 +0800 Subject: [PATCH 010/112] Update version to 14.10.0-rc.2 Updated the version number in `Directory.Build.props` from `14.10.0-rc.1` to `14.10.0-rc.2`, indicating a new iteration in the release candidate phase. --- src/Directory.Build.props | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Directory.Build.props b/src/Directory.Build.props index 4eb252a5e..911999d2f 100644 --- a/src/Directory.Build.props +++ b/src/Directory.Build.props @@ -5,6 +5,6 @@ (C) 2024 edi.wang@outlook.com 14.10.0.0 14.10.0.0 - 14.10.0-rc.1 + 14.10.0-rc.2 \ No newline at end of file From beaa676f94abb6b9f79af4004bcaefdef76c1593 Mon Sep 17 00:00:00 2001 From: Edi Wang Date: Thu, 26 Sep 2024 13:24:24 +0800 Subject: [PATCH 011/112] Update Azure.Storage.Blobs to 12.22.1 Upgraded the Azure.Storage.Blobs package from version 12.22.0 to 12.22.1 in the Moonglade.ImageStorage.csproj file to incorporate the latest fixes and improvements. --- src/Moonglade.ImageStorage/Moonglade.ImageStorage.csproj | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Moonglade.ImageStorage/Moonglade.ImageStorage.csproj b/src/Moonglade.ImageStorage/Moonglade.ImageStorage.csproj index 2d7f848c2..bdc8dd966 100644 --- a/src/Moonglade.ImageStorage/Moonglade.ImageStorage.csproj +++ b/src/Moonglade.ImageStorage/Moonglade.ImageStorage.csproj @@ -10,7 +10,7 @@ - + \ No newline at end of file From 65f081c7bf1ddd9f6e58fdd4065d791268b08a67 Mon Sep 17 00:00:00 2001 From: Edi Wang Date: Thu, 26 Sep 2024 13:24:39 +0800 Subject: [PATCH 012/112] Update version to 14.10.0 in Directory.Build.props The element in the Directory.Build.props file has been updated from 14.10.0-rc.2 to 14.10.0. This change signifies the transition from a release candidate stage to a final stable release, indicating that the software is now ready for general use. --- src/Directory.Build.props | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Directory.Build.props b/src/Directory.Build.props index 911999d2f..b36d9fe0e 100644 --- a/src/Directory.Build.props +++ b/src/Directory.Build.props @@ -5,6 +5,6 @@ (C) 2024 edi.wang@outlook.com 14.10.0.0 14.10.0.0 - 14.10.0-rc.2 + 14.10.0 \ No newline at end of file From f14677211ad3f410eb0caa6be76ca614c2c74468 Mon Sep 17 00:00:00 2001 From: Edi Wang Date: Fri, 27 Sep 2024 07:19:34 +0800 Subject: [PATCH 013/112] Refactor _LightSwitch and remove unused components Centralized _LightSwitch partial to _Layout.cshtml and removed it from individual view files. Removed localized "No Archive" and "No Posts" messages from several views. Eliminated image zoom modal from Post.cshtml and PostPreview.cshtml. --- src/Moonglade.Web/Pages/Archive.cshtml | 2 -- src/Moonglade.Web/Pages/ArchiveList.cshtml | 2 -- src/Moonglade.Web/Pages/CategoryList.cshtml | 2 -- src/Moonglade.Web/Pages/Featured.cshtml | 2 -- src/Moonglade.Web/Pages/Index.cshtml | 2 -- src/Moonglade.Web/Pages/Post.cshtml | 2 -- src/Moonglade.Web/Pages/PostPreview.cshtml | 2 -- src/Moonglade.Web/Pages/Search.cshtml | 2 -- src/Moonglade.Web/Pages/Shared/_Layout.cshtml | 1 + src/Moonglade.Web/Pages/TagList.cshtml | 2 -- src/Moonglade.Web/Pages/Tags.cshtml | 2 -- 11 files changed, 1 insertion(+), 20 deletions(-) diff --git a/src/Moonglade.Web/Pages/Archive.cshtml b/src/Moonglade.Web/Pages/Archive.cshtml index 3f4f01598..ea077c25b 100644 --- a/src/Moonglade.Web/Pages/Archive.cshtml +++ b/src/Moonglade.Web/Pages/Archive.cshtml @@ -72,5 +72,3 @@ else - @SharedLocalizer["No Archive"] - } - - \ No newline at end of file diff --git a/src/Moonglade.Web/Pages/ArchiveList.cshtml b/src/Moonglade.Web/Pages/ArchiveList.cshtml index 43f8f2554..dcb707168 100644 --- a/src/Moonglade.Web/Pages/ArchiveList.cshtml +++ b/src/Moonglade.Web/Pages/ArchiveList.cshtml @@ -24,5 +24,3 @@ } } - - \ No newline at end of file diff --git a/src/Moonglade.Web/Pages/CategoryList.cshtml b/src/Moonglade.Web/Pages/CategoryList.cshtml index 46818f1b4..242a48915 100644 --- a/src/Moonglade.Web/Pages/CategoryList.cshtml +++ b/src/Moonglade.Web/Pages/CategoryList.cshtml @@ -28,5 +28,3 @@ else - @SharedLocalizer["No Posts"] - } - - \ No newline at end of file diff --git a/src/Moonglade.Web/Pages/Featured.cshtml b/src/Moonglade.Web/Pages/Featured.cshtml index 465bbd908..cdc442489 100644 --- a/src/Moonglade.Web/Pages/Featured.cshtml +++ b/src/Moonglade.Web/Pages/Featured.cshtml @@ -20,5 +20,3 @@ else @SharedLocalizer["No Posts"] } - - \ No newline at end of file diff --git a/src/Moonglade.Web/Pages/Index.cshtml b/src/Moonglade.Web/Pages/Index.cshtml index 7997a14fa..04b67055a 100644 --- a/src/Moonglade.Web/Pages/Index.cshtml +++ b/src/Moonglade.Web/Pages/Index.cshtml @@ -29,5 +29,3 @@ else @SharedLocalizer["No Posts"] } - - \ No newline at end of file diff --git a/src/Moonglade.Web/Pages/Post.cshtml b/src/Moonglade.Web/Pages/Post.cshtml index 23a8c0d08..248998206 100644 --- a/src/Moonglade.Web/Pages/Post.cshtml +++ b/src/Moonglade.Web/Pages/Post.cshtml @@ -224,8 +224,6 @@ } } - -