From 9af8101f1095f72402c2ad60e673606dd2e62ce5 Mon Sep 17 00:00:00 2001 From: Bruno Massa Date: Mon, 10 Jul 2023 16:14:14 -0300 Subject: [PATCH 1/2] feat: page Plain and WodCount --- source/Models/Frontmatter.cs | 21 +++++++++++++++++++-- 1 file changed, 19 insertions(+), 2 deletions(-) diff --git a/source/Models/Frontmatter.cs b/source/Models/Frontmatter.cs index 9937f5d..d0acd75 100644 --- a/source/Models/Frontmatter.cs +++ b/source/Models/Frontmatter.cs @@ -3,6 +3,7 @@ using System.Collections.Concurrent; using System.Collections.Generic; using System.IO; using System.Linq; +using System.Text.RegularExpressions; using Fluid; using Markdig; using SuCoS.Helpers; @@ -77,6 +78,11 @@ public class Frontmatter : IBaseContent, IParams /// public int Weight { get; set; } = 0; + /// + /// A list of tags, if any. + /// + public List? Tags { get; set; } + /// /// The source filename, without the extension. ;) /// @@ -134,9 +140,10 @@ public class Frontmatter : IBaseContent, IParams public Frontmatter? Parent { get; set; } /// - /// A list of tags, if any. + /// Plain markdown content, without HTML. /// - public List? Tags { get; set; } + [YamlIgnore] + public string Plain => Markdown.Normalize(RawContent); /// /// A list of tags, if any. @@ -147,6 +154,7 @@ public class Frontmatter : IBaseContent, IParams /// /// Check if the page is expired /// + [YamlIgnore] public bool IsDateExpired => ExpiryDate is not null && ExpiryDate <= clock.Now; /// @@ -158,18 +166,27 @@ public class Frontmatter : IBaseContent, IParams /// /// Just a simple check if the current page is the home page /// + [YamlIgnore] public bool IsHome => Site.Home == this; /// /// Just a simple check if the current page is a section page /// + [YamlIgnore] public bool IsSection => Type == "section"; /// /// Just a simple check if the current page is a "page" /// + [YamlIgnore] public bool IsPage => Type == "page"; + /// + /// The number of words in the main content + /// + [YamlIgnore] + public int WordCount => Regex.Matches(Plain, @"\b[\w']+\b").Count; + /// /// The markdown content converted to HTML /// -- GitLab From ddf87c6a0aef964348a37f35c9eac533db41b7d2 Mon Sep 17 00:00:00 2001 From: Bruno Massa Date: Mon, 10 Jul 2023 17:29:49 -0300 Subject: [PATCH 2/2] fix: correct Plain markdown text --- source/Models/Frontmatter.cs | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/source/Models/Frontmatter.cs b/source/Models/Frontmatter.cs index d0acd75..6500798 100644 --- a/source/Models/Frontmatter.cs +++ b/source/Models/Frontmatter.cs @@ -143,7 +143,7 @@ public class Frontmatter : IBaseContent, IParams /// Plain markdown content, without HTML. /// [YamlIgnore] - public string Plain => Markdown.Normalize(RawContent); + public string Plain => Markdown.ToPlainText(RawContent, Site.MarkdownPipeline); /// /// A list of tags, if any. @@ -185,7 +185,9 @@ public class Frontmatter : IBaseContent, IParams /// The number of words in the main content /// [YamlIgnore] - public int WordCount => Regex.Matches(Plain, @"\b[\w']+\b").Count; + public int WordCount => + Plain.Split(new char[] { ' ', ',', ';', '.', '!', '"', '(', ')', '?' }, + StringSplitOptions.RemoveEmptyEntries).Length; /// /// The markdown content converted to HTML -- GitLab