-
Notifications
You must be signed in to change notification settings - Fork 0
/
build-file-list.js
44 lines (38 loc) · 1.21 KB
/
build-file-list.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
38
39
40
41
42
43
44
const fs = require('fs');
const path = require('path');
// Directories to process
const directories = ['pages', 'blog'];
// Function to get all `.md` files in a directory
function getMarkdownFiles(dirPath) {
try {
return fs
.readdirSync(dirPath)
.filter((file) => file.endsWith('.md')); // Only include Markdown files
} catch (error) {
console.error(`Error reading directory: ${dirPath}`, error);
return [];
}
}
// Function to write `file-list.json` for each directory
function buildFileList(dirPath) {
const files = getMarkdownFiles(dirPath);
const outputFilePath = path.join(dirPath, 'file-list.json');
try {
fs.writeFileSync(outputFilePath, JSON.stringify(files, null, 2));
console.log(`Generated file list: ${outputFilePath}`);
} catch (error) {
console.error(`Error writing file list for: ${dirPath}`, error);
}
}
// Main build process
function main() {
directories.forEach((dir) => {
const dirPath = path.resolve(__dirname, dir);
if (!fs.existsSync(dirPath)) {
console.warn(`Directory not found: ${dirPath}`);
return;
}
buildFileList(dirPath);
});
}
main();