Skip to content

Commit

Permalink
Merge pull request #682 from poppastring/pin-to-home
Browse files Browse the repository at this point in the history
Pin to home - Allows you to pin a single post to the home page for a more static entry point in the site.
  • Loading branch information
poppastring authored Apr 13, 2023
2 parents df36b23 + 1ee225e commit 70b5df3
Show file tree
Hide file tree
Showing 12 changed files with 88 additions and 14 deletions.
2 changes: 1 addition & 1 deletion azure-pipelines.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ pool:

variables:
buildConfiguration: 'Release'
version: 3.3
version: 3.4

steps:
- task: UseDotNet@2
Expand Down
2 changes: 2 additions & 0 deletions source/DasBlog.Services/ConfigFile/Interfaces/ISiteConfig.cs
Original file line number Diff line number Diff line change
Expand Up @@ -370,5 +370,7 @@ public interface ISiteConfig
bool EnableRewritingHashtagsToCategoryLinks { get; set; }
bool EnableRewritingBareLinksToEmbeddings { get; set; }
bool EnableRewritingBareLinksToIcons { get; set; }

string PostPinnedToHomePage { get; set; }
}
}
2 changes: 1 addition & 1 deletion source/DasBlog.Services/ConfigFile/SiteConfig.cs
Original file line number Diff line number Diff line change
Expand Up @@ -251,6 +251,6 @@ public string Root {
public string MastodonServerUrl { get; set; }

public string MastodonAccount { get; set; }

public string PostPinnedToHomePage { get; set; }
}
}
1 change: 1 addition & 0 deletions source/DasBlog.Tests/UnitTests/SiteConfigTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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(); }
}
}
5 changes: 5 additions & 0 deletions source/DasBlog.Web.Repositories/BlogManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
2 changes: 2 additions & 0 deletions source/DasBlog.Web.Repositories/Interfaces/IBlogManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@ public interface IBlogManager

EntryCollection GetEntriesForPage(int pageIndex, string acceptLanguageHeader);

EntryCollection GetAllEntries();

EntrySaveState CreateEntry(Entry entry);

EntrySaveState UpdateEntry(Entry entry);
Expand Down
2 changes: 2 additions & 0 deletions source/DasBlog.Web.UI/Controllers/AdminController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,8 @@ public IActionResult Settings()
var dbsvm = new DasBlogSettingsViewModel();
dbsvm.MetaConfig = mapper.Map<MetaViewModel>(dasBlogSettings.MetaTags);
dbsvm.SiteConfig = mapper.Map<SiteViewModel>(dasBlogSettings.SiteConfiguration);
dbsvm.Posts = blogManager.GetAllEntries()
.Select(entry => mapper.Map<PostViewModel>(entry)).ToList();

return View(dbsvm);
}
Expand Down
31 changes: 26 additions & 5 deletions source/DasBlog.Web.UI/Controllers/HomeController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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
{
Expand Down Expand Up @@ -47,9 +48,7 @@ public IActionResult Index()
{
lpvm = new ListPostsViewModel
{
Posts = blogManager.GetFrontPagePosts(Request.Headers["Accept-Language"])
.Select(entry => mapper.Map<PostViewModel>(entry))
.Select(editentry => editentry).ToList()
Posts = HomePagePosts()
};

foreach( var post in lpvm.Posts )
Expand Down Expand Up @@ -92,7 +91,6 @@ public IActionResult Page(int index)
return Index();
}


var lpvm = new ListPostsViewModel
{
Posts = blogManager.GetEntriesForPage(index, Request.Headers["Accept-Language"])
Expand Down Expand Up @@ -157,6 +155,29 @@ private ListPostsViewModel AddComments(ListPostsViewModel listPostsViewModel)

return listPostsViewModel;
}

private IList<PostViewModel> HomePagePosts()
{
IList<PostViewModel> posts = new List<PostViewModel>();

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<PostViewModel>(entry));
}
}
else
{
posts = blogManager.GetFrontPagePosts(Request.Headers["Accept-Language"])
.Select(entry => mapper.Map<PostViewModel>(entry)).ToList();
}

return posts;
}
}
}

Original file line number Diff line number Diff line change
@@ -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<BlogPostListViewModel> Init(List<PostViewModel> 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;
}
}
}
Original file line number Diff line number Diff line change
@@ -1,13 +1,12 @@
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
{
public class DasBlogSettingsViewModel
{
public MetaViewModel MetaConfig { get; set; }
public SiteViewModel SiteConfig { get; set; }
public List<PostViewModel> Posts { get; set; }
}
}
10 changes: 7 additions & 3 deletions source/DasBlog.Web.UI/Models/AdminViewModels/SiteViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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; }
Expand Down
15 changes: 15 additions & 0 deletions source/DasBlog.Web.UI/Views/Admin/Settings.cshtml
Original file line number Diff line number Diff line change
Expand Up @@ -157,6 +157,21 @@

</div>

<div class="form-group row mb-3">

@Html.LabelFor(m => @Model.SiteConfig.PostPinnedToHomePage, null, new { @class = "col-form-label col-sm-2" })

<div class="col-sm-3">
@Html.DropDownListFor(n => n.SiteConfig.PostPinnedToHomePage,
new SelectList(new BlogPostListViewModel().Init(Model.Posts), "Id", "Name"),
new { @class = "form-select col-1" })
</div>


@Html.ValidationMessageFor(m => m.SiteConfig.PostPinnedToHomePage, null, new { @class = "text-danger" })

</div>

<div class="form-check row mb-3">
<div class="col-sm-10 offset-sm-2">
<div class="col-sm-2">
Expand Down

0 comments on commit 70b5df3

Please sign in to comment.