transform about into a landing page and generalize code (#12)
This commit is contained in:
@@ -1,9 +1,12 @@
|
|||||||
const express = require('express')
|
const express = require('express')
|
||||||
|
const { getLandingPage } = require('../services/contentful')
|
||||||
|
const { catchErrors } = require('../handlers/errorHandlers')
|
||||||
const router = express.Router()
|
const router = express.Router()
|
||||||
|
|
||||||
/* GET about page. */
|
/* GET the about landing page. */
|
||||||
router.get('/', function (req, res, next) {
|
router.get('/', catchErrors(async function (req, res, next) {
|
||||||
res.render('about', { title: 'About' })
|
const landingPage = await getLandingPage('about', req.query.locale, req.query.api)
|
||||||
})
|
res.render('landingPage', { title: 'About', landingPage })
|
||||||
|
}))
|
||||||
|
|
||||||
module.exports = router
|
module.exports = router
|
||||||
|
|||||||
@@ -3,10 +3,10 @@ const { getLandingPage } = require('../services/contentful')
|
|||||||
const { catchErrors } = require('../handlers/errorHandlers')
|
const { catchErrors } = require('../handlers/errorHandlers')
|
||||||
const router = express.Router()
|
const router = express.Router()
|
||||||
|
|
||||||
/* GET home page. */
|
/* GET the home landing page. */
|
||||||
router.get('/', catchErrors(async function (req, res, next) {
|
router.get('/', catchErrors(async function (req, res, next) {
|
||||||
const landingPage = await getLandingPage(req.query.locale, req.query.api)
|
const landingPage = await getLandingPage('home', req.query.locale, req.query.api)
|
||||||
res.render('index', { title: 'Contentful University', landingPage })
|
res.render('landingPage', { title: 'Contentful University', landingPage })
|
||||||
}))
|
}))
|
||||||
|
|
||||||
module.exports = router
|
module.exports = router
|
||||||
|
|||||||
@@ -31,11 +31,10 @@ exports.getCourses = assert((locale = 'en-US', api = `cda`) => {
|
|||||||
.then((response) => response.items)
|
.then((response) => response.items)
|
||||||
}, 'Course')
|
}, 'Course')
|
||||||
|
|
||||||
exports.getLandingPage = (locale = 'en-US', api = `cda`) => {
|
exports.getLandingPage = (slug, locale = 'en-US', api = `cda`) => {
|
||||||
// our Home page is fully configureable via Contentful
|
// Landing pages like the home or about page are fully controlable via Contentful.
|
||||||
const client = api === 'cda' ? cdaClient : cpaClient
|
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': slug, include: 10})
|
||||||
return client.getEntries({content_type: 'landingPage', locale, 'fields.slug': 'contentful-university', include: 10})
|
|
||||||
.then((response) => response.items[0])
|
.then((response) => response.items[0])
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -1,6 +0,0 @@
|
|||||||
extends layout
|
|
||||||
|
|
||||||
block content
|
|
||||||
.layout-centered
|
|
||||||
h1= title
|
|
||||||
p Welcome to #{title}
|
|
||||||
@@ -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)
|
|
||||||
18
views/landingPage.pug
Normal file
18
views/landingPage.pug
Normal file
@@ -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)
|
||||||
Reference in New Issue
Block a user