Skip to content

Commit 4ae8a04

Browse files
committed
chore(rebuild): add todo and update title generation to account for undefined titles
1 parent 18fd324 commit 4ae8a04

File tree

1 file changed

+13
-3
lines changed

1 file changed

+13
-3
lines changed

src/server.jsx

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,9 +16,9 @@ const bundles = [
1616
'/index.bundle.js'
1717
];
1818

19+
// TODO: Use a `walk` utility from `directory-tree-webpack-plugin`
1920
const Content = require('./_content.json');
20-
21-
const paths = Content.children.reduce((paths, page) => {
21+
const pathsToTitles = Content.children.reduce((paths, page) => {
2222
if (page.type === 'directory') {
2323
page.children.forEach(child => (paths[child.url] = child.title));
2424
} else {
@@ -31,7 +31,17 @@ const paths = Content.children.reduce((paths, page) => {
3131
// Export method for `SSGPlugin`
3232
export default locals => {
3333
let { assets } = locals.webpackStats.compilation;
34-
let title = paths[locals.path] === 'webpack' ? paths[locals.path] : `${paths[locals.path]} | webpack`;
34+
let title;
35+
36+
if ( locals.path === '/' ) {
37+
title = pathsToTitles[locals.path];
38+
39+
} else if ( !pathsToTitles[locals.path] ) {
40+
if ( !locals.path.endsWith('/') ) locals.path += '/';
41+
title = locals.path.replace(/.*\/(.+)\//g, '$1');
42+
title = title.replace(/-/g, ' ');
43+
44+
} else title =`${pathsToTitles[locals.path]} | webpack`;
3545

3646
return ReactDOMServer.renderToString(
3747
<StaticRouter location={locals.path} context={{}}>

0 commit comments

Comments
 (0)