-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add the ability to configure a post render script
- Loading branch information
Showing
9 changed files
with
96 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,6 +2,7 @@ | |
* | ||
|
||
!src/ | ||
!scripts/ | ||
!.babelrc | ||
!package.json | ||
!yarn.lock |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
<!DOCTYPE html> | ||
<html lang="en"> | ||
<head> | ||
<meta charset="utf-8"> | ||
<title>A static HTML page (post render script)</title> | ||
</head> | ||
<body> | ||
<h1>A static HTML page (post render script)</h1> | ||
</body> | ||
</html> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
|
||
postRenderFunction = () => { | ||
if ('/post-render-script.html' === window.location.pathname) { | ||
const paragraphElement = document.createElement('p') | ||
const textNode = document.createTextNode("This element has been created by the post render script."); | ||
|
||
paragraphElement.appendChild(textNode) | ||
|
||
document.body.append(paragraphElement) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
/** | ||
* Post render script executed by Puppeteer's evaluate method before returning | ||
* the rendered html page. See https://github.com/puppeteer/puppeteer/blob/main/docs/api.md#pageevaluatepagefunction-args) | ||
* for more information. | ||
* | ||
* In order to use a custom post render script you have to mount your own | ||
* script as a Docker volume to `/app/scripts/postRender.js` location. | ||
* Your custom script will just have to assign the function you want to execute | ||
* to the `postRenderFunction` variable. | ||
* | ||
* Example: | ||
* ```javascript | ||
* // Adds the serialized Redux store | ||
* postRenderFunction = function () { | ||
* var preloadedState = yourReduxStore.getState(); | ||
* var script = document.createElement('script'); | ||
* script.type = 'text/javascript'; | ||
* script.text = 'window.__PRELOADED_STATE__ = ${JSON.stringify(preloadedState).replace(/</g, \\u003c')}'; | ||
* | ||
* document.body.prepend(script); | ||
* } | ||
* ``` | ||
*/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters