diff --git a/assets/js/bookmark.js b/assets/js/bookmark.js index 8e3ae6a..add30fd 100644 --- a/assets/js/bookmark.js +++ b/assets/js/bookmark.js @@ -52,5 +52,5 @@ document.addEventListener('DOMContentLoaded', () => { document.addEventListener('pjax:success', scrollToMark); }; - init(CONFIG.bookmark.save); + init(NexT.CONFIG.bookmark.save); }); diff --git a/assets/js/comments-buttons.js b/assets/js/comments-buttons.js index 505c21b..8a01a1d 100644 --- a/assets/js/comments-buttons.js +++ b/assets/js/comments-buttons.js @@ -7,13 +7,13 @@ element.addEventListener('click', () => { commentButton.forEach(active => active.classList.toggle('active', active === element)); document.querySelectorAll('.comment-position').forEach(active => active.classList.toggle('active', active.classList.contains(commentClass))); - if (CONFIG.comments.storage) { + if (NexT.CONFIG.comments.storage) { localStorage.setItem('comments_active', commentClass); } }); }); - let { activeClass } = CONFIG.comments; - if (CONFIG.comments.storage) { + let { activeClass } = NexT.CONFIG.comments; + if (NexT.CONFIG.comments.storage) { activeClass = localStorage.getItem('comments_active') || activeClass; } if (activeClass) { diff --git a/assets/js/comments.js b/assets/js/comments.js index 4045e8c..05666c6 100644 --- a/assets/js/comments.js +++ b/assets/js/comments.js @@ -1,8 +1,8 @@ /* global CONFIG */ window.addEventListener('tabs:register', () => { - let { activeClass } = CONFIG.comments; - if (CONFIG.comments.storage) { + let { activeClass } = NexT.CONFIG.comments; + if (NexT.CONFIG.comments.storage) { activeClass = localStorage.getItem('comments_active') || activeClass; } if (activeClass) { @@ -12,7 +12,7 @@ window.addEventListener('tabs:register', () => { } } }); -if (CONFIG.comments.storage) { +if (NexT.CONFIG.comments.storage) { window.addEventListener('tabs:click', event => { if (!event.target.matches('.tabs-comment .tab-content .tab-pane')) return; const commentClass = event.target.classList[1]; diff --git a/assets/js/config.js b/assets/js/config.js index cde3ea8..ada03fb 100644 --- a/assets/js/config.js +++ b/assets/js/config.js @@ -5,6 +5,10 @@ if (!window.NexT) window.NexT = {}; const siteConfig = { "hostname" : "{{ .Site.BaseURL }}", "root" : "/", + "vendor" : { + "plugins" : "{{ .Site.Params.vendors.plugins }}", + "router" : "{{ .Scratch.Get "router" }}" + }, "images" : "{{ .Site.Params.images }}", "scheme" : "{{ .Site.Params.scheme }}", "darkmode" : {{ .Site.Params.darkmode }}, @@ -39,6 +43,43 @@ if (!window.NexT) window.NexT = {}; "path" : "/search.json", "localsearch": {{ .Site.Params.localSearch | jsonify }}, {{- end }} + {{- with .Site.Params.waline }} + "waline" : { + "js" : {{ $.Site.Data.resources.waline.js | jsonify }}, + "css" : {{ $.Site.Data.resources.waline.css | jsonify }}, + "config" : {{ . | jsonify }} + }, + {{- end }} + {{- with .Site.Params.artalk }} + "artalk" : { + "js" : {{ $.Site.Data.resources.artalk.js | jsonify }}, + "css" : {{ $.Site.Data.resources.artalk.css | jsonify }}, + "config" : {{ . | jsonify }} + }, + {{- end }} + {{- with .Site.Params.giscus }} + "giscus" : { + "js" : "{{ $.Site.Data.resources.giscus.js }}", + "config" : {{ . | jsonify }} + }, + {{- end }} + {{- with .Site.Params.livere }} + "livere" : { + "js" : "{{ $.Site.Data.resources.livere.js }}" + }, + {{- end }} + {{- with .Site.Params.utterances }} + "utterances" : { + "js" : "{{ $.Site.Data.resources.utterances.js }}", + "config" : {{ . | jsonify }} + }, + {{- end }} + {{- with .Site.Params.addThisId }} + "addthis" : { + "js" : "{{ $.Site.Data.resources.addthis.js }}", + "config" : { "pubid" : "{{ . }}" } + }, + {{- end }} "lang" : "{{ .Site.LanguageCode }}", "permalink" : "{{ .Page.Permalink | absURL }}", "title" : "{{ .Page.Title }}", @@ -46,6 +87,6 @@ if (!window.NexT) window.NexT = {}; "isPage" : {{ .IsPage }} }; - window.CONFIG = new Proxy(siteConfig, {}); + window.NexT.CONFIG = new Proxy(siteConfig, {}); })(); \ No newline at end of file diff --git a/assets/js/motion.js b/assets/js/motion.js index f98867e..b13725d 100644 --- a/assets/js/motion.js +++ b/assets/js/motion.js @@ -10,12 +10,12 @@ NexT.motion.integrator = { }, add: function(fn) { const sequence = fn(); - if (CONFIG.motion.async) this.queue.push(sequence); + if (NexT.CONFIG.motion.async) this.queue.push(sequence); else this.queue = this.queue.concat(sequence); return this; }, bootstrap: function() { - if (!CONFIG.motion.async) this.queue = [this.queue]; + if (!NexT.CONFIG.motion.async) this.queue = [this.queue]; this.queue.forEach(sequence => { const timeline = window.anime.timeline({ duration: 200, @@ -52,12 +52,12 @@ NexT.motion.middleWares = { } pushToSequence('header.header'); - CONFIG.scheme === 'Mist' && getMistLineSettings('.logo-line'); - CONFIG.scheme === 'Muse' && pushToSequence('.custom-logo-image'); + NexT.CONFIG.scheme === 'Mist' && getMistLineSettings('.logo-line'); + NexT.CONFIG.scheme === 'Muse' && pushToSequence('.custom-logo-image'); pushToSequence('.site-title'); pushToSequence('.site-brand-container .toggle', true); pushToSequence('.site-subtitle'); - (CONFIG.scheme === 'Pisces' || CONFIG.scheme === 'Gemini') && pushToSequence('.custom-logo-image'); + (NexT.CONFIG.scheme === 'Pisces' || NexT.CONFIG.scheme === 'Gemini') && pushToSequence('.custom-logo-image'); document.querySelectorAll('.menu-item').forEach(targets => { sequence.push({ @@ -82,7 +82,7 @@ NexT.motion.middleWares = { postList: function() { const sequence = []; - const { postblock, postheader, postbody, collheader } = CONFIG.motion.transition; + const { postblock, postheader, postbody, collheader } = NexT.CONFIG.motion.transition; function animate(animation, selector) { if (!animation) return; @@ -105,9 +105,9 @@ NexT.motion.middleWares = { sidebar: function() { const sidebar = document.querySelector('.sidebar'); - const sidebarTransition = CONFIG.motion.transition.sidebar; + const sidebarTransition = NexT.CONFIG.motion.transition.sidebar; // Only for Pisces | Gemini. - if (sidebarTransition && (CONFIG.scheme === 'Pisces' || CONFIG.scheme === 'Gemini')) { + if (sidebarTransition && (NexT.CONFIG.scheme === 'Pisces' || NexT.CONFIG.scheme === 'Gemini')) { return [{ targets : sidebar, complete: () => sidebar.classList.add('animated', sidebarTransition) diff --git a/assets/js/next-boot.js b/assets/js/next-boot.js index 66bb821..1eb0443 100644 --- a/assets/js/next-boot.js +++ b/assets/js/next-boot.js @@ -4,8 +4,8 @@ NexT.boot = {}; NexT.boot.registerEvents = function() { - NexT.utils.registerScrollPercent(); - NexT.utils.registerCanIUseTag(); + // NexT.utils.registerScrollPercent(); + // NexT.utils.registerCanIUseTag(); // Mobile top menu bar. document.querySelector('.site-nav-toggle .toggle').addEventListener('click', event => { @@ -33,33 +33,35 @@ NexT.boot.registerEvents = function() { NexT.boot.refresh = function() { + if (!NexT.CONFIG.isPage) return; /** * Register JS handlers by condition option. * Need to add config option in Front-End at 'scripts/helpers/next-config.js' file. */ - //CONFIG.prism && window.Prism.highlightAll(); - /*CONFIG.mediumzoom && window.mediumZoom('.post-body :not(a) > img, .post-body > img', { + //NexT.CONFIG.prism && window.Prism.highlightAll(); + /*NexT.CONFIG.mediumzoom && window.mediumZoom('.post-body :not(a) > img, .post-body > img', { background: 'var(--content-bg-color)' });*/ - CONFIG.lazyload && window.lozad('.post-body img').observe(); - CONFIG.pangu && window.pangu.spacingPage(); + // NexT.CONFIG.lazyload && window.lozad('.post-body img').observe(); + // NexT.CONFIG.pangu && window.pangu.spacingPage(); - CONFIG.isPage && NexT.utils.replacePostCRLink(); - CONFIG.isPage && CONFIG.copybtn && NexT.utils.registerCopyCode(); - NexT.utils.registerTabsTag(); - /*NexT.utils.registerActiveMenuItem(); + NexT.utils.replacePostCRLink(); + NexT.utils.initCommontesDispaly(); + NexT.CONFIG.copybtn && NexT.utils.registerCopyCode(); + /*NexT.utils.registerTabsTag(); + NexT.utils.registerActiveMenuItem(); NexT.utils.registerLangSelect();*/ - CONFIG.isPage && NexT.utils.registerSidebarTOC(); - CONFIG.isPage && NexT.utils.registerPostReward(); - CONFIG.isPage && NexT.utils.initCommontesDispaly(); - CONFIG.isPage && NexT.utils.registerCommonSwitch(); - NexT.utils.wrapTableWithBox(); - NexT.utils.registerVideoIframe(); + NexT.utils.registerSidebarTOC(); + NexT.utils.registerPostReward(); + NexT.utils.registerCommonSwitch(); + /*NexT.utils.wrapTableWithBox(); + NexT.utils.registerVideoIframe();*/ + }; NexT.boot.motion = function() { // Define Motion Sequence & Bootstrap Motion. - if (CONFIG.motion.enable) { + if (NexT.CONFIG.motion.enable) { NexT.motion.integrator .add(NexT.motion.middleWares.header) .add(NexT.motion.middleWares.postList) @@ -72,6 +74,6 @@ NexT.boot.motion = function() { document.addEventListener('DOMContentLoaded', () => { NexT.boot.registerEvents(); - NexT.boot.refresh(); NexT.boot.motion(); + NexT.boot.refresh(); }); diff --git a/assets/js/pjax.js b/assets/js/pjax.js index da61136..8813925 100644 --- a/assets/js/pjax.js +++ b/assets/js/pjax.js @@ -11,21 +11,21 @@ const pjax = new Pjax({ ], analytics: false, cacheBust: false, - scrollTo : !CONFIG.bookmark.enable + scrollTo : !NexT.CONFIG.bookmark.enable }); document.addEventListener('pjax:success', () => { pjax.executeScripts(document.querySelectorAll('script[data-pjax]')); NexT.boot.refresh(); // Define Motion Sequence & Bootstrap Motion. - if (CONFIG.motion.enable) { + if (NexT.CONFIG.motion.enable) { NexT.motion.integrator .init() .add(NexT.motion.middleWares.subMenu) .add(NexT.motion.middleWares.postList) .bootstrap(); } - if (CONFIG.sidebar.display !== 'remove') { + if (NexT.CONFIG.sidebar.display !== 'remove') { const hasTOC = document.querySelector('.post-toc'); document.querySelector('.sidebar-inner').classList.toggle('sidebar-nav-active', hasTOC); NexT.utils.activateSidebarPanel(hasTOC ? 0 : 1); diff --git a/assets/js/schemes/muse.js b/assets/js/schemes/muse.js index ae5addb..9d8b291 100644 --- a/assets/js/schemes/muse.js +++ b/assets/js/schemes/muse.js @@ -2,7 +2,7 @@ document.addEventListener('DOMContentLoaded', () => { - const isRight = CONFIG.sidebar.position === 'right'; + const isRight = NexT.CONFIG.sidebar.position === 'right'; const sidebarToggleMotion = { mouse: {}, @@ -46,7 +46,7 @@ document.addEventListener('DOMContentLoaded', () => { document.body.classList.remove('sidebar-active'); } }; - if (CONFIG.sidebar.display !== 'remove') sidebarToggleMotion.init(); + if (NexT.CONFIG.sidebar.display !== 'remove') sidebarToggleMotion.init(); function updateFooterPosition() { const footer = document.querySelector('.footer'); diff --git a/assets/js/third-party/comments/artalk.js b/assets/js/third-party/comments/artalk.js new file mode 100644 index 0000000..a037939 --- /dev/null +++ b/assets/js/third-party/comments/artalk.js @@ -0,0 +1,36 @@ +document.addEventListener('DOMContentLoaded', () => { + + const element = '.artalk-container'; + if (!NexT.CONFIG.comments.enable + || !NexT.CONFIG.artalk + || !NexT.utils.checkDOMExist(element)) return; + + const artalk_css = NexT.utils.getCDNResource(NexT.CONFIG.artalk.css); + NexT.utils.getStyle(artalk_css, null); + + const artalk_js = NexT.utils.getCDNResource(NexT.CONFIG.artalk.js); + const { + site, + placeholder, + server, + } = NexT.CONFIG.artalk.config; + + NexT.utils.loadComments(element) + .then(() => NexT.utils.getScript(artalk_js, { + })) + .then(() => { + + new Artalk({ + el : element, + pageKey : NexT.CONFIG.permalink, + pageTitle : NexT.CONFIG.title, + server : server, + site : site, + locale : NexT.CONFIG.lang, + placeholder : placeholder, + darkMode : 'auto' + }); + + NexT.utils.hiddeLodingCmp(element); + }); +}); \ No newline at end of file diff --git a/assets/js/third-party/comments/changyan.js b/assets/js/third-party/comments/changyan.js deleted file mode 100644 index 18a1be4..0000000 --- a/assets/js/third-party/comments/changyan.js +++ /dev/null @@ -1,39 +0,0 @@ -/* global NexT, CONFIG */ - -document.addEventListener('page:loaded', () => { - const { appid, appkey } = CONFIG.changyan; - const mainJs = 'https://cy-cdn.kuaizhan.com/upload/changyan.js'; - const countJs = `https://cy-cdn.kuaizhan.com/upload/plugins/plugins.list.count.js?clientId=${appid}`; - - // Get the number of comments - setTimeout(() => { - return NexT.utils.getScript(countJs, { - attributes: { - async: true, - id : 'cy_cmt_num' - } - }); - }, 0); - - // When scroll to comment section - if (CONFIG.page.comments && !CONFIG.page.isHome) { - NexT.utils.loadComments('#SOHUCS') - .then(() => { - return NexT.utils.getScript(mainJs, { - attributes: { - async: true - } - }); - }) - .then(() => { - window.changyan.api.config({ - appid, - conf: appkey - }); - }) - .catch(error => { - // eslint-disable-next-line no-console - console.error('Failed to load Changyan', error); - }); - } -}); diff --git a/assets/js/third-party/comments/disqus.js b/assets/js/third-party/comments/disqus.js deleted file mode 100644 index 381c26f..0000000 --- a/assets/js/third-party/comments/disqus.js +++ /dev/null @@ -1,41 +0,0 @@ -/* global NexT, CONFIG, DISQUS */ - -document.addEventListener('page:loaded', () => { - - if (CONFIG.disqus.count) { - const loadCount = () => { - NexT.utils.getScript(`https://${CONFIG.disqus.shortname}.disqus.com/count.js`, { - attributes: { id: 'dsq-count-scr' } - }); - }; - - // defer loading until the whole page loading is completed - window.addEventListener('load', loadCount, false); - } - - if (CONFIG.page.comments) { - // `disqus_config` should be a global variable - // See https://help.disqus.com/en/articles/1717084-javascript-configuration-variables - window.disqus_config = function() { - this.page.url = CONFIG.page.permalink; - this.page.identifier = CONFIG.page.path; - this.page.title = CONFIG.page.title; - if (CONFIG.disqus.i18n.disqus !== 'disqus') { - this.language = CONFIG.disqus.i18n.disqus; - } - }; - NexT.utils.loadComments('#disqus_thread').then(() => { - if (window.DISQUS) { - DISQUS.reset({ - reload: true, - config: window.disqus_config - }); - } else { - NexT.utils.getScript(`https://${CONFIG.disqus.shortname}.disqus.com/embed.js`, { - attributes: { dataset: { timestamp: '' + +new Date() } } - }); - } - }); - } - -}); diff --git a/assets/js/third-party/comments/disqusjs.js b/assets/js/third-party/comments/disqusjs.js deleted file mode 100644 index df5f36c..0000000 --- a/assets/js/third-party/comments/disqusjs.js +++ /dev/null @@ -1,18 +0,0 @@ -/* global NexT, CONFIG, DisqusJS */ - -document.addEventListener('page:loaded', () => { - if (!CONFIG.page.comments) return; - - NexT.utils.loadComments('#disqus_thread') - .then(() => NexT.utils.getScript(CONFIG.disqusjs.js, { condition: window.DisqusJS })) - .then(() => { - window.dsqjs = new DisqusJS({ - api : CONFIG.disqusjs.api || 'https://disqus.com/api/', - apikey : CONFIG.disqusjs.apikey, - shortname : CONFIG.disqusjs.shortname, - url : CONFIG.page.permalink, - identifier: CONFIG.page.path, - title : CONFIG.page.title - }); - }); -}); diff --git a/assets/js/third-party/comments/giscus.js b/assets/js/third-party/comments/giscus.js new file mode 100644 index 0000000..18c1995 --- /dev/null +++ b/assets/js/third-party/comments/giscus.js @@ -0,0 +1,41 @@ +document.addEventListener('DOMContentLoaded', () => { + + const element = '.giscus-container'; + if (!NexT.CONFIG.comments.enable + || !NexT.CONFIG.giscus + || !NexT.utils.checkDOMExist(element)) return; + + const { + category, + categoryid, + emit, + inputposition, + mapping, + reactions, + repo, + repoid, + theme } = NexT.CONFIG.giscus.config; + + + NexT.utils.loadComments(element) + .then(() => NexT.utils.getScript(NexT.CONFIG.giscus.js, { + attributes: { + 'async' : true, + 'crossorigin' : 'anonymous', + 'data-repo' : repo, + 'data-repo-id' : repoid, + 'data-category' : category, + 'data-category-id' : categoryid, + 'data-mapping' : mapping, + 'data-reactions-enabled' : reactions ? 1:0, + 'data-emit-metadata' : emit ? 1:0, + 'data-input-position' : inputposition, + 'data-theme' : theme, + 'data-lang' : NexT.CONFIG.lang, + 'data-loading' : 'lazy' + }, + parentNode: document.querySelector(element) + })); + + NexT.utils.hiddeLodingCmp(element); +}); \ No newline at end of file diff --git a/assets/js/third-party/comments/gitalk.js b/assets/js/third-party/comments/gitalk.js deleted file mode 100644 index 08d07f4..0000000 --- a/assets/js/third-party/comments/gitalk.js +++ /dev/null @@ -1,24 +0,0 @@ -/* global NexT, CONFIG, Gitalk */ - -document.addEventListener('page:loaded', () => { - if (!CONFIG.page.comments) return; - - NexT.utils.loadComments('.gitalk-container') - .then(() => NexT.utils.getScript(CONFIG.gitalk.js, { - condition: window.Gitalk - })) - .then(() => { - const gitalk = new Gitalk({ - clientID : CONFIG.gitalk.client_id, - clientSecret : CONFIG.gitalk.client_secret, - repo : CONFIG.gitalk.repo, - owner : CONFIG.gitalk.github_id, - admin : [CONFIG.gitalk.admin_user], - id : CONFIG.gitalk.path_md5, - proxy : CONFIG.gitalk.proxy, - language : CONFIG.gitalk.language || window.navigator.language, - distractionFreeMode: CONFIG.gitalk.distraction_free_mode - }); - gitalk.render(document.querySelector('.gitalk-container')); - }); -}); diff --git a/assets/js/third-party/comments/isso.js b/assets/js/third-party/comments/isso.js deleted file mode 100644 index 2c70601..0000000 --- a/assets/js/third-party/comments/isso.js +++ /dev/null @@ -1,15 +0,0 @@ -/* global NexT, CONFIG */ - -document.addEventListener('page:loaded', () => { - if (!CONFIG.page.comments) return; - - NexT.utils.loadComments('#isso-thread') - .then(() => NexT.utils.getScript(`${CONFIG.isso}js/embed.min.js`, { - attributes: { - dataset: { - isso: `${CONFIG.isso}` - } - }, - parentNode: document.querySelector('#isso-thread') - })); -}); diff --git a/assets/js/third-party/comments/livere.js b/assets/js/third-party/comments/livere.js index c4bcd2e..1dd9d53 100644 --- a/assets/js/third-party/comments/livere.js +++ b/assets/js/third-party/comments/livere.js @@ -1,19 +1,18 @@ -/* global NexT, CONFIG, LivereTower */ +document.addEventListener('DOMContentLoaded', () => { -document.addEventListener('page:loaded', () => { - if (!CONFIG.page.comments) return; + const element = '#lv-container'; + if (!NexT.CONFIG.comments.enable + || !NexT.CONFIG.livere + || !NexT.utils.checkDOMExist(element)) return; - NexT.utils.loadComments('#lv-container').then(() => { - window.livereOptions = { - refer: CONFIG.page.path.replace(/index\.html$/, '') - }; - - if (typeof LivereTower === 'function') return; - - NexT.utils.getScript('https://cdn-city.livere.com/js/embed.dist.js', { + NexT.utils.loadComments(element).then(() => { + NexT.utils.getScript(NexT.CONFIG.livere.js, { attributes: { async: true - } + }, + parentNode: document.querySelector(element) }); + + NexT.utils.hiddeLodingCmp(element); }); }); diff --git a/assets/js/third-party/comments/utterances.js b/assets/js/third-party/comments/utterances.js index 332ee05..3cf9cc1 100644 --- a/assets/js/third-party/comments/utterances.js +++ b/assets/js/third-party/comments/utterances.js @@ -1,17 +1,27 @@ -/* global NexT, CONFIG */ +document.addEventListener('DOMContentLoaded', () => { -document.addEventListener('page:loaded', () => { - if (!CONFIG.page.comments) return; + const element = '.utterances-container'; + if (!NexT.CONFIG.comments.enable + || !NexT.CONFIG.utterances + || !NexT.utils.checkDOMExist(element)) return; - NexT.utils.loadComments('.utterances-container') - .then(() => NexT.utils.getScript('https://utteranc.es/client.js', { + const { + repo, + issueterm, + label, + theme } = NexT.CONFIG.utterances.config; + + NexT.utils.loadComments(element) + .then(() => NexT.utils.getScript(NexT.CONFIG.utterances.js, { attributes: { - async : true, - crossOrigin : 'anonymous', - 'repo' : CONFIG.utterances.repo, - 'issue-term': CONFIG.utterances.issue_term, - 'theme' : CONFIG.utterances.theme + 'async' : true, + 'crossorigin' : 'anonymous', + 'repo' : repo, + 'issue-term' : issueterm, + 'theme' : theme }, - parentNode: document.querySelector('.utterances-container') + parentNode: document.querySelector(element) })); + + NexT.utils.hiddeLodingCmp(element); }); diff --git a/assets/js/third-party/comments/waline.js b/assets/js/third-party/comments/waline.js new file mode 100644 index 0000000..6f52ac8 --- /dev/null +++ b/assets/js/third-party/comments/waline.js @@ -0,0 +1,48 @@ +document.addEventListener('DOMContentLoaded', () => { + + const element = '.waline-container'; + if (!NexT.CONFIG.comments.enable + || !NexT.CONFIG.waline + || !NexT.utils.checkDOMExist(element)) return; + + const { + emoji, + imguploader, + pageview, + placeholder, + requiredmeta, + serverurl, + wordlimit + } = NexT.CONFIG.waline.config; + + + const waline_css = NexT.utils.getCDNResource(NexT.CONFIG.waline.css); + NexT.utils.getStyle(waline_css, null); + + const waline_js = NexT.utils.getCDNResource(NexT.CONFIG.waline.js); + + const locale = { + placeholder: placeholder + }; + + NexT.utils.loadComments(element) + .then(() => NexT.utils.getScript(waline_js, { + })) + .then(() => { + + Waline.init({ + locale, + el : element, + pageview : pageview, + emoji : emoji, + imageUploader : imguploader, + wordLimit : wordlimit, + requiredMeta : requiredmeta, + serverURL : serverurl, + lang : NexT.CONFIG.lang, + dark : "auto" + }); + + NexT.utils.hiddeLodingCmp(element); + }); +}); \ No newline at end of file diff --git a/assets/js/third-party/share/addthis.js b/assets/js/third-party/share/addthis.js new file mode 100644 index 0000000..1a498b2 --- /dev/null +++ b/assets/js/third-party/share/addthis.js @@ -0,0 +1,16 @@ +document.addEventListener('DOMContentLoaded', () => { + + const element = '.addthis_inline_share_toolbox'; + if (!NexT.CONFIG.addthis || !NexT.utils.checkDOMExist(element)) return; + + const addthis_js = NexT.CONFIG.addthis.js + '?pubid=' + NexT.CONFIG.addthis.config.pubid; + + NexT.utils.loadComments(element).then(() => { + NexT.utils.getScript(addthis_js, { + attributes: { + async: true + }, + parentNode: document.querySelector(element) + }); + }); +}); \ No newline at end of file diff --git a/assets/js/utils.js b/assets/js/utils.js index 3baa4de..3edb066 100644 --- a/assets/js/utils.js +++ b/assets/js/utils.js @@ -23,8 +23,31 @@ HTMLElement.prototype.wrap = function(wrapper) { NexT.utils = { + checkDOMExist: function(selector) { + return document.querySelector(selector) != null; + }, + + getCDNResource: function(res) { + let { plugins, router } = NexT.CONFIG.vendor; + let { name, version, file, alias } = res; + + let npm_name = name; + let res_src = ''; + switch(plugins) { + case 'cdnjs': + let cdnjs_name = alias || name; + let cdnjs_file = file.replace(/\.js$/, '.min.js').replace(/^(dist|lib|source\/js|)\/(browser\/|)/, ''); + res_src = `${router}/${cdnjs_name}/${version}/${cdnjs_file}` + break; + default: + res_src = `${router}/${npm_name}@${version}/${file}` + } + + return res_src; + }, + replacePostCRLink: function() { - if (CONFIG.hostname.startsWith('http')) return; + if (NexT.CONFIG.hostname.startsWith('http')) return; // Try to support mutli domain without base URL sets. let href = window.location.href; if (href.indexOf('#')>-1){ @@ -41,7 +64,7 @@ NexT.utils = { */ registerCopyCode: function() { let figure = document.querySelectorAll('.highlight pre'); - if (figure.length === 0 || !CONFIG.copybtn) return; + if (figure.length === 0 || !NexT.CONFIG.copybtn) return; figure.forEach(element => { let cn = element.querySelector('code').className; // TODO seems hard code need find other ways fixed it. @@ -170,13 +193,14 @@ NexT.utils = { // https://stackoverflow.com/questions/20306204/using-queryselector-with-ids-that-are-numbers const tActive = document.getElementById(element.querySelector('a').getAttribute('href').replace('#', '')); [...tActive.parentNode.children].forEach(target => { + // Array.prototype.slice.call(tActive.parentNode.children).forEach(target => { target.classList.toggle('active', target === tActive); }); // Trigger event tActive.dispatchEvent(new Event('tabs:click', { bubbles: true })); - if (!CONFIG.stickytabs) return; + if (!NexT.CONFIG.stickytabs) return; const offset = nav.parentNode.getBoundingClientRect().top + window.scrollY + 10; window.anime({ targets : document.scrollingElement, @@ -204,7 +228,7 @@ NexT.utils = { /*registerActiveMenuItem: function() { document.querySelectorAll('.menu-item a[href]').forEach(target => { const isSamePath = target.pathname === location.pathname || target.pathname === location.pathname.replace('index.html', ''); - const isSubPath = !CONFIG.root.startsWith(target.pathname) && location.pathname.startsWith(target.pathname); + const isSubPath = !NexT.CONFIG.root.startsWith(target.pathname) && location.pathname.startsWith(target.pathname); target.classList.toggle('menu-item-active', target.hostname === location.hostname && (isSamePath || isSubPath)); }); }, @@ -212,7 +236,7 @@ NexT.utils = { registerLangSelect: function() { const selects = document.querySelectorAll('.lang-select'); selects.forEach(sel => { - sel.value = CONFIG.page.lang; + sel.value = NexT.CONFIG.page.lang; sel.addEventListener('change', () => { const target = sel.options[sel.selectedIndex]; document.querySelectorAll('.lang-select-label span').forEach(span => { @@ -278,6 +302,11 @@ NexT.utils = { }); }, + hiddeLodingCmp: function(selector) { + const loadding = document.querySelector(selector).previousElementSibling; + loadding.style.display = 'none'; + }, + activateNavByIndex: function(index) { const target = document.querySelectorAll('.post-toc li a.nav-link')[index]; if (!target || target.classList.contains('active-current')) return; @@ -303,13 +332,13 @@ NexT.utils = { }, updateSidebarPosition: function() { - if (window.innerWidth < 992 || CONFIG.scheme === 'Pisces' || CONFIG.scheme === 'Gemini') return; + if (window.innerWidth < 992 || NexT.CONFIG.scheme === 'Pisces' || NexT.CONFIG.scheme === 'Gemini') return; // Expand sidebar on post detail page by default, when post has a toc. const hasTOC = document.querySelector('.post-toc'); - let display = CONFIG.sidebar; + let display = NexT.CONFIG.sidebar; if (typeof display !== 'boolean') { // There's no definition sidebar in the page front-matter. - display = CONFIG.sidebar.display === 'always' || (CONFIG.sidebar.display === 'post' && hasTOC); + display = NexT.CONFIG.sidebar.display === 'always' || (NexT.CONFIG.sidebar.display === 'post' && hasTOC); } if (display) { window.dispatchEvent(new Event('sidebar:show')); @@ -344,6 +373,15 @@ NexT.utils = { }); }, + getStyle: function(src, parent) { + const link = document.createElement('link'); + link.setAttribute('rel', 'stylesheet'); + link.setAttribute('type', 'text/css'); + link.setAttribute('href', src); + + (parent || document.head).appendChild(link); + }, + getScript: function(src, options = {}, legacyCondition) { if (typeof options === 'function') { return this.getScript(src, { @@ -362,6 +400,7 @@ NexT.utils = { } = {}, parentNode = null } = options; + return new Promise((resolve, reject) => { if (condition) { resolve(); @@ -401,7 +440,7 @@ NexT.utils = { } return new Promise(resolve => { const element = document.querySelector(selector); - if (!CONFIG.comments.lazyload || !element) { + if (!NexT.CONFIG.comments.lazyload || !element) { resolve(); return; } diff --git a/data/resources.yaml b/data/resources.yaml index f7c4ac1..c0d03c5 100644 --- a/data/resources.yaml +++ b/data/resources.yaml @@ -1,12 +1,11 @@ +# CDN 公共资源商列表 # Public CDN vendor list -# vendors: - cdnjs: "//cdnjs.cloudflare.com/ajax/libs/${name}/${version}/${file}" - unpkg: "//unpkg.com/${name}@${version}/${file}" + cdnjs: "https://cdnjs.cloudflare.com/ajax/libs" + unpkg: "https://unpkg.com" - -# Javascript Resources -# +# JavaScript 资源 +# JavaScript Resources js: - name: animejs version: 3.2.1 @@ -15,8 +14,8 @@ js: version: 3.2.0 file: es5/tex-mml-chtml.js +# CSS 资源 # CSS Resources -# css: - name: '@fortawesome/fontawesome-free' version: 6.1.1 @@ -24,4 +23,45 @@ css: alias: font-awesome - name: animate.css version: 3.1.1 - file: animate.min.css \ No newline at end of file + file: animate.min.css + +# 第三方服务组件资源 +# 3rd servcies Resource + +# 文章分享 +# Share +addthis: + js: https://s7.addthis.com/js/300/addthis_widget.js + +# 评论组件资源 +# Comment component Resources +waline: + js: + name: '@waline/client' + version: 2.6.1 + file: dist/waline.js + alias: waline + css: + name: '@waline/client' + version: 2.6.1 + file: dist/waline.css + alias: waline + +artalk: + js: + name: artalk + version: 2.3.4 + file: dist/Artalk.js + css: + name: artalk + version: 2.3.4 + file: dist/Artalk.css + +giscus: + js: https://giscus.app/client.js + +utterances: + js: https://utteranc.es/client.js + +livere: + js: https://cdn-city.livere.com/js/embed.dist.js \ No newline at end of file diff --git a/exampleSite/start.sh b/exampleSite/start.sh index b4e8e82..59f814c 100644 --- a/exampleSite/start.sh +++ b/exampleSite/start.sh @@ -20,4 +20,4 @@ EOT next `cat ../VERSION` -hugo server -D -t ../.. --port 1414 --panicOnWarning \ No newline at end of file +hugo server -D -t ../.. --port 1414 --panicOnWarning --config config.dev.yaml diff --git a/layouts/partials/_thirdparty/comment/artalk.html b/layouts/partials/_thirdparty/comment/artalk.html index f0683a3..6c97b81 100644 --- a/layouts/partials/_thirdparty/comment/artalk.html +++ b/layouts/partials/_thirdparty/comment/artalk.html @@ -1,20 +1 @@ -{{- with .Site.Params.artalk }} - - - - -
- - -{{- end }} - +
diff --git a/layouts/partials/_thirdparty/comment/giscus.html b/layouts/partials/_thirdparty/comment/giscus.html index 2b4a8e6..94aaa01 100644 --- a/layouts/partials/_thirdparty/comment/giscus.html +++ b/layouts/partials/_thirdparty/comment/giscus.html @@ -1,18 +1 @@ -{{- with .Site.Params.giscus }} -
- -{{- end }} \ No newline at end of file +
\ No newline at end of file diff --git a/layouts/partials/_thirdparty/comment/livere.html b/layouts/partials/_thirdparty/comment/livere.html index 9a2ff67..a150bae 100644 --- a/layouts/partials/_thirdparty/comment/livere.html +++ b/layouts/partials/_thirdparty/comment/livere.html @@ -1,13 +1 @@ -{{- with .Site.Params.LiveRe }} -
- -{{- end }} \ No newline at end of file +
\ No newline at end of file diff --git a/layouts/partials/_thirdparty/comment/utterances.html b/layouts/partials/_thirdparty/comment/utterances.html index 2d26357..6c935c6 100644 --- a/layouts/partials/_thirdparty/comment/utterances.html +++ b/layouts/partials/_thirdparty/comment/utterances.html @@ -1,9 +1 @@ -{{- with .Site.Params.utterances }} - -{{- end }} +
diff --git a/layouts/partials/_thirdparty/comment/waline.html b/layouts/partials/_thirdparty/comment/waline.html index a533da5..0e0d1d7 100644 --- a/layouts/partials/_thirdparty/comment/waline.html +++ b/layouts/partials/_thirdparty/comment/waline.html @@ -1,23 +1 @@ -{{- with .Site.Params.waline }} -
- - - - -{{- end }} \ No newline at end of file +
\ No newline at end of file diff --git a/layouts/partials/_thirdparty/share/addthis.html b/layouts/partials/_thirdparty/share/addthis.html index f171c68..683aeb0 100644 --- a/layouts/partials/_thirdparty/share/addthis.html +++ b/layouts/partials/_thirdparty/share/addthis.html @@ -1,5 +1,3 @@ -{{- with .Site.Params.addThisId }} -
- -
+{{- if isset .Site.Params "addthisid" }} +
{{- end }} \ No newline at end of file diff --git a/layouts/partials/head/favicon.html b/layouts/partials/head/favicon.html index f956361..3fc20ac 100644 --- a/layouts/partials/head/favicon.html +++ b/layouts/partials/head/favicon.html @@ -1,7 +1,9 @@ - - - - - +{{- with .Site.Params.favicon }} + + + + + +{{- end }} \ No newline at end of file diff --git a/layouts/partials/head/style.html b/layouts/partials/head/style.html index c43d385..4e2d1ab 100644 --- a/layouts/partials/head/style.html +++ b/layouts/partials/head/style.html @@ -1,22 +1,22 @@ {{- $cssRes := .Site.Data.resources.css }} {{- $vendor := .Site.Params.vendors.plugins }} -{{- $vendorCDN := .Scratch.Get "pluginCDN" }} +{{- $router := .Scratch.Get "router" }} +{{ $cssFmt := "%s/%s@%s/%s" }} {{- range $css := $cssRes }} - {{- $pluginCSS := $vendorCDN }} {{- $npm := $css.name }} {{- $file := $css.file }} {{- if eq $vendor "cdnjs" }} {{- with $css.alias }} {{- $npm = . }} - {{- end }} + {{- end }} {{- $file = replaceRE `(dist|lib|source\/js)\/` "" $css.file }} + {{- $cssFmt = "%s/%s/%s/%s" }} {{- end }} - {{- $pluginCSS = replace $pluginCSS "${name}" $npm }} - {{- $pluginCSS = replace $pluginCSS "${version}" $css.version }} - {{- $pluginCSS = replace $pluginCSS "${file}" $file }} - + {{- $pluginCSS := printf $cssFmt $router $npm $css.version $file }} + {{- end }} + {{- $scss := resources.Get "css/main.scss" }} {{- $scss = $scss | resources.ExecuteAsTemplate "main.scss" . }} diff --git a/layouts/partials/init.html b/layouts/partials/init.html index 2071831..446d64b 100644 --- a/layouts/partials/init.html +++ b/layouts/partials/init.html @@ -8,7 +8,6 @@ {{- .Scratch.Set "postsCount" (len (where .Page.Site.RegularPages "Section" "in" .Site.Params.mainSections)) -}} {{- .Scratch.Set "catsCount" (len .Site.Taxonomies.categories) -}} {{- .Scratch.Set "tagsCount" (len .Site.Taxonomies.tags) -}} -{{- $vendors := .Site.Data.resources.vendors -}} -{{- $pluginVen := .Site.Params.vendors.plugins -}} -{{- $pluginCDN := index $vendors $pluginVen -}} -{{- .Scratch.Set "pluginCDN" $pluginCDN -}} \ No newline at end of file +{{- $vendor := .Site.Params.vendors.plugins -}} +{{- $router := index .Site.Data.resources.vendors $vendor -}} +{{- .Scratch.Set "router" $router -}} \ No newline at end of file diff --git a/layouts/partials/scripts.html b/layouts/partials/scripts.html index a89f54e..1a87d20 100644 --- a/layouts/partials/scripts.html +++ b/layouts/partials/scripts.html @@ -1,9 +1,9 @@ {{- $jsRes := .Site.Data.resources.js }} {{- $vendor := .Site.Params.vendors.plugins }} -{{- $vendorCDN := .Scratch.Get "pluginCDN" }} +{{- $router := .Scratch.Get "router" }} +{{ $jsFmt := "%s/%s@%s/%s" }} {{- range $js := $jsRes }} - {{- $pluginJS := $vendorCDN }} {{- $npm := $js.name }} {{- $file := $js.file }} {{- if eq $vendor "cdnjs" }} @@ -11,10 +11,9 @@ {{- $npm = . }} {{- end }} {{- $file = replaceRE `(dist|lib|source\/js)\/` "" $js.file }} + {{- $jsFmt = "%s/%s/%s/%s" }} {{- end }} - {{- $pluginJS = replace $pluginJS "${name}" $npm }} - {{- $pluginJS = replace $pluginJS "${version}" $js.version }} - {{- $pluginJS = replace $pluginJS "${file}" $file }} + {{- $pluginJS := printf $jsFmt $router $npm $js.version $file }} {{- end }} @@ -39,8 +38,32 @@ {{- $pjaxjs := resources.Get "js/pjax.js" }} {{- $nextjs = $nextjs | append $pjaxjs }} {{- end }} +{{- if isset .Site.Params "addthisid" }} +{{- $addthisjs := resources.Get "js/third-party/share/addthis.js" }} +{{- $nextjs = $nextjs | append $addthisjs }} +{{- end }} +{{- if isset .Site.Params "waline" }} +{{- $walinejs := resources.Get "js/third-party/comments/waline.js" }} +{{- $nextjs = $nextjs | append $walinejs }} +{{- end }} +{{- if isset .Site.Params "giscus" }} +{{- $giscusjs := resources.Get "js/third-party/comments/giscus.js" }} +{{- $nextjs = $nextjs | append $giscusjs }} +{{- end }} +{{- if isset .Site.Params "livere" }} +{{- $liverejs := resources.Get "js/third-party/comments/livere.js" }} +{{- $nextjs = $nextjs | append $liverejs }} +{{- end }} +{{- if isset .Site.Params "artalk" }} +{{- $artalkjs := resources.Get "js/third-party/comments/artalk.js" }} +{{- $nextjs = $nextjs | append $artalkjs }} +{{- end }} +{{- if isset .Site.Params "utterances" }} +{{- $utterancesjs := resources.Get "js/third-party/comments/utterances.js" }} +{{- $nextjs = $nextjs | append $utterancesjs }} +{{- end }} {{- $nextjs = $nextjs | resources.Concat "js/hugo-next.js"}} {{ if hugo.IsProduction }} {{- $nextjs = $nextjs | minify | fingerprint }} {{ end }} - \ No newline at end of file + \ No newline at end of file diff --git a/assets/js/third-party/analytics/baidu-analytics.js b/static/js/third-party/analytics/baidu-analytics.js similarity index 100% rename from assets/js/third-party/analytics/baidu-analytics.js rename to static/js/third-party/analytics/baidu-analytics.js diff --git a/assets/js/third-party/analytics/google-analytics.js b/static/js/third-party/analytics/google-analytics.js similarity index 100% rename from assets/js/third-party/analytics/google-analytics.js rename to static/js/third-party/analytics/google-analytics.js diff --git a/assets/js/third-party/analytics/growingio.js b/static/js/third-party/analytics/growingio.js similarity index 100% rename from assets/js/third-party/analytics/growingio.js rename to static/js/third-party/analytics/growingio.js diff --git a/assets/js/third-party/chat/chatra.js b/static/js/third-party/chat/chatra.js similarity index 100% rename from assets/js/third-party/chat/chatra.js rename to static/js/third-party/chat/chatra.js diff --git a/assets/js/third-party/chat/gitter.js b/static/js/third-party/chat/gitter.js similarity index 100% rename from assets/js/third-party/chat/gitter.js rename to static/js/third-party/chat/gitter.js diff --git a/assets/js/third-party/chat/tidio.js b/static/js/third-party/chat/tidio.js similarity index 100% rename from assets/js/third-party/chat/tidio.js rename to static/js/third-party/chat/tidio.js diff --git a/assets/js/third-party/fancybox.js b/static/js/third-party/fancybox.js similarity index 100% rename from assets/js/third-party/fancybox.js rename to static/js/third-party/fancybox.js diff --git a/assets/js/third-party/math/katex.js b/static/js/third-party/math/katex.js similarity index 100% rename from assets/js/third-party/math/katex.js rename to static/js/third-party/math/katex.js diff --git a/assets/js/third-party/math/mathjax.js b/static/js/third-party/math/mathjax.js similarity index 100% rename from assets/js/third-party/math/mathjax.js rename to static/js/third-party/math/mathjax.js diff --git a/assets/js/third-party/pace.js b/static/js/third-party/pace.js similarity index 100% rename from assets/js/third-party/pace.js rename to static/js/third-party/pace.js diff --git a/assets/js/third-party/quicklink.js b/static/js/third-party/quicklink.js similarity index 100% rename from assets/js/third-party/quicklink.js rename to static/js/third-party/quicklink.js diff --git a/assets/js/third-party/rating.js b/static/js/third-party/rating.js similarity index 100% rename from assets/js/third-party/rating.js rename to static/js/third-party/rating.js diff --git a/assets/js/third-party/search/algolia-search.js b/static/js/third-party/search/algolia-search.js similarity index 100% rename from assets/js/third-party/search/algolia-search.js rename to static/js/third-party/search/algolia-search.js diff --git a/assets/js/third-party/search/local-search.js b/static/js/third-party/search/local-search.js similarity index 100% rename from assets/js/third-party/search/local-search.js rename to static/js/third-party/search/local-search.js diff --git a/assets/js/third-party/statistics/firestore.js b/static/js/third-party/statistics/firestore.js similarity index 100% rename from assets/js/third-party/statistics/firestore.js rename to static/js/third-party/statistics/firestore.js diff --git a/assets/js/third-party/statistics/lean-analytics.js b/static/js/third-party/statistics/lean-analytics.js similarity index 100% rename from assets/js/third-party/statistics/lean-analytics.js rename to static/js/third-party/statistics/lean-analytics.js diff --git a/assets/js/third-party/tags/mermaid.js b/static/js/third-party/tags/mermaid.js similarity index 100% rename from assets/js/third-party/tags/mermaid.js rename to static/js/third-party/tags/mermaid.js diff --git a/assets/js/third-party/tags/pdf.js b/static/js/third-party/tags/pdf.js similarity index 100% rename from assets/js/third-party/tags/pdf.js rename to static/js/third-party/tags/pdf.js