@@ -3,6 +3,9 @@ import React from 'react';
3
3
import { Switch , Route } from 'react-router-dom' ;
4
4
import { hot as Hot } from 'react-hot-loader' ;
5
5
6
+ // Import Utilities
7
+ import { ExtractPages , ExtractSections } from '../../utilities/content-utils' ;
8
+
6
9
// Import Components
7
10
import NotificationBar from '../NotificationBar/NotificationBar' ;
8
11
import Navigation from '../Navigation/Navigation' ;
@@ -31,8 +34,9 @@ class Site extends React.Component {
31
34
render ( ) {
32
35
let { location } = this . props ;
33
36
let { mobileSidebarOpen } = this . state ;
34
- let sections = this . _sections ;
37
+ let sections = ExtractSections ( Content ) ;
35
38
let section = sections . find ( ( { url } ) => location . pathname . startsWith ( url ) ) ;
39
+ let pages = ExtractPages ( Content ) ;
36
40
37
41
return (
38
42
< div className = "site" >
@@ -70,7 +74,7 @@ class Site extends React.Component {
70
74
render = { props => (
71
75
< Container className = "site__content" >
72
76
< Switch >
73
- { this . _pages . map ( page => (
77
+ { pages . map ( page => (
74
78
< Route
75
79
key = { page . url }
76
80
exact = { true }
@@ -123,20 +127,6 @@ class Site extends React.Component {
123
127
} ) ;
124
128
}
125
129
126
- /**
127
- * Flatten an array of `Content` items
128
- *
129
- * @param {array } array - ...
130
- * @return {array } - ...
131
- */
132
- _flatten = array => {
133
- return array . reduce ( ( flat , item ) => {
134
- return flat . concat (
135
- Array . isArray ( item . children ) ? this . _flatten ( item . children ) : item
136
- ) ;
137
- } , [ ] ) ;
138
- }
139
-
140
130
/**
141
131
* Strip any non-applicable properties
142
132
*
@@ -154,28 +144,6 @@ class Site extends React.Component {
154
144
children : children ? this . _strip ( children ) : [ ]
155
145
} ) ) ;
156
146
}
157
-
158
- /**
159
- * Get top-level sections
160
- *
161
- * @return {array } - ...
162
- */
163
- get _sections ( ) {
164
- return Content . children . filter ( item => (
165
- item . type === 'directory'
166
- ) ) ;
167
- }
168
-
169
- /**
170
- * Get all markdown pages
171
- *
172
- * @return {array } - ...
173
- */
174
- get _pages ( ) {
175
- return this . _flatten ( Content . children ) . filter ( item => {
176
- return item . extension === '.md' ;
177
- } ) ;
178
- }
179
147
}
180
148
181
149
export default Hot ( module ) ( Site ) ;
0 commit comments