💄 Modify git block style

Link #1
This commit is contained in:
zhengyi 2023-12-25 16:54:49 +08:00
parent 1aba2c77d9
commit 9841351866
4 changed files with 75 additions and 4 deletions

View File

@ -1 +1,7 @@
export const RENDER_CLASS = "halo-render halo-render-wrapper"
export const LANGUAGE_COLOR: {[key: string]: string} = {
"Java": "#3478CD",
"Default": "#333333"
}

View File

@ -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;

View File

@ -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": "&#xe881;",
"github": "&#xe885;",
"gitee": "&#xe7d5;",
"gitea": "&#xeba0;"
}
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">&#xe7df;</span>${info.stars}</span>`+
`<span class="count-item"><span class="icon">&#xe764;</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

View File

@ -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"],