1
1
'use strict'
2
2
3
- // filter out excluded versions
4
- const excludeComponentVersions = ( targetCollection , page ) => {
5
- if ( page . attributes [ 'excluded-versions' ] ) {
6
- const excludedComponentVersions = page . attributes [ 'excluded-versions' ]
7
- . split ( ',' ) . map ( ( it ) => it . trim ( ) )
8
- // console.debug('[DEBUG:SORT_COMPONENTS] excluding versions: ', excludedComponentVersions)
9
- excludedComponentVersions . forEach ( ( componentVersion , index ) => {
10
- const [ componentName , versionName ] = componentVersion . split ( ':' )
11
- const component = targetCollection . find ( ( { name } ) => name === componentName )
12
- if ( ! component ) {
13
- console . warn ( `No component found for excluded-versions[${ index } ] -> ${ componentVersion } ` )
14
- } else {
15
- component . versions = component . versions . map ( ( nextVersion ) => {
16
- return {
17
- ...nextVersion ,
18
- isHidden : nextVersion . version === versionName ,
19
- }
20
- } )
21
- }
22
- } )
23
- }
24
- return targetCollection
25
- }
26
-
27
- module . exports = ( collection , property , orderSpec , { data : { root } } ) => {
3
+ module . exports = ( collection , property , orderSpec ) => {
28
4
if ( orderSpec == null || orderSpec === '*' ) return Object . values ( collection )
29
5
const sourceCollection = Object . values ( collection ) . reduce ( ( accum , it ) => accum . set ( it [ property ] , it ) , new Map ( ) )
30
6
const order = orderSpec
@@ -36,15 +12,13 @@ module.exports = (collection, property, orderSpec, { data: { root } }) => {
36
12
} )
37
13
const restIdx = order . indexOf ( '*' )
38
14
if ( ~ restIdx ) order . splice ( restIdx , 1 )
39
- let targetCollection = order . reduce ( ( accum , key ) => {
15
+ const targetCollection = order . reduce ( ( accum , key ) => {
40
16
if ( sourceCollection . has ( key ) ) {
41
17
accum . push ( sourceCollection . get ( key ) )
42
18
sourceCollection . delete ( key )
43
19
}
44
20
return accum
45
21
} , [ ] )
46
22
if ( ~ restIdx ) targetCollection . splice ( restIdx , 0 , ...sourceCollection . values ( ) )
47
- targetCollection = excludeComponentVersions ( targetCollection , root . page )
48
- // console.debug('[DEBUG:SORT_COMPONENTS] targetCollection: ', targetCollection)
49
23
return targetCollection
50
24
}
0 commit comments