redeyed-jekyll-theme 0.1.0 → 0.1.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/LICENSE +21 -21
- data/README.md +54 -52
- data/_config.yml +25 -18
- data/_data/assets/cross-origin.yml +1 -7
- data/_data/assets/self-host.yml +0 -6
- data/_data/locale/en.yml +63 -58
- data/_data/locale/es-ES.yml +79 -0
- data/_data/locale/fr-FR.yml +79 -0
- data/_data/locale/id-ID.yml +79 -0
- data/_data/locale/ko-KR.yml +79 -0
- data/_data/locale/my-MM.yml +79 -0
- data/_data/locale/pt-BR.yml +79 -0
- data/_data/locale/ru-RU.yml +79 -0
- data/_data/locale/uk-UA.yml +79 -0
- data/_data/locale/vi-VN.yml +77 -0
- data/_data/locale/zh-CN.yml +78 -0
- data/_includes/{breadcrumbs.html → elements/breadcrumbs.html} +0 -0
- data/_includes/{datetime.html → elements/datetime.html} +0 -0
- data/_includes/{favicons.html → elements/favicons.html} +14 -14
- data/_includes/{javascript.html → elements/javascript.html} +2 -2
- data/_includes/{jsdelivr-combine.html → elements/jsdelivr-combine.html} +18 -18
- data/_includes/elements/lang.html +11 -0
- data/_includes/{navbar.html → elements/navbar.html} +5 -5
- data/_includes/{no-linenos.html → elements/no-linenos.html} +0 -0
- data/_includes/{options.html → elements/options.html} +13 -13
- data/_includes/{pagination.html → elements/pagination.html} +0 -0
- data/_includes/{readtime.html → elements/readtime.html} +0 -0
- data/_includes/{related-posts.html → elements/related-posts.html} +0 -0
- data/_includes/{search-loader.html → elements/search-loader.html} +46 -46
- data/_includes/{search-results.html → elements/search-results.html} +0 -0
- data/_includes/{toc.html → elements/toc.html} +0 -0
- data/_includes/{back-to-top.html → extensions/back-to-top.html} +2 -2
- data/_includes/extensions/code-highlight.html +89 -0
- data/_includes/extensions/comments/disqus.html +17 -0
- data/_includes/extensions/comments/giscus.html +56 -0
- data/_includes/extensions/comments/gitment.html +15 -0
- data/_includes/extensions/comments/utterances.html +46 -0
- data/_includes/extensions/geopattern.html +19 -0
- data/_includes/extensions/google-analytics.html +7 -0
- data/_includes/{google-tags-body.html → extensions/google-tags-body.html} +3 -3
- data/_includes/{google-tags-head.html → extensions/google-tags-head.html} +5 -5
- data/_includes/extensions/google-translate.html +108 -0
- data/_includes/extensions/hashlocate.html +44 -0
- data/_includes/extensions/mathjax.html +9 -0
- data/_includes/{mode-toggle.html → extensions/theme-mode.html} +0 -10
- data/_includes/extensions/theme-toggle.html +108 -0
- data/_includes/extensions/trianglify.html +26 -0
- data/_includes/functions/get-article-excerpt.html +33 -0
- data/_includes/functions/get-article-words.html +18 -0
- data/_includes/functions/get-banner.html +67 -0
- data/_includes/functions/get-categories.html +9 -0
- data/_includes/functions/get-datetimes.html +13 -0
- data/_includes/functions/get-reading-time.html +39 -0
- data/_includes/functions/get-tags.html +9 -0
- data/_includes/functions/get-value.html +41 -0
- data/_includes/functions/log.html +17 -0
- data/_includes/head.html +4 -4
- data/_includes/{copyright.html → views/copyright.html} +0 -0
- data/_includes/{footer.html → views/footer.html} +0 -0
- data/_includes/{header-banner.html → views/header-banner.html} +0 -0
- data/_includes/{header-wide.html → views/header-wide.html} +0 -0
- data/_includes/{header.html → views/header.html} +0 -0
- data/_includes/{panel-bottom.html → views/panel-bottom.html} +0 -0
- data/_includes/{panel-foot-2.html → views/panel-foot-2.html} +0 -0
- data/_includes/{panel-foot-3.html → views/panel-foot-3.html} +0 -0
- data/_includes/{panel-foot-4.html → views/panel-foot-4.html} +0 -0
- data/_includes/{panel-foot-full.html → views/panel-foot-full.html} +0 -0
- data/_includes/{panel-top-2.html → views/panel-top-2.html} +0 -0
- data/_includes/{panel-top-3.html → views/panel-top-3.html} +0 -0
- data/_includes/{panel-top-4.html → views/panel-top-4.html} +0 -0
- data/_includes/{panel-top-full.html → views/panel-top-full.html} +0 -0
- data/_includes/{post-nav.html → views/post-nav.html} +0 -0
- data/_includes/{post-share.html → views/post-share.html} +0 -0
- data/_includes/{sidebar.html → views/sidebar.html} +0 -0
- data/_javascript/common/back-to-top.js +20 -20
- data/_javascript/common/mode-toggle.js +13 -13
- data/_javascript/common/scroll-helper.js +36 -36
- data/_javascript/common/search-display.js +129 -129
- data/_javascript/common/sidebar.js +30 -30
- data/_javascript/common/tooltip-loader.js +6 -6
- data/_javascript/common/topbar-switcher.js +90 -90
- data/_javascript/common/topbar-title.js +67 -67
- data/_javascript/utils/category-collapse.js +30 -30
- data/_javascript/utils/checkbox.js +12 -12
- data/_javascript/utils/clipboard.js +133 -133
- data/_javascript/utils/img-extra.js +47 -47
- data/_javascript/utils/locale-datetime.js +45 -45
- data/_javascript/utils/pageviews.js +250 -250
- data/_javascript/utils/smooth-scroll.js +96 -96
- data/_layouts/archive.html +5 -0
- data/_layouts/categories.html +5 -0
- data/_layouts/category.html +5 -0
- data/_layouts/compress.html +10 -10
- data/_layouts/error.html +44 -0
- data/_layouts/errors/404.html +9 -0
- data/_layouts/home.html +5 -0
- data/_layouts/page.html +5 -5
- data/_layouts/panel-both.html +13 -13
- data/_layouts/panel-left.html +13 -13
- data/_layouts/panel-none.html +24 -26
- data/_layouts/panel-right.html +13 -13
- data/_layouts/post.html +5 -5
- data/_layouts/tag.html +5 -0
- data/_layouts/tags.html +5 -0
- data/{_includes/comments.html → _sass/addon/alerts.scss} +0 -0
- data/_sass/addon/common.scss +56 -1494
- data/_sass/addon/mixins.scss +31 -38
- data/_sass/addon/syntax.scss +246 -0
- data/_sass/{layout/page.scss → addon/typography.scss} +0 -0
- data/_sass/layout/_base.scss +16 -0
- data/_sass/redeyed-jekyll-theme.scss +30 -15
- data/_sass/{layout/panel-both.scss → theme/scheme-brew.scss} +0 -0
- data/_sass/theme/scheme-dark.scss +220 -0
- data/_sass/theme/scheme-light.scss +220 -0
- data/_sass/theme/syntax-dark.scss +150 -0
- data/_sass/{colors/light-syntax.scss → theme/syntax-light.scss} +4 -4
- data/_sass/theme/variables.scss +60 -0
- metadata +147 -105
- data/_includes/ga-site-tag.html +0 -8
- data/_includes/lang.html +0 -6
- data/_includes/mermaid.html +0 -1
- data/_sass/addon/variables.scss +0 -31
- data/_sass/colors/brew-scheme.scss +0 -7
- data/_sass/colors/dark-scheme.scss +0 -21
- data/_sass/colors/dark-syntax.scss +0 -88
- data/_sass/colors/light-scheme.scss +0 -7
- data/_sass/layout/panel-left.scss +0 -0
- data/_sass/layout/panel-none.scss +0 -146
- data/_sass/layout/panel-right.scss +0 -0
- data/_sass/layout/post.scss +0 -0
@@ -1,250 +1,250 @@
|
|
1
|
-
/*
|
2
|
-
* Count page views form GA or local cache file.
|
3
|
-
*
|
4
|
-
* Dependencies:
|
5
|
-
* - jQuery
|
6
|
-
* - countUp.js <https://github.com/inorganik/countUp.js>
|
7
|
-
*/
|
8
|
-
|
9
|
-
const getInitStatus = (function () {
|
10
|
-
let hasInit = false;
|
11
|
-
return () => {
|
12
|
-
let ret = hasInit;
|
13
|
-
if (!hasInit) {
|
14
|
-
hasInit = true;
|
15
|
-
}
|
16
|
-
return ret;
|
17
|
-
};
|
18
|
-
}());
|
19
|
-
|
20
|
-
const PvOpts = (function () {
|
21
|
-
function getContent(selector) {
|
22
|
-
return $(selector).attr("content");
|
23
|
-
}
|
24
|
-
|
25
|
-
function hasContent(selector) {
|
26
|
-
let content = getContent(selector);
|
27
|
-
return (typeof content !== "undefined" && content !== false);
|
28
|
-
}
|
29
|
-
|
30
|
-
return {
|
31
|
-
getProxyMeta() {
|
32
|
-
return getContent("meta[name=pv-proxy-endpoint]");
|
33
|
-
},
|
34
|
-
getLocalMeta() {
|
35
|
-
return getContent("meta[name=pv-cache-path]");
|
36
|
-
},
|
37
|
-
hasProxyMeta() {
|
38
|
-
return hasContent("meta[name=pv-proxy-endpoint]");
|
39
|
-
},
|
40
|
-
hasLocalMeta() {
|
41
|
-
return hasContent("meta[name=pv-cache-path]");
|
42
|
-
}
|
43
|
-
};
|
44
|
-
|
45
|
-
}());
|
46
|
-
|
47
|
-
const PvStorage = (function () {
|
48
|
-
const Keys = {
|
49
|
-
KEY_PV: "pv",
|
50
|
-
KEY_PV_SRC: "pv_src",
|
51
|
-
KEY_CREATION: "pv_created_date"
|
52
|
-
};
|
53
|
-
|
54
|
-
const Source = {
|
55
|
-
LOCAL: "same-origin",
|
56
|
-
PROXY: "cors"
|
57
|
-
};
|
58
|
-
|
59
|
-
function get(key) {
|
60
|
-
return localStorage.getItem(key);
|
61
|
-
}
|
62
|
-
|
63
|
-
function set(key, val) {
|
64
|
-
localStorage.setItem(key, val);
|
65
|
-
}
|
66
|
-
|
67
|
-
function saveCache(pv, src) {
|
68
|
-
set(Keys.KEY_PV, pv);
|
69
|
-
set(Keys.KEY_PV_SRC, src);
|
70
|
-
set(Keys.KEY_CREATION, new Date().toJSON());
|
71
|
-
}
|
72
|
-
|
73
|
-
return {
|
74
|
-
keysCount() {
|
75
|
-
return Object.keys(Keys).length;
|
76
|
-
},
|
77
|
-
hasCache() {
|
78
|
-
return (localStorage.getItem(Keys.KEY_PV) !== null);
|
79
|
-
},
|
80
|
-
getCache() {
|
81
|
-
return JSON.parse(localStorage.getItem(Keys.KEY_PV));
|
82
|
-
},
|
83
|
-
saveLocalCache(pv) {
|
84
|
-
saveCache(pv, Source.LOCAL);
|
85
|
-
},
|
86
|
-
saveProxyCache(pv) {
|
87
|
-
saveCache(pv, Source.PROXY);
|
88
|
-
},
|
89
|
-
isExpired() {
|
90
|
-
let date = new Date(get(Keys.KEY_CREATION));
|
91
|
-
date.setHours(date.getHours() + 1); // per hour
|
92
|
-
return Date.now() >= date.getTime();
|
93
|
-
},
|
94
|
-
isFromLocal() {
|
95
|
-
return get(Keys.KEY_PV_SRC) === Source.LOCAL;
|
96
|
-
},
|
97
|
-
isFromProxy() {
|
98
|
-
return get(Keys.KEY_PV_SRC) === Source.PROXY;
|
99
|
-
},
|
100
|
-
newerThan(pv) {
|
101
|
-
return PvStorage.getCache().totalsForAllResults["ga:pageviews"] > pv.totalsForAllResults["ga:pageviews"];
|
102
|
-
},
|
103
|
-
inspectKeys() {
|
104
|
-
if (localStorage.length !== PvStorage.keysCount()) {
|
105
|
-
localStorage.clear();
|
106
|
-
return;
|
107
|
-
}
|
108
|
-
|
109
|
-
for(let i = 0; i < localStorage.length; i++){
|
110
|
-
const key = localStorage.key(i);
|
111
|
-
switch (key) {
|
112
|
-
case Keys.KEY_PV:
|
113
|
-
case Keys.KEY_PV_SRC:
|
114
|
-
case Keys.KEY_CREATION:
|
115
|
-
break;
|
116
|
-
default:
|
117
|
-
localStorage.clear();
|
118
|
-
return;
|
119
|
-
}
|
120
|
-
}
|
121
|
-
}
|
122
|
-
};
|
123
|
-
}()); /* PvStorage */
|
124
|
-
|
125
|
-
function countUp(min, max, destId) {
|
126
|
-
if (min < max) {
|
127
|
-
let numAnim = new CountUp(destId, min, max);
|
128
|
-
if (!numAnim.error) {
|
129
|
-
numAnim.start();
|
130
|
-
} else {
|
131
|
-
console.error(numAnim.error);
|
132
|
-
}
|
133
|
-
}
|
134
|
-
}
|
135
|
-
|
136
|
-
function countPV(path, rows) {
|
137
|
-
let count = 0;
|
138
|
-
|
139
|
-
if (typeof rows !== "undefined" ) {
|
140
|
-
for (let i = 0; i < rows.length; ++i) {
|
141
|
-
const gaPath = rows[parseInt(i, 10)][0];
|
142
|
-
if (gaPath === path) { /* path format see: site.permalink */
|
143
|
-
count += parseInt(rows[parseInt(i, 10)][1], 10);
|
144
|
-
break;
|
145
|
-
}
|
146
|
-
}
|
147
|
-
}
|
148
|
-
|
149
|
-
return count;
|
150
|
-
}
|
151
|
-
|
152
|
-
function tacklePV(rows, path, elem, hasInit) {
|
153
|
-
let count = countPV(path, rows);
|
154
|
-
count = (count === 0 ? 1 : count);
|
155
|
-
|
156
|
-
if (!hasInit) {
|
157
|
-
elem.text(new Intl.NumberFormat().format(count));
|
158
|
-
} else {
|
159
|
-
const initCount = parseInt(elem.text().replace(/,/g, ""), 10);
|
160
|
-
if (count > initCount) {
|
161
|
-
countUp(initCount, count, elem.attr("id"));
|
162
|
-
}
|
163
|
-
}
|
164
|
-
}
|
165
|
-
|
166
|
-
function displayPageviews(data) {
|
167
|
-
if (typeof data === "undefined") {
|
168
|
-
return;
|
169
|
-
}
|
170
|
-
|
171
|
-
let hasInit = getInitStatus();
|
172
|
-
const rows = data.rows; /* could be undefined */
|
173
|
-
|
174
|
-
if ($("#post-list").length > 0) { /* the Home page */
|
175
|
-
$(".post-preview").each(function() {
|
176
|
-
const path = $(this).find("a").attr("href");
|
177
|
-
tacklePV(rows, path, $(this).find(".pageviews"), hasInit);
|
178
|
-
});
|
179
|
-
|
180
|
-
} else if ($(".post").length > 0) { /* the post */
|
181
|
-
const path = window.location.pathname;
|
182
|
-
tacklePV(rows, path, $("#pv"), hasInit);
|
183
|
-
}
|
184
|
-
}
|
185
|
-
|
186
|
-
function fetchProxyPageviews() {
|
187
|
-
if (PvOpts.hasProxyMeta()) {
|
188
|
-
$.ajax({
|
189
|
-
type: "GET",
|
190
|
-
url: PvOpts.getProxyMeta(),
|
191
|
-
dataType: "jsonp",
|
192
|
-
jsonpCallback: "displayPageviews",
|
193
|
-
success: (data) => {
|
194
|
-
PvStorage.saveProxyCache(JSON.stringify(data));
|
195
|
-
},
|
196
|
-
error: (jqXHR, textStatus, errorThrown) => {
|
197
|
-
console.log("Failed to load pageviews from proxy server: " + errorThrown);
|
198
|
-
}
|
199
|
-
});
|
200
|
-
}
|
201
|
-
}
|
202
|
-
|
203
|
-
function fetchLocalPageviews(hasCache = false) {
|
204
|
-
return fetch(PvOpts.getLocalMeta())
|
205
|
-
.then(response => response.json())
|
206
|
-
.then(data => {
|
207
|
-
if (hasCache) {
|
208
|
-
// The cache from the proxy will sometimes be more recent than the local one
|
209
|
-
if (PvStorage.isFromProxy() && PvStorage.newerThan(data)) {
|
210
|
-
return;
|
211
|
-
}
|
212
|
-
}
|
213
|
-
displayPageviews(data);
|
214
|
-
PvStorage.saveLocalCache(JSON.stringify(data));
|
215
|
-
});
|
216
|
-
}
|
217
|
-
|
218
|
-
$(function() {
|
219
|
-
if ($(".pageviews").length <= 0) {
|
220
|
-
return;
|
221
|
-
}
|
222
|
-
|
223
|
-
PvStorage.inspectKeys();
|
224
|
-
|
225
|
-
if (PvStorage.hasCache()) {
|
226
|
-
displayPageviews(PvStorage.getCache());
|
227
|
-
|
228
|
-
if (PvStorage.isExpired()) {
|
229
|
-
if (PvOpts.hasLocalMeta()) {
|
230
|
-
fetchLocalPageviews(true).then(fetchProxyPageviews);
|
231
|
-
} else {
|
232
|
-
fetchProxyPageviews();
|
233
|
-
}
|
234
|
-
|
235
|
-
} else {
|
236
|
-
if (PvStorage.isFromLocal()) {
|
237
|
-
fetchProxyPageviews();
|
238
|
-
}
|
239
|
-
}
|
240
|
-
|
241
|
-
} else { // no cached
|
242
|
-
|
243
|
-
if (PvOpts.hasLocalMeta()) {
|
244
|
-
fetchLocalPageviews().then(fetchProxyPageviews);
|
245
|
-
} else {
|
246
|
-
fetchProxyPageviews();
|
247
|
-
}
|
248
|
-
}
|
249
|
-
|
250
|
-
});
|
1
|
+
/*
|
2
|
+
* Count page views form GA or local cache file.
|
3
|
+
*
|
4
|
+
* Dependencies:
|
5
|
+
* - jQuery
|
6
|
+
* - countUp.js <https://github.com/inorganik/countUp.js>
|
7
|
+
*/
|
8
|
+
|
9
|
+
const getInitStatus = (function () {
|
10
|
+
let hasInit = false;
|
11
|
+
return () => {
|
12
|
+
let ret = hasInit;
|
13
|
+
if (!hasInit) {
|
14
|
+
hasInit = true;
|
15
|
+
}
|
16
|
+
return ret;
|
17
|
+
};
|
18
|
+
}());
|
19
|
+
|
20
|
+
const PvOpts = (function () {
|
21
|
+
function getContent(selector) {
|
22
|
+
return $(selector).attr("content");
|
23
|
+
}
|
24
|
+
|
25
|
+
function hasContent(selector) {
|
26
|
+
let content = getContent(selector);
|
27
|
+
return (typeof content !== "undefined" && content !== false);
|
28
|
+
}
|
29
|
+
|
30
|
+
return {
|
31
|
+
getProxyMeta() {
|
32
|
+
return getContent("meta[name=pv-proxy-endpoint]");
|
33
|
+
},
|
34
|
+
getLocalMeta() {
|
35
|
+
return getContent("meta[name=pv-cache-path]");
|
36
|
+
},
|
37
|
+
hasProxyMeta() {
|
38
|
+
return hasContent("meta[name=pv-proxy-endpoint]");
|
39
|
+
},
|
40
|
+
hasLocalMeta() {
|
41
|
+
return hasContent("meta[name=pv-cache-path]");
|
42
|
+
}
|
43
|
+
};
|
44
|
+
|
45
|
+
}());
|
46
|
+
|
47
|
+
const PvStorage = (function () {
|
48
|
+
const Keys = {
|
49
|
+
KEY_PV: "pv",
|
50
|
+
KEY_PV_SRC: "pv_src",
|
51
|
+
KEY_CREATION: "pv_created_date"
|
52
|
+
};
|
53
|
+
|
54
|
+
const Source = {
|
55
|
+
LOCAL: "same-origin",
|
56
|
+
PROXY: "cors"
|
57
|
+
};
|
58
|
+
|
59
|
+
function get(key) {
|
60
|
+
return localStorage.getItem(key);
|
61
|
+
}
|
62
|
+
|
63
|
+
function set(key, val) {
|
64
|
+
localStorage.setItem(key, val);
|
65
|
+
}
|
66
|
+
|
67
|
+
function saveCache(pv, src) {
|
68
|
+
set(Keys.KEY_PV, pv);
|
69
|
+
set(Keys.KEY_PV_SRC, src);
|
70
|
+
set(Keys.KEY_CREATION, new Date().toJSON());
|
71
|
+
}
|
72
|
+
|
73
|
+
return {
|
74
|
+
keysCount() {
|
75
|
+
return Object.keys(Keys).length;
|
76
|
+
},
|
77
|
+
hasCache() {
|
78
|
+
return (localStorage.getItem(Keys.KEY_PV) !== null);
|
79
|
+
},
|
80
|
+
getCache() {
|
81
|
+
return JSON.parse(localStorage.getItem(Keys.KEY_PV));
|
82
|
+
},
|
83
|
+
saveLocalCache(pv) {
|
84
|
+
saveCache(pv, Source.LOCAL);
|
85
|
+
},
|
86
|
+
saveProxyCache(pv) {
|
87
|
+
saveCache(pv, Source.PROXY);
|
88
|
+
},
|
89
|
+
isExpired() {
|
90
|
+
let date = new Date(get(Keys.KEY_CREATION));
|
91
|
+
date.setHours(date.getHours() + 1); // per hour
|
92
|
+
return Date.now() >= date.getTime();
|
93
|
+
},
|
94
|
+
isFromLocal() {
|
95
|
+
return get(Keys.KEY_PV_SRC) === Source.LOCAL;
|
96
|
+
},
|
97
|
+
isFromProxy() {
|
98
|
+
return get(Keys.KEY_PV_SRC) === Source.PROXY;
|
99
|
+
},
|
100
|
+
newerThan(pv) {
|
101
|
+
return PvStorage.getCache().totalsForAllResults["ga:pageviews"] > pv.totalsForAllResults["ga:pageviews"];
|
102
|
+
},
|
103
|
+
inspectKeys() {
|
104
|
+
if (localStorage.length !== PvStorage.keysCount()) {
|
105
|
+
localStorage.clear();
|
106
|
+
return;
|
107
|
+
}
|
108
|
+
|
109
|
+
for(let i = 0; i < localStorage.length; i++){
|
110
|
+
const key = localStorage.key(i);
|
111
|
+
switch (key) {
|
112
|
+
case Keys.KEY_PV:
|
113
|
+
case Keys.KEY_PV_SRC:
|
114
|
+
case Keys.KEY_CREATION:
|
115
|
+
break;
|
116
|
+
default:
|
117
|
+
localStorage.clear();
|
118
|
+
return;
|
119
|
+
}
|
120
|
+
}
|
121
|
+
}
|
122
|
+
};
|
123
|
+
}()); /* PvStorage */
|
124
|
+
|
125
|
+
function countUp(min, max, destId) {
|
126
|
+
if (min < max) {
|
127
|
+
let numAnim = new CountUp(destId, min, max);
|
128
|
+
if (!numAnim.error) {
|
129
|
+
numAnim.start();
|
130
|
+
} else {
|
131
|
+
console.error(numAnim.error);
|
132
|
+
}
|
133
|
+
}
|
134
|
+
}
|
135
|
+
|
136
|
+
function countPV(path, rows) {
|
137
|
+
let count = 0;
|
138
|
+
|
139
|
+
if (typeof rows !== "undefined" ) {
|
140
|
+
for (let i = 0; i < rows.length; ++i) {
|
141
|
+
const gaPath = rows[parseInt(i, 10)][0];
|
142
|
+
if (gaPath === path) { /* path format see: site.permalink */
|
143
|
+
count += parseInt(rows[parseInt(i, 10)][1], 10);
|
144
|
+
break;
|
145
|
+
}
|
146
|
+
}
|
147
|
+
}
|
148
|
+
|
149
|
+
return count;
|
150
|
+
}
|
151
|
+
|
152
|
+
function tacklePV(rows, path, elem, hasInit) {
|
153
|
+
let count = countPV(path, rows);
|
154
|
+
count = (count === 0 ? 1 : count);
|
155
|
+
|
156
|
+
if (!hasInit) {
|
157
|
+
elem.text(new Intl.NumberFormat().format(count));
|
158
|
+
} else {
|
159
|
+
const initCount = parseInt(elem.text().replace(/,/g, ""), 10);
|
160
|
+
if (count > initCount) {
|
161
|
+
countUp(initCount, count, elem.attr("id"));
|
162
|
+
}
|
163
|
+
}
|
164
|
+
}
|
165
|
+
|
166
|
+
function displayPageviews(data) {
|
167
|
+
if (typeof data === "undefined") {
|
168
|
+
return;
|
169
|
+
}
|
170
|
+
|
171
|
+
let hasInit = getInitStatus();
|
172
|
+
const rows = data.rows; /* could be undefined */
|
173
|
+
|
174
|
+
if ($("#post-list").length > 0) { /* the Home page */
|
175
|
+
$(".post-preview").each(function() {
|
176
|
+
const path = $(this).find("a").attr("href");
|
177
|
+
tacklePV(rows, path, $(this).find(".pageviews"), hasInit);
|
178
|
+
});
|
179
|
+
|
180
|
+
} else if ($(".post").length > 0) { /* the post */
|
181
|
+
const path = window.location.pathname;
|
182
|
+
tacklePV(rows, path, $("#pv"), hasInit);
|
183
|
+
}
|
184
|
+
}
|
185
|
+
|
186
|
+
function fetchProxyPageviews() {
|
187
|
+
if (PvOpts.hasProxyMeta()) {
|
188
|
+
$.ajax({
|
189
|
+
type: "GET",
|
190
|
+
url: PvOpts.getProxyMeta(),
|
191
|
+
dataType: "jsonp",
|
192
|
+
jsonpCallback: "displayPageviews",
|
193
|
+
success: (data) => {
|
194
|
+
PvStorage.saveProxyCache(JSON.stringify(data));
|
195
|
+
},
|
196
|
+
error: (jqXHR, textStatus, errorThrown) => {
|
197
|
+
console.log("Failed to load pageviews from proxy server: " + errorThrown);
|
198
|
+
}
|
199
|
+
});
|
200
|
+
}
|
201
|
+
}
|
202
|
+
|
203
|
+
function fetchLocalPageviews(hasCache = false) {
|
204
|
+
return fetch(PvOpts.getLocalMeta())
|
205
|
+
.then(response => response.json())
|
206
|
+
.then(data => {
|
207
|
+
if (hasCache) {
|
208
|
+
// The cache from the proxy will sometimes be more recent than the local one
|
209
|
+
if (PvStorage.isFromProxy() && PvStorage.newerThan(data)) {
|
210
|
+
return;
|
211
|
+
}
|
212
|
+
}
|
213
|
+
displayPageviews(data);
|
214
|
+
PvStorage.saveLocalCache(JSON.stringify(data));
|
215
|
+
});
|
216
|
+
}
|
217
|
+
|
218
|
+
$(function() {
|
219
|
+
if ($(".pageviews").length <= 0) {
|
220
|
+
return;
|
221
|
+
}
|
222
|
+
|
223
|
+
PvStorage.inspectKeys();
|
224
|
+
|
225
|
+
if (PvStorage.hasCache()) {
|
226
|
+
displayPageviews(PvStorage.getCache());
|
227
|
+
|
228
|
+
if (PvStorage.isExpired()) {
|
229
|
+
if (PvOpts.hasLocalMeta()) {
|
230
|
+
fetchLocalPageviews(true).then(fetchProxyPageviews);
|
231
|
+
} else {
|
232
|
+
fetchProxyPageviews();
|
233
|
+
}
|
234
|
+
|
235
|
+
} else {
|
236
|
+
if (PvStorage.isFromLocal()) {
|
237
|
+
fetchProxyPageviews();
|
238
|
+
}
|
239
|
+
}
|
240
|
+
|
241
|
+
} else { // no cached
|
242
|
+
|
243
|
+
if (PvOpts.hasLocalMeta()) {
|
244
|
+
fetchLocalPageviews().then(fetchProxyPageviews);
|
245
|
+
} else {
|
246
|
+
fetchProxyPageviews();
|
247
|
+
}
|
248
|
+
}
|
249
|
+
|
250
|
+
});
|