@@ -19,23 +19,23 @@ export const getComponentName = component => kebabCase(component).replace(/{/g,
19
19
export const getCleanComponentName = component => getComponentName ( component ) . replace ( / ( { | } ) / g, '' )
20
20
21
21
export const parseUrl = value => {
22
- const anchor = document . createElement ( 'a' )
23
- anchor . href = value
22
+ const $ anchor = document . createElement ( 'a' )
23
+ $ anchor. href = value
24
24
25
25
// We need to add the anchor to the document to make sure the
26
26
// `pathname` is correctly detected in any browser
27
- document . body . appendChild ( anchor )
27
+ document . body . appendChild ( $ anchor)
28
28
29
29
const result = [ 'hash' , 'host' , 'hostname' , 'pathname' , 'port' , 'protocol' , 'search' ] . reduce (
30
30
( result , prop ) => {
31
- result [ prop ] = anchor [ prop ] || null
31
+ result [ prop ] = $ anchor[ prop ] || null
32
32
return result
33
33
} ,
34
34
{ }
35
35
)
36
36
37
37
// Make sure to remove the anchor from document as soon as possible
38
- document . body . removeChild ( anchor )
38
+ document . body . removeChild ( $ anchor)
39
39
40
40
// Normalize port
41
41
if ( ! result . port && result . protocol ) {
@@ -146,31 +146,31 @@ export const updateMetaTOC = (tocData = {}, meta = null) => {
146
146
return tocData
147
147
}
148
148
149
- export const importAll = r => {
150
- const obj = { }
151
-
152
- r . keys ( )
153
- . map ( r )
154
- . map ( m => m . meta || m )
155
- . map ( m => ( {
156
- slug :
157
- typeof m . slug === 'undefined' ? ( m . title || '' ) . replace ( ' ' , '-' ) . toLowerCase ( ) : m . slug ,
158
- ... m
159
- } ) )
160
- . sort ( ( a , b ) => {
161
- if ( a . slug < b . slug ) return - 1
162
- else if ( a . slug > b . slug ) return 1
163
- return 0
164
- } )
165
- . forEach ( m => {
166
- if ( m . components ) {
167
- // Normalize `meta.components` to array of objects form
168
- m . components = m . components . map ( c => ( typeof c === 'string' ? { component : c } : c ) )
169
- }
170
- obj [ m . slug ] = m
171
- } )
172
-
173
- return obj
149
+ export const importAll = context => {
150
+ // Get array of datas by keys from context
151
+ const datas = context . keys ( ) . map ( context )
152
+
153
+ return (
154
+ datas
155
+ // Filter out private datas
156
+ . filter ( data => ! data . private )
157
+ // Map meta information
158
+ . map ( data => data . meta || data )
159
+ // Normalize meta information
160
+ . map ( meta => ( {
161
+ ... meta ,
162
+ slug :
163
+ meta . slug === undefined ? ( meta . title || '' ) . replace ( ' ' , '-' ) . toLowerCase ( ) : meta . slug
164
+ } ) )
165
+ // Sort by slug
166
+ . sort ( ( a , b ) => {
167
+ if ( a . slug < b . slug ) return - 1
168
+ else if ( a . slug > b . slug ) return 1
169
+ return 0
170
+ } )
171
+ // Build one object keyed by slug
172
+ . reduce ( ( result , meta ) => ( { ... result , [ meta . slug ] : meta } ) , { } )
173
+ )
174
174
}
175
175
176
176
// Smooth Scroll handler methods
0 commit comments