-
Notifications
You must be signed in to change notification settings - Fork 39
/
daily.js
42 lines (32 loc) 路 1.05 KB
/
daily.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
const sample = require('lodash/sample');
const fs = require('fs');
function run() {
try {
const readme = fs.readFileSync('./README.md', 'utf-8');
const Point = '</a></h3>';
const index = readme.indexOf(Point);
const before = readme.substring(0, index + 9);
const now = new Date();
const year = now.getFullYear();
let month = now.getMonth() + 1;
month = month < 10 ? `0${month}` : month;
let day = now.getDate();
day = day < 10 ? `0${day}` : day;
const date = `${year}-${month}-${day}`;
const quotation = fs.readFileSync('./quotations.md', 'utf-8');
const quotations = quotation.split('\n').filter(it => it.startsWith('-'));
console.log(`quotations: ${quotations.length}`);
const dayily = sample(quotations);
console.log(`dayily: ${dayily}`);
const newReadme = `${before}
<kbd>${date}</kbd>
${dayily}
<!-- Randomly taken from quotations.md -->
`;
fs.writeFileSync('./README.md', newReadme);
console.log('Update Success!');
} catch (error) {
console.log(error.message);
}
}
run();