lib/services/publish.js
function processPublishRules(publishingChain, uri, pageData, locals) {

  // check whether page is archived, then run the rest of the publishing chain
  return _checkForArchived(uri)
    .then(initialObj => {
      return bluebird.reduce(publishingChain, (acc, fn, index) => {
        if (!acc.val) {
          return bluebird.try(() => fn(uri, pageData, locals))
            .then(val => {
              acc.val = val;
              return acc;
            })
            .catch(e => {
              acc.errors[fn.name || index] = e.message;
              return bluebird.resolve(acc);
            });
        }
        return acc;
      }, initialObj);
    })
    .catch(err => bluebird.resolve(err)); // err object constructed in _checkForArchived function above
}
function processPublishRules(publishingChain, uri, pageData, locals) {

  // check whether page is archived, then run the rest of the publishing chain
  return _checkForArchived(uri)
    .then(initialObj => {
      return bluebird.reduce(publishingChain, (acc, fn, index) => {
        if (!acc.val) {
          return bluebird.try(() => fn(uri, pageData, locals))
            .then(val => {
              acc.val = val;
              return acc;
            })
            .catch(e => {
              acc.errors[fn.name || index] = e.message;
              return bluebird.resolve(acc);
            });
        }
        return acc;
      }, initialObj);
    })
    .catch(err => bluebird.resolve(err)); // err object constructed in _checkForArchived function above
}
function processPublishRules ( publishingChain , uri , pageData , locals ) { // check whether page is archived, then run the rest of the publishing chain return _checkForArchived ( uri ) . then ( initialObj => { return bluebird . reduce ( publishingChain , ( acc , fn , index ) => { if ( ! acc . val ) { return bluebird . try ( ( ) => fn ( uri , pageData , locals ) ) . then ( val => { acc . val = val ; return acc ; } ) . catch ( e => { acc . errors [ fn . name || index ] = e . message ; return bluebird . resolve ( acc ) ; } ) ; } return acc ; } , initialObj ) ; } ) . catch ( err => bluebird . resolve ( err ) ) ; // err object constructed in _checkForArchived function above }
Reduce through the publishing rules supplied
by the site and aggregate the error messages
until a valid url is retrieved. Once retrieved,
skip the rest of the rules quickly and return
the result.

@param {Array} publishingChain
@param {String} uri
@param {Object} pageData
@param {Object} locals
@returns {Promise}
Reduce through the publishing rules supplied by the site and aggregate the error messages until a valid url is retrieved . Once retrieved skip the rest of the rules quickly and return the result .