-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathutils.ts
65 lines (53 loc) · 2.03 KB
/
utils.ts
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
export function renderMarkdown(markdownText = '') {
const htmlText = markdownText
.replace(/^### (.*$)/gm, '<h3>$1</h3>')
.replace(/^## (.*$)/gm, '<h2>$1</h2>')
.replace(/^# (.*$)/gm, '<h1>$1</h1>')
.replace(/^> (.*$)/gm, '<blockquote>$1</blockquote>')
.replace(/\*\*(.*)\*\*/g, '<b>$1</b>')
.replace(/\*(.*)\*/g, '<i>$1</i>')
.replace(/!\[(.*?)\]\((.*?)\)/g, '<img alt=\'$1\' src=\'$2\' />')
.replace(/\[(.*?)\]\((.*?)\)/g, '<a href=\'$2\'>$1</a>')
.replace(/`(.*?)`/g, '<code>$1</code>')
.replace(/\n$/gm, '<br />')
return htmlText.trim()
}
export function renderCommitMessage(msg: string) {
return renderMarkdown(msg)
.replace(/#(\d+)/g, '<a href=\'https://github.com/agiletech-web-dev/js-utils-es/issues/$1\'>#$1</a>')
}
const mapAuthors = [
{
nameDipslay: 'Hung Hoang',
username: 'hunghg255',
mapByNameAliases: ['Hung Hoang', 'Hoang Hung'],
mapByEmailAliases: ['[email protected]'],
},
];
export function generateGithubAvatar(nameCommit: string, hash: string) {
const match = mapAuthors.find((author) => {
return author.mapByNameAliases.includes(nameCommit) || author.mapByEmailAliases.includes(nameCommit) || author.username === nameCommit;
});
if (match) {
return `https://github.com/${match.username}.png`;
}
return `https://gravatar.com/avatar/${hash}?d=retro`;
}
export function generateUserName(nameCommit: string) {
const match = mapAuthors.find((author) => {
return author.mapByNameAliases.includes(nameCommit) || author.mapByEmailAliases.includes(nameCommit) || author.username === nameCommit;
});
if (match) {
return match.nameDipslay || nameCommit;
}
return nameCommit;
}
export function generateGithubLink(nameCommit: string) {
const match = mapAuthors.find((author) => {
return author.mapByNameAliases.includes(nameCommit) || author.mapByEmailAliases.includes(nameCommit) || author.username === nameCommit;
});
if (match) {
return `https://github.com/${match.username}`;
}
return `https://github.com/${nameCommit}`;
}