From fd8e52f12e71a46922aa2b354991085fa43ec5e9 Mon Sep 17 00:00:00 2001 From: Bruno Massa Date: Thu, 13 Jul 2023 02:47:24 -0300 Subject: [PATCH] feat: site BaseURL, Description, Copyright --- source/{Models => Helpers}/SiteCacheManager.cs | 3 ++- source/Models/ISite.cs | 1 + source/Models/Site.cs | 18 +++++++++++++++++- source/Models/SiteSettings.cs | 16 +++++++++++++--- source/ServerHandlers/StaticFileRequest.cs | 2 +- test/Parser/YAMLParserTests.cs | 11 ++++++++--- .../RegisteredPageRequestHandlerTests.cs | 1 - 7 files changed, 42 insertions(+), 10 deletions(-) rename source/{Models => Helpers}/SiteCacheManager.cs (95%) diff --git a/source/Models/SiteCacheManager.cs b/source/Helpers/SiteCacheManager.cs similarity index 95% rename from source/Models/SiteCacheManager.cs rename to source/Helpers/SiteCacheManager.cs index 6694fbd..a689967 100644 --- a/source/Models/SiteCacheManager.cs +++ b/source/Helpers/SiteCacheManager.cs @@ -1,8 +1,9 @@ using System; using System.Collections.Concurrent; using System.Collections.Generic; +using SuCoS.Models; -namespace SuCoS.Models; +namespace SuCoS.Helpers; /// /// Manages all the lists and dictionaries used for cache for the site diff --git a/source/Models/ISite.cs b/source/Models/ISite.cs index a78e9e6..be775bd 100644 --- a/source/Models/ISite.cs +++ b/source/Models/ISite.cs @@ -3,6 +3,7 @@ using System.Collections.Generic; using System.IO; using Fluid; using Serilog; +using SuCoS.Helpers; using SuCoS.Models.CommandLineOptions; namespace SuCoS.Models; diff --git a/source/Models/Site.cs b/source/Models/Site.cs index f2e353d..95ce7f0 100644 --- a/source/Models/Site.cs +++ b/source/Models/Site.cs @@ -7,6 +7,7 @@ using System.Threading; using System.Threading.Tasks; using Fluid; using Serilog; +using SuCoS.Helpers; using SuCoS.Models.CommandLineOptions; using SuCoS.Parser; @@ -37,10 +38,25 @@ internal class Site : ISite #region SiteSettings /// - /// Site Title. + /// Site Title/Name /// public string Title => settings.Title; + /// + /// Site description + /// + public string? Description => settings.Description; + + /// + /// Copyright information + /// + public string? Copyright => settings.Copyright; + + /// + /// The base URL that will be used to build internal links. + /// + public string BaseURL => settings.BaseURL; + /// /// The appearance of a URL is either ugly or pretty. /// diff --git a/source/Models/SiteSettings.cs b/source/Models/SiteSettings.cs index 4de5802..5a52350 100644 --- a/source/Models/SiteSettings.cs +++ b/source/Models/SiteSettings.cs @@ -9,19 +9,29 @@ namespace SuCoS.Models; public class SiteSettings : IParams { /// - /// Site Title. + /// Site Title/Name. /// public string Title { get; set; } = string.Empty; + /// + /// Site description + /// + public string? Description { get; set; } + + /// + /// Copyright information + /// + public string? Copyright { get; set; } + /// /// The base URL that will be used to build internal links. /// - public string BaseUrl { get; set; } = "./"; + public string BaseURL { get; set; } = string.Empty; /// /// The appearance of a URL is either ugly or pretty. /// - public bool UglyURLs { get; set; } = false; + public bool UglyURLs { get; set; } #region IParams diff --git a/source/ServerHandlers/StaticFileRequest.cs b/source/ServerHandlers/StaticFileRequest.cs index a2e849a..bfa59c4 100644 --- a/source/ServerHandlers/StaticFileRequest.cs +++ b/source/ServerHandlers/StaticFileRequest.cs @@ -12,7 +12,7 @@ namespace SuCoS.ServerHandlers; internal class StaticFileRequest : IServerHandlers { private readonly string basePath; - private bool inTheme; + private readonly bool inTheme; /// /// Constructor diff --git a/test/Parser/YAMLParserTests.cs b/test/Parser/YAMLParserTests.cs index 7bc74f6..cd746f0 100644 --- a/test/Parser/YAMLParserTests.cs +++ b/test/Parser/YAMLParserTests.cs @@ -43,7 +43,9 @@ This is a test using real data. Real Data Test "; private const string siteContentCONST = @" Title: My Site -BaseUrl: https://www.example.com/ +BaseURL: https://www.example.com/ +Description: Tastiest C# Static Site Generator of the World +Copyright: Copyright message customParam: Custom Value NestedData: Level2: @@ -151,9 +153,12 @@ Title // Act var site = parser.ParseSiteSettings(siteContentCONST); + // Asset - Assert.Equal("https://www.example.com/", site.BaseUrl); Assert.Equal("My Site", site.Title); + Assert.Equal("https://www.example.com/", site.BaseURL); + Assert.Equal("Tastiest C# Static Site Generator of the World", site.Description); + Assert.Equal("Copyright message", site.Copyright); } [Fact] @@ -254,7 +259,7 @@ Title var site = parser.ParseSiteSettings(siteContentCONST); Assert.NotNull(site); Assert.Equal("My Site", site.Title); - Assert.Equal("https://www.example.com/", site.BaseUrl); + Assert.Equal("https://www.example.com/", site.BaseURL); } [Fact] diff --git a/test/ServerHandlers/RegisteredPageRequestHandlerTests.cs b/test/ServerHandlers/RegisteredPageRequestHandlerTests.cs index ccf7d53..eb2a175 100644 --- a/test/ServerHandlers/RegisteredPageRequestHandlerTests.cs +++ b/test/ServerHandlers/RegisteredPageRequestHandlerTests.cs @@ -1,5 +1,4 @@ using Microsoft.AspNetCore.Http; -using SuCoS.Models; using SuCoS.Models.CommandLineOptions; using SuCoS.ServerHandlers; using Xunit; -- GitLab