-
Notifications
You must be signed in to change notification settings - Fork 0
/
moveAssets.js
33 lines (27 loc) · 872 Bytes
/
moveAssets.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
const fs = require('fs');
const path = require('path');
const postsDir = 'posts/';
const outputDir = '_site/';
function copyAssetsRecursively(srcDir, destDir) {
if (!fs.existsSync(destDir)) {
fs.mkdirSync(destDir, { recursive: true });
}
fs.readdirSync(srcDir, { withFileTypes: true }).forEach(entry => {
const srcPath = path.join(srcDir, entry.name);
const destPath = path.join(destDir, entry.name);
if (entry.isDirectory()) {
copyAssetsRecursively(srcPath, destPath);
} else {
if (path.extname(entry.name) !== '.md') {
fs.copyFileSync(srcPath, destPath);
}
}
});
}
fs.readdirSync(postsDir, { withFileTypes: true }).forEach(entry => {
if (entry.isDirectory()) {
const fullDirPath = path.join(postsDir, entry.name);
const outputPostDir = path.join(outputDir, entry.name);
copyAssetsRecursively(fullDirPath, outputPostDir);
}
});