Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

First implementation of static pages as per #686. #688

Merged
merged 1 commit into from
Sep 2, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions source/DasBlog.Web.Repositories/BlogManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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());
Expand Down
2 changes: 1 addition & 1 deletion source/DasBlog.Web.Repositories/Interfaces/IBlogManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
9 changes: 9 additions & 0 deletions source/DasBlog.Web.UI/Controllers/BlogPostController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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<BlogPostController> logger,
IBlogPostViewModelCreator modelViewCreator, IMemoryCache memoryCache, IExternalEmbeddingHandler embeddingHandler, IRecaptchaService recaptcha)
Expand Down Expand Up @@ -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<StaticPageViewModel>(sp);
return View("LoadStaticPage", spvm);

}
return RedirectToAction("index", "home");
}
}
Expand Down
21 changes: 21 additions & 0 deletions source/DasBlog.Web.UI/Mappers/ProfileSaticPages.cs
Original file line number Diff line number Diff line change
@@ -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<StaticPage, StaticPageViewModel>();
}
}
}
18 changes: 18 additions & 0 deletions source/DasBlog.Web.UI/Models/BlogViewModels/StaticPageViewModel.cs
Original file line number Diff line number Diff line change
@@ -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; }

}
}
1 change: 1 addition & 0 deletions source/DasBlog.Web.UI/Startup.cs
Original file line number Diff line number Diff line change
Expand Up @@ -232,6 +232,7 @@ public void ConfigureServices(IServiceCollection services)
mapperConfig.AddProfile(new ProfileDasBlogUser(serviceProvider.GetService<ISiteSecurityManager>()));
mapperConfig.AddProfile(new ProfileSettings());
mapperConfig.AddProfile(new ProfileActivityPub());
mapperConfig.AddProfile(new ProfileStaticPage());
})
.AddMvc()
.AddXmlSerializerFormatters();
Expand Down
4 changes: 4 additions & 0 deletions source/DasBlog.Web.UI/Views/BlogPost/LoadStaticPage.cshtml
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
@model DasBlog.Web.Models.BlogViewModels.StaticPageViewModel
@using DasBlog.Core.Common
@Html.Raw(Model.Content)

16 changes: 16 additions & 0 deletions source/newtelligence.DasBlog.Runtime/BlogDataService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
}
}
2 changes: 2 additions & 0 deletions source/newtelligence.DasBlog.Runtime/IBlogDataService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -233,5 +233,7 @@ EntryCollection GetEntries(
/// </summary>
/// <returns></returns>
DateTime GetLastCommentUpdate();

StaticPage GetStaticPage( string pagename );
}
}
45 changes: 45 additions & 0 deletions source/newtelligence.DasBlog.Runtime/StaticPage.cs
Original file line number Diff line number Diff line change
@@ -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;
}
}
}
}