Skip to content

Commit 87d6037

Browse files
committed
use renderToStaticNodeStream rather than renderToStaticMarkup
1 parent 8e6e2bc commit 87d6037

13 files changed

Lines changed: 135 additions & 75 deletions

File tree

package-lock.json

Lines changed: 61 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@
3737
"babel-loader": "^8.0.6",
3838
"fs-extra": "^8.1.0",
3939
"glob": "^7.1.4",
40+
"mini-css-extract-plugin": "^0.8.0",
4041
"prop-types": "^15.7.2",
4142
"react": "^16.9.0",
4243
"react-dom": "^16.9.0",

src/scripts/client/util/browser.util.js

Lines changed: 25 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,20 @@
11
/*global ga*/
22
/*eslint no-undef: "error"*/
33

4+
function createScriptTag(src = null, scriptBody = "") {
5+
if (!src && !scriptBody)
6+
return;
7+
8+
const s = document.createElement('script');
9+
s.async = true;
10+
11+
if (!!src)
12+
s.src = src;
13+
else if (!!scriptBody)
14+
s.innerHTML = scriptBody;
15+
document.body.appendChild(s);
16+
}
17+
418
function getQueryStringParamByName(name, url) {
519
if (!url)
620
url = window.location.href;
@@ -27,7 +41,17 @@ function trackEvent(evtCategory, evtAction, evtLabel, evtValue) {
2741
}
2842
}
2943

44+
function createGAScript() {
45+
const gaKey = document.body.dataset.track;
46+
if (gaKey) {
47+
createScriptTag('https://www.google-analytics.com/analytics.js');
48+
createScriptTag(null, `window.ga = function () { ga.q.push(arguments) }; ga.q = []; ga.l = +new Date;
49+
ga('create', '${gaKey}', 'auto'); ga('set','transport','beacon'); ga('send', 'pageview');`);
50+
}
51+
}
52+
3053
module.exports = {
3154
getQueryStringParamByName,
32-
trackEvent
55+
trackEvent,
56+
createGAScript
3357
};

src/scripts/components/Head.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import React from 'react';
22

33
import processRelPath from '../model/head';
44

5-
const Head = ({title, description, styles, scripts, rel}) => {
5+
const Head = ({ title, description, styles, scripts, rel }) => {
66
const { touchHref, webMan, styleLinks, scriptLinks } = processRelPath(rel, styles, scripts);
77
return (
88
<head>

src/scripts/index.js

Lines changed: 18 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -5,29 +5,26 @@ import Header from './components/Header';
55
import Main from './components/Main';
66
import Footer from './components/Footer';
77

8-
import indexModel from './model/index';
9-
10-
const Root = () => {
8+
const Root = ({title,description,scripts,styles,rel, gaKey}) => {
119
return (
1210
<html className="no-js" lang="en">
13-
<Head {...indexModel} />
14-
15-
<body className='container'>
16-
<Header title={indexModel.title} />
17-
<Main>
18-
<div className="row">
19-
<aside>
20-
<p>left side</p>
21-
</aside>
22-
<section>
23-
<p>Main content</p>
24-
</section>
25-
<aside>
26-
<p>right side</p>
27-
</aside>
28-
</div>
29-
</Main>
30-
<Footer />
11+
<Head title={title} description={description} scripts={scripts} styles={styles} rel={rel} />
12+
<body data-track={gaKey} className='container'>
13+
<Header title={title} />
14+
<Main>
15+
<div className="row">
16+
<aside>
17+
<p>left side</p>
18+
</aside>
19+
<section>
20+
<p>Main content</p>
21+
</section>
22+
<aside>
23+
<p>right side</p>
24+
</aside>
25+
</div>
26+
</Main>
27+
<Footer />
3128
</body>
3229
</html>
3330
);

src/scripts/main.js

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,7 @@
1-
"use strict";
2-
31
import '../styles/main.scss'; //Yep, that's right. You can import SASS/CSS files too! Webpack will run the associated loader and plug this into the page.
42

5-
//import * as utils from './client/util/browser.util';
3+
import {createGAScript} from './client/util/browser.util';
64

7-
$( () => {
8-
$('.navbar-collapse.collapse.in > ul > li > a').on('click', () => {
9-
$('.navbar-toggle').trigger('click');
10-
});
11-
});
5+
window.document.onload = function () {
6+
createGAScript();
7+
};

src/scripts/model/index.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,5 +7,6 @@ export default {
77
description: pkg.description,
88
scripts: glob.sync('**/*.js', { cwd: Conf.target.js_path }),
99
styles: glob.sync('**/*.css', { cwd: Conf.target.css_path }),
10-
rel: './'
10+
rel: './',
11+
gaKey: Conf.TRACK_ID
1112
}

tool/base.config.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ const JS_BUNDLE_NAME = APP_NAME + "-bundle.js";
1414
const Config = {
1515
CUR_VER: pkg.version,
1616
CUR_DIR,
17-
TRACK_ID: "UA-xxxxxxxx-1",
17+
TRACK_ID: "UA-xxx-1111",
1818
APP_NAME,
1919
SRC_BASE,
2020
TAR_BASE,

tool/build.bundle.js

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
"use strict";
2-
31
import buildJSandSASS from './webpack.runner';
42

53
buildJSandSASS.compileOnce();

tool/build.page.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import Conf from './base.config';
22
import helper from './build.transform';
33

44
function transformDefaultPage() {
5-
helper.transformOnePage('index.js', null, Conf.src.js_path, Conf.target.path);
5+
helper.transformOnePage('index.js', './model/index.js', Conf.src.js_path, Conf.target.path);
66
}
77

88
function main() {

0 commit comments

Comments
 (0)