Browse Source

Merge branch 'develop' of git.digitaltelepresence.com:digital-telepresence/dtp-base into develop

pull/36/head
Rob Colbert 2 years ago
parent
commit
333cc23367
  1. 9
      app/controllers/home.js
  2. 14
      app/controllers/user.js
  3. 11
      app/services/feed.js
  4. 2
      app/views/admin/layouts/main.pug
  5. 4
      app/views/components/library.pug
  6. 2
      app/views/components/navbar.pug
  7. 2
      app/views/components/off-canvas.pug
  8. 2
      app/views/layouts/main-sidebar.pug
  9. 10
      app/views/newsroom/components/feed-entry-list-item.pug
  10. 7
      client/less/site/main.less
  11. 5
      dtp-sites.js
  12. 7
      lib/site-common.js

9
app/controllers/home.js

@ -63,12 +63,7 @@ class HomeController extends SiteController {
} }
async getHome (req, res, next) { async getHome (req, res, next) {
const { const { announcement: announcementService, hive: hiveService, post: postService } = this.dtp.services;
announcement: announcementService,
feed: feedService,
hive: hiveService,
post: postService,
} = this.dtp.services;
try { try {
res.locals.announcements = await announcementService.getLatest(req.user); res.locals.announcements = await announcementService.getLatest(req.user);
res.locals.featuredPosts = await postService.getFeaturedPosts(3); res.locals.featuredPosts = await postService.getFeaturedPosts(3);
@ -77,8 +72,6 @@ class HomeController extends SiteController {
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.locals.newsfeed = await feedService.getNewsfeed();
res.render('index'); res.render('index');
} catch (error) { } catch (error) {
this.log.error('failed to render home view', { error }); this.log.error('failed to render home view', { error });

14
app/controllers/user.js

@ -33,12 +33,12 @@ class UserController extends SiteController {
const otpSetup = otpAuthService.middleware('Account', { const otpSetup = otpAuthService.middleware('Account', {
adminRequired: false, adminRequired: false,
otpRequired: true, otpRequired: true,
otpRedirectURL: async (req) => { return `/user/${req.user._id}`; }, otpRedirectURL: async (req) => { return `/user/${req.user.username}`; },
}); });
const otpMiddleware = otpAuthService.middleware('Account', { const otpMiddleware = otpAuthService.middleware('Account', {
adminRequired: false, adminRequired: false,
otpRequired: false, otpRequired: false,
otpRedirectURL: async (req) => { return `/user/${req.user._id}`; }, otpRedirectURL: async (req) => { return `/user/${req.user.username}`; },
}); });
router.use( router.use(
@ -61,8 +61,8 @@ class UserController extends SiteController {
} }
router.param('username', this.populateUsername.bind(this)); router.param('username', this.populateUsername.bind(this));
router.param('userId', this.populateUser.bind(this)); router.param('userId', this.populateUserId.bind(this));
router.param('coreUserId', this.populateCoreUser.bind(this)); router.param('coreUserId', this.populateCoreUserId.bind(this));
router.post( router.post(
'/core/:coreUserId/settings', '/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; const { user: userService } = this.dtp.services;
try { try {
userId = mongoose.Types.ObjectId(userId); 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; const { coreNode: coreNodeService } = this.dtp.services;
try { try {
coreUserId = mongoose.Types.ObjectId(coreUserId); coreUserId = mongoose.Types.ObjectId(coreUserId);
@ -218,7 +218,7 @@ class UserController extends SiteController {
if (error) { if (error) {
return next(error); return next(error);
} }
res.redirect(`/user/${res.locals.user._id}`); res.redirect(`/user/${res.locals.user.username}`);
}); });
} catch (error) { } catch (error) {
this.log.error('failed to create new user', { error }); this.log.error('failed to create new user', { error });

11
app/services/feed.js

@ -30,6 +30,17 @@ class FeedService extends SiteService {
this.jobQueue = await this.getJobQueue('newsroom', this.dtp.config.jobQueues.newsroom); 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) { async create (feedDefinition) {
feedDefinition.url = feedDefinition.url.trim(); feedDefinition.url = feedDefinition.url.trim();
const feedContent = await this.load(feedDefinition.url); const feedContent = await this.load(feedDefinition.url);

2
app/views/admin/layouts/main.pug

@ -16,4 +16,4 @@ block content-container
include ../components/menu include ../components/menu
div(class="uk-width-1-1 uk-flex-first uk-width-expand@m").uk-width-expand div(class="uk-width-1-1 uk-flex-first uk-width-expand@m").uk-width-expand
block content block content

4
app/views/components/library.pug

@ -40,7 +40,7 @@ include section-title
function getUserProfileUrl (user) { function getUserProfileUrl (user) {
if (user.core) { if (user.core) {
return `/user/core/${user._id}`; return `/user/core/${user.username}`;
} }
return `/user/${user.username}`; return `/user/${user.username}`;
} }
@ -60,6 +60,6 @@ mixin renderBackButton (options)
mixin renderUserLink (user) mixin renderUserLink (user)
if user.coreUserId 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 else
a(href=`/user/${user.username}`)= user.displayName || user.username a(href=`/user/${user.username}`)= user.displayName || user.username

2
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-heading.uk-text-center= user.displayName || user.username
li.uk-nav-divider li.uk-nav-divider
li 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 span.nav-item-icon
i.fas.fa-user i.fas.fa-user
span Profile span Profile

2
app/views/components/off-canvas.pug

@ -60,7 +60,7 @@ mixin renderMenuItem (iconClass, label)
.uk-width-expand Chat .uk-width-expand Chat
li(class={ "uk-active": (currentView === 'user-settings') }) 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 div(uk-grid).uk-grid-collapse
.uk-width-auto .uk-width-auto
.app-menu-icon .app-menu-icon

2
app/views/layouts/main-sidebar.pug

@ -1,6 +1,8 @@
extends main extends main
block content-container block content-container
block content-header block content-header
section.uk-section.uk-section-default.uk-section-small section.uk-section.uk-section-default.uk-section-small
.uk-container .uk-container
div(uk-grid)#dtp-content-grid div(uk-grid)#dtp-content-grid

10
app/views/newsroom/components/feed-entry-list-item.pug

@ -1,9 +1,9 @@
mixin renderNewsroomFeedEntryListItem (entry) mixin renderNewsroomFeedEntryListItem (entry)
.uk-text-bold a(href= entry.link, target="_blank").dtp-link
a(href= entry.link, target="_blank").uk-link-reset= entry.title div= entry.title
.uk-text-small .uk-article-meta
div(uk-grid).uk-grid-small div(uk-grid).uk-grid-small.uk-grid-divider
.uk-width-expand .uk-width-auto.uk-text-truncate
a(href= entry.feed.link, target="_blank").uk-link-reset= entry.feed.title a(href= entry.feed.link, target="_blank").uk-link-reset= entry.feed.title
.uk-width-auto .uk-width-auto
div= moment(entry.published).fromNow() div= moment(entry.published).fromNow()

7
client/less/site/main.less

@ -50,6 +50,13 @@ body {
} }
} }
a.dtp-link {
color: inherit;
&:hover {
color: @global-link-hover-color;
}
}
.dtp-site-footer { .dtp-site-footer {
.uk-subnav { .uk-subnav {
a.dtp-social-link { a.dtp-social-link {

5
dtp-sites.js

@ -22,15 +22,16 @@ module.config = {
http: require(path.join(module.rootPath, 'config', 'http')), http: require(path.join(module.rootPath, 'config', 'http')),
https: require(path.join(module.rootPath, 'config', 'https')), https: require(path.join(module.rootPath, 'config', 'https')),
registerMiddleware: async (dtp, app) => { registerMiddleware: async (dtp, app) => {
module.log.info('registering Page service middleware'); module.log.info('registering Page service middleware');
const { const {
feed: feedService,
gabTV: gabTvService, gabTV: gabTvService,
page: pageService, page: pageService,
siteLink: siteLinkService, siteLink: siteLinkService,
venue: venueService, venue: venueService,
} = module.services; } = module.services;
app.use( app.use(
feedService.middleware({ maxEntryCount: 5 }),
pageService.menuMiddleware.bind(pageService), pageService.menuMiddleware.bind(pageService),
siteLinkService.middleware(), siteLinkService.middleware(),
venueService.channelMiddleware(), venueService.channelMiddleware(),
@ -42,7 +43,7 @@ module.config = {
module.log = new SiteLog(module, module.config.component); module.log = new SiteLog(module, module.config.component);
module.shutdown = async ( ) => { module.shutdown = async ( ) => {
await SitePlatform.shutdown();
}; };
(async ( ) => { (async ( ) => {

7
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) { isValidString (text) {
return text && (typeof text === 'string') && (text.length > 0); return text && (typeof text === 'string') && (text.length > 0);
} }

Loading…
Cancel
Save