Make changes to code to improve readability
This commit is contained in:
committed by
Benedikt Rötsch
parent
a110d848c0
commit
cdb0a07ff7
2
app.js
2
app.js
@@ -38,7 +38,7 @@ app.use(async function (request, response, next) {
|
|||||||
deliveryToken: process.env.CONTENTFUL_DELIVERY_TOKEN,
|
deliveryToken: process.env.CONTENTFUL_DELIVERY_TOKEN,
|
||||||
previewToken: process.env.CONTENTFUL_PREVIEW_TOKEN,
|
previewToken: process.env.CONTENTFUL_PREVIEW_TOKEN,
|
||||||
editorialFeatures: false,
|
editorialFeatures: false,
|
||||||
// Overwrite default settings using those stored in a cookie
|
// Overwrite default settings using those stored in cookie, if present
|
||||||
...request.cookies.theExampleAppSettings
|
...request.cookies.theExampleAppSettings
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -3,24 +3,25 @@ const url = require('url')
|
|||||||
module.exports = (modifier) => {
|
module.exports = (modifier) => {
|
||||||
return (request, response, next) => {
|
return (request, response, next) => {
|
||||||
const baseUrl = url.format({ protocol: request.protocol, host: request.get('host') })
|
const baseUrl = url.format({ protocol: request.protocol, host: request.get('host') })
|
||||||
const parts = url.parse(request.url).pathname.split('/').filter(Boolean)
|
const urlComponents = url.parse(request.url).pathname.split('/').filter(Boolean)
|
||||||
let items = []
|
let breadcrumbs = []
|
||||||
|
|
||||||
items.push({ label: 'Home', url: baseUrl })
|
breadcrumbs.push({ label: 'Home', url: baseUrl })
|
||||||
items = items.concat(parts.map((part, i, array) => {
|
// Map components of the path to breadcrumbs with resolvable URLs
|
||||||
|
let mappedComponents = urlComponents.map((component, i, array) => {
|
||||||
const path = array.slice(0, i + 1).join('/')
|
const path = array.slice(0, i + 1).join('/')
|
||||||
return {
|
return {
|
||||||
label: part.replace(/-/g, ' '),
|
label: component.replace(/-/g, ' '),
|
||||||
url: url.resolve(baseUrl, path),
|
url: url.resolve(baseUrl, path),
|
||||||
path: path
|
path: path
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
)
|
breadcrumbs = breadcrumbs.concat(mappedComponents)
|
||||||
if (modifier) {
|
if (modifier) {
|
||||||
items = items.map(modifier)
|
breadcrumbs = breadcrumbs.map(modifier)
|
||||||
}
|
}
|
||||||
// Make it global
|
// Make it global
|
||||||
request.app.locals.breadcrumb = items
|
request.app.locals.breadcrumb = breadcrumbs
|
||||||
next()
|
next()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -142,7 +142,7 @@ module.exports.postSettings = async (request, response, next) => {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// When no errors occurred
|
// If no errors, then cache the new settings in the cookie
|
||||||
if (!errorList.length) {
|
if (!errorList.length) {
|
||||||
// Store new settings
|
// Store new settings
|
||||||
updateCookie(response, SETTINGS_NAME, settings)
|
updateCookie(response, SETTINGS_NAME, settings)
|
||||||
|
|||||||
Reference in New Issue
Block a user