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; const { post: postService } = this.dtp.services;
try { try {
res.locals.pagination = this.getPaginationParameters(req, 20); 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'); res.render('admin/post/index');
} catch (error) { } catch (error) {
this.log.error('failed to fetch posts', { error }); this.log.error('failed to fetch posts', { error });

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

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

@ -16,6 +16,18 @@ class GabTVService extends SiteService {
super(dtp, module.exports); 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) { async getChannelEpisodes (channelSlug, options) {
const { cache: cacheService } = this.dtp.services; const { cache: cacheService } = this.dtp.services;
const cacheKey = `gabtv:ch:${channelSlug}`; const cacheKey = `gabtv:ch:${channelSlug}`;

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

@ -19,7 +19,7 @@ block content
li(data-post-id= post._id) li(data-post-id= post._id)
div(uk-grid).uk-grid-small.uk-flex-middle div(uk-grid).uk-grid-small.uk-flex-middle
.uk-width-expand .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 .uk-text-small
div(uk-grid).uk-grid-small div(uk-grid).uk-grid-small
.uk-width-auto .uk-width-auto
@ -29,7 +29,12 @@ block content
span last update: #{moment(post.updated).format('MMM DD, YYYY [at] hh:mm:ss a')} span last update: #{moment(post.updated).format('MMM DD, YYYY [at] hh:mm:ss a')}
.uk-width-auto .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 .uk-width-auto
a(href=`/admin/post/${post._id}`).uk-button.dtp-button-primary a(href=`/admin/post/${post._id}`).uk-button.dtp-button-primary
+renderButtonIcon('fa-pen', 'Edit') +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 extends layouts/main
block content block content
mixin renderSidebarEpisode(episode)
.uk-card.uk-card-secondary.uk-card-small.uk-card-hover
.uk-card-media-top include components/page-sidebar
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")}
.uk-padding .uk-padding
.uk-container .uk-container
@ -58,32 +48,4 @@ block content
//- Sidebar //- Sidebar
div(class="uk-width-1-1 uk-width-1-3@m") div(class="uk-width-1-1 uk-width-1-3@m")
//- Gab TV 3 Most Recent Episodes +renderPageSidebar()
.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,18 +1,25 @@
extends ../layouts/main extends ../layouts/main
block content block content
include ../components/page-sidebar
section.uk-section.uk-section-default section.uk-section.uk-section-default
.uk-container .uk-container
article(dtp-post-id= post._id) div(uk-grid)
.uk-margin .uk-width-2-3
div(uk-grid) article(dtp-post-id= post._id)
.uk-width-expand .uk-margin
h1.article-title= post.title div(uk-grid)
if user && user.flags.isAdmin .uk-width-expand
.uk-width-auto h1.article-title= post.title
a(href=`/admin/post/${post._id}`).uk-button.dtp-button-text EDIT if user && user.flags.isAdmin
.uk-text-lead= post.summary .uk-width-auto
.uk-margin a(href=`/admin/post/${post._id}`).uk-button.dtp-button-text EDIT
.uk-article-meta= moment(post.created).format('MMM DD, YYYY [at] hh:mm a') .uk-text-lead= post.summary
.uk-margin .uk-margin
!= post.content .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 * Application logic middleware
*/ */
module.app.use(async (req, res, next) => { module.app.use(async (req, res, next) => {
res.locals.dtp = { try {
request: req, res.locals.dtp = {
}; request: req,
res.locals.socialIcons = [ };
{ res.locals.socialIcons = [
url: 'https://facebook.com', {
label: 'Facebook', url: 'https://facebook.com',
icon: 'fa-facebook' label: 'Facebook',
}, icon: 'fa-facebook'
{ },
url: 'https://twitter.com', {
label: 'Twitter', url: 'https://twitter.com',
icon: 'fa-twitter' label: 'Twitter',
}, icon: 'fa-twitter'
{ },
url: 'https://instagram.com', {
label: 'Instagram', url: 'https://instagram.com',
icon: 'fa-instagram' label: 'Instagram',
}, icon: 'fa-instagram'
]; },
return next(); ];
return next();
} catch (error) {
module.log.error('failed to populate general request data', { error });
return next(error);
}
}); });
/* /*

Loading…
Cancel
Save