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/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/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/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..1ca46e6 100644 --- a/assets/js/config.js +++ b/assets/js/config.js @@ -1,51 +1,67 @@ if (!window.NexT) window.NexT = {}; (function() { + const className = 'next-config'; - const siteConfig = { - "hostname" : "{{ .Site.BaseURL }}", - "root" : "/", - "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 }} - "lang" : "{{ .Site.LanguageCode }}", - "permalink" : "{{ .Page.Permalink | absURL }}", - "title" : "{{ .Page.Title }}", - "isHome" : {{ .IsHome }}, - "isPage" : {{ .IsPage }} }; - - window.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/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..8f96889 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,41 @@ 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. */ - //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(); - - CONFIG.isPage && NexT.utils.replacePostCRLink(); - CONFIG.isPage && CONFIG.copybtn && NexT.utils.registerCopyCode(); - NexT.utils.registerTabsTag(); - /*NexT.utils.registerActiveMenuItem(); + // NexT.CONFIG.lazyload && window.lozad('.post-body img').observe(); + // NexT.CONFIG.pangu && window.pangu.spacingPage(); + /*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.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 +80,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..8b5dcc2 --- /dev/null +++ b/assets/js/third-party/comments/artalk.js @@ -0,0 +1,36 @@ +document.addEventListener('DOMContentLoaded', () => { + + const element = '.artalk-container'; + if (!NexT.CONFIG.page.comments + || !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.cfg; + + 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..62529a8 --- /dev/null +++ b/assets/js/third-party/comments/giscus.js @@ -0,0 +1,41 @@ +document.addEventListener('DOMContentLoaded', () => { + + const element = '.giscus-container'; + if (!NexT.CONFIG.page.comments + || !NexT.CONFIG.giscus + || !NexT.utils.checkDOMExist(element)) return; + + const { + category, + categoryid, + emit, + inputposition, + mapping, + reactions, + repo, + repoid, + theme } = NexT.CONFIG.giscus.cfg; + + + 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..2051f05 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.page.comments + || !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..afb6751 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.page.comments + || !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.cfg; + + 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..8153566 --- /dev/null +++ b/assets/js/third-party/comments/waline.js @@ -0,0 +1,48 @@ +document.addEventListener('DOMContentLoaded', () => { + + const element = '.waline-container'; + if (!NexT.CONFIG.page.comments + || !NexT.CONFIG.waline + || !NexT.utils.checkDOMExist(element)) return; + + const { + emoji, + imguploader, + pageview, + placeholder, + requiredmeta, + serverurl, + wordlimit + } = NexT.CONFIG.waline.cfg; + + + 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..17371a3 --- /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.cfg.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..9c083a1 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){ @@ -40,8 +63,10 @@ NexT.utils = { * One-click copy code support. */ registerCopyCode: function() { + if (!NexT.CONFIG.copybtn) return; + 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 +195,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 +230,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 +238,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 => { @@ -253,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){ @@ -278,6 +304,15 @@ NexT.utils = { }); }, + hideCommontes:function() { + document.querySelector('.post-comments').style.display = 'none'; + }, + + 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 +338,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 +379,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 +406,7 @@ NexT.utils = { } = {}, parentNode = null } = options; + return new Promise((resolve, reject) => { if (condition) { resolve(); @@ -401,7 +446,7 @@ NexT.utils = { } return new Promise(resolve => { const element = document.querySelector(selector); - if (!CONFIG.comments.lazyload || !element) { + if (!element) { resolve(); return; } 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 diff --git a/data/resources.yaml b/data/resources.yaml index f7c4ac1..e95a2f7 100644 --- a/data/resources.yaml +++ b/data/resources.yaml @@ -1,27 +1,73 @@ +# 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 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 version: 3.1.1 - file: animate.min.css \ No newline at end of file + file: animate.min.css + +# 第三方服务组件资源 +# 3rd servcies Resource + +# 站点统计 +# Site analytics engine +analytics: + la: https://sdk.51.la/js-sdk-pro.min.js + +# 文章分享 +# 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/config.yaml b/exampleSite/config.yaml index 947960d..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" @@ -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 @@ -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,16 +802,24 @@ 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: # + categoryId: # + # 帖子上的反应将会显示在评论前 + # 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 # 讨论区帖子标题,可选值: pathname | url | title | og:title | 自定义 # Available values: pathname | url | title | og:title | custom mapping: title @@ -854,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. 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/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/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/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/_default/list.html b/layouts/_default/list.html index 35c4d71..19015ab 100644 --- a/layouts/_default/list.html +++ b/layouts/_default/list.html @@ -1,29 +1,7 @@ -{{ range .Paginator.Pages.GroupByDate "2006" }} -
- {{ .Key }} -
-{{ range .Pages }} - -{{ end }} -{{ end }} \ No newline at end of file +{{- if and .Page.IsSection (eq .Section "archives") }} + {{- $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 }} 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/_thirdparty/analytics/51la.html b/layouts/partials/_thirdparty/analytics/51la.html index 3aca679..07e9221 100644 --- a/layouts/partials/_thirdparty/analytics/51la.html +++ b/layouts/partials/_thirdparty/analytics/51la.html @@ -1,2 +1,17 @@ - - + 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 d1b476f..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/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.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 0105e07..37a5b2f 100644 --- a/layouts/partials/head/analytics.html +++ b/layouts/partials/head/analytics.html @@ -1,5 +1,3 @@ -{{- with .Site.Params.analytics }} -{{- if isset . "laid" }} - {{ partial "_thirdparty/analytics/51la.html" .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..be3caaf --- /dev/null +++ b/layouts/partials/head/config.html @@ -0,0 +1,10 @@ + \ 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..5ceb18a 100644 --- a/layouts/partials/init.html +++ b/layouts/partials/init.html @@ -1,14 +1,91 @@ {{/* 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 }} -{{- .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 +{{ $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)) }} +{{ 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) }} + +{{ $vendor := .Site.Params.vendors.plugins }} +{{ $router := index .Site.Data.resources.vendors $vendor }} +{{ $globalVars.Set "router" $router }} + +{{ $config := dict + "hostname" .Site.BaseURL + "root" "/" + "lang" .Site.LanguageCode + "vendor" (dict "plugins" $vendor "router" $router) + "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 +}} + +{{ 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 }} 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 diff --git a/layouts/partials/scripts.html b/layouts/partials/scripts.html index a89f54e..0b4a23c 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,14 +11,15 @@ {{- $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 }} -{{- $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" }} @@ -39,8 +40,32 @@ {{- $pjaxjs := resources.Get "js/pjax.js" }} {{- $nextjs = $nextjs | append $pjaxjs }} {{- end }} -{{- $nextjs = $nextjs | resources.Concat "js/hugo-next.js"}} +{{- 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/main.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