jekyll-zeta 0.9.0 → 0.9.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (3) hide show
  1. checksums.yaml +4 -4
  2. data/_includes/heatmap.js +287 -233
  3. metadata +1 -1
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 1936ba60486879de4de21ff2e9fa7b67a6a8488345c7ef3d3b84bb47f2a2433b
4
- data.tar.gz: 4c1b68385474906261beb1a672db82b2d27ecb7a13731cdc063ccab10b50e044
3
+ metadata.gz: bb48706f987ba8e19910a12134effc421afee6d6a3bf0b1cdf1f6e0c5d153a0b
4
+ data.tar.gz: c0832d36039ad7c9329e3c5881fd42b30a2268d5ea00553d87969f4bc4e7f726
5
5
  SHA512:
6
- metadata.gz: 3d80ee99b7c683f13fca9c08757347fc5ed2fdcd7b8bf8bdeddeb9edeebfdc29e1e18cf3713c8b46ca956cf91655d886636e65945768454549416ce4cb61acf2
7
- data.tar.gz: 4ed94efbfd3466987d90303b3087c6af9de12556b7f42d75ff6e564c02676a7b5948c2d6a1a83c65240a3733e40c63fe5776b8d9d2f59ef94a907c7a1da3ac44
6
+ metadata.gz: 6b24f8726abafde268178ed833190e2cd2933aaaf3d557d19b9804833d0178da38c792d50e43477a784afa8257c51038c7f960a56007d05eedd607be921e8f1e
7
+ data.tar.gz: 01e73136eada84c3a79a1fb40bdb140cd06fe40698aa42cc39ba6357e856891e11a8eaaa04bdd79fbdab6b48b48b7cbc0d0467b1270c37ca3c872410bc5affcf
data/_includes/heatmap.js CHANGED
@@ -1,296 +1,350 @@
1
+ ;!(function () {
1
2
 
3
+ var GDATA = window._G_DATA;
4
+ if (!GDATA) {
5
+ GDATA = {}
6
+ window._G_DATA = GDATA
7
+ }
2
8
 
3
- ;!function(){
4
9
 
5
- function date2ymd(t){
6
- let m = t.getMonth() + 1;
7
- let d = t.getDate()
8
- return `${t.getFullYear()}-${m< 10 ? '0' + m : m }-${d<10 ? '0'+d:d}`
9
- }
10
+ function date2ymd(t) {
11
+ let m = t.getMonth() + 1;
12
+ let d = t.getDate();
13
+ return `${t.getFullYear()}-${m < 10 ? "0" + m : m}-${d < 10 ? "0" + d : d}`;
14
+ }
10
15
 
11
- const dateEnd = endYear && endYear.length == 4 ? new Date(`${endYear}-12-31`) : new Date();
16
+ const dateEnd =
17
+ endYear && endYear.length == 4 ? new Date(`${endYear}-12-31`) : new Date();
12
18
 
13
- const endStamp = dateEnd.getTime()
14
- const dayEleId = Math.random().toString(16).substring(2);
15
- let arr = _allyearurl.split('/');
16
- arr.pop();
17
- const jsonUrlBase = arr.join('/')
19
+ const endStamp = dateEnd.getTime();
20
+ const dayEleId = Math.random().toString(16).substring(2);
21
+ let arr = _allyearurl.split("/");
22
+ arr.pop();
23
+ const jsonUrlBase = arr.join("/");
18
24
 
25
+ const ColumnsCount = 53;
26
+ const RowCount = 7;
27
+ const DayCount = (ColumnsCount - 1) * RowCount + dateEnd.getDay() + 1;
19
28
 
20
- const ColumnsCount = 53;
21
- const RowCount = 7;
22
- const DayCount = (ColumnsCount - 1) * RowCount + dateEnd.getDay() + 1;
29
+ let queue = window._y_queue || []
30
+ window._y_queue = queue;
31
+
23
32
 
24
- !function fillData(){
25
- let year = '' + dateEnd.getFullYear()
26
- let preYear = '' + (year - 1)
27
- fetch(_allyearurl)
28
- .then(r => r.json())
29
- .then(d=>{
30
- let yearCfg = d ;
31
- let arr = []
32
- if (yearCfg[year]) {
33
- arr.push(getYearData(year ))
33
+ function getAllYearCfg(){
34
+
35
+
36
+ if (GDATA['_allYear']) {
37
+ return GDATA['_allYear'];
34
38
  }
35
39
 
36
- if (yearCfg[preYear]) {
37
- arr.push(getYearData(preYear ))
40
+ if (window._isFetchAllYearData == 1) {
41
+ return new Promise(r=>{
42
+ queue.push(r);
43
+ })
38
44
  }
39
- Promise.all(arr).then(alldata=>{
40
- let combineData = {};
41
- let d1 = alldata[0];
42
- let d2 = alldata[1];
43
-
44
- for (const key in d1) {
45
- if (Object.prototype.hasOwnProperty.call(d1, key)) {
46
- const element = d1[key];
47
- let keyNew = 'K1-' + key;
48
- combineData[keyNew] = element
49
- }
50
- }
51
45
 
52
- for (const key in d2) {
53
- if (Object.prototype.hasOwnProperty.call(d2, key)) {
54
- const element = d2[key];
55
- let keyNew = 'K2-' + key;
56
- combineData[keyNew] = element
46
+
47
+ window._isFetchAllYearData = 1;
48
+ return fetch(_allyearurl)
49
+ .then((r) => r.json())
50
+ .then(d => {
51
+ window._isFetchAllYearData = 0;
52
+ if (queue.length) {
53
+ queue.forEach(calback=>{calback(d)});
54
+ queue.length = 0;
55
+ }
56
+ GDATA['_allYear'] = d ;return d ;})
57
+ }
58
+ !(function fillData() {
59
+ let year = "" + dateEnd.getFullYear();
60
+ let preYear = "" + (year - 1);
61
+ getAllYearCfg()
62
+ .then((d) => {
63
+ let yearCfg = d;
64
+ let arr = [];
65
+ if (yearCfg[year]) {
66
+ arr.push(getYearData(year));
57
67
  }
58
- }
59
68
 
69
+ if (yearCfg[preYear]) {
70
+ arr.push(getYearData(preYear));
71
+ }
72
+ Promise.all(arr).then((alldata) => {
73
+ let combineData = {};
74
+ let d1 = alldata[0];
75
+ let d2 = alldata[1];
76
+
77
+ for (const key in d1) {
78
+ if (Object.prototype.hasOwnProperty.call(d1, key)) {
79
+ const element = d1[key];
80
+ let keyNew = "K1-" + key;
81
+ combineData[keyNew] = element;
82
+ }
83
+ }
60
84
 
61
- updateCell(combineData);
62
- })
63
- })
85
+ for (const key in d2) {
86
+ if (Object.prototype.hasOwnProperty.call(d2, key)) {
87
+ const element = d2[key];
88
+ let keyNew = "K2-" + key;
89
+ combineData[keyNew] = element;
90
+ }
91
+ }
64
92
 
65
- function getIndex(ymd){
66
- return DayCount - Math.floor((endStamp - new Date(ymd).getTime())/ (24 * 3600000)) -1
67
- }
93
+ updateCell(combineData);
94
+ });
95
+ });
96
+
97
+ function getIndex(ymd) {
98
+ return (
99
+ DayCount -
100
+ Math.floor((endStamp - new Date(ymd).getTime()) / (24 * 3600000)) -
101
+ 1
102
+ );
103
+ }
68
104
 
69
- function idx2Ymd(idx){
70
- let t = new Date(endStamp - ( (DayCount - 1) - idx) * 3600000 * 24)
71
- let m = t.getMonth() + 1
72
- let d = t.getDate()
73
- return `${t.getFullYear()}-${m< 10 ? '0' + m : m }-${d<10 ? '0'+d:d}`
74
- }
105
+ function idx2Ymd(idx) {
106
+ let t = new Date(endStamp - (DayCount - 1 - idx) * 3600000 * 24);
107
+ let m = t.getMonth() + 1;
108
+ let d = t.getDate();
109
+ return `${t.getFullYear()}-${m < 10 ? "0" + m : m}-${
110
+ d < 10 ? "0" + d : d
111
+ }`;
112
+ }
75
113
 
76
- function updateCell(data){
77
- if(!data)return
114
+ function updateCell(data) {
115
+ if (!data) return;
78
116
 
79
- console.log(data)
80
117
 
81
- let daysEle = document.getElementById(dayEleId)
82
- let dayCells = daysEle.childNodes
118
+ let daysEle = document.getElementById(dayEleId);
119
+ let dayCells = daysEle.childNodes;
83
120
 
84
- let Map = {}
121
+ let Map = {};
85
122
 
86
- for (const key in data) {
87
- if (Object.prototype.hasOwnProperty.call(data, key)) {
88
- const element = data[key];
89
- if(Array.isArray(element)){
90
- element.forEach(e=>{
91
- if(e.date && e.title && e.url){
92
- let arr = Map[e.date]
93
- if (!arr) {
94
- arr = []
95
- Map[e.date] = arr
123
+ for (const key in data) {
124
+ if (Object.prototype.hasOwnProperty.call(data, key)) {
125
+ const element = data[key];
126
+ if (Array.isArray(element)) {
127
+ element.forEach((e) => {
128
+ if (e.date && e.title && e.url) {
129
+ let arr = Map[e.date];
130
+ if (!arr) {
131
+ arr = [];
132
+ Map[e.date] = arr;
133
+ }
134
+ arr.push(e);
96
135
  }
97
- arr.push(e)
98
- }
99
- })
136
+ });
137
+ }
100
138
  }
101
139
  }
102
- }
103
140
 
141
+ let ymdArr = [];
104
142
 
143
+ for (const dateKeyYmd in Map) {
144
+ if (Object.prototype.hasOwnProperty.call(Map, dateKeyYmd)) {
145
+ ymdArr.push(dateKeyYmd);
146
+ }
147
+ }
105
148
 
106
- let ymdArr = []
149
+ var G_idxOfDay = DayCount - 1;
107
150
 
108
- for (const dateKeyYmd in Map) {
109
- if (Object.prototype.hasOwnProperty.call(Map, dateKeyYmd)) {
110
- ymdArr.push(dateKeyYmd)
111
- }
112
- }
151
+ function shuffle(array) {
152
+ let currentIndex = array.length;
113
153
 
154
+ // While there remain elements to shuffle...
155
+ while (currentIndex != 0) {
156
+ // Pick a remaining element...
157
+ let randomIndex = Math.floor(Math.random() * currentIndex);
158
+ currentIndex--;
114
159
 
115
- var G_idxOfDay = DayCount - 1;
116
-
117
- function shuffle(array) {
118
- let currentIndex = array.length;
119
-
120
- // While there remain elements to shuffle...
121
- while (currentIndex != 0) {
122
-
123
- // Pick a remaining element...
124
- let randomIndex = Math.floor(Math.random() * currentIndex);
125
- currentIndex--;
126
-
127
- // And swap it with the current element.
128
- [array[currentIndex], array[randomIndex]] = [
129
- array[randomIndex], array[currentIndex]];
160
+ // And swap it with the current element.
161
+ [array[currentIndex], array[randomIndex]] = [
162
+ array[randomIndex],
163
+ array[currentIndex],
164
+ ];
165
+ }
130
166
  }
131
- }
132
167
 
133
- const SEQ = new Array(DayCount)
134
- let tmp = DayCount
135
- while (tmp -- > 0) {
136
- SEQ[tmp] = tmp
137
- }
138
-
139
- shuffle(SEQ)
140
-
141
- function update1Day(){
142
- if (G_idxOfDay < 0) {
143
- return
168
+ const SEQ = new Array(DayCount);
169
+ let tmp = DayCount;
170
+ while (tmp-- > 0) {
171
+ SEQ[tmp] = tmp;
144
172
  }
145
- const idxOfDay = SEQ[G_idxOfDay --];
146
- let dateKeyYmd = idx2Ymd(idxOfDay )
147
- let arrPostInOneDay = Map[dateKeyYmd];
148
- const dayCell = dayCells[idxOfDay]
149
- const nobg = parseInt(dateKeyYmd.substring(5,7))%2 == 1? 'hm-check-no-b' : 'hm-check-no-a';
150
- dayCell.classList = `heatmap-day-cell ${!arrPostInOneDay ? nobg :arrPostInOneDay.length > 1 ? 'hm-check2' : 'hm-check' }`
151
-
152
- if ((arrPostInOneDay && arrPostInOneDay.length > 0 )) {
153
- let isDirectly = arrPostInOneDay.length == 1
154
- let tip = document.createElement("div");
155
-
156
- if (isDirectly) {
157
- let lnk = document.createElement('a');
158
- lnk.href = arrPostInOneDay[0].url
159
- dayCell.appendChild(lnk)
160
- }
161
-
162
- tip.className = "hm-tip";
163
- let desc = ''
164
- arrPostInOneDay.forEach(element => {
165
-
166
- let lnk = document.createElement('a');
167
- lnk.className = 'hm-tiplink'
168
- lnk.href = element.url
169
- tip.appendChild(lnk)
170
173
 
171
- let t = document.createElement('span')
172
- t.className = 'hm-date'
173
- t.innerText = dateKeyYmd.substring(5);
174
- lnk.appendChild(t);
174
+ shuffle(SEQ);
175
175
 
176
-
177
- let t2 = document.createElement('span')
178
- t2.className = 'hm-title'
179
- t2.innerText = element.title
180
- lnk.appendChild(t2);
181
-
182
- });
183
- dayCell.appendChild(tip);
184
-
176
+ function update1Day() {
177
+ if (G_idxOfDay < 0) {
178
+ return;
179
+ }
180
+ const idxOfDay = SEQ[G_idxOfDay--];
181
+ let dateKeyYmd = idx2Ymd(idxOfDay);
182
+ let arrPostInOneDay = Map[dateKeyYmd];
183
+ const dayCell = dayCells[idxOfDay];
184
+ const nobg =
185
+ parseInt(dateKeyYmd.substring(5, 7)) % 2 == 1
186
+ ? "hm-check-no-b"
187
+ : "hm-check-no-a";
188
+ dayCell.classList = `heatmap-day-cell ${
189
+ !arrPostInOneDay
190
+ ? nobg
191
+ : arrPostInOneDay.length > 1
192
+ ? "hm-check2"
193
+ : "hm-check"
194
+ }`;
195
+
196
+ if (arrPostInOneDay && arrPostInOneDay.length > 0) {
197
+ let isDirectly = arrPostInOneDay.length == 1;
198
+ let tip = document.createElement("div");
199
+
200
+ if (isDirectly) {
201
+ let lnk = document.createElement("a");
202
+ lnk.href = arrPostInOneDay[0].url;
203
+ dayCell.appendChild(lnk);
204
+ }
205
+
206
+ tip.className = "hm-tip";
207
+ let desc = "";
208
+ arrPostInOneDay.forEach((element) => {
209
+ let lnk = document.createElement("a");
210
+ lnk.className = "hm-tiplink";
211
+ lnk.href = element.url;
212
+ tip.appendChild(lnk);
213
+
214
+ let t = document.createElement("span");
215
+ t.className = "hm-date";
216
+ t.innerText = dateKeyYmd.substring(5);
217
+ lnk.appendChild(t);
218
+
219
+ let t2 = document.createElement("span");
220
+ t2.className = "hm-title";
221
+ t2.innerText = element.title;
222
+ lnk.appendChild(t2);
223
+ });
224
+ dayCell.appendChild(tip);
225
+ }
185
226
  }
186
-
187
- }
188
-
189
227
 
190
- function updateMultiDays(){
191
- let day = heatMapLoadCount;
192
- if (!day || day <= 0) {
193
- day = 8;
194
- }
195
- while (day -- ) {
196
- update1Day();
197
- }
228
+ function updateMultiDays() {
229
+ let day = heatMapLoadCount;
230
+ if (!day || day <= 0) {
231
+ day = 8;
232
+ }
233
+ while (day--) {
234
+ update1Day();
235
+ }
198
236
 
199
- if (G_idxOfDay >= 0) {
200
- requestAnimationFrame(updateMultiDays)
237
+ if (G_idxOfDay >= 0) {
238
+ requestAnimationFrame(updateMultiDays);
239
+ }
201
240
  }
241
+ requestAnimationFrame(updateMultiDays);
202
242
 
243
+ return;
203
244
  }
204
- requestAnimationFrame(updateMultiDays)
205
-
206
- return
207
-
208
- }
209
-
210
-
211
-
212
- function getYearData(year){
213
- return fetch(`${jsonUrlBase}/${year}.json`)
214
- .then(r => r.json())
215
- .catch(e=>{
216
- return null
217
- })
218
-
219
- }
220
-
221
-
222
-
223
-
224
- }()
225
-
226
-
227
245
 
228
- ;(function initMap(){
246
+ function getYearData(year) {
247
+ year = '' + year
229
248
 
230
- let Father = document.getElementById(heatmapid);
231
-
232
- const Frag = document.createDocumentFragment();
233
-
234
- const monthEle = document.createElement("div");
235
- monthEle.className = "heatmap-month";
236
- Frag.appendChild(monthEle);
237
- const monthStr = _MonthStr.split(" ");
238
-
239
-
240
- let nowM = dateEnd.getMonth();
241
- let nowWeek = dateEnd.getDay();
242
-
243
-
244
- for (let i = 0; i < monthStr.length ; i++) {
245
- let m = document.createElement("span");
246
- m.className = "heatmap-month-cell";
247
- m.innerHTML = `${monthStr[(i + nowM + 1) % 12]}`;
248
- monthEle.appendChild(m);
249
- }
249
+
250
+ if(GDATA[year]){
250
251
 
251
- const weekEle = document.createElement("div");
252
- weekEle.className = "heatmap-week";
253
- const WeekStr = _showWeek.split(" ");
252
+ return GDATA[year]
253
+ }
254
254
 
255
- for (let i = 0; i < WeekStr.length; i++) {
256
- let m = document.createElement("div");
257
- m.className = "heatmap-week-cell";
258
- m.innerHTML = `<span>${WeekStr[i]}</span>`;
259
- weekEle.appendChild(m);
260
- }
255
+ let queueFlgKey = '_singleyearFlg' + year
256
+ let queueArrKey = '_singleyearQueue' + year
257
+ if (GDATA[queueFlgKey] == 1) {
258
+ // console.log('put in queue',year,Math.random())
259
+ let arrQueue = GDATA[queueArrKey]
260
+ if (!arrQueue) {
261
+ arrQueue = []
262
+ GDATA[queueArrKey] = arrQueue;
263
+ }
264
+
265
+ return new Promise(r=>{
266
+ arrQueue.push(r);
267
+ });
268
+ }
261
269
 
262
- Frag.appendChild(weekEle);
263
270
 
264
- const dayEle = document.createElement("div");
271
+ GDATA[queueFlgKey] = 1;
272
+ // console.log('RealQuery',year,Math.random())
273
+ return fetch(`${jsonUrlBase}/${year}.json`)
274
+ .then((r) => r.json())
275
+ .then(d=>{
276
+ GDATA[queueFlgKey] = 0 ;GDATA[year] = d;
277
+ let queue = GDATA[queueArrKey];
278
+ // console.log('queryFinish',year)
279
+ if(queue && queue.length){
280
+ queue.forEach(cb=>{
281
+ // console.log('queryFinishQueue',year,queue.length,Math.random());
282
+ cb(d);})
283
+ queue.length = 0;
284
+ GDATA[queueArrKey] = undefined
285
+ }
286
+
287
+ return d})
288
+ .catch((e) => {
289
+ return null;
290
+ });
291
+ }
292
+ })();
293
+ (function initMap() {
294
+ let Father = document.getElementById(heatmapid);
265
295
 
266
- dayEle.className = "heatmap-day";
267
- dayEle.id = dayEleId;
296
+ const Frag = document.createDocumentFragment();
268
297
 
298
+ const monthEle = document.createElement("div");
299
+ monthEle.className = "heatmap-month";
300
+ Frag.appendChild(monthEle);
301
+ const monthStr = _MonthStr.split(" ");
269
302
 
270
- let firstDateDayDiff = (ColumnsCount - 1) * RowCount + nowWeek;
303
+ let nowM = dateEnd.getMonth();
304
+ let nowWeek = dateEnd.getDay();
271
305
 
306
+ for (let i = 0; i < monthStr.length; i++) {
307
+ let m = document.createElement("span");
308
+ m.className = "heatmap-month-cell";
309
+ m.innerHTML = `${monthStr[(i + nowM + 1) % 12]}`;
310
+ monthEle.appendChild(m);
311
+ }
272
312
 
273
- console.log(nowWeek, firstDateDayDiff);
313
+ const weekEle = document.createElement("div");
314
+ weekEle.className = "heatmap-week";
315
+ const WeekStr = _showWeek.split(" ");
274
316
 
275
- for (let c = 0; c < ColumnsCount; c++) {
276
- for (let r = 0; r < RowCount; r++) {
277
- if (r > nowWeek && c == ColumnsCount - 1) {
278
- break
317
+ for (let i = 0; i < WeekStr.length; i++) {
318
+ let m = document.createElement("div");
319
+ m.className = "heatmap-week-cell";
320
+ m.innerHTML = `<span>${WeekStr[i]}</span>`;
321
+ weekEle.appendChild(m);
279
322
  }
280
323
 
281
- let m = document.createElement("span");
282
- m.classList = `heatmap-day-cell hm-check-nodata`
283
- dayEle.appendChild(m);
284
- }
285
- }
324
+ Frag.appendChild(weekEle);
286
325
 
326
+ const dayEle = document.createElement("div");
287
327
 
288
- Frag.appendChild(dayEle);
289
- Father.append(Frag);
290
- })()
328
+ dayEle.className = "heatmap-day";
329
+ dayEle.id = dayEleId;
291
330
 
331
+ let firstDateDayDiff = (ColumnsCount - 1) * RowCount + nowWeek;
292
332
 
333
+ // console.log(nowWeek, firstDateDayDiff);
293
334
 
335
+ for (let c = 0; c < ColumnsCount; c++) {
336
+ for (let r = 0; r < RowCount; r++) {
337
+ if (r > nowWeek && c == ColumnsCount - 1) {
338
+ break;
339
+ }
294
340
 
341
+ let m = document.createElement("span");
342
+ m.classList = `heatmap-day-cell hm-check-nodata`;
343
+ dayEle.appendChild(m);
344
+ }
345
+ }
295
346
 
296
- }();
347
+ Frag.appendChild(dayEle);
348
+ Father.append(Frag);
349
+ })();
350
+ })();
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: jekyll-zeta
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.9.0
4
+ version: 0.9.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - vitock