diff --git a/source/DasBlog.Web.Repositories/BlogManager.cs b/source/DasBlog.Web.Repositories/BlogManager.cs index e8bd91dbe..f30fc8334 100644 --- a/source/DasBlog.Web.Repositories/BlogManager.cs +++ b/source/DasBlog.Web.Repositories/BlogManager.cs @@ -59,6 +59,11 @@ public Entry GetBlogPost(string posttitle, DateTime? dt) } } + public StaticPage GetStaticPage(string posttitle) + { + return dataService.GetStaticPage(posttitle); + } + public Entry GetBlogPostByGuid(Guid postid) { return dataService.GetEntry(postid.ToString()); diff --git a/source/DasBlog.Web.Repositories/Interfaces/IBlogManager.cs b/source/DasBlog.Web.Repositories/Interfaces/IBlogManager.cs index 797399788..a3c9e689b 100644 --- a/source/DasBlog.Web.Repositories/Interfaces/IBlogManager.cs +++ b/source/DasBlog.Web.Repositories/Interfaces/IBlogManager.cs @@ -8,7 +8,7 @@ namespace DasBlog.Managers.Interfaces public interface IBlogManager { Entry GetBlogPost(string posttitle, DateTime? postDate); - + StaticPage GetStaticPage(string posttitle); Entry GetBlogPostByGuid(Guid postid); Entry GetEntryForEdit(string postid); diff --git a/source/DasBlog.Web.UI/Controllers/BlogPostController.cs b/source/DasBlog.Web.UI/Controllers/BlogPostController.cs index 93f4a639f..846806532 100644 --- a/source/DasBlog.Web.UI/Controllers/BlogPostController.cs +++ b/source/DasBlog.Web.UI/Controllers/BlogPostController.cs @@ -41,6 +41,7 @@ public class BlogPostController : DasBlogBaseController private readonly IExternalEmbeddingHandler embeddingHandler; private readonly IRecaptchaService recaptcha; + public BlogPostController(IBlogManager blogManager, IHttpContextAccessor httpContextAccessor, IDasBlogSettings dasBlogSettings, IMapper mapper, ICategoryManager categoryManager, IFileSystemBinaryManager binaryManager, ILogger logger, IBlogPostViewModelCreator modelViewCreator, IMemoryCache memoryCache, IExternalEmbeddingHandler embeddingHandler, IRecaptchaService recaptcha) @@ -96,6 +97,14 @@ public IActionResult Post(string posttitle, string day, string month, string yea } else { + // Post was not found. Let's see if it's a static page before we route user to home page. + var sp = blogManager.GetStaticPage(posttitle); + if(sp != null) + { + var spvm = mapper.Map(sp); + return View("LoadStaticPage", spvm); + + } return RedirectToAction("index", "home"); } } diff --git a/source/DasBlog.Web.UI/Mappers/ProfileSaticPages.cs b/source/DasBlog.Web.UI/Mappers/ProfileSaticPages.cs new file mode 100644 index 000000000..bf4caace4 --- /dev/null +++ b/source/DasBlog.Web.UI/Mappers/ProfileSaticPages.cs @@ -0,0 +1,21 @@ +using AutoMapper; +using DasBlog.Web.Models.BlogViewModels; +using DasBlog.Core.Common; +using DasBlog.Core.Extensions; +using newtelligence.DasBlog.Runtime; +using System.Collections.Generic; +using System.Linq; +using DasBlog.Services; +using DasBlog.Core.Common.Comments; +using DasBlog.Web.Models.AdminViewModels; + +namespace DasBlog.Web.Mappers +{ + public class ProfileStaticPage : Profile + { + public ProfileStaticPage() + { + CreateMap(); + } + } +} diff --git a/source/DasBlog.Web.UI/Models/BlogViewModels/StaticPageViewModel.cs b/source/DasBlog.Web.UI/Models/BlogViewModels/StaticPageViewModel.cs new file mode 100644 index 000000000..caaa45a3a --- /dev/null +++ b/source/DasBlog.Web.UI/Models/BlogViewModels/StaticPageViewModel.cs @@ -0,0 +1,18 @@ +using System; +using System.Collections.Generic; +using System.ComponentModel.DataAnnotations; +using Microsoft.AspNetCore.Http; +using Microsoft.AspNetCore.Mvc.Rendering; +using Newtonsoft.Json; + +namespace DasBlog.Web.Models.BlogViewModels +{ + public class StaticPageViewModel + { + public string Name {get; set; } + + [DataType(DataType.MultilineText)] + public string Content { get; set; } + + } +} diff --git a/source/DasBlog.Web.UI/Startup.cs b/source/DasBlog.Web.UI/Startup.cs index 7d26c0323..b1544f6c9 100644 --- a/source/DasBlog.Web.UI/Startup.cs +++ b/source/DasBlog.Web.UI/Startup.cs @@ -232,6 +232,7 @@ public void ConfigureServices(IServiceCollection services) mapperConfig.AddProfile(new ProfileDasBlogUser(serviceProvider.GetService())); mapperConfig.AddProfile(new ProfileSettings()); mapperConfig.AddProfile(new ProfileActivityPub()); + mapperConfig.AddProfile(new ProfileStaticPage()); }) .AddMvc() .AddXmlSerializerFormatters(); diff --git a/source/DasBlog.Web.UI/Views/BlogPost/LoadStaticPage.cshtml b/source/DasBlog.Web.UI/Views/BlogPost/LoadStaticPage.cshtml new file mode 100644 index 000000000..2e1c92029 --- /dev/null +++ b/source/DasBlog.Web.UI/Views/BlogPost/LoadStaticPage.cshtml @@ -0,0 +1,4 @@ +@model DasBlog.Web.Models.BlogViewModels.StaticPageViewModel +@using DasBlog.Core.Common +@Html.Raw(Model.Content) + diff --git a/source/newtelligence.DasBlog.Runtime/BlogDataService.cs b/source/newtelligence.DasBlog.Runtime/BlogDataService.cs index be95de9f4..06a06f1a2 100644 --- a/source/newtelligence.DasBlog.Runtime/BlogDataService.cs +++ b/source/newtelligence.DasBlog.Runtime/BlogDataService.cs @@ -1421,5 +1421,21 @@ DateTime IBlogDataService.GetLastCommentUpdate() return data.lastCommentUpdate; } + + public StaticPage GetStaticPage( string pagename ) + { + StaticPage page = new StaticPage(); + page.Name = pagename; + string staticPathLocation = this.contentBaseDirectory + "\\static\\" + pagename + ".html"; + if (File.Exists(staticPathLocation)) + { + page.Content = File.ReadAllText(staticPathLocation); + } + else + { + return null; + } + return page; + } } } diff --git a/source/newtelligence.DasBlog.Runtime/IBlogDataService.cs b/source/newtelligence.DasBlog.Runtime/IBlogDataService.cs index 637c6cd18..2cb5dfb94 100644 --- a/source/newtelligence.DasBlog.Runtime/IBlogDataService.cs +++ b/source/newtelligence.DasBlog.Runtime/IBlogDataService.cs @@ -233,5 +233,7 @@ EntryCollection GetEntries( /// /// DateTime GetLastCommentUpdate(); + + StaticPage GetStaticPage( string pagename ); } } diff --git a/source/newtelligence.DasBlog.Runtime/StaticPage.cs b/source/newtelligence.DasBlog.Runtime/StaticPage.cs new file mode 100644 index 000000000..84a4b19c9 --- /dev/null +++ b/source/newtelligence.DasBlog.Runtime/StaticPage.cs @@ -0,0 +1,45 @@ +using NodaTime; +using System; +using System.Collections; +using System.Globalization; +using System.IO; +using System.Net; +using System.Text; +using System.Xml; +using System.Xml.Serialization; +using System.Collections.Generic; + +namespace newtelligence.DasBlog.Runtime +{ + [Serializable] + [XmlRoot(Namespace=Data.NamespaceURI)] + [XmlType(Namespace=Data.NamespaceURI)] + public class StaticPage + { + string _content; + string _name; + + public string Name + { + get + { + return _name; + } + set + { + _name = value; + } + } + public string Content + { + get + { + return _content; + } + set + { + _content = value; + } + } + } +}