|
| 1 | +export function renderMarkdown(markdownText = '') { |
| 2 | + const htmlText = markdownText |
| 3 | + .replace(/^### (.*$)/gm, '<h3>$1</h3>') |
| 4 | + .replace(/^## (.*$)/gm, '<h2>$1</h2>') |
| 5 | + .replace(/^# (.*$)/gm, '<h1>$1</h1>') |
| 6 | + .replace(/^> (.*$)/gm, '<blockquote>$1</blockquote>') |
| 7 | + .replace(/\*\*(.*)\*\*/g, '<b>$1</b>') |
| 8 | + .replace(/\*(.*)\*/g, '<i>$1</i>') |
| 9 | + .replace(/!\[(.*?)\]\((.*?)\)/g, '<img alt=\'$1\' src=\'$2\' />') |
| 10 | + .replace(/\[(.*?)\]\((.*?)\)/g, '<a href=\'$2\'>$1</a>') |
| 11 | + .replace(/`(.*?)`/g, '<code>$1</code>') |
| 12 | + .replace(/\n$/gm, '<br />') |
| 13 | + |
| 14 | + return htmlText.trim() |
| 15 | +} |
| 16 | + |
| 17 | +export function renderCommitMessage(msg: string) { |
| 18 | + return renderMarkdown(msg) |
| 19 | + .replace(/#(\d+)/g, '<a href=\'https://github.com/agiletech-web-dev/js-utils-es/issues/$1\'>#$1</a>') |
| 20 | +} |
| 21 | + |
| 22 | +const mapAuthors = [ |
| 23 | + { |
| 24 | + nameDipslay: 'Hung Hoang', |
| 25 | + username: 'hunghg255', |
| 26 | + mapByNameAliases: ['Hung Hoang', 'Hoang Hung'], |
| 27 | + mapByEmailAliases: ['[email protected]'], |
| 28 | + }, |
| 29 | +]; |
| 30 | + |
| 31 | +export function generateGithubAvatar(nameCommit: string, hash: string) { |
| 32 | + const match = mapAuthors.find((author) => { |
| 33 | + return author.mapByNameAliases.includes(nameCommit) || author.mapByEmailAliases.includes(nameCommit) || author.username === nameCommit; |
| 34 | + }); |
| 35 | + |
| 36 | + if (match) { |
| 37 | + return `https://github.com/${match.username}.png`; |
| 38 | + } |
| 39 | + |
| 40 | + return `https://gravatar.com/avatar/${hash}?d=retro`; |
| 41 | +} |
| 42 | + |
| 43 | +export function generateUserName(nameCommit: string) { |
| 44 | + const match = mapAuthors.find((author) => { |
| 45 | + return author.mapByNameAliases.includes(nameCommit) || author.mapByEmailAliases.includes(nameCommit) || author.username === nameCommit; |
| 46 | + }); |
| 47 | + |
| 48 | + if (match) { |
| 49 | + return match.nameDipslay || nameCommit; |
| 50 | + } |
| 51 | + |
| 52 | + return nameCommit; |
| 53 | +} |
| 54 | + |
| 55 | +export function generateGithubLink(nameCommit: string) { |
| 56 | + const match = mapAuthors.find((author) => { |
| 57 | + return author.mapByNameAliases.includes(nameCommit) || author.mapByEmailAliases.includes(nameCommit) || author.username === nameCommit; |
| 58 | + }); |
| 59 | + |
| 60 | + if (match) { |
| 61 | + return `https://github.com/${match.username}`; |
| 62 | + } |
| 63 | + |
| 64 | + return `https://github.com/${nameCommit}`; |
| 65 | +} |
0 commit comments