From 9b719070b0bbeca0853cc5d14e74b5294f87c503 Mon Sep 17 00:00:00 2001 From: "1152958806@qq.com" <1152958806@qq.com> Date: Sat, 11 Nov 2023 00:55:24 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BC=98=E5=8C=96=E9=93=BE=E6=8E=A5=E5=8D=A1?= =?UTF-8?q?=E7=89=87=20link?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- templates/assets/js/custom.js | 203 ++------------------------- templates/assets/zhheo/zhheoblog.css | 18 ++- 2 files changed, 26 insertions(+), 195 deletions(-) diff --git a/templates/assets/js/custom.js b/templates/assets/js/custom.js index 1a33028b..b3138a2d 100644 --- a/templates/assets/js/custom.js +++ b/templates/assets/js/custom.js @@ -88,136 +88,6 @@ document.addEventListener("DOMContentLoaded", () => { } ); - // github仓库 - customElements.define( - "hao-github", - class GithubDom extends HTMLElement { - constructor() { - super(); - this.owner = this.getAttribute("owner") || ""; - this.repo = this.getAttribute("repo") || ""; - if (this.owner.length === 0 || this.repo.length === 0) { - return; - } - this.innerHTML = ` -
` - this.fetchDataAndRender(); - } - async fetchDataAndRender() { - try { - const res = await this.fetchRepoInfo(); - const commits = await this.fetchRepoCommits(); - this.render(res, commits); - } catch (error) { - console.error("Error:", error); - } - } - async fetchRepoInfo() { - const response = await fetch(`/apis/api.plugin.halo.run/v1alpha1/plugins/HaoTag/github/repository?owner=${this.owner}&repo=${this.repo}`); - const data = await response.json(); - return data.data.repository; - } - async fetchRepoCommits() { - const response = await fetch(`https://api.github.com/repos/${this.owner}/${this.repo}/stats/participation`); - const commits = await response.json(); - return commits.all; - } - render(res, commits) { - let updatedAtDate = new Date(res.updatedAt); - let currentYear = new Date().getFullYear(); - let dateFormatOptions = { month: 'long', day: 'numeric' }; - if (updatedAtDate.getFullYear() !== currentYear) { - dateFormatOptions.year = 'numeric'; - } - let updatedAt = updatedAtDate.toLocaleDateString("en-US", dateFormatOptions); - let points = commits.map((value, index) => `${index*3},${value+1}`).join(' '); - let polyline = this.generatePolyline(points); - this.innerHTML = this.generateHTMLTemplate(res, polyline, updatedAt); - } - generatePolyline(points) { - return ``; - } - generateHTMLTemplate(res, polyline, updatedAt) { - return `
-
-
- - ${res.name} - - - Public - -

- ${res.description || ""} -

-
-
- - - - - - - - - - - ${polyline} - - - - - - - -
-
-
- - - ${res.primaryLanguage.name || "Unknown"} - - - - ${res.stargazerCount || 0} - - - - ${res.licenseInfo.nickname || "NO LICENCE"} - - - - - - ${res.forks.totalCount || 0} - - - - ${res.issues.totalCount || 0} - - - - ${res.pullRequests.totalCount || 0} - - - Updated on ${updatedAt || "Unknown"} - -
-
- ` - } - } - ); - - // 彩虹虚线 customElements.define( "hao-dotted", @@ -420,10 +290,20 @@ document.addEventListener("DOMContentLoaded", () => { super(); this.options = { link: this.getAttribute("link"), - logo: this.getAttribute("logo"), + logo: this.getAttribute("logo") || '', title: this.getAttribute("title") || '', described: this.getAttribute("described") || '', }; + let tagLinkLeft = ` + ` + if(this.options.logo!=null && this.options.logo!=''){ + tagLinkLeft = ` + ` + } let htmlStr = `
{ draggable="false">