mirror of
https://github.com/Pomax/BezierInfo-2.git
synced 2025-08-31 20:11:59 +02:00
.
This commit is contained in:
32
tools/generate-full-index.js
Normal file
32
tools/generate-full-index.js
Normal file
@@ -0,0 +1,32 @@
|
||||
/**********************************************************************
|
||||
*
|
||||
* This script takes the article as generated by webpack, and uses the
|
||||
* ReactDOMServer library to serialize it to pure HTML markup. This is
|
||||
* then injected into the index.html template, with code injected to
|
||||
* load the
|
||||
*
|
||||
**********************************************************************/
|
||||
|
||||
var fs = require("fs-extra");
|
||||
var path = require("path");
|
||||
const BASEDIR = path.join(__dirname, "..");
|
||||
|
||||
var React = require("react");
|
||||
var Server = require("react-dom/server");
|
||||
|
||||
var FullArticle = require(path.join(BASEDIR, "./article")).FullArticle;
|
||||
var article = React.createElement(FullArticle, {});
|
||||
var staticMarkup = Server.renderToStaticMarkup(article);
|
||||
|
||||
// make sure to remove the `<base>` tag from the index, and replace the JSX "className" with "class"
|
||||
var html = fs.readFileSync(path.join(BASEDIR, "index.template.html")).toString();
|
||||
html = html.replace(' <base href="..">\n', '');
|
||||
html = html.replace('<script src="en-GB/article.js');
|
||||
html = "<!-- AUTOGENERATED CONTENT, PLEASE EDIT 'index.template.html' INSTEAD! -->\n" + html;
|
||||
|
||||
// surgery:
|
||||
var parts = html.split('<article>');
|
||||
var leadin = parts[0];
|
||||
var reassembled = `${leadin}<article>${staticMarkup}</article></body>\n</html>\n`;
|
||||
|
||||
fs.writeFileSync(path.join(BASEDIR, "index.full.html"), reassembled);
|
Reference in New Issue
Block a user