-
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathstatic.jsx
41 lines (37 loc) · 1.24 KB
/
static.jsx
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
28
29
30
31
32
33
34
35
36
37
38
39
40
41
'use strict';
var React = require('react');
var Router = require('react-router');
var routes = require('./routes');
var DocumentTitle = require('react-document-title');
var Html = React.createClass({
render: function() {
return (
<html>
<head>
<link rel="stylesheet" type="text/css" href="/css/styles.css" />
<title>{this.props.title}</title>
</head>
<body>
<div id="wrap" dangerouslySetInnerHTML={{__html: this.props.markup}}></div>
</body>
<script src="/js/bundle.js"></script>
</html>
);
}
});
// given a url, our router will decide which Handler to use in the callback
// the corresponding markup is then created and pass on to the html component
// and rendered as static html data to be returned.
// This StaticRender function will be used by our static page builder to provide the
// html data that will be written to disk.
var StaticRender = function(url) {
var html;
var title = DocumentTitle.rewind();
Router.run(routes, url, function(Handler, state) {
var markup = React.renderToString(<Handler />);
html = React.renderToStaticMarkup(<Html title={title} markup={markup} />);
});
console.log(html);
return html;
};
module.exports = StaticRender;