diff --git a/azure-pipelines.yml b/azure-pipelines.yml index 65c4bee0..c07097ff 100644 --- a/azure-pipelines.yml +++ b/azure-pipelines.yml @@ -10,7 +10,7 @@ pool: variables: buildConfiguration: 'Release' - version: 3.3 + version: 3.4 steps: - task: UseDotNet@2 diff --git a/source/DasBlog.Services/ConfigFile/Interfaces/ISiteConfig.cs b/source/DasBlog.Services/ConfigFile/Interfaces/ISiteConfig.cs index 5acf2e78..b2cca4fd 100644 --- a/source/DasBlog.Services/ConfigFile/Interfaces/ISiteConfig.cs +++ b/source/DasBlog.Services/ConfigFile/Interfaces/ISiteConfig.cs @@ -370,5 +370,7 @@ public interface ISiteConfig bool EnableRewritingHashtagsToCategoryLinks { get; set; } bool EnableRewritingBareLinksToEmbeddings { get; set; } bool EnableRewritingBareLinksToIcons { get; set; } + + string PostPinnedToHomePage { get; set; } } } diff --git a/source/DasBlog.Services/ConfigFile/SiteConfig.cs b/source/DasBlog.Services/ConfigFile/SiteConfig.cs index b4f9b8b0..be2345db 100644 --- a/source/DasBlog.Services/ConfigFile/SiteConfig.cs +++ b/source/DasBlog.Services/ConfigFile/SiteConfig.cs @@ -251,6 +251,6 @@ public string Root { public string MastodonServerUrl { get; set; } public string MastodonAccount { get; set; } - + public string PostPinnedToHomePage { get; set; } } } diff --git a/source/DasBlog.Tests/UnitTests/SiteConfigTest.cs b/source/DasBlog.Tests/UnitTests/SiteConfigTest.cs index 91363d38..21487251 100644 --- a/source/DasBlog.Tests/UnitTests/SiteConfigTest.cs +++ b/source/DasBlog.Tests/UnitTests/SiteConfigTest.cs @@ -173,5 +173,6 @@ public class SiteConfigTest : ISiteConfig public bool EnableRewritingHashtagsToCategoryLinks { get => throw new NotImplementedException(); set => throw new NotImplementedException(); } public bool EnableRewritingBareLinksToEmbeddings { get => throw new NotImplementedException(); set => throw new NotImplementedException(); } public bool EnableRewritingBareLinksToIcons { get => throw new NotImplementedException(); set => throw new NotImplementedException(); } + public string PostPinnedToHomePage { get => throw new NotImplementedException(); set => throw new NotImplementedException(); } } } diff --git a/source/DasBlog.Web.Repositories/BlogManager.cs b/source/DasBlog.Web.Repositories/BlogManager.cs index bdb0a977..e8bd91db 100644 --- a/source/DasBlog.Web.Repositories/BlogManager.cs +++ b/source/DasBlog.Web.Repositories/BlogManager.cs @@ -205,6 +205,11 @@ public void DeleteEntry(string postid) LogEvent(EventCodes.EntryDeleted, entry); } + public EntryCollection GetAllEntries() + { + return dataService.GetEntries(false); + } + private static StringCollection GetSearchWords(string searchString) { var searchWords = new StringCollection(); diff --git a/source/DasBlog.Web.Repositories/Interfaces/IBlogManager.cs b/source/DasBlog.Web.Repositories/Interfaces/IBlogManager.cs index 8aefe59f..79739978 100644 --- a/source/DasBlog.Web.Repositories/Interfaces/IBlogManager.cs +++ b/source/DasBlog.Web.Repositories/Interfaces/IBlogManager.cs @@ -17,6 +17,8 @@ public interface IBlogManager EntryCollection GetEntriesForPage(int pageIndex, string acceptLanguageHeader); + EntryCollection GetAllEntries(); + EntrySaveState CreateEntry(Entry entry); EntrySaveState UpdateEntry(Entry entry); diff --git a/source/DasBlog.Web.UI/Controllers/AdminController.cs b/source/DasBlog.Web.UI/Controllers/AdminController.cs index f028adaf..f2f6826b 100644 --- a/source/DasBlog.Web.UI/Controllers/AdminController.cs +++ b/source/DasBlog.Web.UI/Controllers/AdminController.cs @@ -46,6 +46,8 @@ public IActionResult Settings() var dbsvm = new DasBlogSettingsViewModel(); dbsvm.MetaConfig = mapper.Map(dasBlogSettings.MetaTags); dbsvm.SiteConfig = mapper.Map(dasBlogSettings.SiteConfiguration); + dbsvm.Posts = blogManager.GetAllEntries() + .Select(entry => mapper.Map(entry)).ToList(); return View(dbsvm); } diff --git a/source/DasBlog.Web.UI/Controllers/HomeController.cs b/source/DasBlog.Web.UI/Controllers/HomeController.cs index 68ce5307..aa30b9d1 100644 --- a/source/DasBlog.Web.UI/Controllers/HomeController.cs +++ b/source/DasBlog.Web.UI/Controllers/HomeController.cs @@ -11,10 +11,11 @@ using Microsoft.AspNetCore.Mvc; using Microsoft.Extensions.Caching.Memory; using Microsoft.Extensions.Logging; +using Quartz.Util; using System; +using System.Collections.Generic; using System.Diagnostics; using System.Linq; -using System.Threading.Tasks; namespace DasBlog.Web.Controllers { @@ -47,9 +48,7 @@ public IActionResult Index() { lpvm = new ListPostsViewModel { - Posts = blogManager.GetFrontPagePosts(Request.Headers["Accept-Language"]) - .Select(entry => mapper.Map(entry)) - .Select(editentry => editentry).ToList() + Posts = HomePagePosts() }; foreach( var post in lpvm.Posts ) @@ -92,7 +91,6 @@ public IActionResult Page(int index) return Index(); } - var lpvm = new ListPostsViewModel { Posts = blogManager.GetEntriesForPage(index, Request.Headers["Accept-Language"]) @@ -157,6 +155,29 @@ private ListPostsViewModel AddComments(ListPostsViewModel listPostsViewModel) return listPostsViewModel; } + + private IList HomePagePosts() + { + IList posts = new List(); + + if (!dasBlogSettings.SiteConfiguration.PostPinnedToHomePage.IsNullOrWhiteSpace() && + Guid.TryParse(dasBlogSettings.SiteConfiguration.PostPinnedToHomePage, out var results)) + { + var entry = blogManager.GetBlogPostByGuid(results); + + if (entry != null) + { + posts.Add(mapper.Map(entry)); + } + } + else + { + posts = blogManager.GetFrontPagePosts(Request.Headers["Accept-Language"]) + .Select(entry => mapper.Map(entry)).ToList(); + } + + return posts; + } } } diff --git a/source/DasBlog.Web.UI/Models/AdminViewModels/BlogPostListViewModel.cs b/source/DasBlog.Web.UI/Models/AdminViewModels/BlogPostListViewModel.cs new file mode 100644 index 00000000..a32666b6 --- /dev/null +++ b/source/DasBlog.Web.UI/Models/AdminViewModels/BlogPostListViewModel.cs @@ -0,0 +1,23 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using DasBlog.Web.Models.BlogViewModels; + +namespace DasBlog.Web.Models.AdminViewModels +{ + public class BlogPostListViewModel + { + public string Name { get; set; } + + public string Id { get; set; } + + public List Init(List posts) + { + var allposts = posts.Select(p => new BlogPostListViewModel { Name = p.Title, Id = p.EntryId }).ToList(); + + allposts.Insert(0, new BlogPostListViewModel { Name = "--Disable Pinning--", Id = "" }); + + return allposts; + } + } +} diff --git a/source/DasBlog.Web.UI/Models/AdminViewModels/DasBlogSettingsViewModel.cs b/source/DasBlog.Web.UI/Models/AdminViewModels/DasBlogSettingsViewModel.cs index eaca5efb..2d4a37de 100644 --- a/source/DasBlog.Web.UI/Models/AdminViewModels/DasBlogSettingsViewModel.cs +++ b/source/DasBlog.Web.UI/Models/AdminViewModels/DasBlogSettingsViewModel.cs @@ -1,7 +1,5 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Threading.Tasks; +using System.Collections.Generic; +using DasBlog.Web.Models.BlogViewModels; namespace DasBlog.Web.Models.AdminViewModels { @@ -9,5 +7,6 @@ public class DasBlogSettingsViewModel { public MetaViewModel MetaConfig { get; set; } public SiteViewModel SiteConfig { get; set; } + public List Posts { get; set; } } } diff --git a/source/DasBlog.Web.UI/Models/AdminViewModels/SiteViewModel.cs b/source/DasBlog.Web.UI/Models/AdminViewModels/SiteViewModel.cs index 3fc1b87f..f1850b7b 100644 --- a/source/DasBlog.Web.UI/Models/AdminViewModels/SiteViewModel.cs +++ b/source/DasBlog.Web.UI/Models/AdminViewModels/SiteViewModel.cs @@ -302,21 +302,25 @@ public class SiteViewModel [Description("Help meet some of the EU General Data Protection Regulation (GDPR) requirements")] public bool CookieConsentEnabled { get; set; } - [DisplayName("Default Sources (seperated by semi colon")] + [DisplayName("Default Sources (separated by semi colon")] [Description("")] [StringLength(50, MinimumLength = 1, ErrorMessage = "{0} should be between 1 to 50 characters")] public string DefaultSources { get; set; } - [DisplayName("Mastadon Server")] + [DisplayName("Mastodon Server")] [Description("")] [DataType(DataType.Url, ErrorMessage = "Invalid URL format")] public string MastodonServerUrl { get; set; } - [DisplayName("Mastadon Account (@username)")] + [DisplayName("Mastodon Account (@username)")] [Description("")] [RegularExpression("(@)((?:[A-Za-z0-9-_]*))")] public string MastodonAccount { get; set; } + [DisplayName("Pin this Post to the Home Page")] + [Description("")] + [DataType(DataType.Text, ErrorMessage = "Invalid Guid format")] + public string PostPinnedToHomePage { get; set; } public bool EntryTitleAsLink { get; set; } public bool ObfuscateEmail { get; set; } diff --git a/source/DasBlog.Web.UI/Views/Admin/Settings.cshtml b/source/DasBlog.Web.UI/Views/Admin/Settings.cshtml index cf3b0df0..fc7f8250 100644 --- a/source/DasBlog.Web.UI/Views/Admin/Settings.cshtml +++ b/source/DasBlog.Web.UI/Views/Admin/Settings.cshtml @@ -157,6 +157,21 @@ +
+ + @Html.LabelFor(m => @Model.SiteConfig.PostPinnedToHomePage, null, new { @class = "col-form-label col-sm-2" }) + +
+ @Html.DropDownListFor(n => n.SiteConfig.PostPinnedToHomePage, + new SelectList(new BlogPostListViewModel().Init(Model.Posts), "Id", "Name"), + new { @class = "form-select col-1" }) +
+ + + @Html.ValidationMessageFor(m => m.SiteConfig.PostPinnedToHomePage, null, new { @class = "text-danger" }) + +
+