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 `