-
Notifications
You must be signed in to change notification settings - Fork 37
/
update-quote.js
31 lines (25 loc) · 923 Bytes
/
update-quote.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
const fs = require('fs');
async function updateQuote() {
try {
const quotes = require('./quotes.json');
const randomIndex = Math.floor(Math.random() * quotes.length);
const { quote, author } = quotes[randomIndex];
const cardDesign = `
<!--STARTS_HERE_QUOTE_CARD-->
<p align="center">
<img src="https://readme-daily-quotes.vercel.app/api?author=${encodeURIComponent(author)}"e=${encodeURIComponent(quote)}&theme=dark&bg_color=220a28&author_color=ffeb95&accent_color=c56a90">
</p>
<!--ENDS_HERE_QUOTE_CARD-->
`;
const readmePath = './README.md';
let readmeContent = fs.readFileSync(readmePath, 'utf-8');
readmeContent = readmeContent.replace(
/<!--STARTS_HERE_QUOTE_CARD-->(.|\n)*<!--ENDS_HERE_QUOTE_CARD-->/,
cardDesign
);
fs.writeFileSync(readmePath, readmeContent);
} catch (error) {
console.error('Error updating quote:', error);
}
}
updateQuote();