🎨 🐛 Rename file & path & remove unused file.
This commit is contained in:
parent
27d3a33222
commit
351d6728d0
@ -25,4 +25,4 @@
|
||||
|
||||
@import 'post';
|
||||
@import 'pages';
|
||||
@import 'third-party';
|
||||
@import '3rd';
|
||||
|
@ -4,6 +4,6 @@ NexT.plugins.others.translate = function() {
|
||||
if (!NexT.utils.checkDOMExist(element)) return;
|
||||
NexT.utils.lazyLoadComponent(element, function() {
|
||||
window.translateelement_styles='/css/google-translate.min.css';
|
||||
NexT.utils.getScript('/js/third-party/google-translate.min.js');
|
||||
NexT.utils.getScript('/js/3rd/google-translate.min.js');
|
||||
});
|
||||
}
|
@ -27,15 +27,15 @@ expired: true
|
||||
|
||||
## 动物
|
||||
|
||||

|
||||

|
||||

|
||||

|
||||

|
||||

|
||||

|
||||

|
||||
|
||||
## 风景
|
||||
|
||||

|
||||

|
||||

|
||||

|
||||

|
||||

|
||||

|
||||

|
||||
|
||||
|
@ -1,6 +1,6 @@
|
||||
{{/* Get third party js plugins resource */}}
|
||||
|
||||
{{ $pluginPath := printf "%s/%s/%s" "js/third-party" .class .plugin }}
|
||||
{{ $pluginPath := printf "%s/%s/%s" "js/3rd" .class .plugin }}
|
||||
{{ $targetPath := printf "js/%s" .plugin }}
|
||||
{{ $plugin := resources.Get $pluginPath | resources.ExecuteAsTemplate $targetPath .ctx }}
|
||||
|
||||
|
@ -4,7 +4,7 @@
|
||||
{{ $router := .Scratch.Get "router" }}
|
||||
|
||||
{{ range $css := $cssRes }}
|
||||
{{ $pluginCss := partial "_funs/get_res.html" (dict "res" . "vendor" $vendor "router" $router) }}
|
||||
{{ $pluginCss := partial "_funs/get_cdn_res.html" (dict "res" . "vendor" $vendor "router" $router) }}
|
||||
<link type="text/css" rel="stylesheet" href="{{ $pluginCss }}" />
|
||||
{{ end }}
|
||||
|
||||
|
@ -3,7 +3,7 @@
|
||||
{{ $vendor := .Site.Params.vendors.plugins }}
|
||||
{{ $router := .Scratch.Get "router" }}
|
||||
{{ range $jsRes }}
|
||||
{{ $pluginJS := partial "_funs/get_res.html" (dict "res" . "vendor" $vendor "router" $router) }}
|
||||
{{ $pluginJS := partial "_funs/get_cdn_res.html" (dict "res" . "vendor" $vendor "router" $router) }}
|
||||
<script type="text/javascript" src="{{ $pluginJS }}" crossorigin="anonymous" defer></script>
|
||||
{{ end }}
|
||||
|
||||
@ -41,18 +41,18 @@
|
||||
|
||||
{{/* Share scripts */}}
|
||||
{{/** if and .Site.Params.share.enable (isset .Site.Params "sharethisid") }}
|
||||
{{ $sharethisjs := resources.Get "js/third-party/share/sharethis.js" }}
|
||||
{{ $sharethisjs := resources.Get "js/3rd/share/sharethis.js" }}
|
||||
{{ $nextjs = $nextjs | append $sharethisjs }}
|
||||
{{ end **/}}
|
||||
|
||||
{{ with .Site.Params.share }}
|
||||
{{ if or .enable .Params.share }}
|
||||
{{ if isset . "sharethis" }}
|
||||
{{ $sharethisjs := resources.Get "js/third-party/share/sharethis.js" }}
|
||||
{{ $sharethisjs := resources.Get "js/3rd/share/sharethis.js" }}
|
||||
{{ $nextjs = $nextjs | append $sharethisjs }}
|
||||
{{ end }}
|
||||
{{ if isset . "addtoany" }}
|
||||
{{ $addtoanyjs := resources.Get "js/third-party/share/addtoany.js" }}
|
||||
{{ $addtoanyjs := resources.Get "js/3rd/share/addtoany.js" }}
|
||||
{{ $nextjs = $nextjs | append $addtoanyjs }}
|
||||
{{ end }}
|
||||
{{ end }}
|
||||
@ -60,53 +60,53 @@
|
||||
|
||||
{{/* Comments scripts */}}
|
||||
{{ if isset .Site.Params "waline" }}
|
||||
{{ $walinejs := resources.Get "js/third-party/comments/waline.js" }}
|
||||
{{ $walinejs := resources.Get "js/3rd/comments/waline.js" }}
|
||||
{{ $nextjs = $nextjs | append $walinejs }}
|
||||
{{ end }}
|
||||
{{ if isset .Site.Params "waline3" }}
|
||||
{{ $walinejs3 := resources.Get "js/third-party/comments/waline3.js" }}
|
||||
{{ $walinejs3 := resources.Get "js/3rd/comments/waline3.js" }}
|
||||
{{ $nextjs = $nextjs | append $walinejs3 }}
|
||||
{{ end }}
|
||||
{{ if or .Site.Params.postMeta.views.enable .Site.Params.postMeta.comments.enable }}
|
||||
{{ $counterjs := resources.Get "js/third-party/others/counter.js" }}
|
||||
{{ $counterjs := resources.Get "js/3rd/others/counter.js" }}
|
||||
{{ $nextjs = $nextjs | append $counterjs }}
|
||||
{{ end }}
|
||||
{{ if isset .Site.Params "giscus" }}
|
||||
{{ $giscusjs := resources.Get "js/third-party/comments/giscus.js" }}
|
||||
{{ $giscusjs := resources.Get "js/3rd/comments/giscus.js" }}
|
||||
{{ $nextjs = $nextjs | append $giscusjs }}
|
||||
{{ end}}
|
||||
{{ if isset .Site.Params "livere" }}
|
||||
{{ $liverejs := resources.Get "js/third-party/comments/livere.js" }}
|
||||
{{ $liverejs := resources.Get "js/3rd/comments/livere.js" }}
|
||||
{{ $nextjs = $nextjs | append $liverejs }}
|
||||
{{ end }}
|
||||
{{ if isset .Site.Params "artalk" }}
|
||||
{{ $artalkjs := resources.Get "js/third-party/comments/artalk.js" }}
|
||||
{{ $artalkjs := resources.Get "js/3rd/comments/artalk.js" }}
|
||||
{{ $nextjs = $nextjs | append $artalkjs }}
|
||||
{{ end }}
|
||||
{{ if isset .Site.Params "utterances" }}
|
||||
{{ $utterancesjs := resources.Get "js/third-party/comments/utterances.js" }}
|
||||
{{ $utterancesjs := resources.Get "js/3rd/comments/utterances.js" }}
|
||||
{{ $nextjs = $nextjs | append $utterancesjs }}
|
||||
{{ end }}
|
||||
|
||||
{{/* Search engin scripts */}}
|
||||
{{ if .Site.Params.localSearch.enable }}
|
||||
{{ $search := resources.Get "js/third-party/search/local.js" }}
|
||||
{{ $search := resources.Get "js/3rd/search/local.js" }}
|
||||
{{ $nextjs = $nextjs | append $search }}
|
||||
{{ end }}
|
||||
{{ if .Site.Params.algoliaSearch.enable }}
|
||||
{{ $search := resources.Get "js/third-party/search/algolia.js" }}
|
||||
{{ $search := resources.Get "js/3rd/search/algolia.js" }}
|
||||
{{ $nextjs = $nextjs | append $search }}
|
||||
{{ end }}
|
||||
|
||||
{{/* Other not useful scripts, eg: 51la widget, translate */}}
|
||||
{{ with .Site.Params.siteState.views }}
|
||||
{{ if and .enable (eq .plugin "51la") }}
|
||||
{{ $lawt := resources.Get "js/third-party/others/lawidget.js" }}
|
||||
{{ $lawt := resources.Get "js/3rd/others/lawidget.js" }}
|
||||
{{ $nextjs = $nextjs | append $lawt }}
|
||||
{{ end }}
|
||||
{{ end }}
|
||||
{{ if .Site.Params.footer.translate }}
|
||||
{{ $translate := resources.Get "js/third-party/others/translate.js" }}
|
||||
{{ $translate := resources.Get "js/3rd/others/translate.js" }}
|
||||
{{ $nextjs = $nextjs | append $translate }}
|
||||
{{ end }}
|
||||
|
||||
|
@ -1,7 +0,0 @@
|
||||
/* global _hmt */
|
||||
|
||||
if (!window._hmt) window._hmt = [];
|
||||
|
||||
document.addEventListener('pjax:success', () => {
|
||||
_hmt.push(['_trackPageview', location.pathname]);
|
||||
});
|
@ -1,35 +0,0 @@
|
||||
/* global CONFIG, dataLayer, gtag */
|
||||
|
||||
if (!CONFIG.google_analytics.only_pageview) {
|
||||
if (CONFIG.hostname === location.hostname) {
|
||||
window.dataLayer = window.dataLayer || [];
|
||||
window.gtag = function() {
|
||||
dataLayer.push(arguments);
|
||||
};
|
||||
gtag('js', new Date());
|
||||
gtag('config', CONFIG.google_analytics.tracking_id);
|
||||
|
||||
document.addEventListener('pjax:success', () => {
|
||||
gtag('event', 'page_view', {
|
||||
page_location: location.href,
|
||||
page_path : location.pathname,
|
||||
page_title : document.title
|
||||
});
|
||||
});
|
||||
}
|
||||
} else {
|
||||
const sendPageView = () => {
|
||||
if (CONFIG.hostname !== location.hostname) return;
|
||||
const uid = localStorage.getItem('uid') || (Math.random() + '.' + Math.random());
|
||||
localStorage.setItem('uid', uid);
|
||||
navigator.sendBeacon('https://www.google-analytics.com/collect', new URLSearchParams({
|
||||
v : 1,
|
||||
tid: CONFIG.google_analytics.tracking_id,
|
||||
cid: uid,
|
||||
t : 'pageview',
|
||||
dp : encodeURIComponent(location.pathname)
|
||||
}));
|
||||
};
|
||||
document.addEventListener('pjax:complete', sendPageView);
|
||||
sendPageView();
|
||||
}
|
10
static/js/third-party/analytics/growingio.js
vendored
10
static/js/third-party/analytics/growingio.js
vendored
@ -1,10 +0,0 @@
|
||||
/* global CONFIG, gio */
|
||||
|
||||
if (!window.gio) {
|
||||
window.gio = function() {
|
||||
(window.gio.q = window.gio.q || []).push(arguments);
|
||||
};
|
||||
}
|
||||
|
||||
gio('init', `${CONFIG.growingio_analytics}`, {});
|
||||
gio('send');
|
19
static/js/third-party/chat/chatra.js
vendored
19
static/js/third-party/chat/chatra.js
vendored
@ -1,19 +0,0 @@
|
||||
/* global CONFIG, Chatra */
|
||||
|
||||
(function() {
|
||||
if (CONFIG.chatra.embed) {
|
||||
window.ChatraSetup = {
|
||||
mode : 'frame',
|
||||
injectTo: CONFIG.chatra.embed
|
||||
};
|
||||
}
|
||||
|
||||
window.ChatraID = CONFIG.chatra.id;
|
||||
|
||||
const chatButton = document.querySelector('.sidebar-button button');
|
||||
if (chatButton) {
|
||||
chatButton.addEventListener('click', () => {
|
||||
Chatra('openChat', true);
|
||||
});
|
||||
}
|
||||
})();
|
5
static/js/third-party/chat/gitter.js
vendored
5
static/js/third-party/chat/gitter.js
vendored
@ -1,5 +0,0 @@
|
||||
/* global CONFIG */
|
||||
|
||||
((window.gitter = {}).chat = {}).options = {
|
||||
room: CONFIG.gitter.room
|
||||
};
|
10
static/js/third-party/chat/tidio.js
vendored
10
static/js/third-party/chat/tidio.js
vendored
@ -1,10 +0,0 @@
|
||||
/* global tidioChatApi */
|
||||
|
||||
(function() {
|
||||
const chatButton = document.querySelector('.sidebar-button button');
|
||||
if (chatButton) {
|
||||
chatButton.addEventListener('click', () => {
|
||||
tidioChatApi.open();
|
||||
});
|
||||
}
|
||||
})();
|
38
static/js/third-party/fancybox.js
vendored
38
static/js/third-party/fancybox.js
vendored
@ -1,38 +0,0 @@
|
||||
document.addEventListener('page:loaded', () => {
|
||||
|
||||
/**
|
||||
* Wrap images with fancybox.
|
||||
*/
|
||||
document.querySelectorAll('.post-body :not(a) > img, .post-body > img').forEach(element => {
|
||||
const $image = $(element);
|
||||
const imageLink = $image.attr('data-src') || $image.attr('src');
|
||||
const $imageWrapLink = $image.wrap(`<a class="fancybox fancybox.image" href="${imageLink}" itemscope itemtype="http://schema.org/ImageObject" itemprop="url"></a>`).parent('a');
|
||||
if ($image.is('.post-gallery img')) {
|
||||
$imageWrapLink.attr('data-fancybox', 'gallery').attr('rel', 'gallery');
|
||||
} else if ($image.is('.group-picture img')) {
|
||||
$imageWrapLink.attr('data-fancybox', 'group').attr('rel', 'group');
|
||||
} else {
|
||||
$imageWrapLink.attr('data-fancybox', 'default').attr('rel', 'default');
|
||||
}
|
||||
|
||||
const imageTitle = $image.attr('title') || $image.attr('alt');
|
||||
if (imageTitle) {
|
||||
// Do not append image-caption if pandoc has already created a figcaption
|
||||
if (!$imageWrapLink.next('figcaption').length) {
|
||||
$imageWrapLink.append(`<p class="image-caption">${imageTitle}</p>`);
|
||||
}
|
||||
// Make sure img title tag will show correctly in fancybox
|
||||
$imageWrapLink.attr('title', imageTitle).attr('data-caption', imageTitle);
|
||||
}
|
||||
});
|
||||
|
||||
$.fancybox.defaults.hash = false;
|
||||
$('.fancybox').fancybox({
|
||||
loop : true,
|
||||
helpers: {
|
||||
overlay: {
|
||||
locked: false
|
||||
}
|
||||
}
|
||||
});
|
||||
});
|
@ -1 +0,0 @@
|
||||
(function(){var gtConstEvalStartTime=new Date();var h=this||self,l=/^[\w+/_-]+[=]{0,2}$/,m=null;function n(a){return(a=a.querySelector&&a.querySelector("script[nonce]"))&&(a=a.nonce||a.getAttribute("nonce"))&&l.test(a)?a:""}function p(a,b){function c(){}c.prototype=b.prototype;a.i=b.prototype;a.prototype=new c;a.prototype.constructor=a;a.h=function(g,f,k){for(var e=Array(arguments.length-2),d=2;d<arguments.length;d++)e[d-2]=arguments[d];return b.prototype[f].apply(g,e)}}function q(a){return a};function r(a){if(Error.captureStackTrace)Error.captureStackTrace(this,r);else{var b=Error().stack;b&&(this.stack=b)}a&&(this.message=String(a))}p(r,Error);r.prototype.name="CustomError";function u(a,b){a=a.split("%s");for(var c="",g=a.length-1,f=0;f<g;f++)c+=a[f]+(f<b.length?b[f]:"%s");r.call(this,c+a[g])}p(u,r);u.prototype.name="AssertionError";function v(a,b){throw new u("Failure"+(a?": "+a:""),Array.prototype.slice.call(arguments,1));};var w;function x(a,b){this.g=b===y?a:""}x.prototype.toString=function(){return this.g+""};var y={};function z(a){var b=document.getElementsByTagName("head")[0];b||(b=document.body.parentNode.appendChild(document.createElement("head")));b.appendChild(a)}function _loadJs(a){var b=document;var c="SCRIPT";"application/xhtml+xml"===b.contentType&&(c=c.toLowerCase());c=b.createElement(c);c.type="text/javascript";c.charset="UTF-8";if(void 0===w){b=null;var g=h.trustedTypes;if(g&&g.createPolicy){try{b=g.createPolicy("goog#html",{createHTML:q,createScript:q,createScriptURL:q})}catch(t){h.console&&h.console.error(t.message)}w=b}else w=b}a=(b=w)?b.createScriptURL(a):a;a=new x(a,y);a:{try{var f=c&&c.ownerDocument,k=f&&(f.defaultView||f.parentWindow);k=k||h;if(k.Element&&k.Location){var e=k;break a}}catch(t){}e=null}if(e&&"undefined"!=typeof e.HTMLScriptElement&&(!c||!(c instanceof e.HTMLScriptElement)&&(c instanceof e.Location||c instanceof e.Element))){e=typeof c;if("object"==e&&null!=c||"function"==e)try{var d=c.constructor.displayName||c.constructor.name||Object.prototype.toString.call(c)}catch(t){d="<object could not be stringified>"}else d=void 0===c?"undefined":null===c?"null":typeof c;v("Argument is not a %s (or a non-Element, non-Location mock); got: %s","HTMLScriptElement",d)}a instanceof x&&a.constructor===x?d=a.g:(d=typeof a,v("expected object of type TrustedResourceUrl, got '"+a+"' of type "+("object"!=d?d:a?Array.isArray(a)?"array":d:"null")),d="type_error:TrustedResourceUrl");c.src=d;(d=c.ownerDocument&&c.ownerDocument.defaultView)&&d!=h?d=n(d.document):(null===m&&(m=n(h.document)),d=m);d&&c.setAttribute("nonce",d);z(c)}function _loadCss(a){var b=document.createElement("link");b.type="text/css";b.rel="stylesheet";b.charset="UTF-8";b.href=a;z(b)}function _isNS(a){a=a.split(".");for(var b=window,c=0;c<a.length;++c)if(!(b=b[a[c]]))return!1;return!0}function _setupNS(a){a=a.split(".");for(var b=window,c=0;c<a.length;++c)b.hasOwnProperty?b.hasOwnProperty(a[c])?b=b[a[c]]:b=b[a[c]]={}:b=b[a[c]]||(b[a[c]]={});return b}window.addEventListener&&"undefined"==typeof document.readyState&&window.addEventListener("DOMContentLoaded",function(){document.readyState="complete"},!1);if(_isNS('google.translate.Element')){return}(function(){var c=_setupNS('google.translate._const');c._cest=gtConstEvalStartTime;gtConstEvalStartTime=undefined;c._cl=navigator.language||navigator.userLanguage;c._cuc='googleTranslateElementInit';c._cac='';c._cam='';c._ctkk='449649.3822363247';var h='translate.googleapis.com';var s=(true?'https':window.location.protocol=='https:'?'https':'http')+'://';var b=s+h;c._pah=h;c._pas=s;c._pbi='';c._pci=b+'/translate_static/img/te_ctrl3.gif';c._pli=b+'/translate_static/img/loading.gif';c._plla=h+'/translate_a/l';c._pmi=b+'/translate_static/img/mini_google.png';c._ps=window.translateelement_styles;c._puh='translate.google.cn';_loadCss(c._ps);_loadJs(b+`/translate_static/js/element/main_${navigator.language||navigator.userLanguage}.js`)})()})();function googleTranslateElementInit(){new google.translate.TranslateElement({includedLanguages:'zh-CN,zh-TW,en,ru',autoDisplay:false},'google_translate_element')}
|
7
static/js/third-party/math/katex.js
vendored
7
static/js/third-party/math/katex.js
vendored
@ -1,7 +0,0 @@
|
||||
/* global NexT, CONFIG */
|
||||
|
||||
document.addEventListener('page:loaded', () => {
|
||||
if (!CONFIG.enableMath) return;
|
||||
|
||||
NexT.utils.getScript(CONFIG.katex.copy_tex_js).catch(() => {});
|
||||
});
|
36
static/js/third-party/math/mathjax.js
vendored
36
static/js/third-party/math/mathjax.js
vendored
@ -1,36 +0,0 @@
|
||||
/* global NexT, CONFIG, MathJax */
|
||||
|
||||
document.addEventListener('page:loaded', () => {
|
||||
if (!CONFIG.enableMath) return;
|
||||
|
||||
if (typeof MathJax === 'undefined') {
|
||||
window.MathJax = {
|
||||
tex: {
|
||||
inlineMath: { '[+]': [['$', '$']] },
|
||||
tags : CONFIG.mathjax.tags
|
||||
},
|
||||
options: {
|
||||
renderActions: {
|
||||
insertedScript: [200, () => {
|
||||
document.querySelectorAll('mjx-container').forEach(node => {
|
||||
const target = node.parentNode;
|
||||
if (target.nodeName.toLowerCase() === 'li') {
|
||||
target.parentNode.classList.add('has-jax');
|
||||
}
|
||||
});
|
||||
}, '', false]
|
||||
}
|
||||
}
|
||||
};
|
||||
NexT.utils.getScript(CONFIG.mathjax.js, {
|
||||
attributes: {
|
||||
defer: true
|
||||
}
|
||||
});
|
||||
} else {
|
||||
MathJax.startup.document.state(0);
|
||||
MathJax.typesetClear();
|
||||
MathJax.texReset();
|
||||
MathJax.typesetPromise();
|
||||
}
|
||||
});
|
7
static/js/third-party/pace.js
vendored
7
static/js/third-party/pace.js
vendored
@ -1,7 +0,0 @@
|
||||
/* global Pace */
|
||||
|
||||
Pace.options.restartOnPushState = false;
|
||||
|
||||
document.addEventListener('pjax:send', () => {
|
||||
Pace.restart();
|
||||
});
|
37
static/js/third-party/quicklink.js
vendored
37
static/js/third-party/quicklink.js
vendored
@ -1,37 +0,0 @@
|
||||
/* global CONFIG, quicklink */
|
||||
|
||||
(function() {
|
||||
if (typeof CONFIG.quicklink.ignores === 'string') {
|
||||
const ignoresStr = `[${CONFIG.quicklink.ignores}]`;
|
||||
CONFIG.quicklink.ignores = JSON.parse(ignoresStr);
|
||||
}
|
||||
|
||||
let resetFn = null;
|
||||
|
||||
const onRefresh = () => {
|
||||
if (resetFn) resetFn();
|
||||
if (!CONFIG.quicklink.enable) return;
|
||||
|
||||
let ignoresArr = CONFIG.quicklink.ignores || [];
|
||||
if (!Array.isArray(ignoresArr)) {
|
||||
ignoresArr = [ignoresArr];
|
||||
}
|
||||
|
||||
resetFn = quicklink.listen({
|
||||
timeout : CONFIG.quicklink.timeout,
|
||||
priority: CONFIG.quicklink.priority,
|
||||
ignores : [
|
||||
uri => uri.includes('#'),
|
||||
uri => uri === CONFIG.quicklink.url,
|
||||
...ignoresArr
|
||||
]
|
||||
});
|
||||
};
|
||||
|
||||
if (CONFIG.quicklink.delay) {
|
||||
window.addEventListener('load', onRefresh);
|
||||
document.addEventListener('pjax:success', onRefresh);
|
||||
} else {
|
||||
document.addEventListener('page:loaded', onRefresh);
|
||||
}
|
||||
})();
|
22
static/js/third-party/rating.js
vendored
22
static/js/third-party/rating.js
vendored
@ -1,22 +0,0 @@
|
||||
/* global CONFIG, WPac */
|
||||
|
||||
(function() {
|
||||
const widgets = [{
|
||||
widget: 'Rating',
|
||||
id : CONFIG.rating.id,
|
||||
el : 'wpac-rating',
|
||||
color : CONFIG.rating.color
|
||||
}];
|
||||
|
||||
document.addEventListener('page:loaded', () => {
|
||||
if (!CONFIG.page.isPost) return;
|
||||
|
||||
const newWidgets = widgets.map(widget => ({ ...widget }));
|
||||
|
||||
if (window.WPac) {
|
||||
WPac.init(newWidgets);
|
||||
} else {
|
||||
window.wpac_init = newWidgets;
|
||||
}
|
||||
});
|
||||
})();
|
64
static/js/third-party/statistics/firestore.js
vendored
64
static/js/third-party/statistics/firestore.js
vendored
@ -1,64 +0,0 @@
|
||||
/* global CONFIG, firebase */
|
||||
|
||||
firebase.initializeApp({
|
||||
apiKey : CONFIG.firestore.apiKey,
|
||||
projectId: CONFIG.firestore.projectId
|
||||
});
|
||||
|
||||
(function() {
|
||||
const getCount = (doc, increaseCount) => {
|
||||
// IncreaseCount will be false when not in article page
|
||||
return doc.get().then(d => {
|
||||
// Has no data, initialize count
|
||||
let count = d.exists ? d.data().count : 0;
|
||||
// If first view this article
|
||||
if (increaseCount) {
|
||||
// Increase count
|
||||
count++;
|
||||
doc.set({
|
||||
count
|
||||
});
|
||||
}
|
||||
return count;
|
||||
});
|
||||
};
|
||||
|
||||
const appendCountTo = el => {
|
||||
return count => {
|
||||
el.innerText = count;
|
||||
};
|
||||
};
|
||||
|
||||
const db = firebase.firestore();
|
||||
const articles = db.collection(CONFIG.firestore.collection);
|
||||
|
||||
document.addEventListener('page:loaded', () => {
|
||||
|
||||
if (CONFIG.page.isPost) {
|
||||
// Fix issue #118
|
||||
// https://developer.mozilla.org/en-US/docs/Web/API/Node/textContent
|
||||
const title = document.querySelector('.post-title').textContent.trim();
|
||||
const doc = articles.doc(title);
|
||||
let increaseCount = CONFIG.hostname === location.hostname;
|
||||
if (localStorage.getItem(title)) {
|
||||
increaseCount = false;
|
||||
} else {
|
||||
// Mark as visited
|
||||
localStorage.setItem(title, true);
|
||||
}
|
||||
getCount(doc, increaseCount).then(appendCountTo(document.querySelector('.firestore-visitors-count')));
|
||||
} else if (CONFIG.page.isHome) {
|
||||
const promises = [...document.querySelectorAll('.post-title')].map(element => {
|
||||
const title = element.textContent.trim();
|
||||
const doc = articles.doc(title);
|
||||
return getCount(doc);
|
||||
});
|
||||
Promise.all(promises).then(counts => {
|
||||
const metas = document.querySelectorAll('.firestore-visitors-count');
|
||||
counts.forEach((val, idx) => {
|
||||
appendCountTo(metas[idx])(val);
|
||||
});
|
||||
});
|
||||
}
|
||||
});
|
||||
})();
|
102
static/js/third-party/statistics/lean-analytics.js
vendored
102
static/js/third-party/statistics/lean-analytics.js
vendored
@ -1,102 +0,0 @@
|
||||
/* global CONFIG */
|
||||
/* eslint-disable no-console */
|
||||
|
||||
(function() {
|
||||
const leancloudSelector = url => {
|
||||
url = encodeURI(url);
|
||||
return document.getElementById(url).querySelector('.leancloud-visitors-count');
|
||||
};
|
||||
|
||||
const addCount = Counter => {
|
||||
const visitors = document.querySelector('.leancloud_visitors');
|
||||
const url = decodeURI(visitors.id);
|
||||
const title = visitors.dataset.flagTitle;
|
||||
|
||||
Counter('get', `/classes/Counter?where=${encodeURIComponent(JSON.stringify({ url }))}`)
|
||||
.then(response => response.json())
|
||||
.then(({ results }) => {
|
||||
if (results.length > 0) {
|
||||
const counter = results[0];
|
||||
leancloudSelector(url).innerText = counter.time + 1;
|
||||
Counter('put', '/classes/Counter/' + counter.objectId, {
|
||||
time: {
|
||||
'__op' : 'Increment',
|
||||
'amount': 1
|
||||
}
|
||||
})
|
||||
.catch(error => {
|
||||
console.error('Failed to save visitor count', error);
|
||||
});
|
||||
} else if (CONFIG.leancloud_visitors.security) {
|
||||
leancloudSelector(url).innerText = 'Counter not initialized! More info at console err msg.';
|
||||
console.error('ATTENTION! LeanCloud counter has security bug, see how to solve it here: https://github.com/theme-next/hexo-leancloud-counter-security. \n However, you can still use LeanCloud without security, by setting `security` option to `false`.');
|
||||
} else {
|
||||
Counter('post', '/classes/Counter', { title, url, time: 1 })
|
||||
.then(response => response.json())
|
||||
.then(() => {
|
||||
leancloudSelector(url).innerText = 1;
|
||||
})
|
||||
.catch(error => {
|
||||
console.error('Failed to create', error);
|
||||
});
|
||||
}
|
||||
})
|
||||
.catch(error => {
|
||||
console.error('LeanCloud Counter Error', error);
|
||||
});
|
||||
};
|
||||
|
||||
const showTime = Counter => {
|
||||
const visitors = document.querySelectorAll('.leancloud_visitors');
|
||||
const entries = [...visitors].map(element => {
|
||||
return decodeURI(element.id);
|
||||
});
|
||||
|
||||
Counter('get', `/classes/Counter?where=${encodeURIComponent(JSON.stringify({ url: { '$in': entries } }))}`)
|
||||
.then(response => response.json())
|
||||
.then(({ results }) => {
|
||||
for (const url of entries) {
|
||||
const target = results.find(item => item.url === url);
|
||||
leancloudSelector(url).innerText = target ? target.time : 0;
|
||||
}
|
||||
})
|
||||
.catch(error => {
|
||||
console.error('LeanCloud Counter Error', error);
|
||||
});
|
||||
};
|
||||
|
||||
const { app_id, app_key, server_url } = CONFIG.leancloud_visitors;
|
||||
const fetchData = api_server => {
|
||||
const Counter = (method, url, data) => {
|
||||
return fetch(`${api_server}/1.1${url}`, {
|
||||
method,
|
||||
headers: {
|
||||
'X-LC-Id' : app_id,
|
||||
'X-LC-Key' : app_key,
|
||||
'Content-Type': 'application/json'
|
||||
},
|
||||
body: JSON.stringify(data)
|
||||
});
|
||||
};
|
||||
if (CONFIG.page.isPost) {
|
||||
if (CONFIG.hostname !== location.hostname) return;
|
||||
addCount(Counter);
|
||||
} else if (document.querySelectorAll('.post-title-link').length >= 1) {
|
||||
showTime(Counter);
|
||||
}
|
||||
};
|
||||
|
||||
const api_server = app_id.slice(-9) === '-MdYXbMMI' ? `https://${app_id.slice(0, 8).toLowerCase()}.api.lncldglobal.com` : server_url;
|
||||
|
||||
document.addEventListener('page:loaded', () => {
|
||||
if (api_server) {
|
||||
fetchData(api_server);
|
||||
} else {
|
||||
fetch(`https://app-router.leancloud.cn/2/route?appId=${app_id}`)
|
||||
.then(response => response.json())
|
||||
.then(({ api_server }) => {
|
||||
fetchData(`https://${api_server}`);
|
||||
});
|
||||
}
|
||||
});
|
||||
})();
|
32
static/js/third-party/tags/mermaid.js
vendored
32
static/js/third-party/tags/mermaid.js
vendored
@ -1,32 +0,0 @@
|
||||
/* global NexT, CONFIG, mermaid */
|
||||
|
||||
document.addEventListener('page:loaded', () => {
|
||||
const mermaidElements = document.querySelectorAll('.mermaid');
|
||||
if (mermaidElements.length) {
|
||||
NexT.utils.getScript(CONFIG.mermaid.js, {
|
||||
condition: window.mermaid
|
||||
}).then(() => {
|
||||
mermaidElements.forEach(element => {
|
||||
const newElement = document.createElement('div');
|
||||
newElement.innerHTML = element.innerHTML;
|
||||
newElement.className = element.className;
|
||||
const parent = element.parentNode;
|
||||
// Fix issue #347
|
||||
// Support mermaid inside backtick code block
|
||||
if (parent.matches('pre')) {
|
||||
parent.parentNode.replaceChild(newElement, parent);
|
||||
} else {
|
||||
parent.replaceChild(newElement, element);
|
||||
}
|
||||
});
|
||||
mermaid.initialize({
|
||||
theme : CONFIG.darkmode && window.matchMedia('(prefers-color-scheme: dark)').matches ? CONFIG.mermaid.theme.dark : CONFIG.mermaid.theme.light,
|
||||
logLevel : 4,
|
||||
flowchart: { curve: 'linear' },
|
||||
gantt : { axisFormat: '%m/%d/%Y' },
|
||||
sequence : { actorMargin: 50 }
|
||||
});
|
||||
mermaid.init();
|
||||
});
|
||||
}
|
||||
});
|
23
static/js/third-party/tags/pdf.js
vendored
23
static/js/third-party/tags/pdf.js
vendored
@ -1,23 +0,0 @@
|
||||
/* global NexT, CONFIG, PDFObject */
|
||||
|
||||
document.addEventListener('page:loaded', () => {
|
||||
if (document.querySelectorAll('.pdf-container').length) {
|
||||
NexT.utils.getScript(CONFIG.pdf.object_url, {
|
||||
condition: window.PDFObject
|
||||
}).then(() => {
|
||||
document.querySelectorAll('.pdf-container').forEach(element => {
|
||||
PDFObject.embed(element.dataset.target, element, {
|
||||
pdfOpenParams: {
|
||||
navpanes : 0,
|
||||
toolbar : 0,
|
||||
statusbar: 0,
|
||||
pagemode : 'thumbs',
|
||||
view : 'FitH'
|
||||
},
|
||||
PDFJS_URL: CONFIG.pdf.url,
|
||||
height : element.dataset.height
|
||||
});
|
||||
});
|
||||
});
|
||||
}
|
||||
});
|
Loading…
Reference in New Issue
Block a user