From ff6b78bf44454f5e17b8e310b52a490a2eb76285 Mon Sep 17 00:00:00 2001 From: Bruno Massa Date: Sat, 11 May 2024 17:29:24 -0500 Subject: [PATCH 1/5] feat: kinds are now composite enums and converting kind.Index to kind.Home --- Tests/Models/FrontMatterTests.cs | 4 ++-- source/Helpers/FileUtils.cs | 30 +++++++++++++++++++------- source/Models/Kind.cs | 37 +++++++++++++++++++++++++++++--- source/Models/Site.cs | 14 ++++++------ 4 files changed, 65 insertions(+), 20 deletions(-) diff --git a/Tests/Models/FrontMatterTests.cs b/Tests/Models/FrontMatterTests.cs index 2b01efc..3d2d115 100644 --- a/Tests/Models/FrontMatterTests.cs +++ b/Tests/Models/FrontMatterTests.cs @@ -1,5 +1,5 @@ -using SuCoS.Models; using System.Globalization; +using SuCoS.Models; using Xunit; namespace Tests.Models; @@ -9,7 +9,7 @@ public class FrontMatterTests : TestSetup [Theory] [InlineData("Title1", "Section1", "Type1", "URL1", Kind.Single)] [InlineData("Title2", "Section2", "Type2", "URL2", Kind.List)] - [InlineData("Title3", "Section3", "Type3", "URL3", Kind.Index)] + [InlineData("Title3", "Section3", "Type3", "URL3", Kind.Home)] public void Constructor_Sets_Properties_Correctly(string title, string section, string type, string url, Kind kind) { // Act diff --git a/source/Helpers/FileUtils.cs b/source/Helpers/FileUtils.cs index 7d7e7df..703d9b7 100644 --- a/source/Helpers/FileUtils.cs +++ b/source/Helpers/FileUtils.cs @@ -74,15 +74,29 @@ public static class FileUtils // Generate the lookup order for template files based on the theme path, page section, type, and kind string[] sections = page.Section is not null ? [page.Section, string.Empty] : [string.Empty]; var types = new[] { page.Type, "_default" }; - string[] kinds = isBaseTemplate - ? [page.Kind.ToString().ToLower(System.Globalization.CultureInfo.CurrentCulture) + "-baseof", "baseof"] - : [page.Kind.ToString().ToLower(System.Globalization.CultureInfo.CurrentCulture)]; + + // Get all the kinds including the "sub-values" + var kinds = GetAllKinds(page.Kind, isBaseTemplate); + + if (isBaseTemplate) + { + kinds = kinds.Append("baseof"); + } // for each section, each type and each kind - return (from section in sections - from type in types - from kind in kinds - let path = Path.Combine(themePath, section, type!, kind) + ".liquid" - select path).ToList(); + return sections + .SelectMany(section => types.Select(type => new { section, type })) + .SelectMany(x => kinds.Select(kind => new { x.section, x.type, kind })) + .Select(x => Path.Combine(themePath, x.section, x.type!, x.kind) + ".liquid") + .ToList(); } + + private static IEnumerable GetAllKinds(Kind kind, bool isBaseTemplate) => + Enum.GetValues(typeof(Kind)) + .Cast() + .Where(k => kind.HasFlag(k)) + .OrderByDescending(k => k) + .Select(k => isBaseTemplate + ? k.ToString().ToLower(System.Globalization.CultureInfo.CurrentCulture) + "-baseof" + : k.ToString().ToLower(System.Globalization.CultureInfo.CurrentCulture)); } diff --git a/source/Models/Kind.cs b/source/Models/Kind.cs index 99625fc..3dde62d 100644 --- a/source/Models/Kind.cs +++ b/source/Models/Kind.cs @@ -3,20 +3,51 @@ namespace SuCoS.Models; /// /// The type of the output page, if it's a single page, a list of pages or the home page. /// +[Flags] public enum Kind { /// /// A single content page. /// - Single, + Single = 1 << 0, /// /// List of contents /// - List, + List = 1 << 1, /// /// Special page, like the home page. It will be rendered as index.html. /// - Index + Index = 1 << 2, + + /// + /// Created by system + /// + System = 1 << 3, + + /// + /// Taxonomy type of content + /// + IsTaxonomy = 1 << 4, + + /// + /// Special page, like the home page. It will be rendered as index.html. + /// + Home = System | Index, + + /// + /// Root content list type + /// + Section = System | List, + + /// + /// Taxonomy group is equivalent to Section + /// + Taxonomy = System | IsTaxonomy | List, + + /// + /// Each taxonomy (category, tags) item + /// + Term = System | IsTaxonomy | List, } diff --git a/source/Models/Site.cs b/source/Models/Site.cs index ee19533..82198c8 100644 --- a/source/Models/Site.cs +++ b/source/Models/Site.cs @@ -1,9 +1,9 @@ +using System.Collections.Concurrent; using Serilog; using SuCoS.Helpers; using SuCoS.Models.CommandLineOptions; using SuCoS.Parsers; using SuCoS.TemplateEngine; -using System.Collections.Concurrent; namespace SuCoS.Models; @@ -220,16 +220,16 @@ public class Site : ISite public IPage CreateSystemPage(string relativePath, string title, string? sectionName = null, IPage? originalPage = null) { sectionName ??= "section"; - var isIndex = string.IsNullOrEmpty(relativePath); + var isHome = string.IsNullOrEmpty(relativePath); relativePath = Urlizer.Path(relativePath); FrontMatter frontMatter = new() { - Kind = isIndex ? Kind.Index : Kind.List, - Section = isIndex ? "index" : sectionName, + Kind = isHome ? Kind.Home : Kind.List, + Section = isHome ? "index" : sectionName, SourceRelativePath = Urlizer.Path(Path.Combine(relativePath, IndexLeafFileConst)), SourceFullPath = Urlizer.Path(Path.Combine(SourceContentPath, relativePath, IndexLeafFileConst)), Title = title, - Type = isIndex ? "index" : sectionName, + Type = isHome ? "index" : sectionName, URL = relativePath }; @@ -262,7 +262,7 @@ public class Site : ISite return page; } - if (page.Kind != Kind.Index) + if (page.Kind != Kind.Home) { page.PagesReferences.Add(originalPage.Permalink); } @@ -302,7 +302,7 @@ public class Site : ISite { _ = OutputReferences.TryRemove(page.Permalink!, out _); page.Permalink = "/"; - page.Kind = Kind.Index; + page.Kind = Kind.Home; _ = OutputReferences.GetOrAdd(page.Permalink, page); Home = page; -- GitLab From 64f1ecfa16bb631a1b1e4e2ca466b4d0f1b879d4 Mon Sep 17 00:00:00 2001 From: Bruno Massa Date: Sat, 11 May 2024 19:01:54 -0500 Subject: [PATCH 2/5] feat: Kind.Term --- source/Models/IPage.cs | 9 ++++++--- source/Models/ISite.cs | 7 ++++--- source/Models/Page.cs | 6 +++--- source/Models/Site.cs | 40 +++++++++++++++++++++++++--------------- 4 files changed, 38 insertions(+), 24 deletions(-) diff --git a/source/Models/IPage.cs b/source/Models/IPage.cs index efe55cc..62cb04c 100644 --- a/source/Models/IPage.cs +++ b/source/Models/IPage.cs @@ -1,7 +1,7 @@ -using Markdig; -using SuCoS.Helpers; using System.Collections.Concurrent; using System.Collections.ObjectModel; +using Markdig; +using SuCoS.Helpers; namespace SuCoS.Models; @@ -10,7 +10,10 @@ namespace SuCoS.Models; /// public interface IPage : IFrontMatter, IOutput { - /// + /// + /// The kind of the page, if it's a single page, a list of pages or the home page. + /// It's used to determine the proper theme file. + /// new Kind Kind { get; set; } /// diff --git a/source/Models/ISite.cs b/source/Models/ISite.cs index f2084ec..35695da 100644 --- a/source/Models/ISite.cs +++ b/source/Models/ISite.cs @@ -1,9 +1,9 @@ +using System.Collections.Concurrent; using Serilog; using SuCoS.Helpers; using SuCoS.Models.CommandLineOptions; using SuCoS.Parsers; using SuCoS.TemplateEngine; -using System.Collections.Concurrent; namespace SuCoS.Models; @@ -133,8 +133,9 @@ public interface ISite : ISiteSettings /// /// The relative path of the page. /// - /// + /// /// /// The created page for the index. - public IPage CreateSystemPage(string relativePath, string title, string? sectionName = null, IPage? originalPage = null); + public IPage CreateSystemPage(string relativePath, string title, + bool isTaxonomy = false, IPage? originalPage = null); } diff --git a/source/Models/Page.cs b/source/Models/Page.cs index a11c1c4..07c0be0 100644 --- a/source/Models/Page.cs +++ b/source/Models/Page.cs @@ -1,8 +1,8 @@ +using System.Collections.Concurrent; +using System.Collections.ObjectModel; using Markdig; using Microsoft.Extensions.FileSystemGlobbing; using SuCoS.Helpers; -using System.Collections.Concurrent; -using System.Collections.ObjectModel; namespace SuCoS.Models; @@ -359,7 +359,7 @@ endif { foreach (var tagName in Tags) { - _ = Site.CreateSystemPage(Path.Combine("tags", tagName), tagName, "tags", this); + _ = Site.CreateSystemPage(Path.Combine("tags", tagName), tagName, true, this); } } diff --git a/source/Models/Site.cs b/source/Models/Site.cs index 82198c8..9fe3fa8 100644 --- a/source/Models/Site.cs +++ b/source/Models/Site.cs @@ -209,27 +209,27 @@ public class Site : ISite }); } - /// - /// Creates the page for the site index. - /// - /// The relative path of the page. - /// - /// - /// - /// The created page for the index. - public IPage CreateSystemPage(string relativePath, string title, string? sectionName = null, IPage? originalPage = null) + /// + public IPage CreateSystemPage(string relativePath, string title, bool isTaxonomy = false, IPage? originalPage = null) { - sectionName ??= "section"; - var isHome = string.IsNullOrEmpty(relativePath); relativePath = Urlizer.Path(relativePath); + var directoryDepth = GetDirectoryDepth(relativePath); + var isHome = directoryDepth == 0; + var sectionName = GetFirstDirectory(relativePath); + var kind = isHome + ? Kind.Home + : isTaxonomy + ? (directoryDepth > 1 ? Kind.Taxonomy : Kind.Term) + : Kind.List; + FrontMatter frontMatter = new() { - Kind = isHome ? Kind.Home : Kind.List, + Kind = kind, Section = isHome ? "index" : sectionName, SourceRelativePath = Urlizer.Path(Path.Combine(relativePath, IndexLeafFileConst)), SourceFullPath = Urlizer.Path(Path.Combine(SourceContentPath, relativePath, IndexLeafFileConst)), Title = title, - Type = isHome ? "index" : sectionName, + Type = kind == Kind.Home ? "index" : sectionName, URL = relativePath }; @@ -240,10 +240,10 @@ public class Site : ISite { IPage? parent = null; // Check if we need to create a section, even - var sections = (frontMatter.SourceRelativePathDirectory ?? string.Empty).Split('/', StringSplitOptions.RemoveEmptyEntries); + var sections = GetDirectories(frontMatter.SourceRelativePathDirectory); if (sections.Length > 1) { - parent = CreateSystemPage(sections[0], sections[0]); + parent = CreateSystemPage(sections[0], sections[0], isTaxonomy); } var newPage = new Page(frontMatter, this) @@ -276,6 +276,16 @@ public class Site : ISite return page; } + private static string GetFirstDirectory(string relativePath) => + GetDirectories(relativePath)[0]; + + private static int GetDirectoryDepth(string relativePath) => + GetDirectories(relativePath).Length; + + private static string[] GetDirectories(string? relativePath) => + (relativePath ?? string.Empty).Split('/', + StringSplitOptions.RemoveEmptyEntries); + private void ParseIndexPage(string? directory, int level, ref IPage? parent, ref string[] markdownFiles) { var indexLeafBundlePage = markdownFiles.FirstOrDefault(file => Path.GetFileName(file) == IndexLeafFileConst); -- GitLab From 91d82279b374f43d494a31af62093f84f7d3ed5b Mon Sep 17 00:00:00 2001 From: Bruno Massa Date: Sat, 11 May 2024 19:05:27 -0500 Subject: [PATCH 3/5] refactor: Kind removed from front Matter --- source/Models/FrontMatter.cs | 4 ---- source/Models/IFrontMatter.cs | 6 ------ source/Models/IPage.cs | 2 +- source/Models/Page.cs | 6 +----- source/Models/Site.cs | 4 ++-- 5 files changed, 4 insertions(+), 18 deletions(-) diff --git a/source/Models/FrontMatter.cs b/source/Models/FrontMatter.cs index 942b958..6f8587d 100644 --- a/source/Models/FrontMatter.cs +++ b/source/Models/FrontMatter.cs @@ -56,10 +56,6 @@ public class FrontMatter : IFrontMatter [YamlIgnore] public string RawContent { get; set; } = string.Empty; - /// - [YamlIgnore] - public Kind Kind { get; set; } = Kind.Single; - /// [YamlIgnore] public string? SourceRelativePath { get; set; } diff --git a/source/Models/IFrontMatter.cs b/source/Models/IFrontMatter.cs index 3618a4e..29e704e 100644 --- a/source/Models/IFrontMatter.cs +++ b/source/Models/IFrontMatter.cs @@ -104,12 +104,6 @@ public interface IFrontMatter : IParams, IFile /// string RawContent { get; } - /// - /// The kind of the page, if it's a single page, a list of pages or the home page. - /// It's used to determine the proper theme file. - /// - Kind Kind { get; } - /// /// The date to be considered as the publishing date. /// diff --git a/source/Models/IPage.cs b/source/Models/IPage.cs index 62cb04c..0de55a5 100644 --- a/source/Models/IPage.cs +++ b/source/Models/IPage.cs @@ -14,7 +14,7 @@ public interface IPage : IFrontMatter, IOutput /// The kind of the page, if it's a single page, a list of pages or the home page. /// It's used to determine the proper theme file. /// - new Kind Kind { get; set; } + Kind Kind { get; set; } /// /// The source directory of the file. diff --git a/source/Models/Page.cs b/source/Models/Page.cs index 07c0be0..c6d1571 100644 --- a/source/Models/Page.cs +++ b/source/Models/Page.cs @@ -62,11 +62,7 @@ public class Page : IPage public string RawContent => _frontMatter.RawContent; /// - public Kind Kind - { - get => _frontMatter.Kind; - set => (_frontMatter as FrontMatter)!.Kind = value; - } + public Kind Kind { get; set; } = Kind.Single; /// public string? SourceRelativePath => _frontMatter.SourceRelativePath; diff --git a/source/Models/Site.cs b/source/Models/Site.cs index 9fe3fa8..95d6a0a 100644 --- a/source/Models/Site.cs +++ b/source/Models/Site.cs @@ -224,7 +224,6 @@ public class Site : ISite FrontMatter frontMatter = new() { - Kind = kind, Section = isHome ? "index" : sectionName, SourceRelativePath = Urlizer.Path(Path.Combine(relativePath, IndexLeafFileConst)), SourceFullPath = Urlizer.Path(Path.Combine(SourceContentPath, relativePath, IndexLeafFileConst)), @@ -248,7 +247,8 @@ public class Site : ISite var newPage = new Page(frontMatter, this) { - BundleType = BundleType.Branch + BundleType = BundleType.Branch, + Kind = kind }; PostProcessPage(newPage, parent); return newPage; -- GitLab From 63427b795a860b5e51a955e3799d625aca36756d Mon Sep 17 00:00:00 2001 From: Bruno Massa Date: Sun, 12 May 2024 01:21:59 -0500 Subject: [PATCH 4/5] refactor: create taxonomy page before terms --- source/Models/ISite.cs | 26 +++++++++++++---- source/Models/Page.cs | 3 +- source/Models/Site.cs | 64 ++++++++++++++++++++---------------------- 3 files changed, 52 insertions(+), 41 deletions(-) diff --git a/source/Models/ISite.cs b/source/Models/ISite.cs index 35695da..ba660ca 100644 --- a/source/Models/ISite.cs +++ b/source/Models/ISite.cs @@ -91,7 +91,11 @@ public interface ISite : ISiteSettings /// Folder recursive level /// Page of the upper directory /// - public void ParseAndScanSourceFiles(IFileSystem fs, string? directory, int level = 0, IPage? parent = null); + public void ParseAndScanSourceFiles( + IFileSystem fs, + string? directory, + int level = 0, + IPage? parent = null); /// /// Extra calculation and automatic data for each page. @@ -99,7 +103,10 @@ public interface ISite : ISiteSettings /// The given page to be processed /// The parent page, if any /// - public void PostProcessPage(in IPage page, IPage? parent = null, bool overwrite = false); + public void PostProcessPage( + in IPage page, + IPage? parent = null, + bool overwrite = false); /// /// Check if the page have the conditions to be published: valid date and not draft, @@ -108,7 +115,9 @@ public interface ISite : ISiteSettings /// Page or front matter /// options /// - public bool IsValidPage(in IFrontMatter frontMatter, IGenerateOptions? options); + public bool IsValidPage( + in IFrontMatter frontMatter, + IGenerateOptions? options); /// /// Check if the page have a publishing date from the past. @@ -116,7 +125,9 @@ public interface ISite : ISiteSettings /// Page or front matter /// options /// - public bool IsValidDate(in IFrontMatter frontMatter, IGenerateOptions? options); + public bool IsValidDate( + in IFrontMatter frontMatter, + IGenerateOptions? options); /// /// Check if the page is expired @@ -136,6 +147,9 @@ public interface ISite : ISiteSettings /// /// /// The created page for the index. - public IPage CreateSystemPage(string relativePath, string title, - bool isTaxonomy = false, IPage? originalPage = null); + public IPage CreateSystemPage( + string relativePath, + string title, + bool isTaxonomy = false, + IPage? originalPage = null); } diff --git a/source/Models/Page.cs b/source/Models/Page.cs index c6d1571..25fa194 100644 --- a/source/Models/Page.cs +++ b/source/Models/Page.cs @@ -353,9 +353,10 @@ endif // Create tag pages, if any if (Tags is not null) { + Site.CreateSystemPage("tags", "tags", true); foreach (var tagName in Tags) { - _ = Site.CreateSystemPage(Path.Combine("tags", tagName), tagName, true, this); + Site.CreateSystemPage(Path.Combine("tags", tagName), tagName, true, this); } } diff --git a/source/Models/Site.cs b/source/Models/Site.cs index 95d6a0a..3c107d5 100644 --- a/source/Models/Site.cs +++ b/source/Models/Site.cs @@ -102,9 +102,9 @@ public class Site : ISite get { _regularPagesCache ??= OutputReferences - .Where(pair => pair.Value is IPage { IsPage: true } page && pair.Key == page.Permalink) - .Select(pair => (pair.Value as IPage)!) - .OrderBy(page => -page.Weight); + .Where(pair => pair.Value is IPage { IsPage: true } page && pair.Key == page.Permalink) + .Select(pair => (pair.Value as IPage)!) + .OrderBy(page => -page.Weight); return _regularPagesCache; } } @@ -213,37 +213,33 @@ public class Site : ISite public IPage CreateSystemPage(string relativePath, string title, bool isTaxonomy = false, IPage? originalPage = null) { relativePath = Urlizer.Path(relativePath); - var directoryDepth = GetDirectoryDepth(relativePath); - var isHome = directoryDepth == 0; - var sectionName = GetFirstDirectory(relativePath); - var kind = isHome - ? Kind.Home - : isTaxonomy - ? (directoryDepth > 1 ? Kind.Taxonomy : Kind.Term) - : Kind.List; - - FrontMatter frontMatter = new() - { - Section = isHome ? "index" : sectionName, - SourceRelativePath = Urlizer.Path(Path.Combine(relativePath, IndexLeafFileConst)), - SourceFullPath = Urlizer.Path(Path.Combine(SourceContentPath, relativePath, IndexLeafFileConst)), - Title = title, - Type = kind == Kind.Home ? "index" : sectionName, - URL = relativePath - }; + relativePath = relativePath == "homepage" ? "/" : relativePath; - var id = frontMatter.URL; + var id = relativePath; // Get or create the page var lazyPage = CacheManager.AutomaticContentCache.GetOrAdd(id, new Lazy(() => { - IPage? parent = null; - // Check if we need to create a section, even - var sections = GetDirectories(frontMatter.SourceRelativePathDirectory); - if (sections.Length > 1) + var directoryDepth = GetDirectoryDepth(relativePath); + var isHome = directoryDepth == 0; + var sectionName = GetFirstDirectory(relativePath); + var kind = isHome + ? Kind.Home + : isTaxonomy + ? (directoryDepth <= 1 ? Kind.Taxonomy : Kind.Term) + : (directoryDepth <= 1 ? Kind.Section : Kind.List); + + FrontMatter frontMatter = new() { - parent = CreateSystemPage(sections[0], sections[0], isTaxonomy); - } + Section = isHome ? "index" : sectionName, + SourceRelativePath = Urlizer.Path(Path.Combine(relativePath, IndexLeafFileConst)), + SourceFullPath = Urlizer.Path(Path.Combine(SourceContentPath, relativePath, IndexLeafFileConst)), + Title = title, + Type = kind == Kind.Home ? "index" : sectionName, + URL = relativePath + }; + + IPage? parent = null; var newPage = new Page(frontMatter, this) { @@ -277,7 +273,9 @@ public class Site : ISite } private static string GetFirstDirectory(string relativePath) => - GetDirectories(relativePath)[0]; + GetDirectories(relativePath).Length > 0 + ? GetDirectories(relativePath)[0] + : string.Empty; private static int GetDirectoryDepth(string relativePath) => GetDirectories(relativePath).Length; @@ -402,12 +400,10 @@ public class Site : ISite } if (!string.IsNullOrEmpty(page.Section) - && OutputReferences.TryGetValue('/' + page.Section!, out var output)) + && OutputReferences.TryGetValue('/' + page.Section!, out var output) + && (output is IPage section)) { - if (output is IPage section) - { - section.PagesReferences.Add(page.Permalink!); - } + section.PagesReferences.Add(page.Permalink!); } } -- GitLab From e7015ef661ac6c20b73646864e6e1ec8040b0684 Mon Sep 17 00:00:00 2001 From: Bruno Massa Date: Sun, 12 May 2024 23:59:03 -0500 Subject: [PATCH 5/5] fix: fix all tests --- Tests/Models/FrontMatterTests.cs | 12 +++++------- Tests/Models/SiteTests.cs | 2 +- source/Models/IPage.cs | 7 +------ source/Models/Kind.cs | 12 ++++++------ source/Models/Page.cs | 5 +++-- source/Models/Site.cs | 20 +++++++++++--------- 6 files changed, 27 insertions(+), 31 deletions(-) diff --git a/Tests/Models/FrontMatterTests.cs b/Tests/Models/FrontMatterTests.cs index 3d2d115..657a15c 100644 --- a/Tests/Models/FrontMatterTests.cs +++ b/Tests/Models/FrontMatterTests.cs @@ -7,10 +7,10 @@ namespace Tests.Models; public class FrontMatterTests : TestSetup { [Theory] - [InlineData("Title1", "Section1", "Type1", "URL1", Kind.Single)] - [InlineData("Title2", "Section2", "Type2", "URL2", Kind.List)] - [InlineData("Title3", "Section3", "Type3", "URL3", Kind.Home)] - public void Constructor_Sets_Properties_Correctly(string title, string section, string type, string url, Kind kind) + [InlineData("Title1", "Section1", "Type1", "URL1")] + [InlineData("Title2", "Section2", "Type2", "URL2")] + [InlineData("Title3", "Section3", "Type3", "URL3")] + public void Constructor_Sets_Properties_Correctly(string title, string section, string type, string url) { // Act var basicContent = new FrontMatter @@ -18,8 +18,7 @@ public class FrontMatterTests : TestSetup Title = title, Section = section, Type = type, - URL = url, - Kind = kind + URL = url }; // Assert @@ -27,7 +26,6 @@ public class FrontMatterTests : TestSetup Assert.Equal(section, basicContent.Section); Assert.Equal(type, basicContent.Type); Assert.Equal(url, basicContent.URL); - Assert.Equal(kind, basicContent.Kind); } [Theory] diff --git a/Tests/Models/SiteTests.cs b/Tests/Models/SiteTests.cs index ee91f87..60cad0d 100644 --- a/Tests/Models/SiteTests.cs +++ b/Tests/Models/SiteTests.cs @@ -74,7 +74,7 @@ public class SiteTests : TestSetup // Assert Assert.Equal(expectedQuantity, Site.OutputReferences.Values.Count(output => output is IPage { - IsSection: true + Kind: Kind.Section })); } diff --git a/source/Models/IPage.cs b/source/Models/IPage.cs index 0de55a5..6de5c83 100644 --- a/source/Models/IPage.cs +++ b/source/Models/IPage.cs @@ -70,15 +70,10 @@ public interface IPage : IFrontMatter, IOutput /// public bool IsHome => Site.Home == this; - /// - /// Just a simple check if the current page is a section page - /// - public bool IsSection => Type == "section"; - /// /// Just a simple check if the current page is a "page" /// - public bool IsPage => Kind == Kind.Single; + public bool IsPage => (Kind & Kind.Single) == Kind.Single && (Kind & Kind.System) != Kind.System; /// /// The number of words in the main content diff --git a/source/Models/Kind.cs b/source/Models/Kind.cs index 3dde62d..a16a88d 100644 --- a/source/Models/Kind.cs +++ b/source/Models/Kind.cs @@ -9,27 +9,27 @@ public enum Kind /// /// A single content page. /// - Single = 1 << 0, + Single = 1 << 1, /// /// List of contents /// - List = 1 << 1, + List = 1 << 2, /// /// Special page, like the home page. It will be rendered as index.html. /// - Index = 1 << 2, + Index = 1 << 3, /// /// Created by system /// - System = 1 << 3, + System = 1 << 4, /// /// Taxonomy type of content /// - IsTaxonomy = 1 << 4, + IsTaxonomy = 1 << 5, /// /// Special page, like the home page. It will be rendered as index.html. @@ -49,5 +49,5 @@ public enum Kind /// /// Each taxonomy (category, tags) item /// - Term = System | IsTaxonomy | List, + Term = System | Single | IsTaxonomy | List, } diff --git a/source/Models/Page.cs b/source/Models/Page.cs index 25fa194..83f04f3 100644 --- a/source/Models/Page.cs +++ b/source/Models/Page.cs @@ -211,7 +211,7 @@ public class Page : IPage get { _regularPagesCache ??= Pages - .Where(page => page.Kind == Kind.Single) + .Where(page => page.IsPage) .ToList(); return _regularPagesCache; } @@ -350,10 +350,11 @@ endif } } + // TODO: remove the hard coded // Create tag pages, if any if (Tags is not null) { - Site.CreateSystemPage("tags", "tags", true); + Site.CreateSystemPage("tags", "Tags", true); foreach (var tagName in Tags) { Site.CreateSystemPage(Path.Combine("tags", tagName), tagName, true, this); diff --git a/source/Models/Site.cs b/source/Models/Site.cs index 3c107d5..0fdacaf 100644 --- a/source/Models/Site.cs +++ b/source/Models/Site.cs @@ -221,17 +221,17 @@ public class Site : ISite var lazyPage = CacheManager.AutomaticContentCache.GetOrAdd(id, new Lazy(() => { var directoryDepth = GetDirectoryDepth(relativePath); - var isHome = directoryDepth == 0; var sectionName = GetFirstDirectory(relativePath); - var kind = isHome - ? Kind.Home - : isTaxonomy - ? (directoryDepth <= 1 ? Kind.Taxonomy : Kind.Term) - : (directoryDepth <= 1 ? Kind.Section : Kind.List); + var kind = directoryDepth switch + { + 0 => Kind.Home, + 1 => isTaxonomy ? Kind.Taxonomy : Kind.Section, + _ => isTaxonomy ? Kind.Term : Kind.List + }; FrontMatter frontMatter = new() { - Section = isHome ? "index" : sectionName, + Section = directoryDepth == 0 ? "index" : sectionName, SourceRelativePath = Urlizer.Path(Path.Combine(relativePath, IndexLeafFileConst)), SourceFullPath = Urlizer.Path(Path.Combine(SourceContentPath, relativePath, IndexLeafFileConst)), Title = title, @@ -264,7 +264,7 @@ public class Site : ISite } // TODO: still too hardcoded to add the tags reference - if (page.Type != "tags") + if ((page.Kind & Kind.IsTaxonomy) != Kind.IsTaxonomy) { return page; } @@ -401,7 +401,9 @@ public class Site : ISite if (!string.IsNullOrEmpty(page.Section) && OutputReferences.TryGetValue('/' + page.Section!, out var output) - && (output is IPage section)) + && (output is IPage section) + && page.Kind != Kind.Section + && page.Kind != Kind.Taxonomy) { section.PagesReferences.Add(page.Permalink!); } -- GitLab