diff --git a/app/controllers/admin/post.js b/app/controllers/admin/post.js index 7f0004b..7980a38 100644 --- a/app/controllers/admin/post.js +++ b/app/controllers/admin/post.js @@ -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 }); diff --git a/app/controllers/home.js b/app/controllers/home.js index 78f5982..9d821ff 100644 --- a/app/controllers/home.js +++ b/app/controllers/home.js @@ -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'); diff --git a/app/controllers/post.js b/app/controllers/post.js index 2226b9a..a961f6c 100644 --- a/app/controllers/post.js +++ b/app/controllers/post.js @@ -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(); diff --git a/app/services/gab-tv.js b/app/services/gab-tv.js index 4fca04f..6be324f 100644 --- a/app/services/gab-tv.js +++ b/app/services/gab-tv.js @@ -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}`; diff --git a/app/views/admin/post/editor.pug b/app/views/admin/post/editor.pug index ada8afa..cad0ee5 100644 --- a/app/views/admin/post/editor.pug +++ b/app/views/admin/post/editor.pug @@ -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]; diff --git a/app/views/admin/post/index.pug b/app/views/admin/post/index.pug index 3aab8de..a680e8e 100644 --- a/app/views/admin/post/index.pug +++ b/app/views/admin/post/index.pug @@ -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') diff --git a/app/views/components/page-sidebar.pug b/app/views/components/page-sidebar.pug new file mode 100644 index 0000000..eba32cc --- /dev/null +++ b/app/views/components/page-sidebar.pug @@ -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 \ No newline at end of file diff --git a/app/views/index.pug b/app/views/index.pug index 6a490c8..c42dbb5 100644 --- a/app/views/index.pug +++ b/app/views/index.pug @@ -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() \ No newline at end of file diff --git a/app/views/post/view.pug b/app/views/post/view.pug index 522d0cc..28cbe76 100644 --- a/app/views/post/view.pug +++ b/app/views/post/view.pug @@ -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 \ No newline at end of file + 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() \ No newline at end of file diff --git a/lib/site-platform.js b/lib/site-platform.js index 2341ce3..7f9cc6b 100644 --- a/lib/site-platform.js +++ b/lib/site-platform.js @@ -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); + } }); /*