parent
1aba2c77d9
commit
9841351866
|
@ -1 +1,7 @@
|
|||
export const RENDER_CLASS = "halo-render halo-render-wrapper"
|
||||
|
||||
|
||||
export const LANGUAGE_COLOR: {[key: string]: string} = {
|
||||
"Java": "#3478CD",
|
||||
"Default": "#333333"
|
||||
}
|
||||
|
|
|
@ -1,6 +1,10 @@
|
|||
@import "constant";
|
||||
|
||||
@git-color: #3478CD;
|
||||
|
||||
.git {
|
||||
display: flex;
|
||||
gap: 10px;
|
||||
border: 1px solid #ececec;
|
||||
padding: 10px;
|
||||
border-radius: @border-radius;
|
||||
|
@ -12,10 +16,52 @@
|
|||
|
||||
& .repo-name a {
|
||||
font-size: 18px;
|
||||
color: #0052d9;
|
||||
color: @git-color;
|
||||
text-decoration: none;
|
||||
}
|
||||
|
||||
& .icon {
|
||||
font-family: "iconfont", serif;
|
||||
font-size: 24px;
|
||||
color: #333333;
|
||||
}
|
||||
|
||||
& .info {
|
||||
font-size: 14px;
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 15px;
|
||||
|
||||
& .language {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 5px;
|
||||
|
||||
& .dot {
|
||||
width: 14px;
|
||||
height: 14px;
|
||||
border-radius: 50%;
|
||||
}
|
||||
}
|
||||
|
||||
& .count {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 10px;
|
||||
|
||||
& .count-item {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 5px;
|
||||
}
|
||||
|
||||
& .icon {
|
||||
font-size: 18px;
|
||||
color: #818181;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
.description {
|
||||
font-size: 14px;
|
||||
margin: 10px 0;
|
||||
|
|
|
@ -1,4 +1,5 @@
|
|||
import {getGitHubInfo} from "./github-utils";
|
||||
import {LANGUAGE_COLOR, RENDER_CLASS} from "../../constant";
|
||||
|
||||
export const cache: {[key: string]: RepoInfo|-1} = {}
|
||||
|
||||
|
@ -6,6 +7,13 @@ export const utils: {[key: string]: (args: IGitArgs) => Promise<RepoInfo>} = {
|
|||
"github": getGitHubInfo
|
||||
}
|
||||
|
||||
export const icons: {[key: string]: string} = {
|
||||
"gitlab": "",
|
||||
"github": "",
|
||||
"gitee": "",
|
||||
"gitea": ""
|
||||
}
|
||||
|
||||
export function fillContent(id: string,
|
||||
func: string,
|
||||
args: IGitArgs): string | null {
|
||||
|
@ -32,7 +40,7 @@ export function fillContent(id: string,
|
|||
})
|
||||
}).catch(e => {
|
||||
document.querySelectorAll("." + id).forEach(el => {
|
||||
el.innerHTML = "<div class='error'>Error Fetch: " + e.code + `(${e.msg})</div>`
|
||||
el.innerHTML = `<div class='${RENDER_CLASS} git error'>Error Fetch: ` + e.code + `(${e.msg})</div>`
|
||||
})
|
||||
delete cache[id]
|
||||
})
|
||||
|
@ -40,9 +48,18 @@ export function fillContent(id: string,
|
|||
}
|
||||
|
||||
function fill(id: string, info: RepoInfo):string {
|
||||
return `<div class="repo-name"><a href="${info.url}">${info.owner}/${info.name}</a></div>` +
|
||||
const languageColor = LANGUAGE_COLOR[info.language||"Default"] || "#333333"
|
||||
const lang = `<span class="language" style="color: ${languageColor}">` +
|
||||
`<span class="dot" style="background-color: ${languageColor};"></span>${info.language}</span>`
|
||||
const count = `<div class="count">`+
|
||||
`<span class="count-item"><span class="icon"></span>${info.stars}</span>`+
|
||||
`<span class="count-item"><span class="icon"></span>${info.openIssues}</span>` +
|
||||
`</div>`
|
||||
return `<span class="icon">${icons[info.platform || "github"]}</span>` +
|
||||
`<div class="information"><div class="repo-name"><a href="${info.url}">${info.owner}/${info.name}</a></div>` +
|
||||
`<div class="description">${info.description}</div>` +
|
||||
`<div class="info">Stars: ${info.stars} / Watchers: ${info.watchers} / OpenIssues: ${info.openIssues}</div>`
|
||||
`<div class="info">${lang} ${count}</div>` +
|
||||
`</div>`
|
||||
}
|
||||
|
||||
export declare interface IGitArgs {
|
||||
|
@ -51,6 +68,7 @@ export declare interface IGitArgs {
|
|||
}
|
||||
|
||||
export declare interface RepoInfo {
|
||||
platform?: string
|
||||
name?: string
|
||||
owner?: string
|
||||
url?: string
|
||||
|
|
|
@ -11,6 +11,7 @@ export async function getGitHubInfo(args: IGitArgs): Promise<RepoInfo> {
|
|||
})
|
||||
})
|
||||
return {
|
||||
platform: "github",
|
||||
url: json["html_url"],
|
||||
owner: json["owner"]["login"],
|
||||
name: json["name"],
|
||||
|
|
Loading…
Reference in New Issue