diff --git a/app/controllers/home.js b/app/controllers/home.js index 2eb9fd5..5301188 100644 --- a/app/controllers/home.js +++ b/app/controllers/home.js @@ -63,12 +63,7 @@ class HomeController extends SiteController { } async getHome (req, res, next) { - const { - announcement: announcementService, - feed: feedService, - hive: hiveService, - post: postService, - } = this.dtp.services; + const { announcement: announcementService, hive: hiveService, post: postService } = this.dtp.services; try { res.locals.announcements = await announcementService.getLatest(req.user); res.locals.featuredPosts = await postService.getFeaturedPosts(3); @@ -77,8 +72,6 @@ class HomeController extends SiteController { res.locals.pagination = this.getPaginationParameters(req, 20); res.locals.posts = await postService.getPosts(res.locals.pagination); - res.locals.newsfeed = await feedService.getNewsfeed(); - res.render('index'); } catch (error) { this.log.error('failed to render home view', { error }); diff --git a/app/controllers/user.js b/app/controllers/user.js index 8e28dcb..dbdbeaa 100644 --- a/app/controllers/user.js +++ b/app/controllers/user.js @@ -33,12 +33,12 @@ class UserController extends SiteController { const otpSetup = otpAuthService.middleware('Account', { adminRequired: false, otpRequired: true, - otpRedirectURL: async (req) => { return `/user/${req.user._id}`; }, + otpRedirectURL: async (req) => { return `/user/${req.user.username}`; }, }); const otpMiddleware = otpAuthService.middleware('Account', { adminRequired: false, otpRequired: false, - otpRedirectURL: async (req) => { return `/user/${req.user._id}`; }, + otpRedirectURL: async (req) => { return `/user/${req.user.username}`; }, }); router.use( @@ -61,8 +61,8 @@ class UserController extends SiteController { } router.param('username', this.populateUsername.bind(this)); - router.param('userId', this.populateUser.bind(this)); - router.param('coreUserId', this.populateCoreUser.bind(this)); + router.param('userId', this.populateUserId.bind(this)); + router.param('coreUserId', this.populateCoreUserId.bind(this)); router.post( '/core/:coreUserId/settings', @@ -162,7 +162,7 @@ class UserController extends SiteController { } } - async populateUser (req, res, next, userId) { + async populateUserId (req, res, next, userId) { const { user: userService } = this.dtp.services; try { userId = mongoose.Types.ObjectId(userId); @@ -178,7 +178,7 @@ class UserController extends SiteController { } } - async populateCoreUser (req, res, next, coreUserId) { + async populateCoreUserId (req, res, next, coreUserId) { const { coreNode: coreNodeService } = this.dtp.services; try { coreUserId = mongoose.Types.ObjectId(coreUserId); @@ -218,7 +218,7 @@ class UserController extends SiteController { if (error) { return next(error); } - res.redirect(`/user/${res.locals.user._id}`); + res.redirect(`/user/${res.locals.user.username}`); }); } catch (error) { this.log.error('failed to create new user', { error }); diff --git a/app/services/feed.js b/app/services/feed.js index a26e25a..27b55f2 100644 --- a/app/services/feed.js +++ b/app/services/feed.js @@ -30,6 +30,17 @@ class FeedService extends SiteService { this.jobQueue = await this.getJobQueue('newsroom', this.dtp.config.jobQueues.newsroom); } + middleware (options) { + options = Object.assign({ maxEntryCount: 5 }, options); + return async (req, res, next) => { + if (this.isSystemRoute(req.path)) { + return next(); // don't load newsfeeds for non-content routes + } + res.locals.newsfeed = await this.getNewsfeed({ skip: 0, cpp: options.maxEntryCount }); + return next(); + }; + } + async create (feedDefinition) { feedDefinition.url = feedDefinition.url.trim(); const feedContent = await this.load(feedDefinition.url); diff --git a/app/views/admin/layouts/main.pug b/app/views/admin/layouts/main.pug index 3e07d52..cc5f546 100644 --- a/app/views/admin/layouts/main.pug +++ b/app/views/admin/layouts/main.pug @@ -16,4 +16,4 @@ block content-container include ../components/menu div(class="uk-width-1-1 uk-flex-first uk-width-expand@m").uk-width-expand - block content + block content \ No newline at end of file diff --git a/app/views/components/library.pug b/app/views/components/library.pug index 0aa6d3f..9424f97 100644 --- a/app/views/components/library.pug +++ b/app/views/components/library.pug @@ -40,7 +40,7 @@ include section-title function getUserProfileUrl (user) { if (user.core) { - return `/user/core/${user._id}`; + return `/user/core/${user.username}`; } return `/user/${user.username}`; } @@ -60,6 +60,6 @@ mixin renderBackButton (options) mixin renderUserLink (user) if user.coreUserId - a(href=`/user/core/${user._id}`)= `${user.username}@${user.core.meta.domainKey}` + a(href=`/user/core/${user.username}`)= `${user.username}@${user.core.meta.domainKey}` else a(href=`/user/${user.username}`)= user.displayName || user.username \ No newline at end of file diff --git a/app/views/components/navbar.pug b/app/views/components/navbar.pug index f63344f..1cc2f51 100644 --- a/app/views/components/navbar.pug +++ b/app/views/components/navbar.pug @@ -67,7 +67,7 @@ nav(uk-navbar).uk-navbar-container.uk-position-fixed.uk-position-top li.uk-nav-heading.uk-text-center= user.displayName || user.username li.uk-nav-divider li - a(href= user.core ? `/user/core/${user._id}` : `/user/${user.username}`) + a(href= user.core ? `/user/core/${user.username}` : `/user/${user.username}`) span.nav-item-icon i.fas.fa-user span Profile diff --git a/app/views/components/off-canvas.pug b/app/views/components/off-canvas.pug index fb662c9..689900e 100644 --- a/app/views/components/off-canvas.pug +++ b/app/views/components/off-canvas.pug @@ -60,7 +60,7 @@ mixin renderMenuItem (iconClass, label) .uk-width-expand Chat li(class={ "uk-active": (currentView === 'user-settings') }) - a(href=`/user/${user._id}`).uk-display-block + a(href=`/user/${user.username}`).uk-display-block div(uk-grid).uk-grid-collapse .uk-width-auto .app-menu-icon diff --git a/app/views/layouts/main-sidebar.pug b/app/views/layouts/main-sidebar.pug index 52cbef8..2a67a50 100644 --- a/app/views/layouts/main-sidebar.pug +++ b/app/views/layouts/main-sidebar.pug @@ -1,6 +1,8 @@ extends main block content-container + block content-header + section.uk-section.uk-section-default.uk-section-small .uk-container div(uk-grid)#dtp-content-grid diff --git a/app/views/newsroom/components/feed-entry-list-item.pug b/app/views/newsroom/components/feed-entry-list-item.pug index da32d31..d50b368 100644 --- a/app/views/newsroom/components/feed-entry-list-item.pug +++ b/app/views/newsroom/components/feed-entry-list-item.pug @@ -1,9 +1,9 @@ mixin renderNewsroomFeedEntryListItem (entry) - .uk-text-bold - a(href= entry.link, target="_blank").uk-link-reset= entry.title - .uk-text-small - div(uk-grid).uk-grid-small - .uk-width-expand + a(href= entry.link, target="_blank").dtp-link + div= entry.title + .uk-article-meta + div(uk-grid).uk-grid-small.uk-grid-divider + .uk-width-auto.uk-text-truncate a(href= entry.feed.link, target="_blank").uk-link-reset= entry.feed.title .uk-width-auto div= moment(entry.published).fromNow() \ No newline at end of file diff --git a/client/less/site/main.less b/client/less/site/main.less index 73700d0..007a841 100644 --- a/client/less/site/main.less +++ b/client/less/site/main.less @@ -50,6 +50,13 @@ body { } } +a.dtp-link { + color: inherit; + + &:hover { + color: @global-link-hover-color; + } +} .dtp-site-footer { .uk-subnav { a.dtp-social-link { diff --git a/dtp-sites.js b/dtp-sites.js index bea4945..ec36753 100644 --- a/dtp-sites.js +++ b/dtp-sites.js @@ -22,15 +22,16 @@ module.config = { http: require(path.join(module.rootPath, 'config', 'http')), https: require(path.join(module.rootPath, 'config', 'https')), registerMiddleware: async (dtp, app) => { - module.log.info('registering Page service middleware'); const { + feed: feedService, gabTV: gabTvService, page: pageService, siteLink: siteLinkService, venue: venueService, } = module.services; app.use( + feedService.middleware({ maxEntryCount: 5 }), pageService.menuMiddleware.bind(pageService), siteLinkService.middleware(), venueService.channelMiddleware(), @@ -42,7 +43,7 @@ module.config = { module.log = new SiteLog(module, module.config.component); module.shutdown = async ( ) => { - + await SitePlatform.shutdown(); }; (async ( ) => { diff --git a/lib/site-common.js b/lib/site-common.js index 78a1788..3732ce3 100644 --- a/lib/site-common.js +++ b/lib/site-common.js @@ -106,6 +106,13 @@ class SiteCommon extends EventEmitter2 { }); } + isSystemRoute (pathname) { + return pathname.startsWith('/auth') || + pathname.startsWith('/image') || + pathname.startsWith('/manifest') + ; + } + isValidString (text) { return text && (typeof text === 'string') && (text.length > 0); }