-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
265 lines (231 loc) · 17.8 KB
/
index.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
const axios = require('axios');
function split_path(path) {
let path_arr = path.split("/")
let len = path.split("/").length
let res_arr = path_arr.slice(len - 2, len)
return res_arr.join('/')
}
function unit(number) {
let _number = number / 1000;
if (_number >= 1000) {
return parseFloat((_number / 1000).toFixed(1)) + 'm'
} else if (_number >= 1) {
return parseFloat(_number.toFixed(1)) + 'k'
} else {
return number;
}
}
const github = {
repo: (path) => {
return new Promise((resolve, reject) => {
let options = {
url: 'https://api.github.com/repos/' + split_path(path),
method: 'GET',
headers: {
'User-Agent': 'Mozilla/5.0 (iPhone; CPU iPhone OS 13_2_3 like Mac OS X) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/13.0.3 Mobile/15E148 Safari/604.1 Edg/91.0.4472.114',
'Content-Type': 'application/json',
'accept': 'application/vnd.github.v3+json',
}
};
axios(options).then(response => {
resolve(response)
}).catch(error => {
resolve({ 'status': error.response.status })
})
})
}
}
hexo.extend.tag.register('githubrepo', async function (args, content) {
return github.repo(args[0]).then(function (resp) {
if (resp.status != 200) {
return `<style>
/* css part */
.gr-card {
--card-width: 100%;
--card-height: 100px;
display: flex;
width: var(--card-width);
height: var(--card-height);
background-color: #fff;
border-radius: 6px;
overflow: hidden;
box-shadow: 0px 4px 6px rgba(0, 0, 0, .12);
margin-bottom: 20px;
text-align: center;
}
.gr-svg {
width: 80px;
height: 80px;
margin: auto;
}
svg {
width: 80px;
height: 80px;
margin: auto;
}
</style>
<div class="gr-card">
<div class='gr-svg'><svg t="1625560263736" class="icon" viewBox="0 0 1024 1024" version="1.1" xmlns="http://www.w3.org/2000/svg" p-id="5867" width="200" height="200"><path d="M841.554135 289.474752c-32.966703-13.322161-69.997795-24.386329-109.964278-32.966703-10.612569-113.351268-105.222492-202.316207-219.702757-202.316208-114.480265 0-209.090187 88.964939-219.702756 202.316208-39.966483 8.580375-76.997574 19.644542-109.964278 32.966703-97.093716 38.837486-150.382359 94.158324-150.382359 155.124145s53.514443 116.286659 150.382359 155.124146c88.513341 35.450496 205.703197 55.095039 329.667034 55.095039 123.963837 0 241.153693-19.644542 329.667035-55.095039 97.093716-38.837486 150.382359-94.158324 150.382359-155.124146s-53.288644-116.06086-150.382359-155.124145z m-329.441235-176.349283c78.35237 0 144.059978 57.127233 158.962734 132.544211-50.353252-7.451378-103.867696-11.289967-158.962734-11.289967-54.869239 0-108.383682 3.838589-158.736935 11.289967 14.676957-75.416979 80.158765-132.544212 158.736935-132.544211zM819.877398 545.531202c-81.739361 32.740904-191.02624 50.804851-307.764498 50.804851s-226.025138-18.063947-307.764499-50.804851c-71.126792-28.450717-113.577067-66.159206-113.577067-100.706505s42.450276-72.255788 113.577067-100.706505c81.739361-32.740904 191.02624-50.804851 307.764499-50.804851s226.025138 18.063947 307.764498 50.804851c71.126792 28.450717 113.577067 66.159206 113.577067 100.706505s-42.450276 72.029989-113.577067 100.706505z" p-id="5868" fill="#707070"></path><path d="M453.179272 135.931202c-27.547519 11.741566-50.804851 31.160309-67.514002 56.224035-5.419184 8.354576-3.161191 19.418743 4.967586 25.063727 3.161191 2.032194 6.548181 2.935391 9.93517 2.935391 5.870783 0 11.515766-2.935391 15.128556-8.128776 12.644763-19.192944 30.482911-34.0957 51.482249-43.127674 9.257773-3.838589 13.54796-14.451158 9.483573-23.70893-3.612789-8.806174-14.225358-13.096362-23.483132-9.257773zM516.403087 690.268578c-43.579272 0-74.513782 13.322161-94.384123 40.643881-17.838148 24.386329-25.741125 57.804631-25.741125 108.835281s7.902977 84.448953 25.741125 108.835281c19.870342 27.32172 50.804851 40.643881 94.384123 40.643881 43.579272 0 74.513782-13.322161 94.384124-40.643881 17.838148-24.386329 25.741125-57.804631 25.741124-108.835281s-7.902977-84.448953-25.741124-108.835281c-19.870342-27.32172-50.804851-40.643881-94.384124-40.643881z m0 240.250496c-37.031092 0-61.41742-6.322381-61.41742-90.771334 0-84.448953 24.386329-90.771334 61.41742-90.771334s61.41742 6.322381 61.41742 90.771334c-0.225799 84.448953-24.386329 90.771334-61.41742 90.771334zM333.054024 884.230209H305.280706v-164.607717-0.903198-1.580595c0-0.451599 0-0.903197-0.2258-1.354796 0-0.451599-0.225799-0.903197-0.225799-1.354796 0-0.451599-0.225799-1.128997-0.451599-1.580595 0-0.451599-0.225799-0.903197-0.225799-1.128997-0.225799-0.451599-0.225799-1.128997-0.451599-1.580595-0.225799-0.451599-0.225799-0.677398-0.451598-1.128997l-0.677398-1.354796-0.677398-1.354796c-0.225799-0.451599-0.451599-0.903197-0.677398-1.128997-0.225799-0.451599-0.451599-0.903197-0.903198-1.354796-0.225799-0.451599-0.451599-0.677398-0.677398-1.128997-0.225799-0.451599-0.677398-0.903197-0.903197-1.354796-0.225799-0.225799-0.451599-0.677398-0.903198-0.903197-0.451599-0.451599-0.677398-0.903197-1.128996-1.128997l-0.903198-0.903197c-0.451599-0.225799-0.677398-0.677398-1.128996-0.903197-0.451599-0.451599-0.903197-0.677398-1.354796-1.128997-0.225799-0.225799-0.451599-0.451599-0.677398-0.451599 0 0-0.225799 0-0.2258-0.225799-0.451599-0.451599-1.128997-0.677398-1.580595-0.903198-0.225799-0.225799-0.677398-0.451599-0.903197-0.451598-0.451599-0.225799-1.128997-0.451599-1.580596-0.903198-0.451599-0.225799-0.677398-0.451599-1.128996-0.451598-0.451599-0.225799-0.903197-0.451599-1.580596-0.677398-0.451599-0.225799-0.903197-0.225799-1.354796-0.451599-0.451599-0.225799-0.903197-0.225799-1.354796-0.451599-0.451599-0.225799-0.903197-0.225799-1.580595-0.451598-0.451599 0-0.677398-0.225799-1.128997-0.2258-0.677398 0-1.128997-0.225799-1.806395-0.225799H275.475193h-2.709592c-0.451599 0-0.903197 0-1.354796 0.225799-0.451599 0-0.903197 0.225799-1.354796 0.2258-0.451599 0-1.128997 0.225799-1.580596 0.451598-0.451599 0-0.903197 0.225799-1.128996 0.2258-0.451599 0.225799-1.128997 0.225799-1.580596 0.451598-0.451599 0.225799-0.677398 0.225799-1.128996 0.451599l-1.354796 0.677398c-0.451599 0.225799-0.903197 0.451599-1.128997 0.677398-0.451599 0.225799-0.903197 0.451599-1.128997 0.677398-0.451599 0.225799-0.903197 0.451599-1.354796 0.903198-0.451599 0.225799-0.677398 0.451599-1.128996 0.677398-0.451599 0.225799-0.903197 0.677398-1.354796 0.903197-0.225799 0.225799-0.677398 0.451599-0.903198 0.903197l-1.128997 1.128997-0.903197 0.903197c-0.225799 0.451599-0.677398 0.677398-0.903197 1.128997-0.451599 0.451599-0.677398 0.903197-1.128997 1.354796-0.225799 0.225799-0.451599 0.451599-0.451599 0.677398l-137.737596 193.961632c-6.322381 9.031974-7.225579 20.773539-2.257993 30.48291s15.128556 15.805954 26.192723 15.805954h108.383682v16.934951c0 16.257552 13.096362 29.353914 29.353914 29.353914s29.353914-13.096362 29.353914-29.353914V942.938037h27.773319c16.257552 0 29.353914-13.096362 29.353914-29.353914s-12.870562-29.353914-29.128115-29.353914z m-137.963396 0l51.48225-72.481587V884.230209H195.090628zM885.810805 884.230209H858.037486v-164.607717-0.903198-1.580595c0-0.451599 0-0.903197-0.225799-1.354796 0-0.451599-0.225799-0.903197-0.225799-1.354796 0-0.451599-0.225799-1.128997-0.451599-1.580595 0-0.451599-0.225799-0.903197-0.225799-1.128997-0.225799-0.451599-0.225799-1.128997-0.451599-1.580595-0.225799-0.451599-0.225799-0.677398-0.451599-1.128997l-0.677398-1.354796-0.677398-1.354796c-0.225799-0.451599-0.451599-0.903197-0.677398-1.128997-0.225799-0.451599-0.451599-0.903197-0.903197-1.354796-0.225799-0.451599-0.451599-0.677398-0.677398-1.128997-0.225799-0.451599-0.677398-0.903197-0.903198-1.354796-0.225799-0.225799-0.451599-0.677398-0.903197-0.903197-0.451599-0.451599-0.677398-0.903197-1.128997-1.128997l-0.903197-0.903197c-0.451599-0.225799-0.677398-0.677398-1.128997-0.903197-0.451599-0.451599-0.903197-0.677398-1.354796-1.128997-0.225799-0.225799-0.451599-0.451599-0.677398-0.451599 0 0-0.225799 0-0.225799-0.225799-0.451599-0.451599-1.128997-0.677398-1.580595-0.903198-0.225799-0.225799-0.677398-0.451599-0.903198-0.451598-0.451599-0.225799-1.128997-0.451599-1.580595-0.677398-0.451599-0.225799-0.677398-0.451599-1.128997-0.451599-0.451599-0.225799-0.903197-0.451599-1.354796-0.451599-0.451599-0.225799-0.903197-0.225799-1.354796-0.451598-0.451599-0.225799-0.903197-0.225799-1.354796-0.451599-0.451599-0.225799-1.128997-0.225799-1.580595-0.451599-0.451599 0-0.677398-0.225799-1.128997-0.225799-0.677398 0-1.128997-0.225799-1.806395-0.225799h-2.935391-2.709592c-0.451599 0-0.903197 0-1.354796 0.225799-0.451599 0-0.903197 0.225799-1.354796 0.225799-0.451599 0-1.128997 0.225799-1.580596 0.2258-0.451599 0-0.903197 0.225799-1.128996 0.225799-0.451599 0.225799-1.128997 0.225799-1.580596 0.451599-0.451599 0.225799-0.903197 0.225799-1.128996 0.451598l-1.354796 0.677398-1.354796 0.677398c-0.451599 0.225799-0.903197 0.451599-1.128997 0.677398-0.451599 0.225799-0.903197 0.451599-1.354796 0.903198-0.451599 0.225799-0.677398 0.451599-1.128997 0.677398-0.451599 0.225799-0.903197 0.677398-1.354796 0.903197-0.225799 0.225799-0.677398 0.451599-0.903197 0.903198-0.451599 0.451599-0.903197 0.677398-1.128997 1.128996l-0.903197 0.903198c-0.225799 0.451599-0.677398 0.677398-0.903198 1.128996-0.451599 0.451599-0.677398 0.903197-1.128996 1.354796-0.225799 0.225799-0.451599 0.451599-0.451599 0.677398l-137.737596 193.961632c-6.322381 9.031974-7.225579 20.773539-2.257994 30.482911 4.967585 9.709372 15.128556 15.805954 26.192723 15.805954h108.383683v16.93495c0 16.257552 13.096362 29.353914 29.353914 29.353914s29.353914-13.096362 29.353914-29.353914V942.938037h27.773319c16.257552 0 29.353914-13.096362 29.353914-29.353914s-12.870562-29.353914-29.128115-29.353914z m-138.189195 0l51.482249-72.481587V884.230209h-51.482249z" p-id="5869" fill="#707070"></path><path d="M512.1129 344.118192m-29.353914 0a29.353914 29.353914 0 1 0 58.707828 0 29.353914 29.353914 0 1 0-58.707828 0Z" p-id="5870" fill="#707070"></path><path d="M291.281147 373.472106m-29.353914 0a29.353914 29.353914 0 1 0 58.707828 0 29.353914 29.353914 0 1 0-58.707828 0Z" p-id="5871" fill="#707070"></path><path d="M291.281147 499.016538m-29.353914 0a29.353914 29.353914 0 1 0 58.707828 0 29.353914 29.353914 0 1 0-58.707828 0Z" p-id="5872" fill="#707070"></path><path d="M512.1129 541.241014m-29.353914 0a29.353914 29.353914 0 1 0 58.707828 0 29.353914 29.353914 0 1 0-58.707828 0Z" p-id="5873" fill="#707070"></path><path d="M732.718853 373.472106m-29.353914 0a29.353914 29.353914 0 1 0 58.707828 0 29.353914 29.353914 0 1 0-58.707828 0Z" p-id="5874" fill="#707070"></path><path d="M732.718853 499.016538m-29.353914 0a29.353914 29.353914 0 1 0 58.707828 0 29.353914 29.353914 0 1 0-58.707828 0Z" p-id="5875" fill="#707070"></path></svg>
</div>
</div>`
}
let data = resp.data;
// return `<textarea name="123" id="" cols="30" rows="10">${data.description}123</textarea>`;
return `<style>
/* css part */
.gr-card {
--gr-header-width-proportion: 10%;
--gr-footer-width-proportion: 10%;
--gr-content-width-proportion: 80%;
--gr-header-min-width: 80px;
--gr-footer-min-width: 80px;
--gr-card-element-margin: 6px 10px 6px 10px; /* header content footer*/
display: flex;
background-color: #fff;
border-radius: 6px;
overflow: hidden;
box-shadow: 0px 4px 6px rgba(0, 0, 0, .12);
margin-bottom: 20px;
vertical-align: middle;
position: relative;
}
.gr-header {
width: var(--gr-header-width-proportion);
min-width: var(--gr-header-min-width);
margin: var(--gr-card-element-margin);
background-color: #fff;
/* background-color: blueviolet; */
}
.gr-header img {
width: 80px;
height: 80px;
position: relative;
top: 50%;
left: 50%;
transform: translate(-50%,-50%);
object-fit: cover;
border-radius: 50%;
margin: 0px;
}
.gr-content {
width: var(--gr-content-width-proportion);
margin: var(--gr-card-element-margin);
background-color: #fff;
text-align: left;
}
#gr-github-icon {
font-size: 1.3rem;
}
.gr-fullname {
display: -webkit-box;
-webkit-box-orient: vertical;
-webkit-line-clamp: 1;
overflow: hidden;
}
.gr-fullname p {
line-height: 2rem;
margin: 10px 0px 0px 0px;
padding: 0;
font-size: .83rem;
font-weight: bolder;
}
.gr-description {
font-size: .8rem;
line-height: 1.6rem;
display: -webkit-box;
-webkit-box-orient: vertical;
-webkit-line-clamp: 1;
overflow: hidden;
}
.gr-footer {
width: var(--gr-footer-width-proportion);
min-width: var(--gr-footer-min-width);
margin: var(--gr-card-element-margin);
display: flex;
/* background-color: aqua; */
background-color: #fff;
position: relative;
padding: 0px;
}
.gr-language-star {
margin: auto auto 22px auto;
text-align: center;
opacity: 1;
}
.gr-language {
font-size: .8rem;
font-weight: 600;
line-height: 2.2rem;
color: #2070d3;
}
#gr-star-icon {
font-size: .8rem;
display: inherit;
}
.gr-card-toolbar{
display:flex;
width: 100%;
height: 100%;
position: absolute;
opacity: 0;
animation: fade-out;
animation-duration: .4s;
z-index: -1;
/* background-color: #2070d3; */
}
.gr-repo-link {
margin: auto;
}
#gr-repo-link-icon {
font-size: 16px;
}
/* animation part */
@keyframes fade-in {
0% {opacity: 0;}/*初始状态 透明度为0*/
100% {opacity: 1;}/*结束状态 透明度为1*/
}
@keyframes fade-out {
0% {opacity: 1;}/*初始状态 透明度为0*/
100% {opacity: 0;}/*结束状态 透明度为1*/
}
.gr-card:hover .gr-language-star{
opacity: 0;
animation: fade-out;
animation-duration: .3s;
}
.gr-card:hover .gr-card-toolbar{
opacity: 1;
animation: fade-in;
animation-duration: .6s;
z-index: 1;
}
</style>
<div class="gr-card">
<div class="gr-header">
<img src="${data.owner.avatar_url}" alt="">
</div>
<div class="gr-content">
<div class="gr-fullname">
<p><i class="fab fa-github fa-lg" aria-hidden="true" id="gr-github-icon"></i> ${data.full_name}</p>
</div>
<div class="gr-description">
${data.description}
</div>
</div>
<div class="gr-footer">
<div class="gr-language-star">
<span class="gr-language">${data.language}</span>
<i class="far fa-star" aria-hidden="true" id='gr-star-icon'> ${unit(data.stargazers_count)}</i>
</div>
<div class="gr-card-toolbar">
<div class="gr-repo-link">
<a href="${data.html_url}" target="_blank" rel="noopener noreferrer"
title="Open in a new TAB">
<i class="fas fa-external-link-square-alt fa-lg" aria-hidden="true" style="color: black;" id="gr-repo-link-icon"></i>
</a>
</div>
</div>
</div>
</div>`
})
}, { async: true });