forked from mapbox/mapbox-java
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathrender.js
More file actions
27 lines (22 loc) · 807 Bytes
/
Copy pathrender.js
File metadata and controls
27 lines (22 loc) · 807 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
import React from 'react';
import ReactDOMServer from 'react-dom/server';
import App from './components/app';
import remark from 'remark';
import slug from 'remark-slug';
import content from './custom/content';
import fs from 'fs';
var ast = remark()
.use(slug)
.run(remark().parse(content));
var template = fs.readFileSync('./index.html', 'utf8');
var target = process.argv[2];
var startDiv = `<div id='app'>`;
var stopDiv = '</div>';
var startMarker = '<!--START-->' + startDiv;
var stopMarker = stopDiv + '<!--STOP-->';
var startIdx = template.indexOf(startMarker) + startMarker.length;
var stopIdx = template.indexOf(stopMarker);
fs.writeFileSync(target,
template.substring(0, startIdx) +
ReactDOMServer.renderToString(<App ast={ast} content={content} />) +
template.substring(stopIdx));