Skip to content

Commit

Permalink
Add setPreBodyComponents API
Browse files Browse the repository at this point in the history
  • Loading branch information
0x80 committed Jun 7, 2017
1 parent 4645524 commit f10d752
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 2 deletions.
3 changes: 3 additions & 0 deletions packages/gatsby/src/cache-dir/api-ssr-docs.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,9 @@
* @param {function} $0.setHeadComponents Takes an array of components as its
* first argument which are added to the `headComponents` array which is passed
* to the `html.js` component.
* @param {function} $0.setPreBodyComponents Takes an array of components as its
* first argument which are added to the `preBodyComponents` array which is passed
* to the `html.js` component.
* @param {function} $0.setPostBodyComponents Takes an array of components as its
* first argument which are added to the `postBodyComponents` array which is passed
* to the `html.js` component.
Expand Down
13 changes: 11 additions & 2 deletions packages/gatsby/src/cache-dir/static-entry.js
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ module.exports = (locals, callback) => {

let bodyHTML = ``
let headComponents = []
let preBodyComponents = []
let postBodyComponents = []
let bodyProps = {}

Expand All @@ -47,6 +48,10 @@ module.exports = (locals, callback) => {
headComponents = headComponents.concat(components)
}

const setPreBodyComponents = components => {
preBodyComponents = preBodyComponents.concat(components)
}

const setPostBodyComponents = components => {
postBodyComponents = postBodyComponents.concat(components)
}
Expand Down Expand Up @@ -85,6 +90,7 @@ module.exports = (locals, callback) => {
bodyComponent,
replaceBodyHTMLString,
setHeadComponents,
setPreBodyComponents,
setPostBodyComponents,
setBodyProps,
})
Expand All @@ -96,6 +102,7 @@ module.exports = (locals, callback) => {

apiRunner(`onRenderBody`, {
setHeadComponents,
setPreBodyComponents,
setPostBodyComponents,
setBodyProps,
})
Expand Down Expand Up @@ -123,14 +130,14 @@ module.exports = (locals, callback) => {
// ignore
}

const dascripts = [
const scripts = [
`commons`,
`app`,
`layout-component---index`,
pathChunkName(locals.path),
pages.find(page => page.path === locals.path).componentChunkName,
]
dascripts.forEach(script => {
scripts.forEach(script => {
const fetchKey = `assetsByChunkName[${script}]`

let fetchedScript = get(stats, fetchKey)
Expand Down Expand Up @@ -164,10 +171,12 @@ module.exports = (locals, callback) => {
<Html
{...bodyProps}
headComponents={headComponents}
preBodyComponents={preBodyComponents}
postBodyComponents={postBodyComponents}
body={bodyHTML}
path={locals.path}
/>
)}`

callback(null, html)
}

0 comments on commit f10d752

Please sign in to comment.