Change category filter to use slug instead of sys.id (#6)
* Change category filter to use slug instead of sys.id * Add slug to module and card
This commit is contained in:
committed by
Benedikt Rötsch
parent
58d7e87325
commit
f014c76e81
@@ -19,9 +19,13 @@ router.get('/categories/:category', catchErrors(async function (req, res, next)
|
|||||||
let courses = []
|
let courses = []
|
||||||
let categories = []
|
let categories = []
|
||||||
let activeCategory = ''
|
let activeCategory = ''
|
||||||
courses = await getCoursesByCategory(req.params.category, req.query.locale, req.query.api)
|
try {
|
||||||
categories = await getCategories()
|
categories = await getCategories()
|
||||||
activeCategory = categories.find((category) => category.sys.id === req.params.category)
|
activeCategory = categories.find((category) => category.fields.slug === req.params.category)
|
||||||
|
courses = await getCoursesByCategory(activeCategory.sys.id, req.query.locale, req.query.api)
|
||||||
|
} catch (e) {
|
||||||
|
console.log('Error ', e)
|
||||||
|
}
|
||||||
res.render('courses', { title: `${activeCategory.fields.title} (${courses.length})`, categories, courses })
|
res.render('courses', { title: `${activeCategory.fields.title} (${courses.length})`, categories, courses })
|
||||||
}))
|
}))
|
||||||
|
|
||||||
|
|||||||
@@ -14,7 +14,7 @@ block content
|
|||||||
a.sidebar-menu__link.active(href=`/courses`) All courses
|
a.sidebar-menu__link.active(href=`/courses`) All courses
|
||||||
each category in categories
|
each category in categories
|
||||||
li.sidebar-menu__item
|
li.sidebar-menu__item
|
||||||
a.sidebar-menu__link(href=`/courses/categories/${category.sys.id}${queryString}`) #{category.fields.title}
|
a.sidebar-menu__link(href=`/courses/categories/${category.fields.slug}${queryString}`) #{category.fields.title}
|
||||||
section.layout-sidebar__content
|
section.layout-sidebar__content
|
||||||
.courses
|
.courses
|
||||||
h1= title
|
h1= title
|
||||||
|
|||||||
@@ -3,7 +3,7 @@ mixin courseCard(course = {fields: {title: '', description: '', categories: [],
|
|||||||
.course-card__categories
|
.course-card__categories
|
||||||
if(course.fields.categories)
|
if(course.fields.categories)
|
||||||
each category in course.fields.categories
|
each category in course.fields.categories
|
||||||
a.course-card__category(href=`/courses/categories/${category.sys.id}${queryString}`) #{category.fields.title}
|
a.course-card__category(href=`/courses/categories/${category.fields.slug}${queryString}`) #{category.fields.title}
|
||||||
h2.course-card__title= course.fields.title
|
h2.course-card__title= course.fields.title
|
||||||
p.course-card__description= course.fields.shortDescription
|
p.course-card__description= course.fields.shortDescription
|
||||||
.course-card__link-wrapper
|
.course-card__link-wrapper
|
||||||
|
|||||||
@@ -11,7 +11,7 @@ mixin moduleHighlightedCourse(module, course)
|
|||||||
if(course.fields.categories)
|
if(course.fields.categories)
|
||||||
.module-higlighted-course__categories
|
.module-higlighted-course__categories
|
||||||
each category in course.fields.categories
|
each category in course.fields.categories
|
||||||
a.module-higlighted-course__category(href=`/courses/categories/${category.sys.id}${queryString}`) #{category.fields.title}
|
a.module-higlighted-course__category(href=`/courses/categories/${category.fields.slug}${queryString}`) #{category.fields.title}
|
||||||
h2.module-higlighted-course__title= course.fields.title
|
h2.module-higlighted-course__title= course.fields.title
|
||||||
.module-higlighted-course__description-wrapper
|
.module-higlighted-course__description-wrapper
|
||||||
p !{helpers.markdown(course.fields.shortDescription)}
|
p !{helpers.markdown(course.fields.shortDescription)}
|
||||||
|
|||||||
Reference in New Issue
Block a user