-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathupdateReadme.js
40 lines (38 loc) · 1.09 KB
/
updateReadme.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
const fs = require('fs');
const IMAGES = JSON.parse(fs.readFileSync('images.json'));
fs.readFile('README.md', function read(err, data) {
if (err) {
throw err;
}
const file_content = data.toString();
var str = `Name | Len folder | Example \n --- | :---: | :---: \n`;
Object.keys(IMAGES).forEach(key => {
if (key.match('#')) {
fs.renameSync(
`./Images/${key}`,
`./Images/${key.replaceAll('#', 'Hashtag')}`,
function(err) {
if (err) throw err;
}
);
key = key.replaceAll('#', 'Hashtag');
}
let folder = IMAGES[key];
if(!folder) console.log(key)
str +=
'| `' +
key +
'`|' +
`${folder.length}| <img src="./Images/${key}/${
folder[Math.floor(folder.length * Math.random())]
}" width="160"> \n`;
});
const idx =
file_content.indexOf('## Current Folders') + '## Current Folders'.length;
const result =
file_content.slice(0, idx) + '\n' + str ;
fs.writeFile(__dirname + '/README.md', result, err => {
if (err) throw err;
else console.log('Update readme');
});
});