From 1339ffe29bb9b6e33feea94dc7d24dbcacaf3751 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=87=A1=E6=A2=A6=E6=98=9F=E5=B0=98?= Date: Thu, 7 Jul 2022 09:00:07 +0800 Subject: [PATCH 01/14] :construction: Add new config parameters for Giscus comment. --- exampleSite/config.yaml | 6 ++++++ layouts/partials/_thirdparty/comment/giscus.html | 4 ++-- 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/exampleSite/config.yaml b/exampleSite/config.yaml index 947960d..11df1e5 100644 --- a/exampleSite/config.yaml +++ b/exampleSite/config.yaml @@ -815,6 +815,12 @@ params: # 讨论区帖子标题,可选值: pathname | url | title | og:title | 自定义 # Available values: pathname | url | title | og:title | custom mapping: title + # 帖子上的反应将会显示在评论前 + # The reactions for post will be shown before the comments + reactions: false + # 将元数据定期被发送到父页面(被嵌入的页面或控制台,用于调试) + # Metadata will be sent periodically to the parent window + emit: false # 评论输入框的位置,可选值: top | bottom # Aavilable value: top | bottom inputPosition: top diff --git a/layouts/partials/_thirdparty/comment/giscus.html b/layouts/partials/_thirdparty/comment/giscus.html index d1b476f..2b4a8e6 100644 --- a/layouts/partials/_thirdparty/comment/giscus.html +++ b/layouts/partials/_thirdparty/comment/giscus.html @@ -6,8 +6,8 @@ data-category="{{ .category }}" data-category-id="{{ .categoryId }}" data-mapping="{{ .mapping }}" - data-reactions-enabled="0" - data-emit-metadata="1" + data-reactions-enabled="{{ int .reactions }}" + data-emit-metadata="{{ int .emit }}" data-input-position="{{ .inputPosition }}" data-theme="{{ .theme }}" data-lang="{{ $.Site.LanguageCode }}" From bf55ada93cfce61d689da61b8a07774c06269f83 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=87=A1=E6=A2=A6=E6=98=9F=E5=B0=98?= Date: Fri, 8 Jul 2022 10:09:23 +0800 Subject: [PATCH 02/14] :memo: Update the config description information. --- exampleSite/config.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/exampleSite/config.yaml b/exampleSite/config.yaml index 11df1e5..a44ebb9 100644 --- a/exampleSite/config.yaml +++ b/exampleSite/config.yaml @@ -139,7 +139,7 @@ params: appleTouchIcon: /imgs/icons/apple_touch_icon_next.png # 自定义 Logo (目前只支持 Mist 页面模式) - # Custom Logo (Warning: Do not support scheme Mist) + # Custom Logo (Warning: Only support scheme Mist) customLogo: #/imgs/hugo_next_logo.png # 知识共享国际许可 4.0 From 81cff8a5c28b5342ef1aa9f6984dac995c032e9c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=87=A1=E6=A2=A6=E6=98=9F=E5=B0=98?= Date: Wed, 13 Jul 2022 21:25:15 +0800 Subject: [PATCH 03/14] :zap: Improved the comments plug-in load function, close #12 --- assets/js/bookmark.js | 2 +- assets/js/comments-buttons.js | 6 +- assets/js/comments.js | 6 +- assets/js/config.js | 43 +++++++++++++- assets/js/motion.js | 16 +++--- assets/js/next-boot.js | 38 +++++++------ assets/js/pjax.js | 6 +- assets/js/schemes/muse.js | 4 +- assets/js/third-party/comments/artalk.js | 36 ++++++++++++ assets/js/third-party/comments/changyan.js | 39 ------------- assets/js/third-party/comments/disqus.js | 41 ------------- assets/js/third-party/comments/disqusjs.js | 18 ------ assets/js/third-party/comments/giscus.js | 41 +++++++++++++ assets/js/third-party/comments/gitalk.js | 24 -------- assets/js/third-party/comments/isso.js | 15 ----- assets/js/third-party/comments/livere.js | 23 ++++---- assets/js/third-party/comments/utterances.js | 32 +++++++---- assets/js/third-party/comments/waline.js | 48 ++++++++++++++++ assets/js/third-party/share/addthis.js | 16 ++++++ assets/js/utils.js | 57 ++++++++++++++++--- data/resources.yaml | 56 +++++++++++++++--- exampleSite/start.sh | 2 +- .../partials/_thirdparty/comment/artalk.html | 21 +------ .../partials/_thirdparty/comment/giscus.html | 19 +------ .../partials/_thirdparty/comment/livere.html | 14 +---- .../_thirdparty/comment/utterances.html | 10 +--- .../partials/_thirdparty/comment/waline.html | 24 +------- .../partials/_thirdparty/share/addthis.html | 6 +- layouts/partials/head/favicon.html | 12 ++-- layouts/partials/head/style.html | 14 ++--- layouts/partials/init.html | 7 +-- layouts/partials/scripts.html | 35 ++++++++++-- .../third-party/analytics/baidu-analytics.js | 0 .../third-party/analytics/google-analytics.js | 0 .../js/third-party/analytics/growingio.js | 0 .../js/third-party/chat/chatra.js | 0 .../js/third-party/chat/gitter.js | 0 .../js/third-party/chat/tidio.js | 0 {assets => static}/js/third-party/fancybox.js | 0 .../js/third-party/math/katex.js | 0 .../js/third-party/math/mathjax.js | 0 {assets => static}/js/third-party/pace.js | 0 .../js/third-party/quicklink.js | 0 {assets => static}/js/third-party/rating.js | 0 .../js/third-party/search/algolia-search.js | 0 .../js/third-party/search/local-search.js | 0 .../js/third-party/statistics/firestore.js | 0 .../third-party/statistics/lean-analytics.js | 0 .../js/third-party/tags/mermaid.js | 0 {assets => static}/js/third-party/tags/pdf.js | 0 50 files changed, 405 insertions(+), 326 deletions(-) create mode 100644 assets/js/third-party/comments/artalk.js delete mode 100644 assets/js/third-party/comments/changyan.js delete mode 100644 assets/js/third-party/comments/disqus.js delete mode 100644 assets/js/third-party/comments/disqusjs.js create mode 100644 assets/js/third-party/comments/giscus.js delete mode 100644 assets/js/third-party/comments/gitalk.js delete mode 100644 assets/js/third-party/comments/isso.js create mode 100644 assets/js/third-party/comments/waline.js create mode 100644 assets/js/third-party/share/addthis.js rename {assets => static}/js/third-party/analytics/baidu-analytics.js (100%) rename {assets => static}/js/third-party/analytics/google-analytics.js (100%) rename {assets => static}/js/third-party/analytics/growingio.js (100%) rename {assets => static}/js/third-party/chat/chatra.js (100%) rename {assets => static}/js/third-party/chat/gitter.js (100%) rename {assets => static}/js/third-party/chat/tidio.js (100%) rename {assets => static}/js/third-party/fancybox.js (100%) rename {assets => static}/js/third-party/math/katex.js (100%) rename {assets => static}/js/third-party/math/mathjax.js (100%) rename {assets => static}/js/third-party/pace.js (100%) rename {assets => static}/js/third-party/quicklink.js (100%) rename {assets => static}/js/third-party/rating.js (100%) rename {assets => static}/js/third-party/search/algolia-search.js (100%) rename {assets => static}/js/third-party/search/local-search.js (100%) rename {assets => static}/js/third-party/statistics/firestore.js (100%) rename {assets => static}/js/third-party/statistics/lean-analytics.js (100%) rename {assets => static}/js/third-party/tags/mermaid.js (100%) rename {assets => static}/js/third-party/tags/pdf.js (100%) 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 From ad271c1c2075b4b26b4a52a7ed70d1c95c9948c8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=87=A1=E6=A2=A6=E6=98=9F=E5=B0=98?= Date: Wed, 20 Jul 2022 09:03:11 +0800 Subject: [PATCH 04/14] :zap: Use dynamic function load analytic scripts avoid affecting the execution of page functions. --- data/resources.yaml | 5 +++++ .../partials/_thirdparty/analytics/51la.html | 17 +++++++++++++++-- layouts/partials/head/analytics.html | 3 ++- 3 files changed, 22 insertions(+), 3 deletions(-) diff --git a/data/resources.yaml b/data/resources.yaml index c0d03c5..e204c3c 100644 --- a/data/resources.yaml +++ b/data/resources.yaml @@ -28,6 +28,11 @@ css: # 第三方服务组件资源 # 3rd servcies Resource +# 站点统计 +# Site analytics engine +analytics: + la: https://sdk.51.la/js-sdk-pro.min.js + # 文章分享 # Share addthis: diff --git a/layouts/partials/_thirdparty/analytics/51la.html b/layouts/partials/_thirdparty/analytics/51la.html index 3aca679..e64eb90 100644 --- a/layouts/partials/_thirdparty/analytics/51la.html +++ b/layouts/partials/_thirdparty/analytics/51la.html @@ -1,2 +1,15 @@ - - + diff --git a/layouts/partials/head/analytics.html b/layouts/partials/head/analytics.html index 0105e07..77416e5 100644 --- a/layouts/partials/head/analytics.html +++ b/layouts/partials/head/analytics.html @@ -1,5 +1,6 @@ +{{ $ctx := . }} {{- with .Site.Params.analytics }} {{- if isset . "laid" }} - {{ partial "_thirdparty/analytics/51la.html" .laId }} + {{ partial "_thirdparty/analytics/51la.html" (dict "ctx" $ctx "id" .laId) }} {{- end }} {{- end }} \ No newline at end of file From 12fbc945bc07f01a42935e9322b320cf4a88c44f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=87=A1=E6=A2=A6=E6=98=9F=E5=B0=98?= Date: Wed, 20 Jul 2022 15:42:01 +0800 Subject: [PATCH 05/14] :zap: Improve site generate speed with use `partialCached` function. --- layouts/_default/baseof.html | 8 +++++--- layouts/partials/init.html | 13 +++++++++---- 2 files changed, 14 insertions(+), 7 deletions(-) diff --git a/layouts/_default/baseof.html b/layouts/_default/baseof.html index 184cd56..9c7c917 100644 --- a/layouts/_default/baseof.html +++ b/layouts/_default/baseof.html @@ -1,4 +1,6 @@ -{{- partial "init.html" . -}} +{{- range $k, $v := (partialCached "init.html" .) -}} + {{- $.Scratch.Set $k $v -}} +{{- end -}} @@ -28,13 +30,13 @@ {{- block "main" . }}{{- end }} {{- if .IsPage }} - {{- partial "comments.html" . }} + {{- partialCached "comments.html" . }} {{- end }}
diff --git a/layouts/partials/init.html b/layouts/partials/init.html index 446d64b..c572261 100644 --- a/layouts/partials/init.html +++ b/layouts/partials/init.html @@ -5,9 +5,14 @@ {{- errorf "Because that use SCSS framework in Hugo NexT, Please download Hugo extended version on offical site: https://github.com/gohugoio/hugo/releases" -}} {{- end }} -{{- .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) -}} +{{- $globalVars := newScratch -}} + +{{- $globalVars.Set "postsCount" (len (where .Page.Site.RegularPages "Section" "in" .Site.Params.mainSections)) -}} +{{- $globalVars.Set "catsCount" (len .Site.Taxonomies.categories) -}} +{{- $globalVars.Set "tagsCount" (len .Site.Taxonomies.tags) -}} + {{- $vendor := .Site.Params.vendors.plugins -}} {{- $router := index .Site.Data.resources.vendors $vendor -}} -{{- .Scratch.Set "router" $router -}} \ No newline at end of file +{{- $globalVars.Set "router" $router -}} + +{{- return $globalVars.Values -}} From a9ff14d31290c0183c0d80e4669b5fc6ee98a735 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=87=A1=E6=A2=A6=E6=98=9F=E5=B0=98?= Date: Wed, 20 Jul 2022 18:29:31 +0800 Subject: [PATCH 06/14] :wrench: Upgrade the config file settings. --- exampleSite/config.yaml | 58 +++++++++++++++++++++-------------------- 1 file changed, 30 insertions(+), 28 deletions(-) diff --git a/exampleSite/config.yaml b/exampleSite/config.yaml index a44ebb9..8095f1d 100644 --- a/exampleSite/config.yaml +++ b/exampleSite/config.yaml @@ -553,7 +553,7 @@ params: enable: true # 你的 Github 仓库地址 # Your repository url on Github. - permalink: https://github.com/yourname + permalink: https://github.com/hugo-next # 关注说明 # Show this title when cursor move on. title: Follow me on GitHub @@ -765,35 +765,35 @@ params: # 更多配置信息请参考:https://artalk.js.org # Artalk comments system # More info see: https://artalk.js.org - artalk: - site: "默认站点" - placeholder: "请文明发言,谢谢!" - server: # + # artalk: + # site: "默认站点" + # placeholder: "请文明发言,谢谢!" + # server: # # Artalk 评论插件 # 更多配置信息请参考: # LiveRe comments system # You can get your uid from https://livere.com/ - livere: - uid: # + # livere: + # uid: # # Utterances 评论插件 # 更多配置信息请参考:https://utteranc.es # Utterances comments system # For more information: https://utteranc.es - utterances: - # Github 仓库地址,格式:用户名/仓库名称 - # Github repository owner and name - repo: username/repo-name - # 问题标题的模式,可选值:pathname | url | title | og:title - # Available values: pathname | url | title | og:title - issueTerm: pathname - # 问题的标签分类 - # Label flag for Github issues - label: comments - # 主题可选值: github-light | github-dark | preferred-color-scheme | github-dark-orange | icy-dark | dark-blue | photon-dark | boxy-light - # Available values: github-light | github-dark | preferred-color-scheme | github-dark-orange | icy-dark | dark-blue | photon-dark | boxy-light - theme: preferred-color-scheme + # utterances: + # # Github 仓库地址,格式:用户名/仓库名称 + # # Github repository owner and name + # repo: username/repo-name + # # 问题标题的模式,可选值:pathname | url | title | og:title + # # Available values: pathname | url | title | og:title + # issueTerm: pathname + # # 问题的标签分类 + # # Label flag for Github issues + # label: comments + # # 主题可选值: github-light | github-dark | preferred-color-scheme | github-dark-orange | icy-dark | dark-blue | photon-dark | boxy-light + # # Available values: github-light | github-dark | preferred-color-scheme | github-dark-orange | icy-dark | dark-blue | photon-dark | boxy-light + # theme: preferred-color-scheme # Giscus 评论插件 # 更多配置信息请参考:https://giscus.app @@ -802,19 +802,16 @@ params: giscus: # Github 仓库地址,格式:用户名/仓库名称 # Github repository owner and name - repo: username/repo_name + repo: username/repo-name # Giscus 生成的仓库 Id # Generate repository Id from Giscus - repoId: # + repoId: # # 讨论区的分类名称 # Github discussions category - category: Announcements + category: Comments # 讨论区分类 ID # Generate category Id from Giscus - categoryId: # - # 讨论区帖子标题,可选值: pathname | url | title | og:title | 自定义 - # Available values: pathname | url | title | og:title | custom - mapping: title + categoryId: # # 帖子上的反应将会显示在评论前 # The reactions for post will be shown before the comments reactions: false @@ -823,6 +820,11 @@ params: emit: false # 评论输入框的位置,可选值: top | bottom # Aavilable value: top | bottom + # 讨论区帖子标题,可选值: pathname | url | title | og:title | 自定义 + # Available values: pathname | url | title | og:title | custom + mapping: title + # 评论输入框的位置,可选值: top | bottom + # Aavilable value: top | bottom inputPosition: top # 主题可选值: light | light_high_contrast | light_protanopia | light_tritanopia | dark | dark_high_contrast | dark_protanopia | dark_tritanopia | dark_dimmed | transparent_dark | preferred_color_scheme # Available values: light | light_high_contrast | light_protanopia | light_tritanopia | dark | dark_high_contrast | dark_protanopia | dark_tritanopia | dark_dimmed | transparent_dark | preferred_color_scheme @@ -860,7 +862,7 @@ params: # 更多信息请参考:https://invite.51.la/1NUfGTS1?target=V6 # 51La Analytics # See: https://invite.51.la/1NUfGTS1?target=V6 - laId: # + laId: # # TODO # Show Views / Visitors of the website / page with busuanzi. From 31f6e21671f3699594a15fd8811d0eb398cf9851 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=87=A1=E6=A2=A6=E6=98=9F=E5=B0=98?= Date: Fri, 22 Jul 2022 17:16:34 +0800 Subject: [PATCH 07/14] :zap: Improve page scripts configuration files. --- assets/js/config.js | 143 ++++++++---------- assets/js/next-boot.js | 2 +- assets/js/third-party/comments/artalk.js | 16 +- assets/js/third-party/comments/giscus.js | 10 +- assets/js/third-party/comments/livere.js | 6 +- assets/js/third-party/comments/utterances.js | 8 +- assets/js/third-party/comments/waline.js | 12 +- assets/js/third-party/share/addthis.js | 4 +- assets/js/utils.js | 2 +- .../partials/_thirdparty/analytics/51la.html | 10 +- layouts/partials/head.html | 4 +- layouts/partials/head/analytics.html | 7 +- layouts/partials/head/config.html | 63 ++++++++ layouts/partials/init.html | 43 ++++-- layouts/partials/scripts.html | 6 +- 15 files changed, 198 insertions(+), 138 deletions(-) create mode 100644 layouts/partials/head/config.html diff --git a/assets/js/config.js b/assets/js/config.js index ada03fb..1ca46e6 100644 --- a/assets/js/config.js +++ b/assets/js/config.js @@ -1,92 +1,67 @@ if (!window.NexT) window.NexT = {}; (function() { + const className = 'next-config'; - 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 }}, - "version" : "{{ .Site.Data.config.version }}", - "sidebar" : {{ .Site.Params.sidebar | jsonify }}, - "copybtn" : {{ .Site.Params.codeblock.copyBtn }}, - "bookmark" : {{ .Site.Params.bookmark | jsonify }}, - "comments" : {{ .Site.Params.comments | jsonify }}, - "lazyload" : {{ .Site.Params.lazyload }}, - "pangu" : {{ .Site.Params.pangu }}, - "stickytabs" : {{ .Site.Params.tabs.sticky }}, - "motion" : {{ .Site.Params.motion | jsonify }}, - // TODO Find prismjs - //"prism" : "", - "i18n" : { - "placeholder" : "", - "empty" : "${query}", - "hits_time" : "'${hits}', '${time}'", - "hits" : "${hits}" - }, - {{- if .Site.Params.algoliaSearch.enable }} - // TODO - "algolia" : { - "appID" : "", - "apiKey" : "", - "indexName" : "", - "hits" : "" + const staticConfig = {}; + let variableConfig = {}; + + const parse = text => JSON.parse(text || '{}'); + + const update = name => { + const targetEle = document.querySelector(`.${className}[data-name="${name}"]`); + if (!targetEle) return; + const parsedConfig = parse(targetEle.text); + if (name === 'main') { + Object.assign(staticConfig, parsedConfig); + } else { + variableConfig[name] = parsedConfig; } - {{- end }} - {{- if .Site.Params.localSearch.enable }} - // TODO - "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 }}", - "isHome" : {{ .IsHome }}, - "isPage" : {{ .IsPage }} }; - - window.NexT.CONFIG = new Proxy(siteConfig, {}); + update('main'); + + window.NexT.CONFIG = new Proxy({}, { + get(overrideConfig, name) { + let existing; + if (name in staticConfig) { + existing = staticConfig[name]; + } else { + if (!(name in variableConfig)) update(name); + existing = variableConfig[name]; + } + + // For unset override and mixable existing + if (!(name in overrideConfig) && typeof existing === 'object') { + // Get ready to mix. + overrideConfig[name] = {}; + } + + if (name in overrideConfig) { + const override = overrideConfig[name]; + + // When mixable + if (typeof override === 'object' && typeof existing === 'object') { + // Mix, proxy changes to the override. + return new Proxy({ ...existing, ...override }, { + set(target, prop, value) { + target[prop] = value; + override[prop] = value; + return true; + } + }); + } + + return override; + } + + // Only when not mixable and override hasn't been set. + return existing; + } + }); + + // TODO + // document.addEventListener('pjax:success', () => { + // variableConfig = {}; + // }); })(); \ No newline at end of file diff --git a/assets/js/next-boot.js b/assets/js/next-boot.js index 1eb0443..f9decbc 100644 --- a/assets/js/next-boot.js +++ b/assets/js/next-boot.js @@ -33,7 +33,7 @@ NexT.boot.registerEvents = function() { NexT.boot.refresh = function() { - if (!NexT.CONFIG.isPage) return; + if (!NexT.CONFIG.page.isPage) return; /** * Register JS handlers by condition option. * Need to add config option in Front-End at 'scripts/helpers/next-config.js' file. diff --git a/assets/js/third-party/comments/artalk.js b/assets/js/third-party/comments/artalk.js index a037939..19e1401 100644 --- a/assets/js/third-party/comments/artalk.js +++ b/assets/js/third-party/comments/artalk.js @@ -1,19 +1,19 @@ document.addEventListener('DOMContentLoaded', () => { const element = '.artalk-container'; - if (!NexT.CONFIG.comments.enable - || !NexT.CONFIG.artalk + if (!NexT.CONFIG.page.comments + || !NexT.CONFIG.page.artalk || !NexT.utils.checkDOMExist(element)) return; - const artalk_css = NexT.utils.getCDNResource(NexT.CONFIG.artalk.css); + const artalk_css = NexT.utils.getCDNResource(NexT.CONFIG.page.artalk.css); NexT.utils.getStyle(artalk_css, null); - const artalk_js = NexT.utils.getCDNResource(NexT.CONFIG.artalk.js); + const artalk_js = NexT.utils.getCDNResource(NexT.CONFIG.page.artalk.js); const { site, placeholder, server, - } = NexT.CONFIG.artalk.config; + } = NexT.CONFIG.page.artalk.cfg; NexT.utils.loadComments(element) .then(() => NexT.utils.getScript(artalk_js, { @@ -22,11 +22,11 @@ document.addEventListener('DOMContentLoaded', () => { new Artalk({ el : element, - pageKey : NexT.CONFIG.permalink, - pageTitle : NexT.CONFIG.title, + pageKey : NexT.CONFIG.page.permalink, + pageTitle : NexT.CONFIG.page.title, server : server, site : site, - locale : NexT.CONFIG.lang, + locale : NexT.CONFIG.page.lang, placeholder : placeholder, darkMode : 'auto' }); diff --git a/assets/js/third-party/comments/giscus.js b/assets/js/third-party/comments/giscus.js index 18c1995..a67bd83 100644 --- a/assets/js/third-party/comments/giscus.js +++ b/assets/js/third-party/comments/giscus.js @@ -1,8 +1,8 @@ document.addEventListener('DOMContentLoaded', () => { const element = '.giscus-container'; - if (!NexT.CONFIG.comments.enable - || !NexT.CONFIG.giscus + if (!NexT.CONFIG.page.comments + || !NexT.CONFIG.page.giscus || !NexT.utils.checkDOMExist(element)) return; const { @@ -14,11 +14,11 @@ document.addEventListener('DOMContentLoaded', () => { reactions, repo, repoid, - theme } = NexT.CONFIG.giscus.config; + theme } = NexT.CONFIG.page.giscus.cfg; NexT.utils.loadComments(element) - .then(() => NexT.utils.getScript(NexT.CONFIG.giscus.js, { + .then(() => NexT.utils.getScript(NexT.CONFIG.page.giscus.js, { attributes: { 'async' : true, 'crossorigin' : 'anonymous', @@ -31,7 +31,7 @@ document.addEventListener('DOMContentLoaded', () => { 'data-emit-metadata' : emit ? 1:0, 'data-input-position' : inputposition, 'data-theme' : theme, - 'data-lang' : NexT.CONFIG.lang, + 'data-lang' : NexT.CONFIG.page.lang, 'data-loading' : 'lazy' }, parentNode: document.querySelector(element) diff --git a/assets/js/third-party/comments/livere.js b/assets/js/third-party/comments/livere.js index 1dd9d53..8d786f6 100644 --- a/assets/js/third-party/comments/livere.js +++ b/assets/js/third-party/comments/livere.js @@ -1,12 +1,12 @@ document.addEventListener('DOMContentLoaded', () => { const element = '#lv-container'; - if (!NexT.CONFIG.comments.enable - || !NexT.CONFIG.livere + if (!NexT.CONFIG.page.comments + || !NexT.CONFIG.page.livere || !NexT.utils.checkDOMExist(element)) return; NexT.utils.loadComments(element).then(() => { - NexT.utils.getScript(NexT.CONFIG.livere.js, { + NexT.utils.getScript(NexT.CONFIG.page.livere.js, { attributes: { async: true }, diff --git a/assets/js/third-party/comments/utterances.js b/assets/js/third-party/comments/utterances.js index 3cf9cc1..e8e7f60 100644 --- a/assets/js/third-party/comments/utterances.js +++ b/assets/js/third-party/comments/utterances.js @@ -1,18 +1,18 @@ document.addEventListener('DOMContentLoaded', () => { const element = '.utterances-container'; - if (!NexT.CONFIG.comments.enable - || !NexT.CONFIG.utterances + if (!NexT.CONFIG.page.comments + || !NexT.CONFIG.page.utterances || !NexT.utils.checkDOMExist(element)) return; const { repo, issueterm, label, - theme } = NexT.CONFIG.utterances.config; + theme } = NexT.CONFIG.page.utterances.cfg; NexT.utils.loadComments(element) - .then(() => NexT.utils.getScript(NexT.CONFIG.utterances.js, { + .then(() => NexT.utils.getScript(NexT.CONFIG.page.utterances.js, { attributes: { 'async' : true, 'crossorigin' : 'anonymous', diff --git a/assets/js/third-party/comments/waline.js b/assets/js/third-party/comments/waline.js index 6f52ac8..917c922 100644 --- a/assets/js/third-party/comments/waline.js +++ b/assets/js/third-party/comments/waline.js @@ -1,8 +1,8 @@ document.addEventListener('DOMContentLoaded', () => { const element = '.waline-container'; - if (!NexT.CONFIG.comments.enable - || !NexT.CONFIG.waline + if (!NexT.CONFIG.page.comments + || !NexT.CONFIG.page.waline || !NexT.utils.checkDOMExist(element)) return; const { @@ -13,13 +13,13 @@ document.addEventListener('DOMContentLoaded', () => { requiredmeta, serverurl, wordlimit - } = NexT.CONFIG.waline.config; + } = NexT.CONFIG.page.waline.cfg; - const waline_css = NexT.utils.getCDNResource(NexT.CONFIG.waline.css); + const waline_css = NexT.utils.getCDNResource(NexT.CONFIG.page.waline.css); NexT.utils.getStyle(waline_css, null); - const waline_js = NexT.utils.getCDNResource(NexT.CONFIG.waline.js); + const waline_js = NexT.utils.getCDNResource(NexT.CONFIG.page.waline.js); const locale = { placeholder: placeholder @@ -39,7 +39,7 @@ document.addEventListener('DOMContentLoaded', () => { wordLimit : wordlimit, requiredMeta : requiredmeta, serverURL : serverurl, - lang : NexT.CONFIG.lang, + lang : NexT.CONFIG.page.lang, dark : "auto" }); diff --git a/assets/js/third-party/share/addthis.js b/assets/js/third-party/share/addthis.js index 1a498b2..4fe8615 100644 --- a/assets/js/third-party/share/addthis.js +++ b/assets/js/third-party/share/addthis.js @@ -1,9 +1,9 @@ document.addEventListener('DOMContentLoaded', () => { const element = '.addthis_inline_share_toolbox'; - if (!NexT.CONFIG.addthis || !NexT.utils.checkDOMExist(element)) return; + if (!NexT.CONFIG.page.addthis || !NexT.utils.checkDOMExist(element)) return; - const addthis_js = NexT.CONFIG.addthis.js + '?pubid=' + NexT.CONFIG.addthis.config.pubid; + const addthis_js = NexT.CONFIG.page.addthis.js + '?pubid=' + NexT.CONFIG.page.addthis.cfg.pubid; NexT.utils.loadComments(element).then(() => { NexT.utils.getScript(addthis_js, { diff --git a/assets/js/utils.js b/assets/js/utils.js index 3edb066..a53270e 100644 --- a/assets/js/utils.js +++ b/assets/js/utils.js @@ -440,7 +440,7 @@ NexT.utils = { } return new Promise(resolve => { const element = document.querySelector(selector); - if (!NexT.CONFIG.comments.lazyload || !element) { + if (!element) { resolve(); return; } diff --git a/layouts/partials/_thirdparty/analytics/51la.html b/layouts/partials/_thirdparty/analytics/51la.html index e64eb90..07e9221 100644 --- a/layouts/partials/_thirdparty/analytics/51la.html +++ b/layouts/partials/_thirdparty/analytics/51la.html @@ -4,12 +4,14 @@ script.charset = "UTF-8"; script.id = "LA_COLLECT"; - script.src = "{{ .ctx.Site.Data.resources.analytics.la }}"; + script.src = "{{ .Site.Data.resources.analytics.la }}"; script.async = "true" script.onload = function() { - LA.init({ id: "{{ .id }}",ck: "{{ .id }}", autoTrack:true }); + {{ with .Site.Params.analytics.laId }} + LA.init({ id: "{{ . }}",ck: "{{ . }}", autoTrack:true }); + {{ end }} } - document.head.appendChild(script); - }); + document.head.appendChild(script); +}); diff --git a/layouts/partials/head.html b/layouts/partials/head.html index a545428..aac885c 100644 --- a/layouts/partials/head.html +++ b/layouts/partials/head.html @@ -5,4 +5,6 @@ {{- partial "head/facebook.html" . }} {{- partial "head/verify.html" . }} {{- partialCached "head/style.html" . }} -{{- partialCached "head/analytics.html" . }} \ No newline at end of file +{{- partial "head/config.html" . }} +{{- partialCached "head/analytics.html" . }} + diff --git a/layouts/partials/head/analytics.html b/layouts/partials/head/analytics.html index 77416e5..37a5b2f 100644 --- a/layouts/partials/head/analytics.html +++ b/layouts/partials/head/analytics.html @@ -1,6 +1,3 @@ -{{ $ctx := . }} -{{- with .Site.Params.analytics }} -{{- if isset . "laid" }} - {{ partial "_thirdparty/analytics/51la.html" (dict "ctx" $ctx "id" .laId) }} +{{- if isset .Site.Params.analytics "laid" }} + {{ partial "_thirdparty/analytics/51la.html" . }} {{- end }} -{{- end }} \ No newline at end of file diff --git a/layouts/partials/head/config.html b/layouts/partials/head/config.html new file mode 100644 index 0000000..1c8b50c --- /dev/null +++ b/layouts/partials/head/config.html @@ -0,0 +1,63 @@ + \ No newline at end of file diff --git a/layouts/partials/init.html b/layouts/partials/init.html index c572261..a5b8c6c 100644 --- a/layouts/partials/init.html +++ b/layouts/partials/init.html @@ -1,18 +1,37 @@ {{/* Use to defind global variables */}} -{{- if not hugo.IsExtended }} -{{- warnf "Hugo NexT 主题使用了 SCSS 框架,请到官方地址下载 Hugo Extended 版本:https://github.com/gohugoio/hugo/releases" -}} -{{- errorf "Because that use SCSS framework in Hugo NexT, Please download Hugo extended version on offical site: https://github.com/gohugoio/hugo/releases" -}} -{{- end }} +{{ if not hugo.IsExtended }} +{{ warnf "Hugo NexT 主题使用了 SCSS 框架,请到官方地址下载 Hugo Extended 版本:https://github.com/gohugoio/hugo/releases" }} +{{ errorf "Because that use SCSS framework in Hugo NexT, Please download Hugo extended version on offical site: https://github.com/gohugoio/hugo/releases" }} +{{ end }} -{{- $globalVars := newScratch -}} +{{ $globalVars := newScratch }} -{{- $globalVars.Set "postsCount" (len (where .Page.Site.RegularPages "Section" "in" .Site.Params.mainSections)) -}} -{{- $globalVars.Set "catsCount" (len .Site.Taxonomies.categories) -}} -{{- $globalVars.Set "tagsCount" (len .Site.Taxonomies.tags) -}} +{{ $globalVars.Set "postsCount" (len (where .Page.Site.RegularPages "Section" "in" .Site.Params.mainSections)) }} +{{ $globalVars.Set "catsCount" (len .Site.Taxonomies.categories) }} +{{ $globalVars.Set "tagsCount" (len .Site.Taxonomies.tags) }} -{{- $vendor := .Site.Params.vendors.plugins -}} -{{- $router := index .Site.Data.resources.vendors $vendor -}} -{{- $globalVars.Set "router" $router -}} +{{ $vendor := .Site.Params.vendors.plugins }} +{{ $router := index .Site.Data.resources.vendors $vendor }} +{{ $globalVars.Set "router" $router }} -{{- return $globalVars.Values -}} +{{ $vendorDict := dict + "plugins" $vendor + "router" $router +}} +{{ $config := dict + "hostname" .Site.BaseURL + "root" "/" + "vendor" $vendorDict + "darkmode" .Site.Params.darkmode + "version" .Site.Data.config.version + "scheme" .Site.Params.scheme + "sidebar" .Site.Params.sidebar + "copybtn" .Site.Params.codeblock.copyBtn + "bookmark" .Site.Params.bookmark + "lazyload" .Site.Params.lazyload + "motion" .Site.Params.motion +}} +{{ $globalVars.Set "config" $config }} + +{{ return $globalVars.Values }} diff --git a/layouts/partials/scripts.html b/layouts/partials/scripts.html index 1a87d20..0b4a23c 100644 --- a/layouts/partials/scripts.html +++ b/layouts/partials/scripts.html @@ -17,7 +17,9 @@ {{- end }} -{{- $config := resources.Get "js/config.js" | resources.ExecuteAsTemplate "config.js" . }} + + +{{- $config := resources.Get "js/config.js" }} {{- $motion := resources.Get "js/motion.js" }} {{- $boot := resources.Get "js/next-boot.js" }} {{- $utils := resources.Get "js/utils.js" }} @@ -62,7 +64,7 @@ {{- $utterancesjs := resources.Get "js/third-party/comments/utterances.js" }} {{- $nextjs = $nextjs | append $utterancesjs }} {{- end }} -{{- $nextjs = $nextjs | resources.Concat "js/hugo-next.js"}} +{{- $nextjs = $nextjs | resources.Concat "js/main.js"}} {{ if hugo.IsProduction }} {{- $nextjs = $nextjs | minify | fingerprint }} {{ end }} From d42375820d45b1e0423db874cc1660c8782590a2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=87=A1=E6=A2=A6=E6=98=9F=E5=B0=98?= Date: Fri, 22 Jul 2022 18:35:04 +0800 Subject: [PATCH 08/14] :zap: Use script to control comments container show. --- assets/js/next-boot.js | 22 +++++--- assets/js/third-party/comments/artalk.js | 14 ++--- assets/js/third-party/comments/giscus.js | 8 +-- assets/js/third-party/comments/livere.js | 4 +- assets/js/third-party/comments/utterances.js | 6 +- assets/js/third-party/comments/waline.js | 10 ++-- assets/js/third-party/share/addthis.js | 4 +- assets/js/utils.js | 8 ++- layouts/partials/comments.html | 2 - layouts/partials/head/config.html | 59 +------------------- layouts/partials/init.html | 55 ++++++++++++++++-- 11 files changed, 97 insertions(+), 95 deletions(-) diff --git a/assets/js/next-boot.js b/assets/js/next-boot.js index f9decbc..8f96889 100644 --- a/assets/js/next-boot.js +++ b/assets/js/next-boot.js @@ -34,7 +34,20 @@ NexT.boot.registerEvents = function() { NexT.boot.refresh = function() { if (!NexT.CONFIG.page.isPage) return; - /** + + NexT.utils.registerSidebarTOC(); + NexT.utils.replacePostCRLink(); + NexT.utils.registerCopyCode(); + NexT.utils.registerPostReward(); + if(NexT.CONFIG.page.comments) { + NexT.utils.initCommontesDispaly(); + NexT.utils.registerCommonSwitch(); + } else { + NexT.utils.hideCommontes(); + } + + //TODO + /** * Register JS handlers by condition option. * Need to add config option in Front-End at 'scripts/helpers/next-config.js' file. */ @@ -44,16 +57,9 @@ NexT.boot.refresh = function() { });*/ // NexT.CONFIG.lazyload && window.lozad('.post-body img').observe(); // NexT.CONFIG.pangu && window.pangu.spacingPage(); - - NexT.utils.replacePostCRLink(); - NexT.utils.initCommontesDispaly(); - NexT.CONFIG.copybtn && NexT.utils.registerCopyCode(); /*NexT.utils.registerTabsTag(); NexT.utils.registerActiveMenuItem(); NexT.utils.registerLangSelect();*/ - NexT.utils.registerSidebarTOC(); - NexT.utils.registerPostReward(); - NexT.utils.registerCommonSwitch(); /*NexT.utils.wrapTableWithBox(); NexT.utils.registerVideoIframe();*/ diff --git a/assets/js/third-party/comments/artalk.js b/assets/js/third-party/comments/artalk.js index 19e1401..8b5dcc2 100644 --- a/assets/js/third-party/comments/artalk.js +++ b/assets/js/third-party/comments/artalk.js @@ -2,18 +2,18 @@ document.addEventListener('DOMContentLoaded', () => { const element = '.artalk-container'; if (!NexT.CONFIG.page.comments - || !NexT.CONFIG.page.artalk + || !NexT.CONFIG.artalk || !NexT.utils.checkDOMExist(element)) return; - const artalk_css = NexT.utils.getCDNResource(NexT.CONFIG.page.artalk.css); + const artalk_css = NexT.utils.getCDNResource(NexT.CONFIG.artalk.css); NexT.utils.getStyle(artalk_css, null); - const artalk_js = NexT.utils.getCDNResource(NexT.CONFIG.page.artalk.js); + const artalk_js = NexT.utils.getCDNResource(NexT.CONFIG.artalk.js); const { site, placeholder, server, - } = NexT.CONFIG.page.artalk.cfg; + } = NexT.CONFIG.artalk.cfg; NexT.utils.loadComments(element) .then(() => NexT.utils.getScript(artalk_js, { @@ -22,11 +22,11 @@ document.addEventListener('DOMContentLoaded', () => { new Artalk({ el : element, - pageKey : NexT.CONFIG.page.permalink, - pageTitle : NexT.CONFIG.page.title, + pageKey : NexT.CONFIG.permalink, + pageTitle : NexT.CONFIG.title, server : server, site : site, - locale : NexT.CONFIG.page.lang, + locale : NexT.CONFIG.lang, placeholder : placeholder, darkMode : 'auto' }); diff --git a/assets/js/third-party/comments/giscus.js b/assets/js/third-party/comments/giscus.js index a67bd83..62529a8 100644 --- a/assets/js/third-party/comments/giscus.js +++ b/assets/js/third-party/comments/giscus.js @@ -2,7 +2,7 @@ document.addEventListener('DOMContentLoaded', () => { const element = '.giscus-container'; if (!NexT.CONFIG.page.comments - || !NexT.CONFIG.page.giscus + || !NexT.CONFIG.giscus || !NexT.utils.checkDOMExist(element)) return; const { @@ -14,11 +14,11 @@ document.addEventListener('DOMContentLoaded', () => { reactions, repo, repoid, - theme } = NexT.CONFIG.page.giscus.cfg; + theme } = NexT.CONFIG.giscus.cfg; NexT.utils.loadComments(element) - .then(() => NexT.utils.getScript(NexT.CONFIG.page.giscus.js, { + .then(() => NexT.utils.getScript(NexT.CONFIG.giscus.js, { attributes: { 'async' : true, 'crossorigin' : 'anonymous', @@ -31,7 +31,7 @@ document.addEventListener('DOMContentLoaded', () => { 'data-emit-metadata' : emit ? 1:0, 'data-input-position' : inputposition, 'data-theme' : theme, - 'data-lang' : NexT.CONFIG.page.lang, + 'data-lang' : NexT.CONFIG.lang, 'data-loading' : 'lazy' }, parentNode: document.querySelector(element) diff --git a/assets/js/third-party/comments/livere.js b/assets/js/third-party/comments/livere.js index 8d786f6..2051f05 100644 --- a/assets/js/third-party/comments/livere.js +++ b/assets/js/third-party/comments/livere.js @@ -2,11 +2,11 @@ document.addEventListener('DOMContentLoaded', () => { const element = '#lv-container'; if (!NexT.CONFIG.page.comments - || !NexT.CONFIG.page.livere + || !NexT.CONFIG.livere || !NexT.utils.checkDOMExist(element)) return; NexT.utils.loadComments(element).then(() => { - NexT.utils.getScript(NexT.CONFIG.page.livere.js, { + NexT.utils.getScript(NexT.CONFIG.livere.js, { attributes: { async: true }, diff --git a/assets/js/third-party/comments/utterances.js b/assets/js/third-party/comments/utterances.js index e8e7f60..afb6751 100644 --- a/assets/js/third-party/comments/utterances.js +++ b/assets/js/third-party/comments/utterances.js @@ -2,17 +2,17 @@ document.addEventListener('DOMContentLoaded', () => { const element = '.utterances-container'; if (!NexT.CONFIG.page.comments - || !NexT.CONFIG.page.utterances + || !NexT.CONFIG.utterances || !NexT.utils.checkDOMExist(element)) return; const { repo, issueterm, label, - theme } = NexT.CONFIG.page.utterances.cfg; + theme } = NexT.CONFIG.utterances.cfg; NexT.utils.loadComments(element) - .then(() => NexT.utils.getScript(NexT.CONFIG.page.utterances.js, { + .then(() => NexT.utils.getScript(NexT.CONFIG.utterances.js, { attributes: { 'async' : true, 'crossorigin' : 'anonymous', diff --git a/assets/js/third-party/comments/waline.js b/assets/js/third-party/comments/waline.js index 917c922..8153566 100644 --- a/assets/js/third-party/comments/waline.js +++ b/assets/js/third-party/comments/waline.js @@ -2,7 +2,7 @@ document.addEventListener('DOMContentLoaded', () => { const element = '.waline-container'; if (!NexT.CONFIG.page.comments - || !NexT.CONFIG.page.waline + || !NexT.CONFIG.waline || !NexT.utils.checkDOMExist(element)) return; const { @@ -13,13 +13,13 @@ document.addEventListener('DOMContentLoaded', () => { requiredmeta, serverurl, wordlimit - } = NexT.CONFIG.page.waline.cfg; + } = NexT.CONFIG.waline.cfg; - const waline_css = NexT.utils.getCDNResource(NexT.CONFIG.page.waline.css); + const waline_css = NexT.utils.getCDNResource(NexT.CONFIG.waline.css); NexT.utils.getStyle(waline_css, null); - const waline_js = NexT.utils.getCDNResource(NexT.CONFIG.page.waline.js); + const waline_js = NexT.utils.getCDNResource(NexT.CONFIG.waline.js); const locale = { placeholder: placeholder @@ -39,7 +39,7 @@ document.addEventListener('DOMContentLoaded', () => { wordLimit : wordlimit, requiredMeta : requiredmeta, serverURL : serverurl, - lang : NexT.CONFIG.page.lang, + lang : NexT.CONFIG.lang, dark : "auto" }); diff --git a/assets/js/third-party/share/addthis.js b/assets/js/third-party/share/addthis.js index 4fe8615..17371a3 100644 --- a/assets/js/third-party/share/addthis.js +++ b/assets/js/third-party/share/addthis.js @@ -1,9 +1,9 @@ document.addEventListener('DOMContentLoaded', () => { const element = '.addthis_inline_share_toolbox'; - if (!NexT.CONFIG.page.addthis || !NexT.utils.checkDOMExist(element)) return; + if (!NexT.CONFIG.addthis || !NexT.utils.checkDOMExist(element)) return; - const addthis_js = NexT.CONFIG.page.addthis.js + '?pubid=' + NexT.CONFIG.page.addthis.cfg.pubid; + const addthis_js = NexT.CONFIG.addthis.js + '?pubid=' + NexT.CONFIG.addthis.cfg.pubid; NexT.utils.loadComments(element).then(() => { NexT.utils.getScript(addthis_js, { diff --git a/assets/js/utils.js b/assets/js/utils.js index a53270e..9c083a1 100644 --- a/assets/js/utils.js +++ b/assets/js/utils.js @@ -63,6 +63,8 @@ NexT.utils = { * One-click copy code support. */ registerCopyCode: function() { + if (!NexT.CONFIG.copybtn) return; + let figure = document.querySelectorAll('.highlight pre'); if (figure.length === 0 || !NexT.CONFIG.copybtn) return; figure.forEach(element => { @@ -277,7 +279,7 @@ NexT.utils = { }); }, - initCommontesDispaly: function(){ + initCommontesDispaly: function(){ const comms = document.querySelectorAll('.comment-wrap > div'); if (comms.length<=1) return; comms.forEach(function(item){ @@ -302,6 +304,10 @@ NexT.utils = { }); }, + hideCommontes:function() { + document.querySelector('.post-comments').style.display = 'none'; + }, + hiddeLodingCmp: function(selector) { const loadding = document.querySelector(selector).previousElementSibling; loadding.style.display = 'none'; diff --git a/layouts/partials/comments.html b/layouts/partials/comments.html index 3626216..89315f4 100644 --- a/layouts/partials/comments.html +++ b/layouts/partials/comments.html @@ -1,6 +1,5 @@ {{- $root := . -}} {{- with .Site.Params.comments }} -{{- if .enable }} {{- $tc := and .storage (gt (len .nav) 1) }} {{- $active := .active }} {{- $fc := .active }} @@ -41,4 +40,3 @@ {{- end }} -{{- end }} diff --git a/layouts/partials/head/config.html b/layouts/partials/head/config.html index 1c8b50c..be3caaf 100644 --- a/layouts/partials/head/config.html +++ b/layouts/partials/head/config.html @@ -1,63 +1,10 @@ \ No newline at end of file diff --git a/layouts/partials/init.html b/layouts/partials/init.html index a5b8c6c..4b51080 100644 --- a/layouts/partials/init.html +++ b/layouts/partials/init.html @@ -15,14 +15,11 @@ {{ $router := index .Site.Data.resources.vendors $vendor }} {{ $globalVars.Set "router" $router }} -{{ $vendorDict := dict - "plugins" $vendor - "router" $router -}} {{ $config := dict "hostname" .Site.BaseURL "root" "/" - "vendor" $vendorDict + "lang" .Site.LanguageCode + "vendor" (dict "plugins" $vendor "router" $router) "darkmode" .Site.Params.darkmode "version" .Site.Data.config.version "scheme" .Site.Params.scheme @@ -32,6 +29,54 @@ "lazyload" .Site.Params.lazyload "motion" .Site.Params.motion }} + +{{ with .Site.Params.waline }} +{{ $waline := dict + "js" $.Site.Data.resources.waline.js + "css" $.Site.Data.resources.waline.css + "cfg" . +}} +{{ $config = merge $config (dict "waline" $waline) }} +{{ end }} + +{{ with .Site.Params.giscus }} +{{ $giscus := dict + "js" $.Site.Data.resources.giscus.js + "cfg" . +}} +{{ $config = merge $config (dict "giscus" $giscus) }} +{{ end }} + +{{ with .Site.Params.artalk }} +{{ $artalk := dict + "js" $.Site.Data.resources.artalk.js + "css" $.Site.Data.resources.artalk.css + "cfg" . +}} +{{ $config = merge $config (dict "artalk" $artalk) }} +{{ end }} + +{{ with .Site.Params.livere }} +{{ $livere := dict "js" $.Site.Data.resources.livere.js }} +{{ $config = merge $config (dict "livere" $livere) }} +{{ end }} + +{{ with .Site.Params.utterances }} +{{ $utterances := dict + "js" $.Site.Data.resources.utterances.js + "cfg" . +}} +{{ $config = merge $config (dict "utterances" $utterances) }} +{{ end }} + +{{ with .Site.Params.addThisId }} +{{ $addthis := dict + "js" $.Site.Data.resources.addthis.js + "cfg" (dict "pubid" .) +}} +{{ $config = merge $config (dict "addthis" $addthis) }} +{{ end }} + {{ $globalVars.Set "config" $config }} {{ return $globalVars.Values }} From af59e93d2544b6172101d606356a7f5c7b00d60f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=87=A1=E6=A2=A6=E6=98=9F=E5=B0=98?= Date: Tue, 26 Jul 2022 21:41:07 +0800 Subject: [PATCH 09/14] :wrench: Add special list for archives articles show. --- layouts/_default/list.html | 34 +++++----------------------------- layouts/_default/section.html | 3 +++ layouts/partials/init.html | 3 +++ layouts/partials/list.html | 29 +++++++++++++++++++++++++++++ 4 files changed, 40 insertions(+), 29 deletions(-) create mode 100644 layouts/partials/list.html diff --git a/layouts/_default/list.html b/layouts/_default/list.html index 35c4d71..3a56b50 100644 --- a/layouts/_default/list.html +++ b/layouts/_default/list.html @@ -1,29 +1,5 @@ -{{ range .Paginator.Pages.GroupByDate "2006" }} -
- {{ .Key }} -
-{{ range .Pages }} - -{{ end }} -{{ end }} \ No newline at end of file +{{- if and .Page.IsSection (eq .Section "archives") }} + {{ partial "list.html" ((.Paginator (where .Page.Site.RegularPages "Section" "in" .Site.Params.mainSections)).Pages.GroupByDate "2006") }} +{{- else }} + {{ partial "list.html" (.Paginator.Pages.GroupByDate "2006") }} +{{- end }} diff --git a/layouts/_default/section.html b/layouts/_default/section.html index a9bce65..9e73648 100644 --- a/layouts/_default/section.html +++ b/layouts/_default/section.html @@ -8,6 +8,9 @@
{{- $cheers := "Um" }} {{- $posts := .Scratch.Get "postsCount" }} + {{- if and .Page.IsSection (ne .Section "archives") }} + {{- $posts = .Scratch.Get .Section }} + {{- end }} {{- if gt $posts 210 }} {{- $cheers = "Excellent" }} {{- else if gt $posts 130 }} diff --git a/layouts/partials/init.html b/layouts/partials/init.html index 4b51080..723603f 100644 --- a/layouts/partials/init.html +++ b/layouts/partials/init.html @@ -8,6 +8,9 @@ {{ $globalVars := newScratch }} {{ $globalVars.Set "postsCount" (len (where .Page.Site.RegularPages "Section" "in" .Site.Params.mainSections)) }} +{{ range .Site.Params.mainSections }} + {{ $globalVars.Set . (len (where $.Page.Site.RegularPages "Section" .))}} +{{ end }} {{ $globalVars.Set "catsCount" (len .Site.Taxonomies.categories) }} {{ $globalVars.Set "tagsCount" (len .Site.Taxonomies.tags) }} diff --git a/layouts/partials/list.html b/layouts/partials/list.html new file mode 100644 index 0000000..7ddf390 --- /dev/null +++ b/layouts/partials/list.html @@ -0,0 +1,29 @@ +{{ range . }} +
+ {{ .Key }} +
+{{ range .Pages }} + +{{ end }} +{{ end }} \ No newline at end of file From e83dbabc3f3100c995bf1d712c06c6131b2eb708 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=87=A1=E6=A2=A6=E6=98=9F=E5=B0=98?= Date: Tue, 26 Jul 2022 22:18:43 +0800 Subject: [PATCH 10/14] :wrench: Archives page demo shows. --- .gitignore | 15 +++++- exampleSite/config.yaml | 4 +- exampleSite/content/about.md | 19 ------- exampleSite/content/archives/_index.md | 3 ++ .../content/{posts => post}/emoji-support.md | 0 .../content/{posts => post}/external-link.md | 0 .../content/{posts => post}/hello-world.md | 0 .../{posts => post}/markdown-syntax.md | 0 .../{posts => post}/syntax-highlighting.md | 0 .../{posts => post}/table-of-content.md | 0 i18n/en-us.toml | 49 ------------------- i18n/en.yaml | 2 +- i18n/zh-cn.toml | 49 ------------------- i18n/zh-cn.yaml | 2 +- layouts/_default/list.html | 8 +-- 15 files changed, 25 insertions(+), 126 deletions(-) delete mode 100644 exampleSite/content/about.md create mode 100644 exampleSite/content/archives/_index.md rename exampleSite/content/{posts => post}/emoji-support.md (100%) rename exampleSite/content/{posts => post}/external-link.md (100%) rename exampleSite/content/{posts => post}/hello-world.md (100%) rename exampleSite/content/{posts => post}/markdown-syntax.md (100%) rename exampleSite/content/{posts => post}/syntax-highlighting.md (100%) rename exampleSite/content/{posts => post}/table-of-content.md (100%) delete mode 100644 i18n/en-us.toml delete mode 100644 i18n/zh-cn.toml diff --git a/.gitignore b/.gitignore index 1a75d43..6b89457 100644 --- a/.gitignore +++ b/.gitignore @@ -1,6 +1,17 @@ # Ignore files in Hugo NexT theme -exampleSite/ +exampleSite/* + +# Exclude special files in content folder !exampleSite/content +exampleSite/content/* +!exampleSite/content/archives +!exampleSite/content/post + +# Exclude special files in static folder +!exampleSite/static + +# Exclude special files +!exampleSite/config.yaml !exampleSite/start.sh -!exampleSite/config.yaml \ No newline at end of file + diff --git a/exampleSite/config.yaml b/exampleSite/config.yaml index 8095f1d..0536ba9 100644 --- a/exampleSite/config.yaml +++ b/exampleSite/config.yaml @@ -86,7 +86,7 @@ menus: weight: 2 - identifier: archives name: 归档 - pageref: /posts + pageref: /archives pre: archive weight: 3 - identifier: commonweal @@ -103,7 +103,7 @@ params: # 需要显示文章的部分,即content目录下的文件夹名称 # Sections for show in home & archive page # and it's forlder name which under content - mainSections: ["posts"] + mainSections: ["post"] # 年,月,日及时间的格式化样式 # Format style for year,month,date & time yearFormat: "2006" diff --git a/exampleSite/content/about.md b/exampleSite/content/about.md deleted file mode 100644 index ae17cc8..0000000 --- a/exampleSite/content/about.md +++ /dev/null @@ -1,19 +0,0 @@ ---- -title: "关于 Hugo NexT 组织" -description: "" - -date: 2022-06-09T20:12:52+08:00 -lastmod: 2022-06-09T20:12:52+08:00 - -share: false -followme: false -nav: false -copyright: false -url: about.html ---- - -`Hugo NexT` 组织是由众多喜爱 `NexT` 主题及风格的世界各地友人共同组建而成,为的就是让这个主题继续在 `Hugo` 引擎中也能得到发扬光大,在此也欢迎你的加入! - -# 我们的愿景 - -延续 `NexT` 经典的黑白调搭配,保持简单的易用性及强大的功能。 \ No newline at end of file diff --git a/exampleSite/content/archives/_index.md b/exampleSite/content/archives/_index.md new file mode 100644 index 0000000..542863e --- /dev/null +++ b/exampleSite/content/archives/_index.md @@ -0,0 +1,3 @@ +--- +date: 2022-07-26T21:46:25+08:00 +--- \ No newline at end of file diff --git a/exampleSite/content/posts/emoji-support.md b/exampleSite/content/post/emoji-support.md similarity index 100% rename from exampleSite/content/posts/emoji-support.md rename to exampleSite/content/post/emoji-support.md diff --git a/exampleSite/content/posts/external-link.md b/exampleSite/content/post/external-link.md similarity index 100% rename from exampleSite/content/posts/external-link.md rename to exampleSite/content/post/external-link.md diff --git a/exampleSite/content/posts/hello-world.md b/exampleSite/content/post/hello-world.md similarity index 100% rename from exampleSite/content/posts/hello-world.md rename to exampleSite/content/post/hello-world.md diff --git a/exampleSite/content/posts/markdown-syntax.md b/exampleSite/content/post/markdown-syntax.md similarity index 100% rename from exampleSite/content/posts/markdown-syntax.md rename to exampleSite/content/post/markdown-syntax.md diff --git a/exampleSite/content/posts/syntax-highlighting.md b/exampleSite/content/post/syntax-highlighting.md similarity index 100% rename from exampleSite/content/posts/syntax-highlighting.md rename to exampleSite/content/post/syntax-highlighting.md diff --git a/exampleSite/content/posts/table-of-content.md b/exampleSite/content/post/table-of-content.md similarity index 100% rename from exampleSite/content/posts/table-of-content.md rename to exampleSite/content/post/table-of-content.md diff --git a/i18n/en-us.toml b/i18n/en-us.toml deleted file mode 100644 index a162721..0000000 --- a/i18n/en-us.toml +++ /dev/null @@ -1,49 +0,0 @@ -#-------------------------------------- -# English Version -#-------------------------------------- - -[ColoneFlag] - other = ":" - -[SitePostsTitle] - other = "Posts" -[SiteCatesTitle] - other = "Categories" -[SiteTagsTitle] - other = "Tags" -[TableOfContents] - other = "TOC" -[SiteInfo] - other = "Site Info" -[RSSTitle] - other = "RSS Subscribe" -[CCLinkTitle] - other = "Creative Commons" - -[PostPublishDate] - other = "Publish" -[PostPublishTime] - other = "Create Time" -[PostLastModDate] - other = "Update" -[PostLastModTime] - other = "Modify Time" -[PostWords] - other = "Words" -[PostWordCount] - other = "{{- .WordCount -}}" -[PostReading] - other = "Read" -[PostReadTime] - other = "{{- .ReadingTime -}}min" -[PostVisitor] - other = "Views" -[PostCatg] - other = "Categories" -[PostTag] - other = "Tags" -[PostReadMore] - other = "Read More" - -[FooterPowerby] - other = "Power by %s" \ No newline at end of file diff --git a/i18n/en.yaml b/i18n/en.yaml index a719c45..a7ca413 100644 --- a/i18n/en.yaml +++ b/i18n/en.yaml @@ -1,7 +1,7 @@ #-------------------------------------- # English Version #-------------------------------------- -posts: +archives: other: Posts tag: other: Tag diff --git a/i18n/zh-cn.toml b/i18n/zh-cn.toml deleted file mode 100644 index 63d0942..0000000 --- a/i18n/zh-cn.toml +++ /dev/null @@ -1,49 +0,0 @@ -#-------------------------------------- -# 中文版本 -#-------------------------------------- - -[ColoneFlag] - other = ":" - -[SitePostsTitle] - other = "日志" -[SiteCatesTitle] - other = "分类" -[SiteTagsTitle] - other = "标签" -[TableOfContents] - other = "文章目录" -[SiteInfo] - other = "站点概览" -[RSSTitle] - other = "RSS 订阅" -[CCLinkTitle] - other = "共享知识" - -[PostPublishDate] - other = "发表于" -[PostPublishTime] - other = "创建时间" -[PostLastModDate] - other = "更新于" -[PostLastModTime] - other = "修改时间" -[PostWords] - other = "字数" -[PostWordCount] - other = "{{- .WordCount -}}" -[PostReading] - other = "阅读" -[PostReadTime] - other = "{{- .ReadingTime -}}分钟" -[PostVisitor] - other = "浏览数" -[PostCatg] - other = "分类" -[PostTag] - other = "标签" -[PostReadMore] - other = "阅读全文" - -[FooterPowerby] - other = "由 %s 强力驱动" \ No newline at end of file diff --git a/i18n/zh-cn.yaml b/i18n/zh-cn.yaml index 049d65e..1aa9600 100644 --- a/i18n/zh-cn.yaml +++ b/i18n/zh-cn.yaml @@ -2,7 +2,7 @@ # 中文版本 #-------------------------------------- -posts: +archives: other: 文章 tag: other: 标签 diff --git a/layouts/_default/list.html b/layouts/_default/list.html index 3a56b50..42c686a 100644 --- a/layouts/_default/list.html +++ b/layouts/_default/list.html @@ -1,5 +1,7 @@ {{- if and .Page.IsSection (eq .Section "archives") }} - {{ partial "list.html" ((.Paginator (where .Page.Site.RegularPages "Section" "in" .Site.Params.mainSections)).Pages.GroupByDate "2006") }} -{{- else }} - {{ partial "list.html" (.Paginator.Pages.GroupByDate "2006") }} + {{- $paginator := (.Paginate (where .Page.Site.RegularPages "Section" "in" .Site.Params.mainSections) ).Pages.GroupByDate "2006" }} + {{ partial "list.html" $paginator }} +{{ else }} + {{- $paginator := .Paginator.Pages.GroupByDate "2006" }} + {{ partial "list.html" $paginator }} {{- end }} From 87301d1d83987ca8f3202534d431840c4fc071b7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=87=A1=E6=A2=A6=E6=98=9F=E5=B0=98?= Date: Wed, 27 Jul 2022 11:06:02 +0800 Subject: [PATCH 11/14] :bug: fixed the SCSS build waring things. --- assets/css/main.scss | 6 +++--- layouts/_default/list.html | 2 +- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/assets/css/main.scss b/assets/css/main.scss index b43208e..78c46c2 100644 --- a/assets/css/main.scss +++ b/assets/css/main.scss @@ -131,9 +131,9 @@ $gitter_enable : {{ $P.gitter.enable }}; // Comment //$disqusjs_enable : {{ $P.disqusjs.enable }}; $disqusjs_enable : false; -$livere_enable : {{ isset $P.livere "uid" }}; -$utterances_enable : {{ isset $P.utterances "utterances" }}; -$waline_enable : {{ isset $P.waline "serverurl" }}; +$livere_enable : {{ isset $P "livere" }}; +$utterances_enable : {{ isset $P "utterances" }}; +$waline_enable : {{ isset $P "waline" }}; {{- with .Site.Params.comments }} {{- $tce := and (isset . "nav") (and .storage (gt (len .nav) 1)) }} $two_comments_enable : {{ $tce }}; diff --git a/layouts/_default/list.html b/layouts/_default/list.html index 42c686a..19015ab 100644 --- a/layouts/_default/list.html +++ b/layouts/_default/list.html @@ -1,5 +1,5 @@ {{- if and .Page.IsSection (eq .Section "archives") }} - {{- $paginator := (.Paginate (where .Page.Site.RegularPages "Section" "in" .Site.Params.mainSections) ).Pages.GroupByDate "2006" }} + {{- $paginator := (.Paginate (where .Page.Site.RegularPages "Section" "in" .Site.Params.mainSections)).Pages.GroupByDate "2006" }} {{ partial "list.html" $paginator }} {{ else }} {{- $paginator := .Paginator.Pages.GroupByDate "2006" }} From f430f0730b749da64b63198e9ce91d6cc6427867 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=87=A1=E6=A2=A6=E6=98=9F=E5=B0=98?= Date: Wed, 27 Jul 2022 11:21:03 +0800 Subject: [PATCH 12/14] :wrench: Add Hugo version judge logic to avoid the lower version building. Closed #21 --- layouts/partials/init.html | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/layouts/partials/init.html b/layouts/partials/init.html index 723603f..5ceb18a 100644 --- a/layouts/partials/init.html +++ b/layouts/partials/init.html @@ -5,6 +5,12 @@ {{ errorf "Because that use SCSS framework in Hugo NexT, Please download Hugo extended version on offical site: https://github.com/gohugoio/hugo/releases" }} {{ end }} +{{ $version := int (index (split hugo.Version ".") 1) }} +{{ if lt $version 89 }} +{{ warnf "当前 Hugo 版本小于 0.89.0,请到官方地址下载 Hugo 最新版本:https://github.com/gohugoio/hugo/releases" }} +{{ errorf "Current Hugo version is less then 0.89.0, Please download Hugo latest version on offical site: https://github.com/gohugoio/hugo/releases" }} +{{ end }} + {{ $globalVars := newScratch }} {{ $globalVars.Set "postsCount" (len (where .Page.Site.RegularPages "Section" "in" .Site.Params.mainSections)) }} From 6ffddb602fba512a6edd29e04e6ebc0421a8e677 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=87=A1=E6=A2=A6=E6=98=9F=E5=B0=98?= Date: Wed, 27 Jul 2022 13:56:02 +0800 Subject: [PATCH 13/14] :bookmark: Start release Version 4.1.0 . --- VERSION | 2 +- data/config.yaml | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/VERSION b/VERSION index 0c89fc9..99eba4d 100644 --- a/VERSION +++ b/VERSION @@ -1 +1 @@ -4.0.0 \ No newline at end of file +4.1.0 \ No newline at end of file diff --git a/data/config.yaml b/data/config.yaml index dbd6bed..8ca6ecf 100644 --- a/data/config.yaml +++ b/data/config.yaml @@ -1,4 +1,4 @@ # Hugo NexT theme's custom config # -version: 4.0.0 \ No newline at end of file +version: 4.1.0 \ No newline at end of file From 1171bcbfb32120d44f55652f7ef4c32fde9be036 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=87=A1=E6=A2=A6=E6=98=9F=E5=B0=98?= Date: Wed, 27 Jul 2022 21:29:04 +0800 Subject: [PATCH 14/14] :bento: Update the fontawesome version. --- data/resources.yaml | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/data/resources.yaml b/data/resources.yaml index e204c3c..e95a2f7 100644 --- a/data/resources.yaml +++ b/data/resources.yaml @@ -10,15 +10,16 @@ js: - name: animejs version: 3.2.1 file: lib/anime.min.js - - name: mathjax - version: 3.2.0 - file: es5/tex-mml-chtml.js + # TODO + #- name: mathjax + # version: 3.2.0 + # file: es5/tex-mml-chtml.js # CSS 资源 # CSS Resources css: - name: '@fortawesome/fontawesome-free' - version: 6.1.1 + version: 6.1.2 file: css/all.min.css alias: font-awesome - name: animate.css