Introduced Server Side Rendering for Cloud Pages based on React
This commit is contained in:
1 parent
569b849457
commit
1d6772eef3
17 files changed
+456
-61
No files matched your search
@@ -0,0 +1,36 @@
|
||||
function compose(...fns) {
|
||||
return value => [...fns]
|
||||
.reverse()
|
||||
.reduce((acc, fn) => fn(acc), value)
|
||||
}
|
||||
|
||||
/**
|
||||
* AND operator for list of values
|
||||
*
|
||||
* [true, true, true, ...] -> true
|
||||
* [false, true, true, ...] -> false
|
||||
*
|
||||
* @param list
|
||||
* @return {boolean}
|
||||
*/
|
||||
function all(list) {
|
||||
return list.reduce((t, i) => t && i, true)
|
||||
}
|
||||
|
||||
/**
|
||||
* OR operator for list of values
|
||||
*
|
||||
* [true, true, true, ...] -> true
|
||||
* [false, true, true, ...] -> true
|
||||
* [false, false, false, ...] -> false
|
||||
*
|
||||
* @param list
|
||||
* @return {boolean}
|
||||
*/
|
||||
function any(list) {
|
||||
return list.reduce((t, i) => t || i, false)
|
||||
}
|
||||
|
||||
exports.compose = compose
|
||||
exports.all = all
|
||||
exports.any = any
|
||||
@@ -0,0 +1,15 @@
|
||||
import React from 'react'
|
||||
import {renderToStaticMarkup} from 'react-dom/server'
|
||||
|
||||
const App = require('../components/App')
|
||||
|
||||
function renderApp({menu, page}) {
|
||||
const app = (
|
||||
<App menu={menu}>
|
||||
<div dangerouslySetInnerHTML={{__html: page.data}}/>
|
||||
</App>
|
||||
)
|
||||
return renderToStaticMarkup(app)
|
||||
}
|
||||
|
||||
exports.renderApp = renderApp
|
||||
@@ -0,0 +1,14 @@
|
||||
function getPathWithNoTrailingSlash(path) {
|
||||
return path.charAt(path.length - 1) === '/'
|
||||
? path.substr(0, path.length - 1)
|
||||
: path
|
||||
}
|
||||
|
||||
function isEqualPath(a, b, ignoreTrailingSlash = false) {
|
||||
return ignoreTrailingSlash
|
||||
? getPathWithNoTrailingSlash(a) === getPathWithNoTrailingSlash(b)
|
||||
: a === b
|
||||
}
|
||||
|
||||
exports.getPathWithNoTrailingSlash = getPathWithNoTrailingSlash
|
||||
exports.isEqualPath = isEqualPath
|
||||
Reference in new issue
Block a user