featured posts and home page rendering

master
rob 3 years ago
parent fa5b2fe9ce
commit 42f2622769

@ -82,7 +82,7 @@ class PostController extends SiteController {
const { post: postService } = this.dtp.services;
try {
res.locals.pagination = this.getPaginationParameters(req, 20);
res.locals.posts = await postService.getPosts(res.locals.pagination, ['draft', 'published', 'archived']);
res.locals.posts = await postService.getAllPosts(res.locals.pagination);
res.render('admin/post/index');
} catch (error) {
this.log.error('failed to fetch posts', { error });

@ -7,7 +7,6 @@
const DTP_COMPONENT_NAME = 'home';
const path = require('path');
const fs = require('fs');
const express = require('express');
@ -70,6 +69,7 @@ class HomeController extends SiteController {
const { post: postService } = this.dtp.services;
try {
res.locals.pagination = this.getPaginationParameters(req, 20);
res.locals.featuredPosts = await postService.getFeaturedPosts(3);
res.locals.posts = await postService.getPosts(res.locals.pagination);
res.render('index');
} catch (error) {

@ -94,7 +94,26 @@ class PostService extends SiteService {
status = [status];
}
const posts = await Post
.find({ status: { $in: status } })
.find({ status: { $in: status }, 'flags.isFeatured': false })
.sort({ created: -1 })
.skip(pagination.skip)
.limit(pagination.cpp)
.lean();
return posts;
}
async getFeaturedPosts (maxCount = 3) {
const posts = await Post
.find({ status: 'published', 'flags.isFeatured': true })
.sort({ created: -1 })
.limit(maxCount)
.lean();
return posts;
}
async getAllPosts (pagination) {
const posts = await Post
.find()
.sort({ created: -1 })
.skip(pagination.skip)
.limit(pagination.cpp)

@ -30,6 +30,9 @@ block content
.uk-width-auto
div(uk-grid).uk-grid-small.uk-flex-middle
if post.flags.isFeatured
.uk-width-auto
i(style="color: yellow;").fas.fa-star
.uk-width-auto(class={
'uk-text-info': (post.status === 'draft'),
'uk-text-success': (post.status === 'published'),

@ -4,7 +4,7 @@ mixin renderComment (comment)
header.uk-comment-header
div(uk-grid).uk-grid-medium.uk-flex-middle
.uk-width-auto
if comment.author.picture.small
if comment.author.picture && comment.author.picture.small
img(src= `/image/${comment.author.picture.small._id}`).site-profile-picture.sb-small.uk-comment-avatar
else
img(src="/img/default-member.png").site-profile-picture.sb-small.uk-comment-avatar

@ -2,42 +2,22 @@ extends layouts/main-sidebar
block content
include components/page-sidebar
mixin renderBlogPostListItem (post, postIndex = 1, postIndexModulus = 3)
a(href=`/post/${post.slug}`).uk-display-block.uk-link-reset
div(uk-grid).uk-grid-small
div(class='uk-visible@m', class={
'uk-flex-first': ((postIndex % postIndexModulus) === 0),
'uk-flex-last': ((postIndex % postIndexModulus) !== 0),
}).uk-width-1-3
img(src="/img/default-poster.jpg").responsive
div(class='uk-width-1-1 uk-width-2-3@m', class={
'uk-flex-first': ((postIndex % postIndexModulus) !== 0),
'uk-flex-last': ((postIndex % postIndexModulus) === 0),
})
article.uk-article
h4(style="line-height: 1.1;").uk-article-title.uk-margin-small= post.title
.uk-article-meta
if post.updated
span updated: #{moment(post.updated).format("MMM DD YYYY HH:MM a")}
else
span published: #{moment(post.created).format("MMM DD YYYY HH:MM a")}
+renderSectionTitle('Featured')
.uk-margin
div(style="position: relative; overflow: hidden; width: 100%; padding-top: 56.25%")
iframe(
src="https://tv.gab.com/channel/mrjoeprich/embed/what-is-just-joe-radio-61ad9b2165a83d20e95a465d",
width="960",
height="540",
style="position: absolute; top: 0; right: 0; bottom: 0; left: 0; width: 100%; height: 100%;",
)
if featuredEmbed
div.dtp-featured-embed!= featuredEmbed
include post/components/list-item
include post/components/featured-item
if Array.isArray(featuredPosts) && (featuredPosts.length > 0)
+renderSectionTitle('Featured')
- var topPost = featuredPosts.shift();
.uk-margin
+renderBlogPostFeaturedItem(topPost)
if (featuredPosts.length > 0)
.uk-margin
div(uk-grid).uk-grid-small
each post in featuredPosts
.uk-width-1-2
+renderBlogPostFeaturedItem(post)
//- Blog Posts
+renderSectionTitle('Blog Posts')

@ -0,0 +1,12 @@
mixin renderBlogPostFeaturedItem (post)
a(href=`/post/${post.slug}`).uk-display-block.uk-link-reset
div(class='uk-visible@m').uk-margin-small
img(src="/img/default-poster.jpg").responsive
article.uk-article
h4(style="line-height: 1.1;").uk-article-title.uk-margin-small= post.title
.uk-article-meta
if post.updated
span updated: #{moment(post.updated).format("MMM DD YYYY HH:MM a")}
else
span published: #{moment(post.created).format("MMM DD YYYY HH:MM a")}

@ -0,0 +1,21 @@
mixin renderBlogPostListItem (post, postIndex = 1, postIndexModulus = 3)
a(href=`/post/${post.slug}`).uk-display-block.uk-link-reset
div(uk-grid).uk-grid-small
div(class='uk-visible@m', class={
'uk-flex-first': ((postIndex % postIndexModulus) === 0),
'uk-flex-last': ((postIndex % postIndexModulus) !== 0),
}).uk-width-1-3
img(src="/img/default-poster.jpg").responsive
div(class='uk-width-1-1 uk-width-2-3@m', class={
'uk-flex-first': ((postIndex % postIndexModulus) !== 0),
'uk-flex-last': ((postIndex % postIndexModulus) === 0),
})
article.uk-article
h4(style="line-height: 1.1;").uk-article-title.uk-margin-small= post.title
.uk-article-meta
if post.updated
span updated: #{moment(post.updated).format("MMM DD YYYY HH:MM a")}
else
span published: #{moment(post.created).format("MMM DD YYYY HH:MM a")}
Loading…
Cancel
Save