From f37613117a48a2b5188549a32c4d964da2ceaed7 Mon Sep 17 00:00:00 2001 From: scarqin <1054139596@qq.com> Date: Mon, 14 Feb 2022 03:04:19 +0800 Subject: [PATCH 1/2] feat: update to hexo^6.0 --- _config.yml | 2 +- layout/_partial/head.ejs | 3 +- layout/_partial/menu.ejs | 12 +- layout/_partial/post/copyright.ejs | 4 +- layout/_partial/tags-bar.ejs | 2 +- layout/archive.ejs | 7 +- scripts/plugins.js | 3 +- source/js/main.js | 463 ++++++++++++++++------------- source/js/main.min.js | 454 +++++++++++++++++++++++++++- 9 files changed, 734 insertions(+), 216 deletions(-) diff --git a/_config.yml b/_config.yml index bb7926a3..79069c8d 100644 --- a/_config.yml +++ b/_config.yml @@ -164,7 +164,7 @@ title_change: # 设置为 true 发布后将使用 unpkg cdn 最新的主题样式 # 如果想让你的自定义样式生效,把此项设为 false -cdn: true +cdn: false # 设置为 true 将使用 lightbox render 图片 lightbox: true diff --git a/layout/_partial/head.ejs b/layout/_partial/head.ejs index 4dff0620..27371c7f 100644 --- a/layout/_partial/head.ejs +++ b/layout/_partial/head.ejs @@ -38,8 +38,7 @@ var keyWords = config.keywords; if(page.tags){ keyWords = []; - - _.isArray(page.tags) ? ( keyWords = page.tags ) + Array.isArray(page.tags) ? ( keyWords = page.tags ) : page.tags.each(function(k){ keyWords.push(k.name); }); diff --git a/layout/_partial/menu.ejs b/layout/_partial/menu.ejs index 7d65b787..c7c8197b 100644 --- a/layout/_partial/menu.ejs +++ b/layout/_partial/menu.ejs @@ -19,15 +19,23 @@ <% var menuItem, isActive = function(item) { var pageUrl = url_for(page.path) - return item.url === '/' ? pageUrl === url_for(item.url + 'index.html') : _.startsWith(pageUrl, url_for(item.url)) + return item.url === '/' ? pageUrl === url_for(item.url + 'index.html') : pageUrl.startsWith( url_for(item.url)) }; + function startCase(str) { + return str.replace( + /\w\S*/g, + function(txt) { + return txt.charAt(0).toUpperCase() + txt.substr(1).toLowerCase(); + } + ); + } for (var i in theme.menu) { menuItem = theme.menu[i]; %>
  • target="_blank"<% } %> > - <%=(menuItem.text || _.startCase(i)) %> + <%=(menuItem.text || startCase(i)) %>
  • <% } %> diff --git a/layout/_partial/post/copyright.ejs b/layout/_partial/post/copyright.ejs index bcf42eed..229b552b 100644 --- a/layout/_partial/post/copyright.ejs +++ b/layout/_partial/post/copyright.ejs @@ -2,8 +2,8 @@ <% if(theme.postMessage || theme.show_last_updated) { %>
    <%- partial('updated') %> - <% if(theme.postMessage) {%> - <%- _.template(theme.postMessage)(locals) %> + <% if(theme.postMessage) { const templateLiteral = (value) => theme.postMessage;%> + <%- templateLiteral(locals) %> <% } %>
    <% } %> diff --git a/layout/_partial/tags-bar.ejs b/layout/_partial/tags-bar.ejs index a797aa85..9a5679ab 100644 --- a/layout/_partial/tags-bar.ejs +++ b/layout/_partial/tags-bar.ejs @@ -13,7 +13,7 @@ if(type === 'categories' || type === 'tags'){ %> } }) - var index = _.findIndex(options, function(o) { + var index = options.findIndex(function(o) { return is_current(o.path) }) var len = options.length diff --git a/layout/archive.ejs b/layout/archive.ejs index 867300d7..1037a179 100644 --- a/layout/archive.ejs +++ b/layout/archive.ejs @@ -5,12 +5,13 @@
    <% var posts = []; - + const sortBy = (key) => { + return (a, b) => (a[key] < b[key]) ? 1 : ((b[key] < a[key]) ? -1 : 0); + }; page.posts.each(function(post){ posts.push(post); }); - - var sortPosts = _[_.orderBy ? 'orderBy' : 'sortByOrder'](posts, ['date'], ['desc']); + var sortPosts = posts.concat().sort(sortBy("date")); %> <% diff --git a/scripts/plugins.js b/scripts/plugins.js index ffb02ff5..9e38e37e 100644 --- a/scripts/plugins.js +++ b/scripts/plugins.js @@ -4,7 +4,8 @@ hexo.extend.helper.register('theme_version', () => version) const source = (path, cache, ext) => { if (cache) { - const minFile = `${path}${ext === '.js' ? '.min' : ''}${ext}` + // const minFile = `${path}${ext === '.js' ? '.min' : ''}${ext}` + const minFile = `${path}${ext}` return hexo.theme.config.cdn ? `//unpkg.com/${name}@latest${minFile}` : `${minFile}?v=${version}` } else { return path + ext diff --git a/source/js/main.js b/source/js/main.js index f07b28e2..c68d8d50 100644 --- a/source/js/main.js +++ b/source/js/main.js @@ -1,22 +1,27 @@ (function (w, d) { - var body = d.body, $ = d.querySelector.bind(d), $$ = d.querySelectorAll.bind(d), - root = $('html'), - gotop = $('#gotop'), - menu = $('#menu'), - header = $('#header'), - mask = $('#mask'), - menuToggle = $('#menu-toggle'), - menuOff = $('#menu-off'), - loading = $('#loading'), + root = $("html"), + gotop = $("#gotop"), + menu = $("#menu"), + header = $("#header"), + mask = $("#mask"), + menuToggle = $("#menu-toggle"), + menuOff = $("#menu-off"), + loading = $("#loading"), animate = w.requestAnimationFrame, scrollSpeed = 200 / (1000 / 60), forEach = Array.prototype.forEach, - even = ('ontouchstart' in w && /Mobile|Android|iOS|iPhone|iPad|iPod|Windows Phone|KFAPWI/i.test(navigator.userAgent)) ? 'touchstart' : 'click', + even = + "ontouchstart" in w && + /Mobile|Android|iOS|iPhone|iPad|iPod|Windows Phone|KFAPWI/i.test( + navigator.userAgent + ) + ? "touchstart" + : "click", isWX = /micromessenger/i.test(navigator.userAgent), - noop = function () { }, + noop = function () {}, offset = function (el) { var x = el.offsetLeft, y = el.offsetTop; @@ -29,17 +34,20 @@ return { x: x, - y: y + y: y, }; }, - rootScollTop = function() { + rootScollTop = function () { return d.documentElement.scrollTop || d.body.scrollTop; }; var Blog = { goTop: function (end) { var top = rootScollTop(); - var interval = arguments.length > 2 ? arguments[1] : Math.abs(top - end) / scrollSpeed; + var interval = + arguments.length > 2 + ? arguments[1] + : Math.abs(top - end) / scrollSpeed; if (top && top > end) { w.scrollTo(0, Math.max(top - interval, 0)); @@ -53,78 +61,78 @@ }, toggleGotop: function (top) { if (top > w.innerHeight / 2) { - gotop.classList.add('in'); + gotop.classList.add("in"); } else { - gotop.classList.remove('in'); + gotop.classList.remove("in"); } }, toggleMenu: function (flag) { - var main = $('#main'); + var main = $("#main"); if (flag) { - menu.classList.remove('hide'); + menu.classList.remove("hide"); if (w.innerWidth < 1241) { - mask.classList.add('in'); - menu.classList.add('show'); + mask.classList.add("in"); + menu.classList.add("show"); if (isWX) { var top = rootScollTop(); - main.classList.add('lock'); + main.classList.add("lock"); main.scrollTop = top; } else { - root.classList.add('lock'); + root.classList.add("lock"); } } - } else { - menu.classList.remove('show'); - mask.classList.remove('in'); + menu.classList.remove("show"); + mask.classList.remove("in"); if (isWX) { var top = main.scrollTop; - main.classList.remove('lock'); + main.classList.remove("lock"); w.scrollTo(0, top); } else { - root.classList.remove('lock'); + root.classList.remove("lock"); } - } }, fixedHeader: function (top) { if (top > header.clientHeight) { - header.classList.add('fixed'); + header.classList.add("fixed"); } else { - header.classList.remove('fixed'); + header.classList.remove("fixed"); } }, toc: (function () { - var toc = $('#post-toc'); + var toc = $("#post-toc"); if (!toc || !toc.children.length) { return { fixed: noop, - actived: noop - } + actived: noop, + }; } - var bannerH = $('.post-header').clientHeight, + var bannerH = $(".post-header").clientHeight, headerH = header.clientHeight, - titles = $('#post-content').querySelectorAll('h1, h2, h3, h4, h5, h6'); - - toc.querySelector('a[href="#' + titles[0].id + '"]').parentNode.classList.add('active'); - + titles = $("#post-content").querySelectorAll( + "h1, h2, h3, h4, h5, h6" + ); + toc.querySelector( + 'a[href="#' + encodeURIComponent(titles[0].id) + '"]' + ).parentNode.classList.add("active"); // Make every child shrink initially - var tocChilds = toc.querySelectorAll('.post-toc-child'); + var tocChilds = toc.querySelectorAll(".post-toc-child"); for (i = 0, len = tocChilds.length; i < len; i++) { - tocChilds[i].classList.add('post-toc-shrink'); + tocChilds[i].classList.add("post-toc-shrink"); } - var firstChild = - toc.querySelector('a[href="#' + titles[0].id + '"]') - .nextElementSibling; + var firstChild = toc.querySelector( + 'a[href="#' + encodeURIComponent(titles[0].id) + '"]' + ).nextElementSibling; if (firstChild) { - firstChild.classList.add('post-toc-expand'); - firstChild.classList.remove('post-toc-shrink'); + firstChild.classList.add("post-toc-expand"); + firstChild.classList.remove("post-toc-shrink"); } - toc.classList.remove('post-toc-shrink'); + toc.classList.remove("post-toc-shrink"); /** * Handle toc active and expansion @@ -132,30 +140,35 @@ * @param currEle current active li element */ var handleTocActive = function (prevEle, currEle) { - prevEle.classList.remove('active'); - currEle.classList.add('active'); + prevEle.classList.remove("active"); + currEle.classList.add("active"); - var siblingChilds = currEle.parentElement.querySelectorAll('.post-toc-child'); + var siblingChilds = + currEle.parentElement.querySelectorAll(".post-toc-child"); for (j = 0, len1 = siblingChilds.length; j < len1; j++) { - siblingChilds[j].classList.remove('post-toc-expand'); - siblingChilds[j].classList.add('post-toc-shrink'); + siblingChilds[j].classList.remove("post-toc-expand"); + siblingChilds[j].classList.add("post-toc-shrink"); } - var myChild = currEle.querySelector('.post-toc-child'); + var myChild = currEle.querySelector(".post-toc-child"); if (myChild) { - myChild.classList.remove('post-toc-shrink'); - myChild.classList.add('post-toc-expand'); + myChild.classList.remove("post-toc-shrink"); + myChild.classList.add("post-toc-expand"); } }; return { fixed: function (top) { - top >= bannerH - headerH ? toc.classList.add('fixed') : toc.classList.remove('fixed'); + top >= bannerH - headerH + ? toc.classList.add("fixed") + : toc.classList.remove("fixed"); }, actived: function (top) { for (i = 0, len = titles.length; i < len; i++) { if (top > offset(titles[i]).y - headerH - 5) { - var prevListEle = toc.querySelector('li.active'); - var currListEle = toc.querySelector('a[href="#' + titles[i].id + '"]').parentNode; + var prevListEle = toc.querySelector("li.active"); + var currListEle = toc.querySelector( + 'a[href="#' + encodeURIComponent(titles[i].id) + '"]' + ).parentNode; handleTocActive(prevListEle, currListEle); } @@ -163,144 +176,153 @@ if (top < offset(titles[0]).y) { handleTocActive( - toc.querySelector('li.active'), - toc.querySelector('a[href="#' + titles[0].id + '"]').parentNode + toc.querySelector("li.active"), + toc.querySelector('a[href="#' + encodeURIComponent(titles[0].id) + '"]') + .parentNode ); } - } - } + }, + }; })(), hideOnMask: [], modal: function (target) { this.$modal = $(target); - this.$off = this.$modal.querySelector('.close'); + this.$off = this.$modal.querySelector(".close"); var _this = this; this.show = function () { - mask.classList.add('in'); - _this.$modal.classList.add('ready'); + mask.classList.add("in"); + _this.$modal.classList.add("ready"); setTimeout(function () { - _this.$modal.classList.add('in'); - }, 0) - } + _this.$modal.classList.add("in"); + }, 0); + }; this.onHide = noop; this.hide = function () { _this.onHide(); - mask.classList.remove('in'); - _this.$modal.classList.remove('in'); + mask.classList.remove("in"); + _this.$modal.classList.remove("in"); setTimeout(function () { - _this.$modal.classList.remove('ready'); - }, 300) - } + _this.$modal.classList.remove("ready"); + }, 300); + }; this.toggle = function () { - return _this.$modal.classList.contains('in') ? _this.hide() : _this.show(); - } + return _this.$modal.classList.contains("in") + ? _this.hide() + : _this.show(); + }; Blog.hideOnMask.push(this.hide); this.$off && this.$off.addEventListener(even, this.hide); }, share: function () { + var pageShare = $("#pageShare"), + fab = $("#shareFab"); - var pageShare = $('#pageShare'), - fab = $('#shareFab'); + var shareModal = new this.modal("#globalShare"); - var shareModal = new this.modal('#globalShare'); - - $('#menuShare').addEventListener(even, shareModal.toggle); + $("#menuShare").addEventListener(even, shareModal.toggle); if (fab) { - fab.addEventListener(even, function () { - pageShare.classList.toggle('in') - }, false) - - d.addEventListener(even, function (e) { - !fab.contains(e.target) && pageShare.classList.remove('in') - }, false) + fab.addEventListener( + even, + function () { + pageShare.classList.toggle("in"); + }, + false + ); + + d.addEventListener( + even, + function (e) { + !fab.contains(e.target) && + pageShare.classList.remove("in"); + }, + false + ); } - var wxModal = new this.modal('#wxShare'); + var wxModal = new this.modal("#wxShare"); wxModal.onHide = shareModal.hide; - forEach.call($$('.wxFab'), function (el) { - el.addEventListener(even, wxModal.toggle) - }) - + forEach.call($$(".wxFab"), function (el) { + el.addEventListener(even, wxModal.toggle); + }); }, search: function () { - var searchWrap = $('#search-wrap'); + var searchWrap = $("#search-wrap"); function toggleSearch() { - searchWrap.classList.toggle('in'); + searchWrap.classList.toggle("in"); } - $('#search').addEventListener(even, toggleSearch); + $("#search").addEventListener(even, toggleSearch); }, reward: function () { - var modal = new this.modal('#reward'); - $('#rewardBtn').addEventListener(even, modal.toggle); + var modal = new this.modal("#reward"); + $("#rewardBtn").addEventListener(even, modal.toggle); - var $rewardToggle = $('#rewardToggle'); - var $rewardCode = $('#rewardCode'); + var $rewardToggle = $("#rewardToggle"); + var $rewardCode = $("#rewardCode"); if ($rewardToggle) { - $rewardToggle.addEventListener('change', function () { - $rewardCode.src = this.checked ? this.dataset.alipay : this.dataset.wechat - }) + $rewardToggle.addEventListener("change", function () { + $rewardCode.src = this.checked + ? this.dataset.alipay + : this.dataset.wechat; + }); } }, waterfall: function () { - if (w.innerWidth < 760) return; - forEach.call($$('.waterfall'), function (el) { - var childs = el.querySelectorAll('.waterfall-item'); + forEach.call($$(".waterfall"), function (el) { + var childs = el.querySelectorAll(".waterfall-item"); var columns = [0, 0]; forEach.call(childs, function (item) { var i = columns[0] <= columns[1] ? 0 : 1; - item.style.cssText = 'top:' + columns[i] + 'px;left:' + (i > 0 ? '50%' : 0); + item.style.cssText = + "top:" + columns[i] + "px;left:" + (i > 0 ? "50%" : 0); columns[i] += item.offsetHeight; - }) - - el.style.height = Math.max(columns[0], columns[1]) + 'px'; - el.classList.add('in') - }) + }); + el.style.height = Math.max(columns[0], columns[1]) + "px"; + el.classList.add("in"); + }); }, tabBar: function (el) { - el.parentNode.parentNode.classList.toggle('expand') + el.parentNode.parentNode.classList.toggle("expand"); }, page: (function () { - var $elements = $$('.fade, .fade-scale'); + var $elements = $$(".fade, .fade-scale"); var visible = false; return { loaded: function () { forEach.call($elements, function (el) { - el.classList.add('in') + el.classList.add("in"); }); visible = true; }, unload: function () { forEach.call($elements, function (el) { - el.classList.remove('in') + el.classList.remove("in"); }); visible = false; }, - visible: visible - } - + visible: visible, + }; })(), lightbox: (function () { - function LightBox(element) { - this.$img = element.querySelector('img'); - this.$overlay = element.querySelector('overlay'); + this.$img = element.querySelector("img"); + this.$overlay = element.querySelector("overlay"); this.margin = 40; - this.title = this.$img.title || this.$img.alt || ''; + this.title = this.$img.title || this.$img.alt || ""; this.isZoom = false; var naturalW, naturalH, imgRect, docW, docH; @@ -324,26 +346,37 @@ w: w, h: h, t: (docH - h) / 2 - imgRect.top, - l: (docW - w) / 2 - imgRect.left + this.$img.offsetLeft - } - } + l: (docW - w) / 2 - imgRect.left + this.$img.offsetLeft, + }; + }; this.setImgRect = function (rect) { - this.$img.style.cssText = 'width: ' + rect.w + 'px; max-width: ' + rect.w + 'px; height:' + rect.h + 'px; top: ' + rect.t + 'px; left: ' + rect.l + 'px'; - } + this.$img.style.cssText = + "width: " + + rect.w + + "px; max-width: " + + rect.w + + "px; height:" + + rect.h + + "px; top: " + + rect.t + + "px; left: " + + rect.l + + "px"; + }; this.setFrom = function () { this.setImgRect({ w: imgRect.width, h: imgRect.height, t: 0, - l: (element.offsetWidth - imgRect.width) / 2 - }) - } + l: (element.offsetWidth - imgRect.width) / 2, + }); + }; this.setTo = function () { this.setImgRect(this.calcRect()); - } + }; // this.updateSize = function () { // var sw = sh = 1; @@ -374,15 +407,15 @@ if (!this.title) { return; } - this.$caption = d.createElement('div'); + this.$caption = d.createElement("div"); this.$caption.innerHTML = this.title; - this.$caption.className = 'overlay-title'; + this.$caption.className = "overlay-title"; element.appendChild(this.$caption); - } + }; this.removeTitle = function () { - this.$caption && element.removeChild(this.$caption) - } + this.$caption && element.removeChild(this.$caption); + }; var _this = this; @@ -390,68 +423,70 @@ naturalW = this.$img.naturalWidth || this.$img.width; naturalH = this.$img.naturalHeight || this.$img.height; imgRect = this.$img.getBoundingClientRect(); - element.style.height = imgRect.height + 'px'; - element.classList.add('ready'); + element.style.height = imgRect.height + "px"; + element.classList.add("ready"); this.setFrom(); this.addTitle(); - this.$img.classList.add('zoom-in'); + this.$img.classList.add("zoom-in"); setTimeout(function () { - element.classList.add('active'); + element.classList.add("active"); _this.setTo(); _this.isZoom = true; }, 0); - } + }; this.zoomOut = function () { this.isZoom = false; - element.classList.remove('active'); - this.$img.classList.add('zoom-in'); + element.classList.remove("active"); + this.$img.classList.add("zoom-in"); this.setFrom(); setTimeout(function () { - _this.$img.classList.remove('zoom-in'); - _this.$img.style.cssText = ''; + _this.$img.classList.remove("zoom-in"); + _this.$img.style.cssText = ""; _this.removeTitle(); - element.classList.remove('ready'); - element.removeAttribute('style'); + element.classList.remove("ready"); + element.removeAttribute("style"); }, 300); - } + }; - element.addEventListener('click', function (e) { - _this.isZoom ? _this.zoomOut() : e.target.tagName === 'IMG' && _this.zoomIn() - }) + element.addEventListener("click", function (e) { + _this.isZoom + ? _this.zoomOut() + : e.target.tagName === "IMG" && _this.zoomIn(); + }); - d.addEventListener('scroll', function () { - _this.isZoom && _this.zoomOut() - }) + d.addEventListener("scroll", function () { + _this.isZoom && _this.zoomOut(); + }); - w.addEventListener('resize', function () { + w.addEventListener("resize", function () { // _this.isZoom && _this.updateSize() - _this.isZoom && _this.zoomOut() - }) + _this.isZoom && _this.zoomOut(); + }); } - forEach.call($$('.img-lightbox'), function (el) { - new LightBox(el) - }) + forEach.call($$(".img-lightbox"), function (el) { + new LightBox(el); + }); })(), loadScript: function (scripts) { scripts.forEach(function (src) { - var s = d.createElement('script'); + var s = d.createElement("script"); s.src = src; s.async = true; body.appendChild(s); - }) - } + }); + }, }; - w.addEventListener('load', function () { - loading.classList.remove('active'); + w.addEventListener("load", function () { + loading.classList.remove("active"); Blog.page.loaded(); - w.lazyScripts && w.lazyScripts.length && Blog.loadScript(w.lazyScripts) + w.lazyScripts && w.lazyScripts.length && Blog.loadScript(w.lazyScripts); }); - w.addEventListener('DOMContentLoaded', function () { + w.addEventListener("DOMContentLoaded", function () { Blog.waterfall(); var top = rootScollTop(); Blog.toc.fixed(top); @@ -461,13 +496,13 @@ var ignoreUnload = false; var $mailTarget = $('a[href^="mailto"]'); - if($mailTarget) { + if ($mailTarget) { $mailTarget.addEventListener(even, function () { ignoreUnload = true; }); } - w.addEventListener('beforeunload', function (e) { + w.addEventListener("beforeunload", function (e) { if (!ignoreUnload) { Blog.page.unload(); } else { @@ -475,52 +510,72 @@ } }); - w.addEventListener('pageshow', function () { + w.addEventListener("pageshow", function () { // fix OSX safari #162 !Blog.page.visible && Blog.page.loaded(); }); - w.addEventListener('resize', function () { - w.BLOG.even = even = 'ontouchstart' in w ? 'touchstart' : 'click'; + w.addEventListener("resize", function () { + w.BLOG.even = even = "ontouchstart" in w ? "touchstart" : "click"; Blog.toggleMenu(); Blog.waterfall(); }); - gotop.addEventListener(even, function () { - animate(Blog.goTop.bind(Blog, 0)); - }, false); - - menuToggle.addEventListener(even, function (e) { - Blog.toggleMenu(true); - e.preventDefault(); - }, false); - - menuOff.addEventListener(even, function () { - menu.classList.add('hide'); - }, false); + gotop.addEventListener( + even, + function () { + animate(Blog.goTop.bind(Blog, 0)); + }, + false + ); + + menuToggle.addEventListener( + even, + function (e) { + Blog.toggleMenu(true); + e.preventDefault(); + }, + false + ); - mask.addEventListener(even, function (e) { - Blog.toggleMenu(); - Blog.hideOnMask.forEach(function (hide) { - hide() - }); - e.preventDefault(); - }, false); + menuOff.addEventListener( + even, + function () { + menu.classList.add("hide"); + }, + false + ); + + mask.addEventListener( + even, + function (e) { + Blog.toggleMenu(); + Blog.hideOnMask.forEach(function (hide) { + hide(); + }); + e.preventDefault(); + }, + false + ); - d.addEventListener('scroll', function () { - var top = rootScollTop(); - Blog.toggleGotop(top); - Blog.fixedHeader(top); - Blog.toc.fixed(top); - Blog.toc.actived(top); - }, false); + d.addEventListener( + "scroll", + function () { + var top = rootScollTop(); + Blog.toggleGotop(top); + Blog.fixedHeader(top); + Blog.toc.fixed(top); + Blog.toc.actived(top); + }, + false + ); if (w.BLOG.SHARE) { - Blog.share() + Blog.share(); } if (w.BLOG.REWARD) { - Blog.reward() + Blog.reward(); } Blog.noop = noop; @@ -530,14 +585,16 @@ Object.keys(Blog).reduce(function (g, e) { g[e] = Blog[e]; - return g + return g; }, w.BLOG); if (w.Waves) { Waves.init(); - Waves.attach('.global-share li', ['waves-block']); - Waves.attach('.article-tag-list-link, #page-nav a, #page-nav span', ['waves-button']); + Waves.attach(".global-share li", ["waves-block"]); + Waves.attach(".article-tag-list-link, #page-nav a, #page-nav span", [ + "waves-button", + ]); } else { - console.error('Waves loading failed.') + console.error("Waves loading failed."); } })(window, document); diff --git a/source/js/main.min.js b/source/js/main.min.js index 5d5447de..a41396d0 100644 --- a/source/js/main.min.js +++ b/source/js/main.min.js @@ -1 +1,453 @@ -!function(t,e){var s=e.body,n=e.querySelector.bind(e),a=e.querySelectorAll.bind(e),o=n("html"),c=n("#gotop"),l=n("#menu"),r=n("#header"),d=n("#mask"),h=n("#menu-toggle"),f=n("#menu-off"),u=n("#loading"),m=t.requestAnimationFrame,v=12,g=Array.prototype.forEach,p="ontouchstart"in t&&/Mobile|Android|iOS|iPhone|iPad|iPod|Windows Phone|KFAPWI/i.test(navigator.userAgent)?"touchstart":"click",L=/micromessenger/i.test(navigator.userAgent),y=function(){},w=function(t){var e=t.offsetLeft,i=t.offsetTop;if(t.offsetParent){var s=arguments.callee(t.offsetParent);e+=s.x,i+=s.y}return{x:e,y:i}},x=function(){return e.documentElement.scrollTop||e.body.scrollTop},$={goTop:function(e){var i=x(),s=arguments.length>2?arguments[1]:Math.abs(i-e)/v;i&&i>e?(t.scrollTo(0,Math.max(i-s,0)),m(arguments.callee.bind(this,e,s))):e&&e>i?(t.scrollTo(0,Math.min(i+s,e)),m(arguments.callee.bind(this,e,s))):this.toc.actived(e)},toggleGotop:function(e){e>t.innerHeight/2?c.classList.add("in"):c.classList.remove("in")},toggleMenu:function(e){var i=n("#main");if(e){if(l.classList.remove("hide"),t.innerWidth<1241)if(d.classList.add("in"),l.classList.add("show"),L){var s=x();i.classList.add("lock"),i.scrollTop=s}else o.classList.add("lock")}else if(l.classList.remove("show"),d.classList.remove("in"),L){var s=i.scrollTop;i.classList.remove("lock"),t.scrollTo(0,s)}else o.classList.remove("lock")},fixedHeader:function(t){t>r.clientHeight?r.classList.add("fixed"):r.classList.remove("fixed")},toc:function(){var t=n("#post-toc");if(!t||!t.children.length)return{fixed:y,actived:y};var e=n(".post-header").clientHeight,s=r.clientHeight,a=n("#post-content").querySelectorAll("h1, h2, h3, h4, h5, h6");t.querySelector('a[href="#'+a[0].id+'"]').parentNode.classList.add("active");var o=t.querySelectorAll(".post-toc-child");for(i=0,len=o.length;i=e-s?t.classList.add("fixed"):t.classList.remove("fixed")},actived:function(e){for(i=0,len=a.length;iw(a[i]).y-s-5){var n=t.querySelector("li.active"),o=t.querySelector('a[href="#'+a[i].id+'"]').parentNode;l(n,o)}e0?"50%":0),i[e]+=t.offsetHeight}),t.style.height=Math.max(i[0],i[1])+"px",t.classList.add("in")})},tabBar:function(t){t.parentNode.parentNode.classList.toggle("expand")},page:function(){var t=a(".fade, .fade-scale"),e=!1;return{loaded:function(){g.call(t,function(t){t.classList.add("in")}),e=!0},unload:function(){g.call(t,function(t){t.classList.remove("in")}),e=!1},visible:e}}(),lightbox:function(){function i(i){this.$img=i.querySelector("img"),this.$overlay=i.querySelector("overlay"),this.margin=40,this.title=this.$img.title||this.$img.alt||"",this.isZoom=!1;var n,a,o,c,l;this.calcRect=function(){c=s.clientWidth,l=s.clientHeight;var t=l-2*this.margin,e=n,i=a,r=(this.margin,e>c?c/e:1),d=i>t?t/i:1,h=Math.min(r,d);return e*=h,i*=h,{w:e,h:i,t:(l-i)/2-o.top,l:(c-e)/2-o.left+this.$img.offsetLeft}},this.setImgRect=function(t){this.$img.style.cssText="width: "+t.w+"px; max-width: "+t.w+"px; height:"+t.h+"px; top: "+t.t+"px; left: "+t.l+"px"},this.setFrom=function(){this.setImgRect({w:o.width,h:o.height,t:0,l:(i.offsetWidth-o.width)/2})},this.setTo=function(){this.setImgRect(this.calcRect())},this.addTitle=function(){this.title&&(this.$caption=e.createElement("div"),this.$caption.innerHTML=this.title,this.$caption.className="overlay-title",i.appendChild(this.$caption))},this.removeTitle=function(){this.$caption&&i.removeChild(this.$caption)};var r=this;this.zoomIn=function(){n=this.$img.naturalWidth||this.$img.width,a=this.$img.naturalHeight||this.$img.height,o=this.$img.getBoundingClientRect(),i.style.height=o.height+"px",i.classList.add("ready"),this.setFrom(),this.addTitle(),this.$img.classList.add("zoom-in"),setTimeout(function(){i.classList.add("active"),r.setTo(),r.isZoom=!0},0)},this.zoomOut=function(){this.isZoom=!1,i.classList.remove("active"),this.$img.classList.add("zoom-in"),this.setFrom(),setTimeout(function(){r.$img.classList.remove("zoom-in"),r.$img.style.cssText="",r.removeTitle(),i.classList.remove("ready"),i.removeAttribute("style")},300)},i.addEventListener("click",function(t){r.isZoom?r.zoomOut():"IMG"===t.target.tagName&&r.zoomIn()}),e.addEventListener("scroll",function(){r.isZoom&&r.zoomOut()}),t.addEventListener("resize",function(){r.isZoom&&r.zoomOut()})}g.call(a(".img-lightbox"),function(t){new i(t)})}(),loadScript:function(t){t.forEach(function(t){var i=e.createElement("script");i.src=t,i.async=!0,s.appendChild(i)})}};t.addEventListener("load",function(){u.classList.remove("active"),$.page.loaded(),t.lazyScripts&&t.lazyScripts.length&&$.loadScript(t.lazyScripts)}),t.addEventListener("DOMContentLoaded",function(){$.waterfall();var t=x();$.toc.fixed(t),$.toc.actived(t),$.page.loaded()});var E=!1,S=n('a[href^="mailto"]');S&&S.addEventListener(p,function(){E=!0}),t.addEventListener("beforeunload",function(t){E?E=!1:$.page.unload()}),t.addEventListener("pageshow",function(){!$.page.visible&&$.page.loaded()}),t.addEventListener("resize",function(){t.BLOG.even=p="ontouchstart"in t?"touchstart":"click",$.toggleMenu(),$.waterfall()}),c.addEventListener(p,function(){m($.goTop.bind($,0))},!1),h.addEventListener(p,function(t){$.toggleMenu(!0),t.preventDefault()},!1),f.addEventListener(p,function(){l.classList.add("hide")},!1),d.addEventListener(p,function(t){$.toggleMenu(),$.hideOnMask.forEach(function(t){t()}),t.preventDefault()},!1),e.addEventListener("scroll",function(){var t=x();$.toggleGotop(t),$.fixedHeader(t),$.toc.fixed(t),$.toc.actived(t)},!1),t.BLOG.SHARE&&$.share(),t.BLOG.REWARD&&$.reward(),$.noop=y,$.even=p,$.$=n,$.$$=a,Object.keys($).reduce(function(t,e){return t[e]=$[e],t},t.BLOG),t.Waves?(Waves.init(),Waves.attach(".global-share li",["waves-block"]),Waves.attach(".article-tag-list-link, #page-nav a, #page-nav span",["waves-button"])):console.error("Waves loading failed.")}(window,document); +!(function (t, e) { + var s = e.body, + n = e.querySelector.bind(e), + a = e.querySelectorAll.bind(e), + o = n("html"), + c = n("#gotop"), + l = n("#menu"), + r = n("#header"), + d = n("#mask"), + h = n("#menu-toggle"), + f = n("#menu-off"), + u = n("#loading"), + m = t.requestAnimationFrame, + v = 12, + g = Array.prototype.forEach, + p = + "ontouchstart" in t && + /Mobile|Android|iOS|iPhone|iPad|iPod|Windows Phone|KFAPWI/i.test( + navigator.userAgent + ) + ? "touchstart" + : "click", + L = /micromessenger/i.test(navigator.userAgent), + y = function () {}, + w = function (t) { + var e = t.offsetLeft, + i = t.offsetTop; + if (t.offsetParent) { + var s = arguments.callee(t.offsetParent); + (e += s.x), (i += s.y); + } + return { x: e, y: i }; + }, + x = function () { + return e.documentElement.scrollTop || e.body.scrollTop; + }, + $ = { + goTop: function (e) { + var i = x(), + s = + arguments.length > 2 + ? arguments[1] + : Math.abs(i - e) / v; + i && i > e + ? (t.scrollTo(0, Math.max(i - s, 0)), + m(arguments.callee.bind(this, e, s))) + : e && e > i + ? (t.scrollTo(0, Math.min(i + s, e)), + m(arguments.callee.bind(this, e, s))) + : this.toc.actived(e); + }, + toggleGotop: function (e) { + e > t.innerHeight / 2 + ? c.classList.add("in") + : c.classList.remove("in"); + }, + toggleMenu: function (e) { + var i = n("#main"); + if (e) { + if ((l.classList.remove("hide"), t.innerWidth < 1241)) + if ( + (d.classList.add("in"), l.classList.add("show"), L) + ) { + var s = x(); + i.classList.add("lock"), (i.scrollTop = s); + } else o.classList.add("lock"); + } else if ( + (l.classList.remove("show"), d.classList.remove("in"), L) + ) { + var s = i.scrollTop; + i.classList.remove("lock"), t.scrollTo(0, s); + } else o.classList.remove("lock"); + }, + fixedHeader: function (t) { + t > r.clientHeight + ? r.classList.add("fixed") + : r.classList.remove("fixed"); + }, + toc: (function () { + var t = n("#post-toc"); + if (!t || !t.children.length) return { fixed: y, actived: y }; + var e = n(".post-header").clientHeight, + s = r.clientHeight, + a = n("#post-content").querySelectorAll( + "h1, h2, h3, h4, h5, h6" + ); + // t.querySelector( + // 'a[href="#' + a[0].id + '"]' + // ).parentNode.classList.add("active"); + var o = t.querySelectorAll(".post-toc-child"); + for (i = 0, len = o.length; i < len; i++) + o[i].classList.add("post-toc-shrink"); + var c = t.querySelector( + 'a[href="#' + a[0].id + '"]' + ).nextElementSibling; + c && + (c.classList.add("post-toc-expand"), + c.classList.remove("post-toc-shrink")), + t.classList.remove("post-toc-shrink"); + var l = function (t, e) { + t.classList.remove("active"), e.classList.add("active"); + var i = e.parentElement.querySelectorAll(".post-toc-child"); + for (j = 0, len1 = i.length; j < len1; j++) + i[j].classList.remove("post-toc-expand"), + i[j].classList.add("post-toc-shrink"); + var s = e.querySelector(".post-toc-child"); + s && + (s.classList.remove("post-toc-shrink"), + s.classList.add("post-toc-expand")); + }; + return { + fixed: function (i) { + i >= e - s + ? t.classList.add("fixed") + : t.classList.remove("fixed"); + }, + actived: function (e) { + for (i = 0, len = a.length; i < len; i++) + if (e > w(a[i]).y - s - 5) { + var n = t.querySelector("li.active"), + o = t.querySelector( + 'a[href="#' + a[i].id + '"]' + ).parentNode; + l(n, o); + } + e < w(a[0]).y && + l( + t.querySelector("li.active"), + t.querySelector('a[href="#' + a[0].id + '"]') + .parentNode + ); + }, + }; + })(), + hideOnMask: [], + modal: function (t) { + (this.$modal = n(t)), + (this.$off = this.$modal.querySelector(".close")); + var e = this; + (this.show = function () { + d.classList.add("in"), + e.$modal.classList.add("ready"), + setTimeout(function () { + e.$modal.classList.add("in"); + }, 0); + }), + (this.onHide = y), + (this.hide = function () { + e.onHide(), + d.classList.remove("in"), + e.$modal.classList.remove("in"), + setTimeout(function () { + e.$modal.classList.remove("ready"); + }, 300); + }), + (this.toggle = function () { + return e.$modal.classList.contains("in") + ? e.hide() + : e.show(); + }), + $.hideOnMask.push(this.hide), + this.$off && this.$off.addEventListener(p, this.hide); + }, + share: function () { + var t = n("#pageShare"), + i = n("#shareFab"), + s = new this.modal("#globalShare"); + n("#menuShare").addEventListener(p, s.toggle), + i && + (i.addEventListener( + p, + function () { + t.classList.toggle("in"); + }, + !1 + ), + e.addEventListener( + p, + function (e) { + !i.contains(e.target) && + t.classList.remove("in"); + }, + !1 + )); + var o = new this.modal("#wxShare"); + (o.onHide = s.hide), + g.call(a(".wxFab"), function (t) { + t.addEventListener(p, o.toggle); + }); + }, + search: function () { + function t() { + e.classList.toggle("in"); + } + var e = n("#search-wrap"); + n("#search").addEventListener(p, t); + }, + reward: function () { + var t = new this.modal("#reward"); + n("#rewardBtn").addEventListener(p, t.toggle); + var e = n("#rewardToggle"), + i = n("#rewardCode"); + e && + e.addEventListener("change", function () { + i.src = this.checked + ? this.dataset.alipay + : this.dataset.wechat; + }); + }, + waterfall: function () { + t.innerWidth < 760 || + g.call(a(".waterfall"), function (t) { + var e = t.querySelectorAll(".waterfall-item"), + i = [0, 0]; + g.call(e, function (t) { + var e = i[0] <= i[1] ? 0 : 1; + (t.style.cssText = + "top:" + + i[e] + + "px;left:" + + (e > 0 ? "50%" : 0)), + (i[e] += t.offsetHeight); + }), + (t.style.height = Math.max(i[0], i[1]) + "px"), + t.classList.add("in"); + }); + }, + tabBar: function (t) { + t.parentNode.parentNode.classList.toggle("expand"); + }, + page: (function () { + var t = a(".fade, .fade-scale"), + e = !1; + return { + loaded: function () { + g.call(t, function (t) { + t.classList.add("in"); + }), + (e = !0); + }, + unload: function () { + g.call(t, function (t) { + t.classList.remove("in"); + }), + (e = !1); + }, + visible: e, + }; + })(), + lightbox: (function () { + function i(i) { + (this.$img = i.querySelector("img")), + (this.$overlay = i.querySelector("overlay")), + (this.margin = 40), + (this.title = this.$img.title || this.$img.alt || ""), + (this.isZoom = !1); + var n, a, o, c, l; + (this.calcRect = function () { + (c = s.clientWidth), (l = s.clientHeight); + var t = l - 2 * this.margin, + e = n, + i = a, + r = (this.margin, e > c ? c / e : 1), + d = i > t ? t / i : 1, + h = Math.min(r, d); + return ( + (e *= h), + (i *= h), + { + w: e, + h: i, + t: (l - i) / 2 - o.top, + l: (c - e) / 2 - o.left + this.$img.offsetLeft, + } + ); + }), + (this.setImgRect = function (t) { + this.$img.style.cssText = + "width: " + + t.w + + "px; max-width: " + + t.w + + "px; height:" + + t.h + + "px; top: " + + t.t + + "px; left: " + + t.l + + "px"; + }), + (this.setFrom = function () { + this.setImgRect({ + w: o.width, + h: o.height, + t: 0, + l: (i.offsetWidth - o.width) / 2, + }); + }), + (this.setTo = function () { + this.setImgRect(this.calcRect()); + }), + (this.addTitle = function () { + this.title && + ((this.$caption = e.createElement("div")), + (this.$caption.innerHTML = this.title), + (this.$caption.className = "overlay-title"), + i.appendChild(this.$caption)); + }), + (this.removeTitle = function () { + this.$caption && i.removeChild(this.$caption); + }); + var r = this; + (this.zoomIn = function () { + (n = this.$img.naturalWidth || this.$img.width), + (a = this.$img.naturalHeight || this.$img.height), + (o = this.$img.getBoundingClientRect()), + (i.style.height = o.height + "px"), + i.classList.add("ready"), + this.setFrom(), + this.addTitle(), + this.$img.classList.add("zoom-in"), + setTimeout(function () { + i.classList.add("active"), + r.setTo(), + (r.isZoom = !0); + }, 0); + }), + (this.zoomOut = function () { + (this.isZoom = !1), + i.classList.remove("active"), + this.$img.classList.add("zoom-in"), + this.setFrom(), + setTimeout(function () { + r.$img.classList.remove("zoom-in"), + (r.$img.style.cssText = ""), + r.removeTitle(), + i.classList.remove("ready"), + i.removeAttribute("style"); + }, 300); + }), + i.addEventListener("click", function (t) { + r.isZoom + ? r.zoomOut() + : "IMG" === t.target.tagName && r.zoomIn(); + }), + e.addEventListener("scroll", function () { + r.isZoom && r.zoomOut(); + }), + t.addEventListener("resize", function () { + r.isZoom && r.zoomOut(); + }); + } + g.call(a(".img-lightbox"), function (t) { + new i(t); + }); + })(), + loadScript: function (t) { + t.forEach(function (t) { + var i = e.createElement("script"); + (i.src = t), (i.async = !0), s.appendChild(i); + }); + }, + }; + t.addEventListener("load", function () { + u.classList.remove("active"), + $.page.loaded(), + t.lazyScripts && + t.lazyScripts.length && + $.loadScript(t.lazyScripts); + }), + t.addEventListener("DOMContentLoaded", function () { + $.waterfall(); + var t = x(); + $.toc.fixed(t), $.toc.actived(t), $.page.loaded(); + }); + var E = !1, + S = n('a[href^="mailto"]'); + S && + S.addEventListener(p, function () { + E = !0; + }), + t.addEventListener("beforeunload", function (t) { + E ? (E = !1) : $.page.unload(); + }), + t.addEventListener("pageshow", function () { + !$.page.visible && $.page.loaded(); + }), + t.addEventListener("resize", function () { + (t.BLOG.even = p = "ontouchstart" in t ? "touchstart" : "click"), + $.toggleMenu(), + $.waterfall(); + }), + c.addEventListener( + p, + function () { + m($.goTop.bind($, 0)); + }, + !1 + ), + h.addEventListener( + p, + function (t) { + $.toggleMenu(!0), t.preventDefault(); + }, + !1 + ), + f.addEventListener( + p, + function () { + l.classList.add("hide"); + }, + !1 + ), + d.addEventListener( + p, + function (t) { + $.toggleMenu(), + $.hideOnMask.forEach(function (t) { + t(); + }), + t.preventDefault(); + }, + !1 + ), + e.addEventListener( + "scroll", + function () { + var t = x(); + $.toggleGotop(t), + $.fixedHeader(t), + $.toc.fixed(t), + $.toc.actived(t); + }, + !1 + ), + t.BLOG.SHARE && $.share(), + t.BLOG.REWARD && $.reward(), + ($.noop = y), + ($.even = p), + ($.$ = n), + ($.$$ = a), + Object.keys($).reduce(function (t, e) { + return (t[e] = $[e]), t; + }, t.BLOG), + t.Waves + ? (Waves.init(), + Waves.attach(".global-share li", ["waves-block"]), + Waves.attach( + ".article-tag-list-link, #page-nav a, #page-nav span", + ["waves-button"] + )) + : console.error("Waves loading failed."); +})(window, document); From 656387270ded5e63e329b8ae982a96977ef67dcb Mon Sep 17 00:00:00 2001 From: scarqin Date: Tue, 8 Mar 2022 11:05:18 +0800 Subject: [PATCH 2/2] Update README.md --- README.md | 40 +++++++++------------------------------- 1 file changed, 9 insertions(+), 31 deletions(-) diff --git a/README.md b/README.md index a98b75c0..710759d4 100644 --- a/README.md +++ b/README.md @@ -1,33 +1,11 @@ hexo-theme-material-indigo ================ - -[![Join the chat at https://gitter.im/hexo-theme-indigo/Lobby](https://badges.gitter.im/hexo-theme-indigo/Lobby.svg)](https://gitter.im/hexo-theme-indigo/Lobby?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge&utm_content=badge) - -Material Design 风格的Hexo主题,基于 Hexo 3.0+ 制作。 [Preview](http://imys.net/) - -> 现有两个主题分支,我的博客中使用的是 card 分支卡片风格主题,master 分支是旧版平铺式风格主题。 - -## Feature - -1. 仅支持 IE10+ 等现代浏览器。 -2. 去 jQuery,更轻。相信现代浏览器的原生兼容性。 -3. 使用 Less 作为 css 预处理器,需要安装 `hexo-renderer-less`。 -4. 添加了英文字体支持 Roboto。 -5. 添加了一些波纹效果。By [Waves](https://github.com/fians/Waves) -6. 无前端依赖的分享实现。 -7. 基于静态数据的站内搜索,无第三方侵入。 -8. 支持文章打赏。 - -## Useage - -[文档 | Document](https://github.com/yscoder/hexo-theme-indigo/wiki) - -## ChangeLog - -升级前请仔细查看更改内容,如非必要可不升级。 - -[ChangeLog](https://github.com/yscoder/hexo-theme-indigo/releases) - -## OtherVersion - -* [vuepress-theme-indigo](https://github.com/yscoder/vuepress-theme-indigo) +因[原仓库](https://github.com/yscoder/hexo-theme-indigo)停止维护,所以 fork 了一份继续维护配合最新版 hexo + +# 分支说明 +## hexo6 +配合 hexo6 版本的版本 +## scar +按照个人喜好改动的版本,也会修复一些 bug,不同如下: +* fix: 分类下的文章没有按时间排序 +* refator:点击分类菜单不会改变分类顺序