Add blog navigation
This commit is contained in:
parent
3d00f28657
commit
9fd9beb860
5 changed files with 42 additions and 12 deletions
|
@ -22,7 +22,7 @@ namespace Website.Data
|
|||
}
|
||||
}
|
||||
|
||||
public async Task<IEnumerable<BlogPost>> GetLatestPostsAsync(int limit, int offset) {
|
||||
public async Task<IEnumerable<BlogPost>> GetLatestPostsAsync(int limit, int offset = 0) {
|
||||
const string query = "SELECT * FROM blog_posts WHERE post_content<>'' AND post_deleted=0 ORDER BY post_timestamp DESC LIMIT @offset,@limit";
|
||||
using (var connection = _dbProvider.NewConnection()) {
|
||||
connection.Open();
|
||||
|
@ -31,7 +31,7 @@ namespace Website.Data
|
|||
}
|
||||
}
|
||||
|
||||
public async Task<BlogPost> GetLatestPostAsync() => (await GetLatestPostsAsync(1, 0)).First();
|
||||
public async Task<BlogPost> GetLatestPostAsync() => (await GetLatestPostsAsync(1)).First();
|
||||
|
||||
public async Task<int> GetCountAsync()
|
||||
{
|
||||
|
|
18
Website/ViewComponents/BlogNavigationViewComponent.cs
Normal file
18
Website/ViewComponents/BlogNavigationViewComponent.cs
Normal file
|
@ -0,0 +1,18 @@
|
|||
using System.Threading.Tasks;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using Website.Data;
|
||||
|
||||
namespace Website.ViewComponents {
|
||||
public class BlogNavigationViewComponent:ViewComponent {
|
||||
private readonly BlogRepository _repo;
|
||||
|
||||
public BlogNavigationViewComponent(BlogRepository repo) {
|
||||
_repo = repo;
|
||||
}
|
||||
|
||||
public async Task<IViewComponentResult> InvokeAsync() {
|
||||
var posts = await _repo.GetLatestPostsAsync(5);
|
||||
return View(posts);
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,9 @@
|
|||
@model System.Collections.Generic.IEnumerable<Website.Models.BlogPost>
|
||||
|
||||
<h5>Blog:</h5>
|
||||
<ul class="nav-list">
|
||||
@foreach (var post in Model) {
|
||||
<li class="nav-list__link"><a href="/blog/view/@post.Url">@post.Title</a></li>
|
||||
}
|
||||
<li><a href="/blog">View All</a></li>
|
||||
</ul>
|
|
@ -23,7 +23,6 @@
|
|||
@RenderBody()
|
||||
</main>
|
||||
<nav>
|
||||
@Re
|
||||
<h5>Projects:</h5>
|
||||
<ul>
|
||||
<li><a href="link 1">Link 1</a></li>
|
||||
|
@ -31,13 +30,7 @@
|
|||
<li><a href="link 3">Link 3</a></li>
|
||||
<li><a href="//git.robware.uk">View All</a></li>
|
||||
</ul>
|
||||
<h5>Blog:</h5>
|
||||
<ul>
|
||||
<li><a href="link 1">Link 1</a></li>
|
||||
<li><a href="link 2">Link 2</a></li>
|
||||
<li><a href="link 3">Link 3</a></li>
|
||||
<li><a href="/blog">View All</a></li>
|
||||
</ul>
|
||||
@await Component.InvokeAsync("BlogNavigation")
|
||||
</nav>
|
||||
</div>
|
||||
<footer>
|
||||
|
|
|
@ -77,10 +77,20 @@ h1, h2, h3, h4, h5, h6 {
|
|||
}
|
||||
|
||||
nav {
|
||||
flex: 0 0 200px;
|
||||
flex: 0 0 250px;
|
||||
border-left: 1px solid @Grey-400;
|
||||
margin: 20px 0;
|
||||
padding: 0 10px;
|
||||
|
||||
.nav-list{
|
||||
list-style-type: none;
|
||||
margin: 0;
|
||||
padding: 0;
|
||||
|
||||
&__link{
|
||||
margin-bottom: 10px;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -95,7 +105,7 @@ footer {
|
|||
}
|
||||
}
|
||||
|
||||
button {
|
||||
button, .button {
|
||||
background: @accent;
|
||||
border: none;
|
||||
box-shadow: 0px 2px 3px 0px rgba(0, 0, 0, 0.25);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue