-
-
Save ahmadawais/056c0f19551356f0740a64c1f7528989 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
'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