-
Notifications
You must be signed in to change notification settings - Fork 254
/
img.js
22 lines (20 loc) · 947 Bytes
/
img.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
var fs = require('fs')
const path = require('path');
const POSTS_PATH = process.cwd();
// 根目录下所有月份命名的文件夹
var monthes = fs.readdirSync(POSTS_PATH).filter(item => item.match(/\d\d\.\d\d?/));
monthes.forEach((month) => {
const imgdirs = fs.readdirSync(path.join(POSTS_PATH, month)).filter(item => item == 'img');
if (imgdirs.length) {
var imgdir = imgdirs[0];
const imgfiles = fs.readdirSync(path.join(POSTS_PATH, month, imgdir));
imgfiles.forEach((imgfile) => {
const imgpath = path.join(month, imgdir, imgfile)
const img = fs.readFileSync(path.join(POSTS_PATH, imgpath));
if (!fs.existsSync(path.join(POSTS_PATH, 'public', 'oriimg', month))) {
fs.mkdirSync(path.join(POSTS_PATH, 'public', 'oriimg', month))
}
fs.writeFileSync(path.join(POSTS_PATH, 'public', 'oriimg', month, imgfile), img)
})
}
})