Skip to content

Instantly share code, notes, and snippets.

@ahmadawais
Created May 21, 2018 17:59
Show Gist options
  • Save ahmadawais/056c0f19551356f0740a64c1f7528989 to your computer and use it in GitHub Desktop.
Save ahmadawais/056c0f19551356f0740a64c1f7528989 to your computer and use it in GitHub Desktop.
'use strict';
var wp = require( '../services/wp' );
var contentService = require( '../services/content-service' );
var pageNumbers = require( '../services/page-numbers' );
var pageTitle = require( '../services/page-title' );
var RSVP = require( 'rsvp' );
function getHomepage( req, res, next ) {
var pages = pageNumbers( req.params.page );
RSVP.hash({
archiveBase: '',
pages: pages,
title: pageTitle(),
// Primary page content
posts: wp.posts().page( pages.current ),
sidebar: contentService.getSidebarContent()
}).then(function( context ) {
if ( req.params.page && ! context.posts.length ) {
// Invalid pagination: 404
return next();
}
res.render( 'index', context );
}).catch( next );
}
module.exports = getHomepage;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment