-
Notifications
You must be signed in to change notification settings - Fork 0
/
app.js
127 lines (110 loc) · 2.82 KB
/
app.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
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
import { downloadData } from './utils/data.js';
import { createRequire } from 'module';
import chalk from 'chalk';
import boxen from 'boxen';
const require = createRequire(import.meta.url);
const { bold, italic, dim, yellow, green, bgRed } = chalk;
const greenInverse = chalk.bold.inverse.green;
const cyanInverse = chalk.bold.inverse.cyan;
const yellowInverse = chalk.bold.inverse.yellow;
const whiteInverse = chalk.bold.inverse.white;
const pinkInverse = chalk.bold.inverse.magenta;
const blueInverse = chalk.bold.inverse.blue;
const blackInverse = chalk.bold.inverse.black;
const bgcolors = [
greenInverse,
blueInverse,
cyanInverse,
whiteInverse,
yellowInverse,
pinkInverse,
blackInverse
];
// Color utils
const rand = () => Math.floor(Math.random() * bgcolors.length);
let prevColor = null;
const randomBgColor = msg => {
let color = rand();
while (prevColor == color) {
color = rand();
}
prevColor = color;
return bgcolors[rand()](msg);
};
function print(blog) {
// console.log(bold(italic(yellow((blog.name)))));
// console.log();
// console.log((italic(green((blog.description)))));
// console.log();
// let taglist = '';
// blog.tags.forEach((item, i) => {
// let str = ((randomBgColor(' ' + item + ' ')));
// if (i == 0) {
// taglist += str;
// } else {
// taglist += ' - ' + str;
// }
// });
// console.log(taglist);
// console.log();
// console.log(dim(bold(blog.url)));
// console.log();
// console.log();
let strToPrint = '';
strToPrint += italic(yellow(blog.name)) + '\n';
strToPrint += '\n';
strToPrint += italic(green(blog.description)) + '\n';
strToPrint += '\n';
strToPrint += 'Tags: ';
let taglist = '';
blog.tags.forEach((item, i) => {
taglist += randomBgColor(' ' + item + ' ');
});
strToPrint += taglist + '\n';
strToPrint += '\n';
strToPrint += dim(bold(blog.url)) + '\n';
console.log(
boxen(strToPrint, {
title: blog.url,
textAlignment: 'left',
margin: {
top: 1,
bottom: 1
},
padding: 1,
borderColor: `#${Math.floor(Math.random() * 2 ** 24)
.toString(16)
.padStart(6, 0)}`
})
);
}
export async function listBlogs() {
await downloadData();
const blogs = require('./data.cjs');
for (let blog of blogs) {
print(blog);
}
console.log();
console.log(randomBgColor('Created By: Praveen. (https://praveeen.in)'));
console.log();
}
export async function getBlogsFromTag(tag) {
await downloadData();
const blogs = require('./data.cjs');
let flag = false;
for (let blog of blogs) {
for (let t of blog.tags) {
if (!t) continue;
if (t?.toLowerCase() === tag.toLowerCase()) {
flag = true;
print(blog);
}
}
}
if (!flag) {
console.log(bgRed(whiteBright('No blogs found for tag: ' + tag)));
}
console.log();
console.log(randomBgColor('Created By: Praveen. (https://praveeen.in)'));
console.log();
}