File tree Expand file tree Collapse file tree 1 file changed +13
-3
lines changed Expand file tree Collapse file tree 1 file changed +13
-3
lines changed Original file line number Diff line number Diff line change @@ -16,9 +16,9 @@ const bundles = [
16
16
'/index.bundle.js'
17
17
] ;
18
18
19
+ // TODO: Use a `walk` utility from `directory-tree-webpack-plugin`
19
20
const Content = require ( './_content.json' ) ;
20
-
21
- const paths = Content . children . reduce ( ( paths , page ) => {
21
+ const pathsToTitles = Content . children . reduce ( ( paths , page ) => {
22
22
if ( page . type === 'directory' ) {
23
23
page . children . forEach ( child => ( paths [ child . url ] = child . title ) ) ;
24
24
} else {
@@ -31,7 +31,17 @@ const paths = Content.children.reduce((paths, page) => {
31
31
// Export method for `SSGPlugin`
32
32
export default locals => {
33
33
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` ;
35
45
36
46
return ReactDOMServer . renderToString (
37
47
< StaticRouter location = { locals . path } context = { { } } >
You can’t perform that action at this time.
0 commit comments