From ada5a24e0ca833c76471cbc2bd98a6486e7d589f Mon Sep 17 00:00:00 2001 From: Kouji Matsui Date: Mon, 17 Oct 2022 10:07:20 +0900 Subject: [PATCH 01/20] Switched using ILRepack.FullAuto instead ILRepack.Lib.MSBuild.Task. --- mtr/mtr.csproj | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/mtr/mtr.csproj b/mtr/mtr.csproj index 2ed6634..9f764c9 100644 --- a/mtr/mtr.csproj +++ b/mtr/mtr.csproj @@ -9,7 +9,7 @@ - + From cb43d012e66f39a8ded2b5d95925c9a7201d99a3 Mon Sep 17 00:00:00 2001 From: Kouji Matsui Date: Mon, 17 Oct 2022 17:11:37 +0900 Subject: [PATCH 02/20] Updated packages. --- mtr/mtr.csproj | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/mtr/mtr.csproj b/mtr/mtr.csproj index 9f764c9..efd2228 100644 --- a/mtr/mtr.csproj +++ b/mtr/mtr.csproj @@ -4,12 +4,11 @@ Exe net471 mtr - true ..\Images\MarkTheRipper.ico - + From 5a215dad00dde5b70863fc10f7ea7377031bfd43 Mon Sep 17 00:00:00 2001 From: Kouji Matsui Date: Mon, 17 Oct 2022 22:14:58 +0900 Subject: [PATCH 03/20] Made stable tags/categories list by the name. --- ...RelativePathCalculation_subNames=.verified.txt | 8 ++++---- ...ePathCalculation_subNames=aaa-bbb.verified.txt | 8 ++++---- ...ativePathCalculation_subNames=aaa.verified.txt | 8 ++++---- .../Internal/InternalUtilities.cs | 15 +++++++++++++++ MarkTheRipper.Engine/Metadata/EntryAggregator.cs | 6 +++--- 5 files changed, 30 insertions(+), 15 deletions(-) diff --git a/MarkTheRipper.Engine.Tests/BulkRipperTests.RipOffRelativePathCalculation_subNames=.verified.txt b/MarkTheRipper.Engine.Tests/BulkRipperTests.RipOffRelativePathCalculation_subNames=.verified.txt index 3fafa08..6204847 100644 --- a/MarkTheRipper.Engine.Tests/BulkRipperTests.RipOffRelativePathCalculation_subNames=.verified.txt +++ b/MarkTheRipper.Engine.Tests/BulkRipperTests.RipOffRelativePathCalculation_subNames=.verified.txt @@ -5,12 +5,12 @@ -

Tags: reftag

-

Title: ref -

Tags: foo

-

Title: hoehoe

Tags: bar

Title: hoehoe +

Tags: foo

+

Title: hoehoe +

Tags: reftag

+

Title: ref

Hello MarkTheRipper! This is test contents.

diff --git a/MarkTheRipper.Engine.Tests/BulkRipperTests.RipOffRelativePathCalculation_subNames=aaa-bbb.verified.txt b/MarkTheRipper.Engine.Tests/BulkRipperTests.RipOffRelativePathCalculation_subNames=aaa-bbb.verified.txt index fa096be..887c39d 100644 --- a/MarkTheRipper.Engine.Tests/BulkRipperTests.RipOffRelativePathCalculation_subNames=aaa-bbb.verified.txt +++ b/MarkTheRipper.Engine.Tests/BulkRipperTests.RipOffRelativePathCalculation_subNames=aaa-bbb.verified.txt @@ -5,12 +5,12 @@ -

Tags: reftag

-

Title: ref -

Tags: foo

-

Title: hoehoe

Tags: bar

Title: hoehoe +

Tags: foo

+

Title: hoehoe +

Tags: reftag

+

Title: ref

Hello MarkTheRipper! This is test contents.

diff --git a/MarkTheRipper.Engine.Tests/BulkRipperTests.RipOffRelativePathCalculation_subNames=aaa.verified.txt b/MarkTheRipper.Engine.Tests/BulkRipperTests.RipOffRelativePathCalculation_subNames=aaa.verified.txt index 46b9dd1..6e9dd9e 100644 --- a/MarkTheRipper.Engine.Tests/BulkRipperTests.RipOffRelativePathCalculation_subNames=aaa.verified.txt +++ b/MarkTheRipper.Engine.Tests/BulkRipperTests.RipOffRelativePathCalculation_subNames=aaa.verified.txt @@ -5,12 +5,12 @@ -

Tags: reftag

-

Title: ref -

Tags: foo

-

Title: hoehoe

Tags: bar

Title: hoehoe +

Tags: foo

+

Title: hoehoe +

Tags: reftag

+

Title: ref

Hello MarkTheRipper! This is test contents.

