Browse Source

trigger pages and posts recording views only when published

pull/36/head
Andrew 1 year ago
parent
commit
e5a8171087
  1. 1
      .gitignore
  2. 4
      app/controllers/page.js
  3. 5
      app/controllers/post.js

1
.gitignore

@ -7,3 +7,4 @@ data/minio
data/minio.old
node_modules
dist
start-local-*

4
app/controllers/page.js

@ -51,7 +51,9 @@ class PageController extends SiteController {
async getView (req, res, next) {
const { resource: resourceService } = this.dtp.services;
try {
await resourceService.recordView(req, 'Page', res.locals.page._id);
if (res.locals.page.status === 'published') {
await resourceService.recordView(req, 'Page', res.locals.page._id);
}
res.locals.pageSlug = res.locals.page.slug;
res.locals.pageTitle = `${res.locals.page.title} on ${this.dtp.config.site.name}`;
res.render('page/view');

5
app/controllers/post.js

@ -277,8 +277,9 @@ class PostController extends SiteController {
throw new SiteError(403, 'The post is not published');
}
}
await resourceService.recordView(req, 'Post', res.locals.post._id);
if (res.locals.post.status === 'published') {
await resourceService.recordView(req, 'Post', res.locals.post._id);
}
res.locals.countPerPage = 20;
res.locals.pagination = this.getPaginationParameters(req, res.locals.countPerPage);

Loading…
Cancel
Save