diff --git a/routes/about.js b/routes/about.js index ba53760..21090e1 100644 --- a/routes/about.js +++ b/routes/about.js @@ -1,9 +1,12 @@ const express = require('express') +const { getLandingPage } = require('../services/contentful') +const { catchErrors } = require('../handlers/errorHandlers') const router = express.Router() -/* GET about page. */ -router.get('/', function (req, res, next) { - res.render('about', { title: 'About' }) -}) +/* GET the about landing page. */ +router.get('/', catchErrors(async function (req, res, next) { + const landingPage = await getLandingPage('about', req.query.locale, req.query.api) + res.render('landingPage', { title: 'About', landingPage }) +})) module.exports = router diff --git a/routes/index.js b/routes/index.js index 3e02c39..8125467 100644 --- a/routes/index.js +++ b/routes/index.js @@ -3,10 +3,10 @@ const { getLandingPage } = require('../services/contentful') const { catchErrors } = require('../handlers/errorHandlers') const router = express.Router() -/* GET home page. */ +/* GET the home landing page. */ router.get('/', catchErrors(async function (req, res, next) { - const landingPage = await getLandingPage(req.query.locale, req.query.api) - res.render('index', { title: 'Contentful University', landingPage }) + const landingPage = await getLandingPage('home', req.query.locale, req.query.api) + res.render('landingPage', { title: 'Contentful University', landingPage }) })) module.exports = router diff --git a/services/contentful.js b/services/contentful.js index e176eea..d31e9fa 100644 --- a/services/contentful.js +++ b/services/contentful.js @@ -31,11 +31,10 @@ exports.getCourses = assert((locale = 'en-US', api = `cda`) => { .then((response) => response.items) }, 'Course') -exports.getLandingPage = (locale = 'en-US', api = `cda`) => { - // our Home page is fully configureable via Contentful +exports.getLandingPage = (slug, locale = 'en-US', api = `cda`) => { + // Landing pages like the home or about page are fully controlable via Contentful. const client = api === 'cda' ? cdaClient : cpaClient - // TODO slug should be renamed to `contentful-the-example-app` or something .... - return client.getEntries({content_type: 'landingPage', locale, 'fields.slug': 'contentful-university', include: 10}) + return client.getEntries({content_type: 'landingPage', locale, 'fields.slug': slug, include: 10}) .then((response) => response.items[0]) } diff --git a/views/about.pug b/views/about.pug deleted file mode 100644 index fe047a3..0000000 --- a/views/about.pug +++ /dev/null @@ -1,6 +0,0 @@ -extends layout - -block content - .layout-centered - h1= title - p Welcome to #{title} diff --git a/views/index.pug b/views/index.pug deleted file mode 100644 index 15f1616..0000000 --- a/views/index.pug +++ /dev/null @@ -1,18 +0,0 @@ -extends layout - -include mixins/_moduleCopy -include mixins/_moduleHeroImage -include mixins/_moduleHighlightedCourse - -block content - .modules-container - each module in landingPage.fields.contentModules - case module.sys.contentType.sys.id - when 'landingPageModuleCopy' - +moduleCopy(module) - - when 'landingPageModuleHeroImage' - +moduleHeroImage(module) - - when 'landingPageModuleHighlightedCourse' - +moduleHighlightedCourse(module, module.fields.course) diff --git a/views/landingPage.pug b/views/landingPage.pug new file mode 100644 index 0000000..db08ce2 --- /dev/null +++ b/views/landingPage.pug @@ -0,0 +1,18 @@ +extends layout + +include mixins/_moduleCopy +include mixins/_moduleHeroImage +include mixins/_moduleHighlightedCourse + +block content + .modules-container + each module in landingPage.fields.contentModules + case module.sys.contentType.sys.id + when 'landingPageModuleCopy' + +moduleCopy(module) + + when 'landingPageModuleHeroImage' + +moduleHeroImage(module) + + when 'landingPageModuleHighlightedCourse' + +moduleHighlightedCourse(module, module.fields.course)