fix(course): fix non resolved lessons
This commit is contained in:
committed by
Benedikt Rötsch
parent
928ccc0ade
commit
07c5cc77b0
@@ -37,6 +37,7 @@
|
|||||||
"postcss-cssnext": "^3.0.2",
|
"postcss-cssnext": "^3.0.2",
|
||||||
"postcss-import": "^11.0.0",
|
"postcss-import": "^11.0.0",
|
||||||
"postcss-reporter": "^5.0.0",
|
"postcss-reporter": "^5.0.0",
|
||||||
"postcss-url": "^7.1.2"
|
"postcss-url": "^7.1.2",
|
||||||
|
"pug-lint": "^2.5.0"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -33,9 +33,11 @@ router.get('/categories/:category', async function (req, res, next) {
|
|||||||
|
|
||||||
/* GET course detail. */
|
/* GET course detail. */
|
||||||
router.get('/:slug', async function (req, res, next) {
|
router.get('/:slug', async function (req, res, next) {
|
||||||
let course = {}
|
let course = await getCourse(req.params.slug)
|
||||||
course = await getCourse(req.params.slug)
|
const lessons = course.fields.lessons
|
||||||
res.render('course', {title: course.fields.title, course})
|
const lessonIndex = lessons.findIndex((lesson) => lesson.fields.slug === req.params.lslug)
|
||||||
|
const lesson = lessons[lessonIndex]
|
||||||
|
res.render('course', {title: course.fields.title, course, lesson, lessons, lessonIndex})
|
||||||
})
|
})
|
||||||
|
|
||||||
/* GET course lesson detail. */
|
/* GET course lesson detail. */
|
||||||
|
|||||||
@@ -1,47 +1,54 @@
|
|||||||
const { createClient } = require('contentful')
|
const { createClient } = require('contentful')
|
||||||
|
|
||||||
let client = null
|
let cdaClient = null
|
||||||
let previewClient = null
|
let cpaClient = null
|
||||||
|
|
||||||
exports.initClient = (config = {space: process.env.CF_SPACE, accessToken: process.env.CF_ACCESS_TOKEN}) => {
|
exports.initClient = (config = {space: process.env.CF_SPACE, accessToken: process.env.CF_ACCESS_TOKEN}) => {
|
||||||
client = createClient(config)
|
cdaClient = createClient(config)
|
||||||
previewClient = createClient({...config, host: 'preview.contentful.com'})
|
cpaClient = createClient({...config, host: 'preview.contentful.com'})
|
||||||
}
|
}
|
||||||
|
|
||||||
exports.getCourses = () => {
|
exports.getCourses = (locale = 'en-US', api = `cda`) => {
|
||||||
// to get all the courses we simply request from Contentful all the entries
|
// to get all the courses we simply request from Contentful all the entries
|
||||||
// with the content_type `course`
|
// with the content_type `course`
|
||||||
return client.getEntries({content_type: 'course', include: 10})
|
const client = api === 'cda' ? cdaClient : cpaClient
|
||||||
|
return client.getEntries({content_type: 'course', locale, include: 10})
|
||||||
.then((response) => response.items)
|
.then((response) => response.items)
|
||||||
}
|
}
|
||||||
|
|
||||||
exports.getLandingPage = () => {
|
exports.getLandingPage = (locale = 'en-US', api = `cda`) => {
|
||||||
// our Home page is fully configureable via contentful
|
// our Home page is fully configureable via contentful
|
||||||
return client.getEntries({content_type: 'landingPage', 'fields.slug': 'contentful-university', include: 10})
|
const client = api === 'cda' ? cdaClient : cpaClient
|
||||||
|
return client.getEntries({content_type: 'landingPage', locale, 'fields.slug': 'contentful-university', include: 10})
|
||||||
.then((response) => response.items[0])
|
.then((response) => response.items[0])
|
||||||
}
|
}
|
||||||
|
|
||||||
exports.getCourse = (slug) => {
|
exports.getCourse = (slug, locale = 'en-US', api = `cda`) => {
|
||||||
// the SDK support link resolution only when you request the collection endpoint
|
// 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)
|
// That's why we are using getEntries with a query instead of getEntry(entryId)
|
||||||
// make sure to specify the content_type whenever you want to perform a query
|
// make sure to specify the content_type whenever you want to perform a query
|
||||||
return client.getEntries({content_type: 'course', 'fields.slug': slug, include: 10})
|
const client = api === 'cda' ? cdaClient : cpaClient
|
||||||
|
return client.getEntries({content_type: 'course', 'fields.slug': slug, locale, include: 10})
|
||||||
.then((response) => response.items[0])
|
.then((response) => response.items[0])
|
||||||
}
|
}
|
||||||
|
|
||||||
exports.getLessons = (courseId) => {
|
exports.getLessons = (courseId, locale = 'en-US', api = `cda`) => {
|
||||||
// TODO
|
// TODO
|
||||||
}
|
}
|
||||||
|
|
||||||
exports.getCategories = () => {
|
exports.getCategories = (locale = 'en-US', api = `cda`) => {
|
||||||
return client.getEntries({content_type: 'category'})
|
const client = api === 'cda' ? cdaClient : cpaClient
|
||||||
|
return client.getEntries({content_type: 'category', locale})
|
||||||
.then((response) => response.items)
|
.then((response) => response.items)
|
||||||
}
|
}
|
||||||
|
|
||||||
exports.getCoursesByCategory = (category) => {
|
exports.getCoursesByCategory = (category, locale = 'en-US', api = `cda`) => {
|
||||||
|
const client = api === 'cda' ? cdaClient : cpaClient
|
||||||
return client.getEntries({
|
return client.getEntries({
|
||||||
content_type: 'course',
|
content_type: 'course',
|
||||||
'fields.category.sys.contentType.sys.id': category
|
'fields.category.sys.contentType.sys.id': category,
|
||||||
|
locale,
|
||||||
|
include: 10
|
||||||
})
|
})
|
||||||
.then((response) => response.items)
|
.then((response) => response.items)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -10,16 +10,18 @@ block content
|
|||||||
ul
|
ul
|
||||||
li
|
li
|
||||||
a.active(href=`/courses/${course.fields.slug}`) Course overview
|
a.active(href=`/courses/${course.fields.slug}`) Course overview
|
||||||
each lesson in course.fields.lessons
|
each l in course.fields.lessons
|
||||||
li
|
if l.fields
|
||||||
a(href=`/courses/${course.fields.slug}/lessons/${lesson.fields.slug}`) #{lesson.fields.title}
|
li
|
||||||
|
a(href=`/courses/${course.fields.slug}/lessons/${l.fields.slug}`) #{l.fields.title}
|
||||||
section.wrapper-with-sidebar__content
|
section.wrapper-with-sidebar__content
|
||||||
h1= course.fields.title
|
h1= course.fields.title
|
||||||
|
|
||||||
if lesson
|
if lesson
|
||||||
+lesson(lesson)
|
+lesson(lesson)
|
||||||
if lessonIndex + 1< lessons.length
|
if lessonIndex + 1< lessons.length
|
||||||
a.cta(href=`/courses/${course.fields.slug}/lessons/${lessons[lessonIndex + 1].fields.slug}`) View next lesson
|
if lessons[lessonIndex + 1].fields
|
||||||
|
a.cta(href=`/courses/${course.fields.slug}/lessons/${lessons[lessonIndex + 1].fields.slug}`) View next lesson
|
||||||
else
|
else
|
||||||
p !{helpers.markdown(course.fields.description)}
|
p !{helpers.markdown(course.fields.description)}
|
||||||
a.cta(href=`/courses/${course.fields.slug}/lessons/${course.fields.lessons[0].fields.slug}`) Start course
|
a.cta(href=`/courses/${course.fields.slug}/lessons/${course.fields.lessons[0].fields.slug}`) Start course
|
||||||
|
|||||||
@@ -19,3 +19,4 @@ mixin lessonModuleCodeSnippet(module)
|
|||||||
code.ruby= module.fields.ruby
|
code.ruby= module.fields.ruby
|
||||||
pre.lesson-module-code__swift
|
pre.lesson-module-code__swift
|
||||||
code.swift= module.fields.swift
|
code.swift= module.fields.swift
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user