feat(courses): Add Landing Page content modules
This commit is contained in:
committed by
Benedikt Rötsch
parent
e2ceb39e83
commit
0c66b6678c
@@ -1,9 +1,12 @@
|
||||
const express = require('express')
|
||||
const {getLandingPage} = require('../services/contentful')
|
||||
const router = express.Router()
|
||||
|
||||
/* GET home page. */
|
||||
router.get('/', function (req, res, next) {
|
||||
res.render('index', { title: 'Welcome to Contentful university' })
|
||||
router.get('/', async function (req, res, next) {
|
||||
const landingPage = await getLandingPage()
|
||||
console.log(landingPage.fields.contentModules[1].fields)
|
||||
res.render('index', { landingPage })
|
||||
})
|
||||
|
||||
module.exports = router
|
||||
|
||||
@@ -7,12 +7,19 @@ exports.initClient = (config = {space: process.env.CF_SPACE, accessToken: proces
|
||||
client = createClient(config)
|
||||
previewClient = createClient({...config, host: 'preview.contentful.com'})
|
||||
}
|
||||
|
||||
exports.getCourses = () => {
|
||||
// to get all the courses we simply request from Contentful all the entries
|
||||
// with the content_type `course`
|
||||
return client.getEntries({content_type: 'course'})
|
||||
}
|
||||
|
||||
exports.getLandingPage = () => {
|
||||
// our Home page is fully configureable via contentful
|
||||
return client.getEntries({content_type: 'landingPage', 'fields.slug': 'contentful-university'})
|
||||
.then((response) => response.items[0])
|
||||
}
|
||||
|
||||
exports.getCourse = (slug) => {
|
||||
// the SDK support link resolution only when you request the collection endpoint
|
||||
// That's why we are using getEntries with a query instead of getEntry(entryId)
|
||||
|
||||
@@ -5,7 +5,7 @@ block content
|
||||
if lesson
|
||||
p= lesson.fields.description
|
||||
else
|
||||
p= course.fields.description
|
||||
p= course.fields.description
|
||||
ul
|
||||
each lesson in course.fields.lessons
|
||||
li
|
||||
|
||||
@@ -1,11 +1,22 @@
|
||||
extends layout
|
||||
|
||||
include mixins/_copyModule
|
||||
include mixins/_heroImageModule
|
||||
include mixins/_highlightedCourse
|
||||
include mixins/_highlightedLessonsModule
|
||||
|
||||
block content
|
||||
.container
|
||||
section.hero
|
||||
.hero__image
|
||||
.featured-cards-list
|
||||
.featured-cards__list
|
||||
.featured-cards__list
|
||||
.featured-cards__list
|
||||
each module in landingPage.fields.contentModules
|
||||
case module.sys.contentType.sys.id
|
||||
when 'landingPageModuleCopy'
|
||||
+copyModule(module)
|
||||
|
||||
when 'landingPageModuleHeroImage'
|
||||
+heroImageModule(module)
|
||||
|
||||
when 'landingPageModuleHighlightedCourse'
|
||||
+highlightedCourseModule(module)
|
||||
|
||||
when 'landingPageModuleHighlightedLessons'
|
||||
+highlightLessonsModule(module)
|
||||
|
||||
8
views/mixins/_copyModule.pug
Normal file
8
views/mixins/_copyModule.pug
Normal file
@@ -0,0 +1,8 @@
|
||||
mixin copyModule(module)
|
||||
.module
|
||||
.module__copy
|
||||
h1.module__copy__title #{module.fields.title}
|
||||
h3.module__copy__headline #{module.fields.headline}
|
||||
div.module__copy__copy #{module.fields.copy}
|
||||
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
mixin courseCard(course = {fields: {title: '', description: '', categories: [], slug: ''}})
|
||||
.course
|
||||
.course__categories
|
||||
if(course.fields.categories)
|
||||
if course.fields.categories
|
||||
each category in course.fields.categories
|
||||
a.course__categories--category(href=`categories/${category.fields.slug}`) #{category.title}
|
||||
h1.course__title #{course.fields.title}
|
||||
|
||||
6
views/mixins/_heroImageModule.pug
Normal file
6
views/mixins/_heroImageModule.pug
Normal file
@@ -0,0 +1,6 @@
|
||||
mixin heroImageModule(module)
|
||||
.module
|
||||
.module__heroImage
|
||||
h1.module__heroImage__title #{module.fields.title}
|
||||
h2.module__heroImage__headline #{module.fields.headline}
|
||||
img.module__heroImage__image(src=`${module.fields.backgroundImage.fields.file.url}` alt=`${module.fields.backgroundImage.fields.title}`)
|
||||
7
views/mixins/_highlightedCourse.pug
Normal file
7
views/mixins/_highlightedCourse.pug
Normal file
@@ -0,0 +1,7 @@
|
||||
include ./_courseCard
|
||||
|
||||
mixin highlightedCourseModule(module)
|
||||
.module
|
||||
.module__higlightedCourse
|
||||
h1.module__higlightedCourse__title #{module.fields.title}
|
||||
+courseCard(module.course)
|
||||
9
views/mixins/_highlightedLessonsModule.pug
Normal file
9
views/mixins/_highlightedLessonsModule.pug
Normal file
@@ -0,0 +1,9 @@
|
||||
include _lesson
|
||||
|
||||
mixin _highlightLessonsModule(module)
|
||||
.module
|
||||
.module__higlightedLessons
|
||||
h1.module__higlightedLessons__title #{module.fields.title}
|
||||
each lesson in module.fields.lessons
|
||||
+lesson(lesson)
|
||||
|
||||
7
views/mixins/_lesson.pug
Normal file
7
views/mixins/_lesson.pug
Normal file
@@ -0,0 +1,7 @@
|
||||
mixin lesson(lesson)
|
||||
.lesson
|
||||
h1.lesson__tilte #{lesson.fields.title}
|
||||
div.lesson__shortDescription #{lesson.fields.shortDescription}
|
||||
img.lesson__image(src=`${lesson.fields.image.fields.file.url}` alt=`${lesson.fields.image.fields.title}`)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user