diff --git a/MarkTheRipper.Engine/Internal/InternalUtilities.cs b/MarkTheRipper.Engine/Internal/InternalUtilities.cs index 7e61a14..08d426d 100644 --- a/MarkTheRipper.Engine/Internal/InternalUtilities.cs +++ b/MarkTheRipper.Engine/Internal/InternalUtilities.cs @@ -119,6 +119,21 @@ public static IEnumerable Collect(this IEnumerable enumerable, Func< } } + public static SortedDictionary ToSortedDictionary( + this IEnumerable enumerable, + Func keySelector, Func valueSelector) + where TKey : IEquatable + { + var sd = new SortedDictionary(); + foreach (var item in enumerable) + { + var key = keySelector(item); + var value = valueSelector(item); + sd.Add(key, value); + } + return sd; + } + public static IEnumerable Unfold(this T value, Func selector) { var current = value; diff --git a/MarkTheRipper.Engine/Metadata/EntryAggregator.cs b/MarkTheRipper.Engine/Metadata/EntryAggregator.cs index bd18ecd..ca77b36 100644 --- a/MarkTheRipper.Engine/Metadata/EntryAggregator.cs +++ b/MarkTheRipper.Engine/Metadata/EntryAggregator.cs @@ -24,7 +24,7 @@ private static DateTimeOffset GetDate(MarkdownEntry? markdownEntry) => dto : DateTimeOffset.MaxValue; - public static async ValueTask> AggregateTagsAsync( + public static async ValueTask> AggregateTagsAsync( IEnumerable markdownEntries, IMetadataContext metadata, CancellationToken ct) => @@ -40,7 +40,7 @@ await markdownEntry.GetPropertyValueAsync("tags", metadata, Reducer.Instance, ct ConfigureAwait(false)). SelectMany(entries => entries). GroupBy(entry => entry.tag.Name). - ToDictionary( + ToSortedDictionary( g => g.Key, g => new TagEntry( g.Key, @@ -78,7 +78,7 @@ await markdownEntry.GetPropertyValueAsync("category", metadata, Reducer.Instance ct). ConfigureAwait(false)))). ConfigureAwait(false)). - ToDictionary( + ToSortedDictionary( g => g.key, g => g.values); From b7a68dec0aa8a74b8a4c1643722822511bd5388c Mon Sep 17 00:00:00 2001 From: Kouji Matsui Date: Thu, 20 Oct 2022 21:07:17 +0900 Subject: [PATCH 04/20] Refactored. --- .../Metadata/{PartialTemplateEntry.cs => PartialLayoutEntry.cs} | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename MarkTheRipper.Engine/Metadata/{PartialTemplateEntry.cs => PartialLayoutEntry.cs} (100%) diff --git a/MarkTheRipper.Engine/Metadata/PartialTemplateEntry.cs b/MarkTheRipper.Engine/Metadata/PartialLayoutEntry.cs similarity index 100% rename from MarkTheRipper.Engine/Metadata/PartialTemplateEntry.cs rename to MarkTheRipper.Engine/Metadata/PartialLayoutEntry.cs From fb108f99022a94f91a492005924bf4355f9dc5b1 Mon Sep 17 00:00:00 2001 From: Kouji Matsui Date: Sun, 23 Oct 2022 14:07:33 +0900 Subject: [PATCH 05/20] Refactored. --- ...iesTests.AggregateCategories1.verified.txt | 2 +- ...iesTests.AggregateCategories2.verified.txt | 2 +- ...iesTests.AggregateCategories3.verified.txt | 4 +-- ...iesTests.AggregateCategories4.verified.txt | 4 +-- ...iesTests.AggregateCategories5.verified.txt | 6 ++-- ...iesTests.AggregateCategories6.verified.txt | 2 +- ...iesTests.AggregateCategories7.verified.txt | 6 ++-- ...iesTests.AggregateCategories8.verified.txt | 4 +-- ...ategoriesTests.AggregateTags1.verified.txt | 2 +- ...ategoriesTests.AggregateTags2.verified.txt | 4 +-- ...ategoriesTests.AggregateTags3.verified.txt | 4 +-- ...ategoriesTests.AggregateTags4.verified.txt | 6 ++-- ...ategoriesTests.AggregateTags5.verified.txt | 8 ++--- .../ParserTests.AggregateTags1.verified.txt | 2 +- .../ParserTests.AggregateTags2.verified.txt | 4 +-- .../ParserTests.AggregateTags3.verified.txt | 4 +-- .../ParserTests.AggregateTags4.verified.txt | 6 ++-- .../ParserTests.AggregateTags5.verified.txt | 8 ++--- .../TagsTests.AggregateTags1.verified.txt | 2 +- .../TagsTests.AggregateTags2.verified.txt | 4 +-- .../TagsTests.AggregateTags3.verified.txt | 4 +-- .../TagsTests.AggregateTags4.verified.txt | 6 ++-- .../TagsTests.AggregateTags5.verified.txt | 8 ++--- MarkTheRipper.Engine/Expressions/Parser.cs | 12 +++---- .../Internal/InternalUtilities.cs | 2 +- MarkTheRipper.Engine/Internal/KeyComparer.cs | 32 +++++++++++++++++ .../Metadata/MarkdownEntry.cs | 34 +++++++++---------- .../Metadata/MetadataContext.cs | 10 ++++++ MarkTheRipper.Engine/Ripper.cs | 20 +++++------ 29 files changed, 127 insertions(+), 85 deletions(-) create mode 100644 MarkTheRipper.Engine/Internal/KeyComparer.cs diff --git a/MarkTheRipper.Engine.Tests/CategoriesTests.AggregateCategories1.verified.txt b/MarkTheRipper.Engine.Tests/CategoriesTests.AggregateCategories1.verified.txt index f57ffdc..5f587b3 100644 --- a/MarkTheRipper.Engine.Tests/CategoriesTests.AggregateCategories1.verified.txt +++ b/MarkTheRipper.Engine.Tests/CategoriesTests.AggregateCategories1.verified.txt @@ -5,7 +5,7 @@ Name: cat1, Entries: [ { - Metadata: { + HeaderMetadata: { category: { Name: cat1, Parent: { diff --git a/MarkTheRipper.Engine.Tests/CategoriesTests.AggregateCategories2.verified.txt b/MarkTheRipper.Engine.Tests/CategoriesTests.AggregateCategories2.verified.txt index dbb17a2..81bd851 100644 --- a/MarkTheRipper.Engine.Tests/CategoriesTests.AggregateCategories2.verified.txt +++ b/MarkTheRipper.Engine.Tests/CategoriesTests.AggregateCategories2.verified.txt @@ -8,7 +8,7 @@ Name: cat2, Entries: [ { - Metadata: { + HeaderMetadata: { category: { Name: cat2, Parent: { diff --git a/MarkTheRipper.Engine.Tests/CategoriesTests.AggregateCategories3.verified.txt b/MarkTheRipper.Engine.Tests/CategoriesTests.AggregateCategories3.verified.txt index 65ac113..e4c88f6 100644 --- a/MarkTheRipper.Engine.Tests/CategoriesTests.AggregateCategories3.verified.txt +++ b/MarkTheRipper.Engine.Tests/CategoriesTests.AggregateCategories3.verified.txt @@ -5,7 +5,7 @@ Name: cat1, Entries: [ { - Metadata: { + HeaderMetadata: { category: { Name: cat1, Parent: { @@ -16,7 +16,7 @@ } }, { - Metadata: { + HeaderMetadata: { category: { Name: cat1, Parent: { diff --git a/MarkTheRipper.Engine.Tests/CategoriesTests.AggregateCategories4.verified.txt b/MarkTheRipper.Engine.Tests/CategoriesTests.AggregateCategories4.verified.txt index f01ba41..46b376e 100644 --- a/MarkTheRipper.Engine.Tests/CategoriesTests.AggregateCategories4.verified.txt +++ b/MarkTheRipper.Engine.Tests/CategoriesTests.AggregateCategories4.verified.txt @@ -8,7 +8,7 @@ Name: cat2, Entries: [ { - Metadata: { + HeaderMetadata: { category: { Name: cat2, Parent: { @@ -26,7 +26,7 @@ }, Entries: [ { - Metadata: { + HeaderMetadata: { category: { Name: cat1, Parent: { diff --git a/MarkTheRipper.Engine.Tests/CategoriesTests.AggregateCategories5.verified.txt b/MarkTheRipper.Engine.Tests/CategoriesTests.AggregateCategories5.verified.txt index f5c261d..5e49342 100644 --- a/MarkTheRipper.Engine.Tests/CategoriesTests.AggregateCategories5.verified.txt +++ b/MarkTheRipper.Engine.Tests/CategoriesTests.AggregateCategories5.verified.txt @@ -8,7 +8,7 @@ Name: cat2, Entries: [ { - Metadata: { + HeaderMetadata: { category: { Name: cat2, Parent: { @@ -26,7 +26,7 @@ }, Entries: [ { - Metadata: { + HeaderMetadata: { category: { Name: cat1, Parent: { @@ -42,7 +42,7 @@ Name: cat3, Entries: [ { - Metadata: { + HeaderMetadata: { category: { Name: cat3, Parent: { diff --git a/MarkTheRipper.Engine.Tests/CategoriesTests.AggregateCategories6.verified.txt b/MarkTheRipper.Engine.Tests/CategoriesTests.AggregateCategories6.verified.txt index 0671a18..948322c 100644 --- a/MarkTheRipper.Engine.Tests/CategoriesTests.AggregateCategories6.verified.txt +++ b/MarkTheRipper.Engine.Tests/CategoriesTests.AggregateCategories6.verified.txt @@ -2,7 +2,7 @@ Name: (root), Entries: [ { - Metadata: { + HeaderMetadata: { path: content1 } } diff --git a/MarkTheRipper.Engine.Tests/CategoriesTests.AggregateCategories7.verified.txt b/MarkTheRipper.Engine.Tests/CategoriesTests.AggregateCategories7.verified.txt index 2726d12..ff4bf76 100644 --- a/MarkTheRipper.Engine.Tests/CategoriesTests.AggregateCategories7.verified.txt +++ b/MarkTheRipper.Engine.Tests/CategoriesTests.AggregateCategories7.verified.txt @@ -8,7 +8,7 @@ Name: cat2, Entries: [ { - Metadata: { + HeaderMetadata: { category: { Name: cat2, Parent: { @@ -22,7 +22,7 @@ } }, { - Metadata: { + HeaderMetadata: { category: { Name: cat2, Parent: { @@ -40,7 +40,7 @@ }, Entries: [ { - Metadata: { + HeaderMetadata: { category: { Name: cat1, Parent: { diff --git a/MarkTheRipper.Engine.Tests/CategoriesTests.AggregateCategories8.verified.txt b/MarkTheRipper.Engine.Tests/CategoriesTests.AggregateCategories8.verified.txt index 572930a..0d614e8 100644 --- a/MarkTheRipper.Engine.Tests/CategoriesTests.AggregateCategories8.verified.txt +++ b/MarkTheRipper.Engine.Tests/CategoriesTests.AggregateCategories8.verified.txt @@ -8,7 +8,7 @@ Name: cat2, Entries: [ { - Metadata: { + HeaderMetadata: { category: { Name: cat2, Parent: { @@ -32,7 +32,7 @@ Name: cat2, Entries: [ { - Metadata: { + HeaderMetadata: { category: { Name: cat2, Parent: { diff --git a/MarkTheRipper.Engine.Tests/CategoriesTests.AggregateTags1.verified.txt b/MarkTheRipper.Engine.Tests/CategoriesTests.AggregateTags1.verified.txt index b5c49fe..7929d6b 100644 --- a/MarkTheRipper.Engine.Tests/CategoriesTests.AggregateTags1.verified.txt +++ b/MarkTheRipper.Engine.Tests/CategoriesTests.AggregateTags1.verified.txt @@ -2,7 +2,7 @@ tag1: [ { RelativeContentPath: content1, - Metadata: { + HeaderMetadata: { tags: [ tag1 ] diff --git a/MarkTheRipper.Engine.Tests/CategoriesTests.AggregateTags2.verified.txt b/MarkTheRipper.Engine.Tests/CategoriesTests.AggregateTags2.verified.txt index fe6185e..90f23e5 100644 --- a/MarkTheRipper.Engine.Tests/CategoriesTests.AggregateTags2.verified.txt +++ b/MarkTheRipper.Engine.Tests/CategoriesTests.AggregateTags2.verified.txt @@ -2,7 +2,7 @@ tag1: [ { RelativeContentPath: content1, - Metadata: { + HeaderMetadata: { tags: [ tag1, tag2 @@ -13,7 +13,7 @@ tag2: [ { RelativeContentPath: content1, - Metadata: { + HeaderMetadata: { tags: [ tag1, tag2 diff --git a/MarkTheRipper.Engine.Tests/CategoriesTests.AggregateTags3.verified.txt b/MarkTheRipper.Engine.Tests/CategoriesTests.AggregateTags3.verified.txt index d8118a0..09a9ac7 100644 --- a/MarkTheRipper.Engine.Tests/CategoriesTests.AggregateTags3.verified.txt +++ b/MarkTheRipper.Engine.Tests/CategoriesTests.AggregateTags3.verified.txt @@ -2,7 +2,7 @@ tag1: [ { RelativeContentPath: content1, - Metadata: { + HeaderMetadata: { tags: [ tag1 ] @@ -10,7 +10,7 @@ }, { RelativeContentPath: content2, - Metadata: { + HeaderMetadata: { tags: [ tag1 ] diff --git a/MarkTheRipper.Engine.Tests/CategoriesTests.AggregateTags4.verified.txt b/MarkTheRipper.Engine.Tests/CategoriesTests.AggregateTags4.verified.txt index 2b8fd58..57c5526 100644 --- a/MarkTheRipper.Engine.Tests/CategoriesTests.AggregateTags4.verified.txt +++ b/MarkTheRipper.Engine.Tests/CategoriesTests.AggregateTags4.verified.txt @@ -2,7 +2,7 @@ tag1: [ { RelativeContentPath: content1, - Metadata: { + HeaderMetadata: { tags: [ tag1 ] @@ -10,7 +10,7 @@ }, { RelativeContentPath: content2, - Metadata: { + HeaderMetadata: { tags: [ tag1, tag2 @@ -21,7 +21,7 @@ tag2: [ { RelativeContentPath: content2, - Metadata: { + HeaderMetadata: { tags: [ tag1, tag2 diff --git a/MarkTheRipper.Engine.Tests/CategoriesTests.AggregateTags5.verified.txt b/MarkTheRipper.Engine.Tests/CategoriesTests.AggregateTags5.verified.txt index 6556dfc..dbbf8f4 100644 --- a/MarkTheRipper.Engine.Tests/CategoriesTests.AggregateTags5.verified.txt +++ b/MarkTheRipper.Engine.Tests/CategoriesTests.AggregateTags5.verified.txt @@ -2,7 +2,7 @@ tag1: [ { RelativeContentPath: content1, - Metadata: { + HeaderMetadata: { tags: [ tag1 ] @@ -10,7 +10,7 @@ }, { RelativeContentPath: content2, - Metadata: { + HeaderMetadata: { tags: [ tag1, tag2 @@ -21,7 +21,7 @@ tag2: [ { RelativeContentPath: content2, - Metadata: { + HeaderMetadata: { tags: [ tag1, tag2 @@ -32,7 +32,7 @@ tag3: [ { RelativeContentPath: content3, - Metadata: { + HeaderMetadata: { tags: [ tag3 ] diff --git a/MarkTheRipper.Engine.Tests/ParserTests.AggregateTags1.verified.txt b/MarkTheRipper.Engine.Tests/ParserTests.AggregateTags1.verified.txt index 94ff4ae..dca1354 100644 --- a/MarkTheRipper.Engine.Tests/ParserTests.AggregateTags1.verified.txt +++ b/MarkTheRipper.Engine.Tests/ParserTests.AggregateTags1.verified.txt @@ -3,7 +3,7 @@ Name: tag1, Entries: [ { - Metadata: { + HeaderMetadata: { path: content1, tags: [ { diff --git a/MarkTheRipper.Engine.Tests/ParserTests.AggregateTags2.verified.txt b/MarkTheRipper.Engine.Tests/ParserTests.AggregateTags2.verified.txt index ac7ea85..85fd420 100644 --- a/MarkTheRipper.Engine.Tests/ParserTests.AggregateTags2.verified.txt +++ b/MarkTheRipper.Engine.Tests/ParserTests.AggregateTags2.verified.txt @@ -3,7 +3,7 @@ Name: tag1, Entries: [ { - Metadata: { + HeaderMetadata: { path: content1, tags: [ { @@ -21,7 +21,7 @@ Name: tag2, Entries: [ { - Metadata: { + HeaderMetadata: { path: content1, tags: [ { diff --git a/MarkTheRipper.Engine.Tests/ParserTests.AggregateTags3.verified.txt b/MarkTheRipper.Engine.Tests/ParserTests.AggregateTags3.verified.txt index a9fc31b..1f90ad8 100644 --- a/MarkTheRipper.Engine.Tests/ParserTests.AggregateTags3.verified.txt +++ b/MarkTheRipper.Engine.Tests/ParserTests.AggregateTags3.verified.txt @@ -3,7 +3,7 @@ Name: tag1, Entries: [ { - Metadata: { + HeaderMetadata: { path: content1, tags: [ { @@ -13,7 +13,7 @@ } }, { - Metadata: { + HeaderMetadata: { path: content2, tags: [ { diff --git a/MarkTheRipper.Engine.Tests/ParserTests.AggregateTags4.verified.txt b/MarkTheRipper.Engine.Tests/ParserTests.AggregateTags4.verified.txt index 5fb776b..21fbada 100644 --- a/MarkTheRipper.Engine.Tests/ParserTests.AggregateTags4.verified.txt +++ b/MarkTheRipper.Engine.Tests/ParserTests.AggregateTags4.verified.txt @@ -3,7 +3,7 @@ Name: tag1, Entries: [ { - Metadata: { + HeaderMetadata: { path: content1, tags: [ { @@ -13,7 +13,7 @@ } }, { - Metadata: { + HeaderMetadata: { path: content2, tags: [ { @@ -31,7 +31,7 @@ Name: tag2, Entries: [ { - Metadata: { + HeaderMetadata: { path: content2, tags: [ { diff --git a/MarkTheRipper.Engine.Tests/ParserTests.AggregateTags5.verified.txt b/MarkTheRipper.Engine.Tests/ParserTests.AggregateTags5.verified.txt index 099a1d3..075c0e2 100644 --- a/MarkTheRipper.Engine.Tests/ParserTests.AggregateTags5.verified.txt +++ b/MarkTheRipper.Engine.Tests/ParserTests.AggregateTags5.verified.txt @@ -3,7 +3,7 @@ Name: tag1, Entries: [ { - Metadata: { + HeaderMetadata: { path: content1, tags: [ { @@ -13,7 +13,7 @@ } }, { - Metadata: { + HeaderMetadata: { path: content2, tags: [ { @@ -31,7 +31,7 @@ Name: tag2, Entries: [ { - Metadata: { + HeaderMetadata: { path: content2, tags: [ { @@ -49,7 +49,7 @@ Name: tag3, Entries: [ { - Metadata: { + HeaderMetadata: { path: content3, tags: [ { diff --git a/MarkTheRipper.Engine.Tests/TagsTests.AggregateTags1.verified.txt b/MarkTheRipper.Engine.Tests/TagsTests.AggregateTags1.verified.txt index 94ff4ae..dca1354 100644 --- a/MarkTheRipper.Engine.Tests/TagsTests.AggregateTags1.verified.txt +++ b/MarkTheRipper.Engine.Tests/TagsTests.AggregateTags1.verified.txt @@ -3,7 +3,7 @@ Name: tag1, Entries: [ { - Metadata: { + HeaderMetadata: { path: content1, tags: [ { diff --git a/MarkTheRipper.Engine.Tests/TagsTests.AggregateTags2.verified.txt b/MarkTheRipper.Engine.Tests/TagsTests.AggregateTags2.verified.txt index ac7ea85..85fd420 100644 --- a/MarkTheRipper.Engine.Tests/TagsTests.AggregateTags2.verified.txt +++ b/MarkTheRipper.Engine.Tests/TagsTests.AggregateTags2.verified.txt @@ -3,7 +3,7 @@ Name: tag1, Entries: [ { - Metadata: { + HeaderMetadata: { path: content1, tags: [ { @@ -21,7 +21,7 @@ Name: tag2, Entries: [ { - Metadata: { + HeaderMetadata: { path: content1, tags: [ { diff --git a/MarkTheRipper.Engine.Tests/TagsTests.AggregateTags3.verified.txt b/MarkTheRipper.Engine.Tests/TagsTests.AggregateTags3.verified.txt index a9fc31b..1f90ad8 100644 --- a/MarkTheRipper.Engine.Tests/TagsTests.AggregateTags3.verified.txt +++ b/MarkTheRipper.Engine.Tests/TagsTests.AggregateTags3.verified.txt @@ -3,7 +3,7 @@ Name: tag1, Entries: [ { - Metadata: { + HeaderMetadata: { path: content1, tags: [ { @@ -13,7 +13,7 @@ } }, { - Metadata: { + HeaderMetadata: { path: content2, tags: [ { diff --git a/MarkTheRipper.Engine.Tests/TagsTests.AggregateTags4.verified.txt b/MarkTheRipper.Engine.Tests/TagsTests.AggregateTags4.verified.txt index 5fb776b..21fbada 100644 --- a/MarkTheRipper.Engine.Tests/TagsTests.AggregateTags4.verified.txt +++ b/MarkTheRipper.Engine.Tests/TagsTests.AggregateTags4.verified.txt @@ -3,7 +3,7 @@ Name: tag1, Entries: [ { - Metadata: { + HeaderMetadata: { path: content1, tags: [ { @@ -13,7 +13,7 @@ } }, { - Metadata: { + HeaderMetadata: { path: content2, tags: [ { @@ -31,7 +31,7 @@ Name: tag2, Entries: [ { - Metadata: { + HeaderMetadata: { path: content2, tags: [ { diff --git a/MarkTheRipper.Engine.Tests/TagsTests.AggregateTags5.verified.txt b/MarkTheRipper.Engine.Tests/TagsTests.AggregateTags5.verified.txt index 099a1d3..075c0e2 100644 --- a/MarkTheRipper.Engine.Tests/TagsTests.AggregateTags5.verified.txt +++ b/MarkTheRipper.Engine.Tests/TagsTests.AggregateTags5.verified.txt @@ -3,7 +3,7 @@ Name: tag1, Entries: [ { - Metadata: { + HeaderMetadata: { path: content1, tags: [ { @@ -13,7 +13,7 @@ } }, { - Metadata: { + HeaderMetadata: { path: content2, tags: [ { @@ -31,7 +31,7 @@ Name: tag2, Entries: [ { - Metadata: { + HeaderMetadata: { path: content2, tags: [ { @@ -49,7 +49,7 @@ Name: tag3, Entries: [ { - Metadata: { + HeaderMetadata: { path: content3, tags: [ { diff --git a/MarkTheRipper.Engine/Expressions/Parser.cs b/MarkTheRipper.Engine/Expressions/Parser.cs index 0d6ed0d..e7f7f3a 100644 --- a/MarkTheRipper.Engine/Expressions/Parser.cs +++ b/MarkTheRipper.Engine/Expressions/Parser.cs @@ -505,7 +505,7 @@ internal static async ValueTask> ParseMarkdownHe } } - var markdownMetadata = new Dictionary(); + var headerMetadata = new Dictionary(); // `title: Hello world` while (true) @@ -530,7 +530,7 @@ internal static async ValueTask> ParseMarkdownHe ConfigureAwait(false); if (valueExpression != null) { - markdownMetadata[keyName] = valueExpression; + headerMetadata[keyName] = valueExpression; } } else @@ -549,7 +549,7 @@ internal static async ValueTask> ParseMarkdownHe } } - return markdownMetadata; + return headerMetadata; } internal static async ValueTask ParseAndAppendMarkdownHeaderAsync( @@ -678,12 +678,12 @@ public CodeBlockContext( } } - internal static async ValueTask<(Dictionary markdownMetadata, string markdownBody, Func[] inCodeFragments)> ParseMarkdownBodyAsync( + internal static async ValueTask<(Dictionary headerMetadata, string markdownBody, Func[] inCodeFragments)> ParseMarkdownBodyAsync( PathEntry relativeContentPathHint, Func> markdownReader, CancellationToken ct) { - var markdownMetadata = await ParseMarkdownHeaderAsync( + var headerMetadata = await ParseMarkdownHeaderAsync( relativeContentPathHint, markdownReader, ct); var markdownBody = new StringBuilder(); @@ -795,6 +795,6 @@ public CodeBlockContext( } } - return (markdownMetadata, markdownBody.ToString(), inCodeFragments.ToArray()); + return (headerMetadata, markdownBody.ToString(), inCodeFragments.ToArray()); } } diff --git a/MarkTheRipper.Engine/Internal/InternalUtilities.cs b/MarkTheRipper.Engine/Internal/InternalUtilities.cs index 08d426d..6b3e43e 100644 --- a/MarkTheRipper.Engine/Internal/InternalUtilities.cs +++ b/MarkTheRipper.Engine/Internal/InternalUtilities.cs @@ -134,7 +134,7 @@ public static SortedDictionary ToSortedDictionary return sd; } - public static IEnumerable Unfold(this T value, Func selector) + public static IEnumerable Unfold(this T? value, Func selector) { var current = value; while (current != null) diff --git a/MarkTheRipper.Engine/Internal/KeyComparer.cs b/MarkTheRipper.Engine/Internal/KeyComparer.cs new file mode 100644 index 0000000..6fef351 --- /dev/null +++ b/MarkTheRipper.Engine/Internal/KeyComparer.cs @@ -0,0 +1,32 @@ +///////////////////////////////////////////////////////////////////////////////////// +// +// MarkTheRipper - Fantastic faster generates static site comes from simply Markdowns. +// Copyright (c) Kouji Matsui (@kozy_kekyo, @kekyo@mastodon.cloud) +// +// Licensed under Apache-v2: https://opensource.org/licenses/Apache-2.0 +// +///////////////////////////////////////////////////////////////////////////////////// + +using System.Collections.Generic; + +namespace MarkTheRipper.Metadata; + +internal sealed class KeyComparer : + IEqualityComparer> + where TKey : notnull +{ + private KeyComparer() + { + } + + public bool Equals( + KeyValuePair x, + KeyValuePair y) => + x.Key.Equals(y.Key); + + public int GetHashCode( + KeyValuePair obj) => + obj.Key.GetHashCode(); + + public static readonly KeyComparer Instance = new(); +} diff --git a/MarkTheRipper.Engine/Metadata/MarkdownEntry.cs b/MarkTheRipper.Engine/Metadata/MarkdownEntry.cs index 5192d65..3e7e804 100644 --- a/MarkTheRipper.Engine/Metadata/MarkdownEntry.cs +++ b/MarkTheRipper.Engine/Metadata/MarkdownEntry.cs @@ -20,42 +20,42 @@ namespace MarkTheRipper.Metadata; public sealed class MarkdownEntry : IMetadataEntry, IEquatable { - private readonly IReadOnlyDictionary metadata; + private readonly IReadOnlyDictionary headerMetadata; internal readonly string contentBasePath; public MarkdownEntry( - IReadOnlyDictionary metadata, + IReadOnlyDictionary headerMetadata, string contentBasePath) { - this.metadata = metadata; + this.headerMetadata = headerMetadata; this.contentBasePath = contentBasePath; } public MarkdownEntry( - IReadOnlyDictionary metadata, + IReadOnlyDictionary headerMetadata, string contentBasePath) { - this.metadata = metadata.ToDictionary( + this.headerMetadata = headerMetadata.ToDictionary( entry => entry.Key, entry => (IExpression)new ValueExpression(entry.Value)); this.contentBasePath = contentBasePath; } - public IReadOnlyDictionary Metadata => - this.metadata.ToDictionary( + public IReadOnlyDictionary HeaderMetadata => + this.headerMetadata.ToDictionary( entry => entry.Key, entry => entry.Value.ImplicitValue); internal PathEntry MarkdownPath => - this.metadata.TryGetValue("markdownPath", out var markdownPathExpression) && + this.headerMetadata.TryGetValue("markdownPath", out var markdownPathExpression) && Reducer.Instance.UnsafeReduceExpression( markdownPathExpression, MetadataContext.Empty) is { } value && value is PathEntry markdownPath ? markdownPath : PathEntry.Unknown; internal PathEntry StoreToPath => - this.metadata.TryGetValue("path", out var pathExpression) && + this.headerMetadata.TryGetValue("path", out var pathExpression) && Reducer.Instance.UnsafeReduceExpression( pathExpression, MetadataContext.Empty) is { } value && value is PathEntry path ? @@ -70,23 +70,23 @@ internal static bool GetPublishedState( true; internal bool DoesNotPublish => - !GetPublishedState(this.metadata); + !GetPublishedState(this.headerMetadata); internal string Title => - this.metadata.TryGetValue("title", out var titleExpression) && + this.headerMetadata.TryGetValue("title", out var titleExpression) && Reducer.Instance.UnsafeReduceExpressionAndFormat( titleExpression, MetadataContext.Empty) is { } title ? title : "(Untitled)"; internal DateTimeOffset? Date => - this.metadata.TryGetValue("date", out var dateExpression) && + this.headerMetadata.TryGetValue("date", out var dateExpression) && Reducer.Instance.UnsafeReduceExpression( dateExpression, MetadataContext.Empty) is DateTimeOffset date ? date : null; public async ValueTask GetImplicitValueAsync( IMetadataContext metadata, IReducer reducer, CancellationToken ct) => - this.metadata.TryGetValue("title", out var valueExpression) && + this.headerMetadata.TryGetValue("title", out var valueExpression) && await reducer.ReduceExpressionAndFormatAsync( valueExpression, metadata, ct). ConfigureAwait(false) is { } title ? @@ -94,22 +94,22 @@ await reducer.ReduceExpressionAndFormatAsync( public ValueTask GetPropertyValueAsync( string keyName, IMetadataContext metadata, IReducer reducer, CancellationToken ct) => - this.metadata.TryGetValue(keyName, out var valueExpression) ? + this.headerMetadata.TryGetValue(keyName, out var valueExpression) ? reducer.ReduceExpressionAsync(valueExpression, metadata, ct) : InternalUtilities.NullAsync; public bool Equals(MarkdownEntry? other) => other is { } rhs && - this.metadata. + this.headerMetadata. OrderBy(m => m.Key). - SequenceEqual(rhs.metadata.OrderBy(m => m.Key)); + SequenceEqual(rhs.headerMetadata.OrderBy(m => m.Key)); public override bool Equals(object? obj) => obj is MarkdownEntry rhs && Equals(rhs); public override int GetHashCode() => - this.metadata.Aggregate(0, + this.headerMetadata.Aggregate(0, (agg, v) => agg ^ v.Key.GetHashCode() ^ v.Value.GetHashCode()); public override string ToString() => diff --git a/MarkTheRipper.Engine/Metadata/MetadataContext.cs b/MarkTheRipper.Engine/Metadata/MetadataContext.cs index 379fa70..c983d4c 100644 --- a/MarkTheRipper.Engine/Metadata/MetadataContext.cs +++ b/MarkTheRipper.Engine/Metadata/MetadataContext.cs @@ -8,7 +8,9 @@ ///////////////////////////////////////////////////////////////////////////////////// using MarkTheRipper.Expressions; +using MarkTheRipper.Internal; using System.Collections.Generic; +using System.Linq; namespace MarkTheRipper.Metadata; @@ -35,6 +37,14 @@ public void Set(string keyName, IExpression expression) => public IMetadataContext Spawn() => new MetadataContext(this); + public override string ToString() => + string.Join(",", + this.metadata.Concat(this.parent. + Unfold(mc => mc.parent). + SelectMany(mc => mc.metadata)). + Distinct(KeyComparer.Instance). + Select(kv => $"{kv.Key}=[{kv.Value}]")); + public static readonly MetadataContext Empty = new MetadataContext(); } diff --git a/MarkTheRipper.Engine/Ripper.cs b/MarkTheRipper.Engine/Ripper.cs index f843503..e86179e 100644 --- a/MarkTheRipper.Engine/Ripper.cs +++ b/MarkTheRipper.Engine/Ripper.cs @@ -40,7 +40,7 @@ public ValueTask ParseLayoutAsync( ct); private static void InjectAdditionalMetadata( - Dictionary markdownMetadata, + Dictionary headerMetadata, PathEntry markdownPath) { var storeToPathHint = new PathEntry( @@ -48,17 +48,17 @@ private static void InjectAdditionalMetadata( Utilities.GetDirectoryPath(markdownPath.PhysicalPath), Path.GetFileNameWithoutExtension(markdownPath.PhysicalPath) + ".html")); - markdownMetadata["markdownPath"] = new ValueExpression(markdownPath); - markdownMetadata["path"] = new ValueExpression(storeToPathHint); + headerMetadata["markdownPath"] = new ValueExpression(markdownPath); + headerMetadata["path"] = new ValueExpression(storeToPathHint); // Special: Automatic insertion for category when not available. - if (!markdownMetadata.ContainsKey("category")) + if (!headerMetadata.ContainsKey("category")) { var relativeDirectoryPath = Utilities.GetDirectoryPath(markdownPath.PhysicalPath); var pathElements = relativeDirectoryPath. Split(Utilities.PathSeparators, StringSplitOptions.RemoveEmptyEntries); - markdownMetadata.Add("category", new ValueExpression( + headerMetadata.Add("category", new ValueExpression( pathElements.Aggregate( new PartialCategoryEntry(), (agg, v) => new PartialCategoryEntry(v, agg)))); @@ -165,15 +165,15 @@ await markdownWriter.FlushAsync(). } private static IMetadataContext SpawnWithAdditionalMetadata( - Dictionary markdownMetadata, + Dictionary headerMetadata, IMetadataContext parentMetadata, PathEntry markdownPath) { var mc = parentMetadata.Spawn(); - InjectAdditionalMetadata(markdownMetadata, markdownPath); + InjectAdditionalMetadata(headerMetadata, markdownPath); - foreach (var kv in markdownMetadata) + foreach (var kv in headerMetadata) { mc.Set(kv.Key, kv.Value); } @@ -198,7 +198,7 @@ public async ValueTask RenderContentAsync( CancellationToken ct) { // Step 1: Parse markdown metadata and code fragment locations. - var (markdownMetadata, markdownBody, inCodeFragments) = + var (headerMetadata, markdownBody, inCodeFragments) = await Parser.ParseMarkdownBodyAsync( markdownPath, ct => markdownReader.ReadLineAsync().WithCancellation(ct), @@ -215,7 +215,7 @@ await Parser.ParseMarkdownBodyAsync( // Step 3: Spawn new metadata context derived parent. var mc = SpawnWithAdditionalMetadata( - markdownMetadata, + headerMetadata, metadata, markdownPath); From ba12fe928cf87fa978107fc5d4fdf643fca61a05 Mon Sep 17 00:00:00 2001 From: Kouji Matsui Date: Sun, 23 Oct 2022 14:08:06 +0900 Subject: [PATCH 06/20] Fixed duplicated wrapping ValueTask in iterator property value. --- MarkTheRipper.Engine/Metadata/IteratorEntry.cs | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/MarkTheRipper.Engine/Metadata/IteratorEntry.cs b/MarkTheRipper.Engine/Metadata/IteratorEntry.cs index 288f429..1e3eeed 100644 --- a/MarkTheRipper.Engine/Metadata/IteratorEntry.cs +++ b/MarkTheRipper.Engine/Metadata/IteratorEntry.cs @@ -40,9 +40,9 @@ await entry.GetPropertyValueAsync(keyName, metadata, reducer, ct). value : keyName switch { - "index" => new(this.Index), - "count" => new(this.Count), - _ => InternalUtilities.NullAsync, + "index" => this.Index, + "count" => this.Count, + _ => null, }; public override string ToString() => From 5ab8267eaa4a7544f3b5ec51620144b7cdb94893 Mon Sep 17 00:00:00 2001 From: Kouji Matsui Date: Sun, 23 Oct 2022 14:12:37 +0900 Subject: [PATCH 07/20] Fixed iteration for breadcrumbs only one category. --- ...ffBreadcrumb_subNames=aaa-bbb.verified.txt | 1 + MarkTheRipper.Engine.Tests/BulkRipperTests.cs | 2 +- MarkTheRipper.Engine/Expressions/Reducer.cs | 73 ++++++++++--------- .../Metadata/PartialCategoryEntry.cs | 6 +- mtr/embeds/minimum/layouts/page.html | 2 +- mtr/embeds/rich/layouts/page.html | 2 +- mtr/embeds/sidebar/layouts/page.html | 2 +- mtr/embeds/standard/layouts/page.html | 2 +- 8 files changed, 45 insertions(+), 45 deletions(-) diff --git a/MarkTheRipper.Engine.Tests/BulkRipperTests.RipOffBreadcrumb_subNames=aaa-bbb.verified.txt b/MarkTheRipper.Engine.Tests/BulkRipperTests.RipOffBreadcrumb_subNames=aaa-bbb.verified.txt index a3f01a1..f35eb0c 100644 --- a/MarkTheRipper.Engine.Tests/BulkRipperTests.RipOffBreadcrumb_subNames=aaa-bbb.verified.txt +++ b/MarkTheRipper.Engine.Tests/BulkRipperTests.RipOffBreadcrumb_subNames=aaa-bbb.verified.txt @@ -6,6 +6,7 @@
    +
  • aaa
  • bbb

Hello MarkTheRipper! diff --git a/MarkTheRipper.Engine.Tests/BulkRipperTests.cs b/MarkTheRipper.Engine.Tests/BulkRipperTests.cs index 879a154..0c5be8e 100644 --- a/MarkTheRipper.Engine.Tests/BulkRipperTests.cs +++ b/MarkTheRipper.Engine.Tests/BulkRipperTests.cs @@ -238,7 +238,7 @@ This is test contents.

    - {foreach category.breadcrumb} + {foreach category.breadcrumbs}
  • {item.name}
  • {end}
diff --git a/MarkTheRipper.Engine/Expressions/Reducer.cs b/MarkTheRipper.Engine/Expressions/Reducer.cs index 782fa1a..81fff1f 100644 --- a/MarkTheRipper.Engine/Expressions/Reducer.cs +++ b/MarkTheRipper.Engine/Expressions/Reducer.cs @@ -11,7 +11,6 @@ using MarkTheRipper.Metadata; using System; using System.Collections.Generic; -using System.Linq; using System.Threading; using System.Threading.Tasks; @@ -28,25 +27,36 @@ private Reducer() private async ValueTask ReducePropertyAsync( string[] elements, int index, - IExpression currentExpression, + object? currentValue, IMetadataContext metadata, - CancellationToken ct) => - currentExpression is ValueExpression(var currentValue) ? - index < elements.Length && - currentValue is IMetadataEntry entry && - await entry.GetPropertyValueAsync(elements[index++], metadata, this, ct). - ConfigureAwait(false) is { } value ? - value : - currentValue : - currentExpression.ImplicitValue; + CancellationToken ct) + { + if (index < elements.Length) + { + if (currentValue is IMetadataEntry entry && + await entry.GetPropertyValueAsync(elements[index], metadata, this, ct) is { } childValue) + { + return childValue; + } + else + { + return elements[index]; + } + } + else + { + return currentValue; + } + } private ValueTask ReducePropertiesAsync( string[] elements, IMetadataContext metadata, CancellationToken ct) => - 0 < elements.Length && metadata.Lookup(elements[0]) is { } expression ? - this.ReducePropertyAsync(elements, 1, expression, metadata, ct) : + (expression is ValueExpression(var value) ? + this.ReducePropertyAsync(elements, 1, value, metadata, ct) : + new ValueTask(expression.ImplicitValue)) : new ValueTask(elements[0]); #if DEBUG @@ -58,8 +68,7 @@ await entry.GetPropertyValueAsync(elements[index++], metadata, this, ct). var results = new List(); foreach (var expression in expressions) { - var result = await this.ReduceExpressionAsync(expression, metadata, ct). - ConfigureAwait(false); + var result = await this.ReduceExpressionAsync(expression, metadata, ct); results.Add(result); } return results.ToArray(); @@ -78,42 +87,36 @@ await entry.GetPropertyValueAsync(elements[index++], metadata, this, ct). IExpression[] elements, IMetadataContext metadata, CancellationToken ct) => - await this.ReduceExpressionsAsync(elements, metadata, ct). - ConfigureAwait(false); + await this.ReduceExpressionsAsync(elements, metadata, ct); private async ValueTask ReduceApplyAsync( - IExpression function, + IExpression functionExpression, IExpression[] parameters, IMetadataContext metadata, CancellationToken ct) { - var f = await this.ReduceExpressionAsync(function, metadata, ct). - ConfigureAwait(false); - return f switch + var function = await this.ReduceExpressionAsync( + functionExpression, metadata, ct); + return function switch { FunctionDelegate func => await this.ReduceExpressionAsync( - await func(parameters, metadata, this, ct).ConfigureAwait(false), - metadata, ct). - ConfigureAwait(false), + await func(parameters, metadata, this, ct), + metadata, ct), SimpleFunctionDelegate func => await func( - await this.ReduceExpressionsAsync(parameters, metadata, ct). - ConfigureAwait(false), + await this.ReduceExpressionsAsync(parameters, metadata, ct), keyName => metadata.Lookup(keyName) is { } valueExpression ? this.ReduceExpressionAsync(valueExpression, metadata, ct) : default, - await metadata.GetLanguageAsync(ct). - ConfigureAwait(false), + await metadata.GetLanguageAsync(ct), ct), Func>, IFormatProvider, CancellationToken, Task> func => await func( - await this.ReduceExpressionsAsync(parameters, metadata, ct). - ConfigureAwait(false), + await this.ReduceExpressionsAsync(parameters, metadata, ct), keyName => metadata.Lookup(keyName) is { } valueExpression ? this.ReduceExpressionAsync(valueExpression, metadata, ct).AsTask() : Task.FromResult(default(object)), - await metadata.GetLanguageAsync(ct). - ConfigureAwait(false), + await metadata.GetLanguageAsync(ct), ct), _ => throw new InvalidOperationException("Could not apply non-function object."), }; @@ -148,10 +151,8 @@ public async ValueTask ReduceExpressionAndFormatAsync( IMetadataContext metadata, CancellationToken ct) { - var reduced = await this.ReduceExpressionAsync(expression, metadata, ct). - ConfigureAwait(false); - return await MetadataUtilities.FormatValueAsync(reduced, metadata, ct). - ConfigureAwait(false); + var reduced = await this.ReduceExpressionAsync(expression, metadata, ct); + return await MetadataUtilities.FormatValueAsync(reduced, metadata, ct); } internal string UnsafeReduceExpressionAndFormat( diff --git a/MarkTheRipper.Engine/Metadata/PartialCategoryEntry.cs b/MarkTheRipper.Engine/Metadata/PartialCategoryEntry.cs index 521a535..b7ff494 100644 --- a/MarkTheRipper.Engine/Metadata/PartialCategoryEntry.cs +++ b/MarkTheRipper.Engine/Metadata/PartialCategoryEntry.cs @@ -61,10 +61,8 @@ await reducer.ReduceExpressionAsync(rootCategoryExpression, metadata, ct) is Cat public async ValueTask GetPropertyValueAsync( string keyName, IMetadataContext metadata, IReducer reducer, CancellationToken ct) => - await this.GetRealCategoryEntryAsync(metadata, reducer, ct). - ConfigureAwait(false) is { } entry && - await entry.GetPropertyValueAsync(keyName, metadata, reducer, ct). - ConfigureAwait(false) is { } value ? + await this.GetRealCategoryEntryAsync(metadata, reducer, ct) is { } entry && + await entry.GetPropertyValueAsync(keyName, metadata, reducer, ct) is { } value ? value : keyName switch { diff --git a/mtr/embeds/minimum/layouts/page.html b/mtr/embeds/minimum/layouts/page.html index 362421f..d1ed2c9 100644 --- a/mtr/embeds/minimum/layouts/page.html +++ b/mtr/embeds/minimum/layouts/page.html @@ -8,7 +8,7 @@

{title}

-

Category:{foreach category.breadcrumb} {item.name}{end}

+

Category:{foreach category.breadcrumbs} {item.name}{end}

Tags:{foreach tags} {item.name}{end}


diff --git a/mtr/embeds/rich/layouts/page.html b/mtr/embeds/rich/layouts/page.html index e301aae..820af8a 100644 --- a/mtr/embeds/rich/layouts/page.html +++ b/mtr/embeds/rich/layouts/page.html @@ -74,7 +74,7 @@

{title}