1
+ // Config
2
+ import config from './config.js' ;
3
+
1
4
// Available collections
2
5
import { availableCollections } from './settings/available-collections.js' ;
3
6
4
- // Types
5
- import col_posts from './content/posts.js' ;
6
- import col_categories from './content/categories.js' ;
7
- import col_tags from './content/tags.js' ;
8
- import col_projects from './content/projects.js' ;
9
- import col_projects_types from './content/projects_types.js' ;
10
- import col_projects_tags from './content/projects_tags.js' ;
11
- import col_casestudies from './content/casestudies.js' ;
12
- import col_publications from './content/publications.js' ;
13
- import col_persons from './content/persons.js' ;
14
- import col_pages from './content/pages.js' ;
15
- import col_indexes from './content/indexes.js' ;
16
-
17
- // Data
18
- import config from './data/config.js' ;
19
-
20
- const selectedCollections = [ ] ;
7
+ // Collections
8
+ let filesToImport = [ ] ;
9
+ let selectedCollections = [ ] ;
21
10
22
11
// add mandory collections
23
- selectedCollections . push ( col_indexes ) ;
24
- selectedCollections . push ( col_pages ) ;
12
+ filesToImport . push ( './content/indexes.js' ) ;
13
+ filesToImport . push ( './content/pages.js' ) ;
14
+ selectedCollections = [ { } , { } ] ;
25
15
26
16
// add selected collections
27
17
availableCollections . forEach ( element => {
28
- if ( availableCollections . includes ( element ) ) {
29
- selectedCollections . push ( eval ( 'col_' + element ) ) ;
30
- }
18
+ let file = './content/' + element + '.js' ;
19
+ filesToImport . push ( file ) ;
20
+ selectedCollections . push ( { } ) ;
31
21
} ) ;
32
22
33
- // add config
34
- selectedCollections . push ( config ) ;
23
+ // add data
24
+ filesToImport . push ( './data/config.js' ) ;
25
+ selectedCollections . push ( { } ) ;
35
26
36
- export const collections = selectedCollections ;
37
- export default collections ;
27
+ // Import and init
28
+ const countFilesToImport = filesToImport . length ;
29
+ let i = 0 ;
30
+ for ( const file of filesToImport ) {
31
+ import ( file ) . then ( ( module ) => {
32
+ // add collections with order respect
33
+ let index = filesToImport . indexOf ( file ) ;
34
+ selectedCollections . splice ( index , 1 , module . default ) ;
35
+ // Init
36
+ i += 1 ;
37
+ if ( i === countFilesToImport ) {
38
+ config . collections = selectedCollections ;
39
+ window . initCMS ( { config } ) ;
40
+ }
41
+ } ) ;
42
+ }
0 commit comments