@@ -3,6 +3,9 @@ import React from 'react';
33import { Switch , Route } from 'react-router-dom' ;
44import { hot as Hot } from 'react-hot-loader' ;
55
6+ // Import Utilities
7+ import { ExtractPages , ExtractSections } from '../../utilities/content-utils' ;
8+
69// Import Components
710import NotificationBar from '../NotificationBar/NotificationBar' ;
811import Navigation from '../Navigation/Navigation' ;
@@ -31,8 +34,9 @@ class Site extends React.Component {
3134 render ( ) {
3235 let { location } = this . props ;
3336 let { mobileSidebarOpen } = this . state ;
34- let sections = this . _sections ;
37+ let sections = ExtractSections ( Content ) ;
3538 let section = sections . find ( ( { url } ) => location . pathname . startsWith ( url ) ) ;
39+ let pages = ExtractPages ( Content ) ;
3640
3741 return (
3842 < div className = "site" >
@@ -70,7 +74,7 @@ class Site extends React.Component {
7074 render = { props => (
7175 < Container className = "site__content" >
7276 < Switch >
73- { this . _pages . map ( page => (
77+ { pages . map ( page => (
7478 < Route
7579 key = { page . url }
7680 exact = { true }
@@ -123,20 +127,6 @@ class Site extends React.Component {
123127 } ) ;
124128 }
125129
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-
140130 /**
141131 * Strip any non-applicable properties
142132 *
@@ -154,28 +144,6 @@ class Site extends React.Component {
154144 children : children ? this . _strip ( children ) : [ ]
155145 } ) ) ;
156146 }
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- }
179147}
180148
181149export default Hot ( module ) ( Site ) ;
0 commit comments