forked from layer5io/layer5
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgatsby-dev-filesystem-ignore.js
37 lines (30 loc) · 1.36 KB
/
gatsby-dev-filesystem-ignore.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
const fs = require("fs");
const path = require("path");
function getDirectories(srcpath) {
return fs.readdirSync(srcpath)
.map(file => path.join(srcpath, file))
.filter(path => fs.statSync(path).isDirectory());
}
const collectionWithYears = ["blog", "news"];
function devIgnoreArray(folder) {
const folderMap = getDirectories(`${__dirname}/src/collections/${folder}`).map(url => url.replace(`${__dirname}/src/collections/${folder}/`, ""));
if (collectionWithYears.includes(folder)) {
const includeArray = [];
let folderCount = 0;
const foldersWithYears = folderMap.map(name => Number(name)).filter(number => !isNaN(number)).sort((a, b) => b - a).map(year => year.toString());
for (const itemFolder of foldersWithYears) {
includeArray.push(itemFolder);
const numFolders = getDirectories(`${__dirname}/src/collections/${folder}/${itemFolder}`).length;
folderCount = folderCount + numFolders;
if (folderCount > 10) return folderMap.filter(item => !includeArray.includes(item)).map(item => `**/${item}`);
}
} else if (folder === "members") {
const excludeArray = folderMap.filter(item => item !== "lee-calcote");
return excludeArray.slice(10).map(item => `**/${item}`);
} else {
return folderMap.length > 12
? folderMap.slice(12).map(item => `**/${item}`)
: [];
}
}
module.exports = devIgnoreArray;