many updates

- more completeness on blog post and view
- refactored sidebar to a site component
- created Gab TV service sidebar middleware
master
rob 3 years ago
parent 00d8c1e10e
commit 3a30881d7c

@ -80,7 +80,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']);
res.locals.posts = await postService.getPosts(res.locals.pagination, ['draft', 'published', 'archived']);
res.render('admin/post/index');
} catch (error) {
this.log.error('failed to fetch posts', { error });

@ -23,6 +23,7 @@ class HomeController extends SiteController {
const router = express.Router();
dtp.app.use('/', router);
router.use(this.dtp.services.gabTV.channelMiddleware('mrjoeprich'));
router.use(async (req, res, next) => {
res.locals.currentView = 'home';
return next();
@ -35,10 +36,8 @@ class HomeController extends SiteController {
}
async getHome (req, res, next) {
const { gabTV: gabTvService, post: postService } = this.dtp.services;
const { post: postService } = this.dtp.services;
try {
res.locals.gabTvChannel = await gabTvService.getChannelEpisodes('mrjoeprich');
res.locals.pagination = this.getPaginationParameters(req, 20);
res.locals.posts = await postService.getPosts(res.locals.pagination);
res.render('index');

@ -23,6 +23,7 @@ class PostController extends SiteController {
const router = express.Router();
dtp.app.use('/post', router);
router.use(this.dtp.services.gabTV.channelMiddleware('mrjoeprich'));
router.use(async (req, res, next) => {
res.locals.currentView = 'home';
return next();

@ -16,6 +16,18 @@ class GabTVService extends SiteService {
super(dtp, module.exports);
}
channelMiddleware (channelSlug) {
return async (req, res, next) => {
try {
res.locals.gabTvChannel = await this.getChannelEpisodes(channelSlug, { allowCache: true });
return next();
} catch (error) {
this.log.error('failed to populdate Gab TV channel', { channelSlug, error });
return next();
}
};
}
async getChannelEpisodes (channelSlug, options) {
const { cache: cacheService } = this.dtp.services;
const cacheKey = `gabtv:ch:${channelSlug}`;

@ -39,7 +39,7 @@ block viewjs
'bold italic backcolor',
'alignleft aligncenter alignright alignjustify',
'bullist numlist outdent indent removeformat',
'link image',
'link image code',
'help'
];
const pluginItems = [
@ -61,6 +61,8 @@ block viewjs
{ title: 'Body Image', value: 'dtp-image-body' },
{ title: 'Title Image', value: 'dtp-image-title' },
],
document_base_url: '/post/#{post.slug}',
convert_urls: false,
});
window.dtp.app.editor = editors[0];

@ -19,7 +19,7 @@ block content
li(data-post-id= post._id)
div(uk-grid).uk-grid-small.uk-flex-middle
.uk-width-expand
a(href=`/post/${post.slug}`).uk-display-block.uk-text-large.uk-text-truncate #{post.title} #[small= post.slug]
a(href=`/post/${post.slug}`).uk-display-block.uk-text-large.uk-text-truncate #{post.title}
.uk-text-small
div(uk-grid).uk-grid-small
.uk-width-auto
@ -29,7 +29,12 @@ block content
span last update: #{moment(post.updated).format('MMM DD, YYYY [at] hh:mm:ss a')}
.uk-width-auto
div(uk-grid).uk-grid-small
div(uk-grid).uk-grid-small.uk-flex-middle
.uk-width-auto(class={
'uk-text-info': (post.status === 'draft'),
'uk-text-success': (post.status === 'published'),
'uk-text-danger': (post.status === 'archived'),
})= post.status
.uk-width-auto
a(href=`/admin/post/${post._id}`).uk-button.dtp-button-primary
+renderButtonIcon('fa-pen', 'Edit')

@ -0,0 +1,41 @@
mixin renderSidebarEpisode(episode)
.uk-card.uk-card-secondary.uk-card-small.uk-card-hover
.uk-card-media-top
a(href= episode.url, target="_blank", title="Watch on Gab TV")
img(src=episode.image).responsive
.uk-card-body
.uk-card-title.uk-margin-remove.uk-text-truncate
a(href= episode.url, target="_blank", title= `Watch "${episode.title}" on Gab TV`)= episode.title
.uk-text-small Posted: #{moment(episode.date_modified).format("MMM DD YYYY HH:MM a")}
mixin renderPageSidebar ( )
//- Gab TV 3 Most Recent Episodes
.uk-margin
.dtp-border-bottom
h3.uk-heading-bullet
a(href= gabTvChannel.home_page_url, target= "_blank", title= `${gabTvChannel.title} on Gab`).uk-link-reset Gab TV
ul.uk-list
each episode in gabTvChannel.items.slice(0, 3)
li
+renderSidebarEpisode(episode)
//- Newsletter Signup
//- TODO Add sticky
.uk-margin
.dtp-border-bottom.uk-margin
h3.uk-heading-bullet Mailing List
form(method="post", action="/newsletter", onsubmit="return dtp.app.submitForm(event, 'Subscribe to newsletter');").uk-form
.uk-card.uk-card-secondary.uk-card-small
.uk-card-body
p Join the #{site.name} FREE newsletter to get show updates in your inbox.
.uk-margin
label(for="email").uk-form-label.sr-only Email Address
input(id="email", name="email", type="email", placeholder="johnsmith@example.com").uk-input
.uk-card-footer
button(type="submit").uk-button.uk-button-primary Sign Up

@ -1,17 +1,7 @@
extends layouts/main
block content
mixin renderSidebarEpisode(episode)
.uk-card.uk-card-secondary.uk-card-small.uk-card-hover
.uk-card-media-top
a(href= episode.url, target="_blank", title="Watch on Gab TV")
img(src=episode.image).responsive
.uk-card-body
.uk-card-title.uk-margin-remove.uk-text-truncate
a(href= episode.url, target="_blank", title= `Watch "${episode.title}" on Gab TV`)= episode.title
.uk-text-small Posted: #{moment(episode.date_modified).format("MMM DD YYYY HH:MM a")}
include components/page-sidebar
.uk-padding
.uk-container
@ -58,32 +48,4 @@ block content
//- Sidebar
div(class="uk-width-1-1 uk-width-1-3@m")
//- Gab TV 3 Most Recent Episodes
.uk-margin
.dtp-border-bottom
h3.uk-heading-bullet
a(href= gabTvChannel.home_page_url, target= "_blank", title= `${gabTvChannel.title} on Gab`).uk-link-reset Gab TV
ul.uk-list
each episode in gabTvChannel.items.slice(0, 3)
li
+renderSidebarEpisode(episode)
//- Newsletter Signup
//- TODO Add sticky
.uk-margin
.dtp-border-bottom.uk-margin
h3.uk-heading-bullet Mailing List
form(method="post", action="/newsletter", onsubmit="return dtp.app.submitForm(event, 'Subscribe to newsletter');").uk-form
.uk-card.uk-card-secondary.uk-card-small
.uk-card-body
p Join the #{site.name} FREE newsletter to get show updates in your inbox.
.uk-margin
label(for="email").uk-form-label.sr-only Email Address
input(id="email", name="email", type="email", placeholder="johnsmith@example.com").uk-input
.uk-card-footer
button(type="submit").uk-button.uk-button-primary Sign Up
+renderPageSidebar()

@ -1,18 +1,25 @@
extends ../layouts/main
block content
include ../components/page-sidebar
section.uk-section.uk-section-default
.uk-container
article(dtp-post-id= post._id)
.uk-margin
div(uk-grid)
.uk-width-expand
h1.article-title= post.title
if user && user.flags.isAdmin
.uk-width-auto
a(href=`/admin/post/${post._id}`).uk-button.dtp-button-text EDIT
.uk-text-lead= post.summary
.uk-margin
.uk-article-meta= moment(post.created).format('MMM DD, YYYY [at] hh:mm a')
.uk-margin
!= post.content
div(uk-grid)
.uk-width-2-3
article(dtp-post-id= post._id)
.uk-margin
div(uk-grid)
.uk-width-expand
h1.article-title= post.title
if user && user.flags.isAdmin
.uk-width-auto
a(href=`/admin/post/${post._id}`).uk-button.dtp-button-text EDIT
.uk-text-lead= post.summary
.uk-margin
.uk-article-meta= moment(post.created).format('MMM DD, YYYY [at] hh:mm a')
.uk-margin
!= post.content
.uk-width-1-3
+renderPageSidebar()

@ -269,27 +269,32 @@ module.exports.startWebServer = async (dtp) => {
* Application logic middleware
*/
module.app.use(async (req, res, next) => {
res.locals.dtp = {
request: req,
};
res.locals.socialIcons = [
{
url: 'https://facebook.com',
label: 'Facebook',
icon: 'fa-facebook'
},
{
url: 'https://twitter.com',
label: 'Twitter',
icon: 'fa-twitter'
},
{
url: 'https://instagram.com',
label: 'Instagram',
icon: 'fa-instagram'
},
];
return next();
try {
res.locals.dtp = {
request: req,
};
res.locals.socialIcons = [
{
url: 'https://facebook.com',
label: 'Facebook',
icon: 'fa-facebook'
},
{
url: 'https://twitter.com',
label: 'Twitter',
icon: 'fa-twitter'
},
{
url: 'https://instagram.com',
label: 'Instagram',
icon: 'fa-instagram'
},
];
return next();
} catch (error) {
module.log.error('failed to populate general request data', { error });
return next(error);
}
});
/*

Loading…
Cancel
Save