refactor: Cleanup (#21)

* refactor(routes): remove unused sitemap route

* style(comments): enforce consistent comment style

* style(exports): enforce consistent export style

* chore: Add jsDoc for contentful service

* chore: Add jsDoc for contentful service \n \n closes #23

* refactor(app): move query parameter comment to right position and mention comment route middleware

* test(npm): add temporary test script

* refactor(middlewares): split up bootstrap middleware - fixes #23759

* refactor(cookies): use constances to give context the maxAge cookie setting

* refactor(variables): use more descriptive names for variables

* space became spaceId when it was just the id not the full space instance
* all (access) token variable name variants became [api-type]Token
* all clients are now called deliveryClient or previewClient
* cpa and cda only remain when they are used as actual API id
* env variables names adjusted

* perf(helpers): only run marked when content is not empty

* refactor(comments): fix typos

* refactor(comments): add hint why error is logged to console in settings

* chore: Add comments to routes and services

* refactor(requires): order and group requires

* fix(settings): add validation for wrong preview token

* chore: Add comments to routes

* chore: fix typo

* chore: console.error -> throw

* chore: move cookie name to a constant

* chore: Fix app.js comment

* typo: removing t

* chore: typos

* chore: removed unnecessary comment line sign

* chore: newline for readabillity

* chore: remove dangling `t`

* chore: remove `t`, add `l`

* chore: typos

* Fleshed out title

* build(npm): remove unused dependencies

* build(npm): upgrade to latest stable contentful sdk

* chore: Addressing David feedbak

* fix(credentials): update to match the new space

* chore: Addressing code review comments

* chore: Addressing code review comments

* chore: res -> response, req-> request

* chore: include exactly what we need

* chore: Address JPs comments

* chore: Address JPs comments

* chore: Address Fredericks comments

* chore: Address Fredericks comments

* fixup! chore: Address Fredericks comments

* fixup! fixup! chore: Address Fredericks comments

* fixup! fixup! fixup! chore: Address Fredericks comments

* fixup! fixup! fixup! fixup! chore: Address Fredericks comments

* fixup! fixup! fixup! fixup! fixup! chore: Address Fredericks comments

* fixup! fixup! fixup! fixup! fixup! fixup! chore: Address Fredericks comments
This commit is contained in:
Benedikt Rötsch
2017-11-03 10:58:42 +01:00
parent 730ce24cc9
commit 7ad2c1fa4f
25 changed files with 507 additions and 340 deletions

View File

@@ -1,23 +1,28 @@
const marked = require('marked')
// Parse markdown text
exports.markdown = (content) => {
content = content || ''
return marked(removeIvalidDataURL(content), {sanitize: true})
module.exports.markdown = (content = '') => {
if (!content.trim()) {
return ''
}
return marked(removeInvalidDataURL(content), {sanitize: true})
}
// Dump is a handy debugging function we can use to sort of "console.log" our data
exports.dump = (obj) => JSON.stringify(obj, null, 2)
// A handy debugging function we can use to sort of "console.log" our data
module.exports.dump = (obj) => JSON.stringify(obj, null, 2)
// Evil users might try to add base64 url data to execute js
// so we should take care of that
function removeIvalidDataURL (content) {
let regex = /data:\S+;base64\S*/gm
return content.replace(regex, '#')
}
exports.formatMetaTitle = (title) => {
module.exports.formatMetaTitle = (title) => {
if (!title) {
return 'The Example App'
}
return `${title.charAt(0).toUpperCase()}${title.slice(1)} — The Example App`
}
/**
* Evil users might try to add base64 url data to execute js code
* so we should purge any potentially harmful data to mitigate risk
*/
function removeInvalidDataURL (content) {
let regex = /data:\S+;base64\S*/gm
return content.replace(regex, '#')
}