Skip to content

Commit 73607f5

Browse files
montogeekskipjack
authored andcommitted
chore(site) Move page title generation to server.jsx
1 parent 726bb2a commit 73607f5

File tree

2 files changed

+32
-29
lines changed

2 files changed

+32
-29
lines changed

src/server.jsx

Lines changed: 31 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,22 @@ import Favicon from './favicon.ico';
1111

1212
// Define bundles (previously used `Object.values(locals.assets)`) but
1313
// can't retrieve from there anymore due to separate compilation.
14-
const bundles = ['/vendor.bundle.js', '/index.bundle.js'];
14+
const bundles = [
15+
'/vendor.bundle.js',
16+
'/index.bundle.js'
17+
];
18+
19+
const Content = require('./_content.json');
20+
21+
const paths = Content.children.reduce((paths, page) => {
22+
if (page.type === 'directory') {
23+
page.children.forEach(child => (paths[child.url] = child.title));
24+
} else {
25+
paths[page.url] = page.title;
26+
}
27+
28+
return paths;
29+
}, {});
1530

1631
// Export method for `StaticSiteGeneratorPlugin`
1732
// CONSIDER: How high can we mount `Site` into the DOM hierarchy? If
@@ -20,35 +35,35 @@ const bundles = ['/vendor.bundle.js', '/index.bundle.js'];
2035
// description, etc).
2136
export default locals => {
2237
let { assets } = locals.webpackStats.compilation;
23-
let title = locals.paths[locals.path];
38+
let title = paths[locals.path];
2439

2540
return ReactDOMServer.renderToString(
2641
<StaticRouter location={locals.path} context={{}}>
2742
<html>
2843
<head>
29-
<meta charset='utf-8' />
44+
<meta charset="utf-8" />
3045
<meta name="theme-color" content="#2B3A42" />
3146
<meta name="viewport" content="width=device-width, initial-scale=1" />
3247
<title>{title} | webpack</title>
33-
<meta
34-
name="description"
35-
content="webpack is a module bundler. Its main purpose is to bundle JavaScript files for usage in a browser, yet it is also capable of transforming, bundling, or packaging just about any resource or asset."
36-
/>
37-
<link rel="icon" type="image/x-icon" href={Favicon} />
38-
{Object.keys(assets)
39-
.filter(asset => /\.css$/.test(asset))
40-
.map(path => <link key={path} rel="stylesheet" href={`/${path}`} />)}
48+
<meta name="description" content="webpack is a module bundler. Its main purpose is to bundle JavaScript files for usage in a browser, yet it is also capable of transforming, bundling, or packaging just about any resource or asset." />
49+
<link rel="icon" type="image/x-icon" href={ Favicon } />
50+
{ Object.keys(assets).filter(asset => /\.css$/.test(asset)).map(path => (
51+
<link key={ path } rel="stylesheet" href={ `/${path}` } />
52+
))}
4153
</head>
4254
<body>
4355
<div id="root">
4456
<Route
4557
path="/"
46-
render={props => (
47-
<Site {...props} import={path => require(`./content/${path}`)} />
48-
)}
49-
/>
58+
render={ props => (
59+
<Site
60+
{ ...props }
61+
import={ path => require(`./content/${path}`) } />
62+
)} />
5063
</div>
51-
{bundles.map(path => <script key={path} src={path} />)}
64+
{ bundles.map(path => (
65+
<script key={ path } src={ path } />
66+
))}
5267
</body>
5368
</html>
5469
</StaticRouter>

webpack.prod.js

Lines changed: 1 addition & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -8,17 +8,6 @@ const RedirectWebpackPlugin = require('redirect-webpack-plugin');
88

99
// Load Common Configuration
1010
const common = require('./webpack.common.js');
11-
const Content = require('./src/_content.json');
12-
13-
const paths = Content.children.reduce((paths, page) => {
14-
if (page.type === 'directory') {
15-
page.children.forEach(child => (paths[child.url] = child.title));
16-
} else {
17-
paths[page.url] = page.title;
18-
}
19-
20-
return paths;
21-
}, {});
2211

2312
// ...
2413
const prod = {
@@ -39,8 +28,7 @@ module.exports = env => [
3928
},
4029
plugins: [
4130
new SSGPlugin({
42-
paths: Object.keys(paths),
43-
locals: { paths },
31+
crawl: true,
4432
globals: {
4533
window: {}
4634
}

0 commit comments

Comments
 (0)