Skip to content
This repository was archived by the owner on Nov 21, 2023. It is now read-only.

Commit 92cce14

Browse files
committed
better collections import
1 parent 328cedd commit 92cce14

File tree

4 files changed

+35
-35
lines changed

4 files changed

+35
-35
lines changed

admin/app.js

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,8 @@ const { CMS, initCMS: init } = window;
55
// Widgets additional
66
import './app/widgets/index.js';
77

8-
// Import config
9-
import config from './app/config.js';
10-
118
// Import all shortcodes for editor
129
import './app/editor/index.js';
1310

14-
// Init
15-
init({ config });
11+
// Import collections/config and init
12+
import './app/collections.js';

admin/app/collections.js

Lines changed: 31 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -1,37 +1,42 @@
1+
// Config
2+
import config from './config.js';
3+
14
// Available collections
25
import { availableCollections } from './settings/available-collections.js';
36

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 = [];
2110

2211
// 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 = [{},{}];
2515

2616
// add selected collections
2717
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({});
3121
});
3222

33-
// add config
34-
selectedCollections.push(config);
23+
// add data
24+
filesToImport.push('./data/config.js');
25+
selectedCollections.push({});
3526

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+
}

admin/app/config.js

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@ import display_url from './config/display_url.js';
99
import locale from './config/locale.js';
1010
// import i18n from './config/i18n.js';
1111
import slug from './config/slug.js';
12-
import collections from './collections.js';
1312

1413
import { mediaLibrary } from './settings/media-library.js';
1514

@@ -29,8 +28,7 @@ export let config = {
2928
public_folder,
3029

3130
// content
32-
slug,
33-
collections
31+
slug
3432
}
3533

3634
// If media library

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "hugolify-netlify-cms",
3-
"version": "1.1.3",
3+
"version": "1.1.4",
44
"homepage": "https://www.hugolify.com",
55
"repository": "https://github.com/hugolify/hugolify-netlify-cms",
66
"bugs": {

0 commit comments

Comments
 (0)