diff --git a/assets/js/theme.js b/assets/js/theme.js index d5175f8b..72dcd691 100644 --- a/assets/js/theme.js +++ b/assets/js/theme.js @@ -1,85 +1,39 @@ -"use strict"; +class Util { + forEach(elements, handler) { + elements = elements || []; -function _objectDestructuringEmpty(obj) { if (obj == null) throw new TypeError("Cannot destructure undefined"); } - -function _createForOfIteratorHelper(o, allowArrayLike) { var it = typeof Symbol !== "undefined" && o[Symbol.iterator] || o["@@iterator"]; if (!it) { if (Array.isArray(o) || (it = _unsupportedIterableToArray(o)) || allowArrayLike && o && typeof o.length === "number") { if (it) o = it; var i = 0; var F = function F() {}; return { s: F, n: function n() { if (i >= o.length) return { done: true }; return { done: false, value: o[i++] }; }, e: function e(_e2) { throw _e2; }, f: F }; } throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); } var normalCompletion = true, didErr = false, err; return { s: function s() { it = it.call(o); }, n: function n() { var step = it.next(); normalCompletion = step.done; return step; }, e: function e(_e3) { didErr = true; err = _e3; }, f: function f() { try { if (!normalCompletion && it.return != null) it.return(); } finally { if (didErr) throw err; } } }; } - -function _toConsumableArray(arr) { return _arrayWithoutHoles(arr) || _iterableToArray(arr) || _unsupportedIterableToArray(arr) || _nonIterableSpread(); } - -function _nonIterableSpread() { throw new TypeError("Invalid attempt to spread non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); } - -function _unsupportedIterableToArray(o, minLen) { if (!o) return; if (typeof o === "string") return _arrayLikeToArray(o, minLen); var n = Object.prototype.toString.call(o).slice(8, -1); if (n === "Object" && o.constructor) n = o.constructor.name; if (n === "Map" || n === "Set") return Array.from(o); if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen); } - -function _iterableToArray(iter) { if (typeof Symbol !== "undefined" && iter[Symbol.iterator] != null || iter["@@iterator"] != null) return Array.from(iter); } - -function _arrayWithoutHoles(arr) { if (Array.isArray(arr)) return _arrayLikeToArray(arr); } - -function _arrayLikeToArray(arr, len) { if (len == null || len > arr.length) len = arr.length; for (var i = 0, arr2 = new Array(len); i < len; i++) { arr2[i] = arr[i]; } return arr2; } - -function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } } - -function _defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } - -function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); Object.defineProperty(Constructor, "prototype", { writable: false }); return Constructor; } - -var Util = /*#__PURE__*/function () { - function Util() { - _classCallCheck(this, Util); + for (let i = 0; i < elements.length; i++) handler(elements[i]); } - _createClass(Util, [{ - key: "forEach", - value: function forEach(elements, handler) { - elements = elements || []; - - for (var i = 0; i < elements.length; i++) { - handler(elements[i]); - } - } - }, { - key: "getScrollTop", - value: function getScrollTop() { - return document.documentElement && document.documentElement.scrollTop || document.body.scrollTop; - } - }, { - key: "isMobile", - value: function isMobile() { - return window.matchMedia('only screen and (max-width: 680px)').matches; - } - }, { - key: "isTocStatic", - value: function isTocStatic() { - return window.matchMedia('only screen and (max-width: 960px)').matches; - } - }, { - key: "animateCSS", - value: function animateCSS(element, animation, reserved, callback) { - var _element$classList; - - if (!Array.isArray(animation)) animation = [animation]; + getScrollTop() { + return document.documentElement && document.documentElement.scrollTop || document.body.scrollTop; + } - (_element$classList = element.classList).add.apply(_element$classList, ['animate__animated'].concat(_toConsumableArray(animation))); + isMobile() { + return window.matchMedia('only screen and (max-width: 680px)').matches; + } - var handler = function handler() { - var _element$classList2; + isTocStatic() { + return window.matchMedia('only screen and (max-width: 960px)').matches; + } - (_element$classList2 = element.classList).remove.apply(_element$classList2, ['animate__animated'].concat(_toConsumableArray(animation))); + animateCSS(element, animation, reserved, callback) { + if (!Array.isArray(animation)) animation = [animation]; + element.classList.add('animate__animated', ...animation); - element.removeEventListener('animationend', handler); - if (typeof callback === 'function') callback(); - }; + const handler = () => { + element.classList.remove('animate__animated', ...animation); + element.removeEventListener('animationend', handler); + if (typeof callback === 'function') callback(); + }; - if (!reserved) element.addEventListener('animationend', handler, false); - } - }]); - - return Util; -}(); + if (!reserved) element.addEventListener('animationend', handler, false); + } -var Theme = /*#__PURE__*/function () { - function Theme() { - _classCallCheck(this, Theme); +} +class Theme { + constructor() { this.config = window.config; this.data = this.config.data; this.isDark = document.body.getAttribute('theme') === 'dark'; @@ -93,961 +47,844 @@ var Theme = /*#__PURE__*/function () { if (window.objectFitImages) objectFitImages(); } - _createClass(Theme, [{ - key: "initRaw", - value: function initRaw() { - var _this = this; + initRaw() { + this.util.forEach(document.querySelectorAll('[data-raw]'), $raw => { + $raw.innerHTML = this.data[$raw.id]; + }); + } - this.util.forEach(document.querySelectorAll('[data-raw]'), function ($raw) { - $raw.innerHTML = _this.data[$raw.id]; - }); - } - }, { - key: "initSVGIcon", - value: function initSVGIcon() { - this.util.forEach(document.querySelectorAll('[data-svg-src]'), function ($icon) { - fetch($icon.getAttribute('data-svg-src')).then(function (response) { - return response.text(); - }).then(function (svg) { - var $temp = document.createElement('div'); - $temp.insertAdjacentHTML('afterbegin', svg); - var $svg = $temp.firstChild; - $svg.setAttribute('data-svg-src', $icon.getAttribute('data-svg-src')); - $svg.classList.add('icon'); - var $titleElements = $svg.getElementsByTagName('title'); - if ($titleElements.length) $svg.removeChild($titleElements[0]); - $icon.parentElement.replaceChild($svg, $icon); - }).catch(function (err) { - console.error(err); - }); + initSVGIcon() { + this.util.forEach(document.querySelectorAll('[data-svg-src]'), $icon => { + fetch($icon.getAttribute('data-svg-src')).then(response => response.text()).then(svg => { + const $temp = document.createElement('div'); + $temp.insertAdjacentHTML('afterbegin', svg); + const $svg = $temp.firstChild; + $svg.setAttribute('data-svg-src', $icon.getAttribute('data-svg-src')); + $svg.classList.add('icon'); + const $titleElements = $svg.getElementsByTagName('title'); + if ($titleElements.length) $svg.removeChild($titleElements[0]); + $icon.parentElement.replaceChild($svg, $icon); + }).catch(err => { + console.error(err); }); - } - }, { - key: "initTwemoji", - value: function initTwemoji() { - if (this.config.twemoji) twemoji.parse(document.body); - } - }, { - key: "initMenuMobile", - value: function initMenuMobile() { - var $menuToggleMobile = document.getElementById('menu-toggle-mobile'); - var $menuMobile = document.getElementById('menu-mobile'); - $menuToggleMobile.addEventListener('click', function () { - document.body.classList.toggle('blur'); - $menuToggleMobile.classList.toggle('active'); - $menuMobile.classList.toggle('active'); + }); + } + + initTwemoji() { + if (this.config.twemoji) twemoji.parse(document.body); + } + + initMenuMobile() { + const $menuToggleMobile = document.getElementById('menu-toggle-mobile'); + const $menuMobile = document.getElementById('menu-mobile'); + $menuToggleMobile.addEventListener('click', () => { + document.body.classList.toggle('blur'); + $menuToggleMobile.classList.toggle('active'); + $menuMobile.classList.toggle('active'); + }, false); + + this._menuMobileOnClickMask = this._menuMobileOnClickMask || (() => { + $menuToggleMobile.classList.remove('active'); + $menuMobile.classList.remove('active'); + }); + + this.clickMaskEventSet.add(this._menuMobileOnClickMask); + } + + initSwitchTheme() { + this.util.forEach(document.getElementsByClassName('theme-switch'), $themeSwitch => { + $themeSwitch.addEventListener('click', () => { + if (document.body.getAttribute('theme') === 'dark') document.body.setAttribute('theme', 'light');else document.body.setAttribute('theme', 'dark'); + this.isDark = !this.isDark; + window.localStorage && localStorage.setItem('theme', this.isDark ? 'dark' : 'light'); + + for (let event of this.switchThemeEventSet) event(); }, false); + }); + } - this._menuMobileOnClickMask = this._menuMobileOnClickMask || function () { - $menuToggleMobile.classList.remove('active'); - $menuMobile.classList.remove('active'); - }; + initSearch() { + const searchConfig = this.config.search; + const isMobile = this.util.isMobile(); + if (!searchConfig || isMobile && this._searchMobileOnce || !isMobile && this._searchDesktopOnce) return; + const maxResultLength = searchConfig.maxResultLength ? searchConfig.maxResultLength : 10; + const snippetLength = searchConfig.snippetLength ? searchConfig.snippetLength : 50; + const highlightTag = searchConfig.highlightTag ? searchConfig.highlightTag : 'em'; + const suffix = isMobile ? 'mobile' : 'desktop'; + const $header = document.getElementById(`header-${suffix}`); + const $searchInput = document.getElementById(`search-input-${suffix}`); + const $searchToggle = document.getElementById(`search-toggle-${suffix}`); + const $searchLoading = document.getElementById(`search-loading-${suffix}`); + const $searchClear = document.getElementById(`search-clear-${suffix}`); + + if (isMobile) { + this._searchMobileOnce = true; + $searchInput.addEventListener('focus', () => { + document.body.classList.add('blur'); + $header.classList.add('open'); + }, false); + document.getElementById('search-cancel-mobile').addEventListener('click', () => { + $header.classList.remove('open'); + document.body.classList.remove('blur'); + document.getElementById('menu-toggle-mobile').classList.remove('active'); + document.getElementById('menu-mobile').classList.remove('active'); + $searchLoading.style.display = 'none'; + $searchClear.style.display = 'none'; + this._searchMobile && this._searchMobile.autocomplete.setVal(''); + }, false); + $searchClear.addEventListener('click', () => { + $searchClear.style.display = 'none'; + this._searchMobile && this._searchMobile.autocomplete.setVal(''); + }, false); - this.clickMaskEventSet.add(this._menuMobileOnClickMask); - } - }, { - key: "initSwitchTheme", - value: function initSwitchTheme() { - var _this2 = this; - - this.util.forEach(document.getElementsByClassName('theme-switch'), function ($themeSwitch) { - $themeSwitch.addEventListener('click', function () { - if (document.body.getAttribute('theme') === 'dark') document.body.setAttribute('theme', 'light');else document.body.setAttribute('theme', 'dark'); - _this2.isDark = !_this2.isDark; - window.localStorage && localStorage.setItem('theme', _this2.isDark ? 'dark' : 'light'); - - var _iterator = _createForOfIteratorHelper(_this2.switchThemeEventSet), - _step; - - try { - for (_iterator.s(); !(_step = _iterator.n()).done;) { - var event = _step.value; - event(); - } - } catch (err) { - _iterator.e(err); - } finally { - _iterator.f(); - } - }, false); + this._searchMobileOnClickMask = this._searchMobileOnClickMask || (() => { + $header.classList.remove('open'); + $searchLoading.style.display = 'none'; + $searchClear.style.display = 'none'; + this._searchMobile && this._searchMobile.autocomplete.setVal(''); }); + + this.clickMaskEventSet.add(this._searchMobileOnClickMask); + } else { + this._searchDesktopOnce = true; + $searchToggle.addEventListener('click', () => { + document.body.classList.add('blur'); + $header.classList.add('open'); + $searchInput.focus(); + }, false); + $searchClear.addEventListener('click', () => { + $searchClear.style.display = 'none'; + this._searchDesktop && this._searchDesktop.autocomplete.setVal(''); + }, false); + + this._searchDesktopOnClickMask = this._searchDesktopOnClickMask || (() => { + $header.classList.remove('open'); + $searchLoading.style.display = 'none'; + $searchClear.style.display = 'none'; + this._searchDesktop && this._searchDesktop.autocomplete.setVal(''); + }); + + this.clickMaskEventSet.add(this._searchDesktopOnClickMask); } - }, { - key: "initSearch", - value: function initSearch() { - var _this3 = this; - - var searchConfig = this.config.search; - var isMobile = this.util.isMobile(); - if (!searchConfig || isMobile && this._searchMobileOnce || !isMobile && this._searchDesktopOnce) return; - var maxResultLength = searchConfig.maxResultLength ? searchConfig.maxResultLength : 10; - var snippetLength = searchConfig.snippetLength ? searchConfig.snippetLength : 50; - var highlightTag = searchConfig.highlightTag ? searchConfig.highlightTag : 'em'; - var suffix = isMobile ? 'mobile' : 'desktop'; - var $header = document.getElementById("header-".concat(suffix)); - var $searchInput = document.getElementById("search-input-".concat(suffix)); - var $searchToggle = document.getElementById("search-toggle-".concat(suffix)); - var $searchLoading = document.getElementById("search-loading-".concat(suffix)); - var $searchClear = document.getElementById("search-clear-".concat(suffix)); - - if (isMobile) { - this._searchMobileOnce = true; - $searchInput.addEventListener('focus', function () { - document.body.classList.add('blur'); - $header.classList.add('open'); - }, false); - document.getElementById('search-cancel-mobile').addEventListener('click', function () { - $header.classList.remove('open'); - document.body.classList.remove('blur'); - document.getElementById('menu-toggle-mobile').classList.remove('active'); - document.getElementById('menu-mobile').classList.remove('active'); - $searchLoading.style.display = 'none'; - $searchClear.style.display = 'none'; - _this3._searchMobile && _this3._searchMobile.autocomplete.setVal(''); - }, false); - $searchClear.addEventListener('click', function () { - $searchClear.style.display = 'none'; - _this3._searchMobile && _this3._searchMobile.autocomplete.setVal(''); - }, false); - this._searchMobileOnClickMask = this._searchMobileOnClickMask || function () { - $header.classList.remove('open'); - $searchLoading.style.display = 'none'; + $searchInput.addEventListener('input', () => { + if ($searchInput.value === '') $searchClear.style.display = 'none';else $searchClear.style.display = 'inline'; + }, false); + + const initAutosearch = () => { + const autosearch = autocomplete(`#search-input-${suffix}`, { + hint: false, + autoselect: true, + dropdownMenuContainer: `#search-dropdown-${suffix}`, + clearOnSelected: true, + cssClasses: { + noPrefix: true + }, + debug: true + }, { + name: 'search', + source: (query, callback) => { + $searchLoading.style.display = 'inline'; $searchClear.style.display = 'none'; - _this3._searchMobile && _this3._searchMobile.autocomplete.setVal(''); - }; - this.clickMaskEventSet.add(this._searchMobileOnClickMask); - } else { - this._searchDesktopOnce = true; - $searchToggle.addEventListener('click', function () { - document.body.classList.add('blur'); - $header.classList.add('open'); - $searchInput.focus(); - }, false); - $searchClear.addEventListener('click', function () { - $searchClear.style.display = 'none'; - _this3._searchDesktop && _this3._searchDesktop.autocomplete.setVal(''); - }, false); + const finish = results => { + $searchLoading.style.display = 'none'; + $searchClear.style.display = 'inline'; + callback(results); + }; - this._searchDesktopOnClickMask = this._searchDesktopOnClickMask || function () { - $header.classList.remove('open'); - $searchLoading.style.display = 'none'; - $searchClear.style.display = 'none'; - _this3._searchDesktop && _this3._searchDesktop.autocomplete.setVal(''); - }; + if (searchConfig.type === 'lunr') { + const search = () => { + if (lunr.queryHandler) query = lunr.queryHandler(query); + const results = {}; - this.clickMaskEventSet.add(this._searchDesktopOnClickMask); - } + this._index.search(query).forEach(({ + ref, + matchData: { + metadata + } + }) => { + const matchData = this._indexData[ref]; + let { + uri, + title, + content: context + } = matchData; + if (results[uri]) return; + let position = 0; + Object.values(metadata).forEach(({ + content + }) => { + if (content) { + const matchPosition = content.position[0][0]; + if (matchPosition < position || position === 0) position = matchPosition; + } + }); + position -= snippetLength / 5; - $searchInput.addEventListener('input', function () { - if ($searchInput.value === '') $searchClear.style.display = 'none';else $searchClear.style.display = 'inline'; - }, false); + if (position > 0) { + position += context.substr(position, 20).lastIndexOf(' ') + 1; + context = '...' + context.substr(position, snippetLength); + } else { + context = context.substr(0, snippetLength); + } + + Object.keys(metadata).forEach(key => { + title = title.replace(new RegExp(`(${key})`, 'gi'), `<${highlightTag}>$1`); + context = context.replace(new RegExp(`(${key})`, 'gi'), `<${highlightTag}>$1`); + }); + results[uri] = { + 'uri': uri, + 'title': title, + 'date': matchData.date, + 'context': context + }; + }); - var initAutosearch = function initAutosearch() { - var autosearch = autocomplete("#search-input-".concat(suffix), { - hint: false, - autoselect: true, - dropdownMenuContainer: "#search-dropdown-".concat(suffix), - clearOnSelected: true, - cssClasses: { - noPrefix: true - }, - debug: true - }, { - name: 'search', - source: function source(query, callback) { - $searchLoading.style.display = 'inline'; - $searchClear.style.display = 'none'; - - var finish = function finish(results) { - $searchLoading.style.display = 'none'; - $searchClear.style.display = 'inline'; - callback(results); + return Object.values(results).slice(0, maxResultLength); }; - if (searchConfig.type === 'lunr') { - var search = function search() { - if (lunr.queryHandler) query = lunr.queryHandler(query); - var results = {}; - - _this3._index.search(query).forEach(function (_ref) { - var ref = _ref.ref, - metadata = _ref.matchData.metadata; - var matchData = _this3._indexData[ref]; - var uri = matchData.uri, - title = matchData.title, - context = matchData.content; - if (results[uri]) return; - var position = 0; - Object.values(metadata).forEach(function (_ref2) { - var content = _ref2.content; - - if (content) { - var matchPosition = content.position[0][0]; - if (matchPosition < position || position === 0) position = matchPosition; - } + if (!this._index) { + fetch(searchConfig.lunrIndexURL).then(response => response.json()).then(data => { + const indexData = {}; + this._index = lunr(function () { + if (searchConfig.lunrLanguageCode) this.use(lunr[searchConfig.lunrLanguageCode]); + this.ref('objectID'); + this.field('title', { + boost: 50 }); - position -= snippetLength / 5; - - if (position > 0) { - position += context.substr(position, 20).lastIndexOf(' ') + 1; - context = '...' + context.substr(position, snippetLength); - } else { - context = context.substr(0, snippetLength); - } - - Object.keys(metadata).forEach(function (key) { - title = title.replace(new RegExp("(".concat(key, ")"), 'gi'), "<".concat(highlightTag, ">$1")); - context = context.replace(new RegExp("(".concat(key, ")"), 'gi'), "<".concat(highlightTag, ">$1")); + this.field('tags', { + boost: 20 }); - results[uri] = { - 'uri': uri, - 'title': title, - 'date': matchData.date, - 'context': context - }; - }); - - return Object.values(results).slice(0, maxResultLength); - }; - - if (!_this3._index) { - fetch(searchConfig.lunrIndexURL).then(function (response) { - return response.json(); - }).then(function (data) { - var indexData = {}; - _this3._index = lunr(function () { - var _this4 = this; - - if (searchConfig.lunrLanguageCode) this.use(lunr[searchConfig.lunrLanguageCode]); - this.ref('objectID'); - this.field('title', { - boost: 50 - }); - this.field('tags', { - boost: 20 - }); - this.field('categories', { - boost: 20 - }); - this.field('content', { - boost: 10 - }); - this.metadataWhitelist = ['position']; - data.forEach(function (record) { - indexData[record.objectID] = record; - - _this4.add(record); - }); + this.field('categories', { + boost: 20 + }); + this.field('content', { + boost: 10 + }); + this.metadataWhitelist = ['position']; + data.forEach(record => { + indexData[record.objectID] = record; + this.add(record); }); - _this3._indexData = indexData; - finish(search()); - }).catch(function (err) { - console.error(err); - finish([]); - }); - } else finish(search()); - } else if (searchConfig.type === 'algolia') { - _this3._algoliaIndex = _this3._algoliaIndex || algoliasearch(searchConfig.algoliaAppID, searchConfig.algoliaSearchKey).initIndex(searchConfig.algoliaIndex); - - _this3._algoliaIndex.search(query, { - offset: 0, - length: maxResultLength * 8, - attributesToHighlight: ['title'], - attributesToSnippet: ["content:".concat(snippetLength)], - highlightPreTag: "<".concat(highlightTag, ">"), - highlightPostTag: "") - }).then(function (_ref3) { - var hits = _ref3.hits; - var results = {}; - hits.forEach(function (_ref4) { - var uri = _ref4.uri, - date = _ref4.date, - title = _ref4._highlightResult.title, - content = _ref4._snippetResult.content; - if (results[uri] && results[uri].context.length > content.value) return; - results[uri] = { - uri: uri, - title: title.value, - date: date, - context: content.value - }; }); - finish(Object.values(results).slice(0, maxResultLength)); - }).catch(function (err) { + this._indexData = indexData; + finish(search()); + }).catch(err => { console.error(err); finish([]); }); - } - }, - templates: { - suggestion: function suggestion(_ref5) { - var title = _ref5.title, - date = _ref5.date, - context = _ref5.context; - return "
".concat(title, "").concat(date, "
").concat(context, "
"); - }, - empty: function empty(_ref6) { - var query = _ref6.query; - return "
".concat(searchConfig.noResultsFound, ": \"").concat(query, "\"
"); - }, - footer: function footer(_ref7) { - _objectDestructuringEmpty(_ref7); - - var _ref8 = searchConfig.type === 'algolia' ? { - searchType: 'algolia', - icon: '', - href: 'https://www.algolia.com/' - } : { - searchType: 'Lunr.js', - icon: '', - href: 'https://lunrjs.com/' - }, - searchType = _ref8.searchType, - icon = _ref8.icon, - href = _ref8.href; - - return "
Search by ").concat(icon, " ").concat(searchType, "
"); - } - } - }); - autosearch.on('autocomplete:selected', function (_event, suggestion, _dataset, _context) { - window.location.assign(suggestion.uri); - }); - if (isMobile) _this3._searchMobile = autosearch;else _this3._searchDesktop = autosearch; - }; - - if (searchConfig.lunrSegmentitURL && !document.getElementById('lunr-segmentit')) { - var script = document.createElement('script'); - script.id = 'lunr-segmentit'; - script.type = 'text/javascript'; - script.src = searchConfig.lunrSegmentitURL; - script.async = true; - - if (script.readyState) { - script.onreadystatechange = function () { - if (script.readyState == 'loaded' || script.readyState == 'complete') { - script.onreadystatechange = null; - initAutosearch(); - } - }; - } else { - script.onload = function () { - initAutosearch(); - }; - } - - document.body.appendChild(script); - } else initAutosearch(); - } - }, { - key: "initDetails", - value: function initDetails() { - this.util.forEach(document.getElementsByClassName('details'), function ($details) { - var $summary = $details.getElementsByClassName('details-summary')[0]; - $summary.addEventListener('click', function () { - $details.classList.toggle('open'); - }, false); - }); - } - }, { - key: "initLightGallery", - value: function initLightGallery() { - if (this.config.lightgallery) lightGallery(document.getElementById('content'), { - plugins: [lgThumbnail, lgZoom], - selector: '.lightgallery', - speed: 400, - hideBarsDelay: 2000, - allowMediaOverlap: true, - exThumbImage: 'data-thumbnail', - toggleThumb: true, - thumbWidth: 80, - thumbHeight: '60px', - actualSize: false, - showZoomInOutIcons: true - }); - } - }, { - key: "initHighlight", - value: function initHighlight() { - var _this5 = this; - - this.util.forEach(document.querySelectorAll('.highlight > pre.chroma'), function ($preChroma) { - var $chroma = document.createElement('div'); - $chroma.className = $preChroma.className; - var $table = document.createElement('table'); - $chroma.appendChild($table); - var $tbody = document.createElement('tbody'); - $table.appendChild($tbody); - var $tr = document.createElement('tr'); - $tbody.appendChild($tr); - var $td = document.createElement('td'); - $tr.appendChild($td); - $preChroma.parentElement.replaceChild($chroma, $preChroma); - $td.appendChild($preChroma); - }); - this.util.forEach(document.querySelectorAll('.highlight > .chroma'), function ($chroma) { - var $codeElements = $chroma.querySelectorAll('pre.chroma > code'); - - if ($codeElements.length) { - var $code = $codeElements[$codeElements.length - 1]; - var $header = document.createElement('div'); - $header.className = 'code-header ' + $code.className.toLowerCase(); - var $title = document.createElement('span'); - $title.classList.add('code-title'); - $title.insertAdjacentHTML('afterbegin', ''); - $title.addEventListener('click', function () { - $chroma.classList.toggle('open'); - }, false); - $header.appendChild($title); - var $ellipses = document.createElement('span'); - $ellipses.insertAdjacentHTML('afterbegin', ''); - $ellipses.classList.add('ellipses'); - $ellipses.addEventListener('click', function () { - $chroma.classList.add('open'); - }, false); - $header.appendChild($ellipses); - var $copy = document.createElement('span'); - $copy.insertAdjacentHTML('afterbegin', ''); - $copy.classList.add('copy'); - var code = $code.innerText; - if (_this5.config.code.maxShownLines < 0 || code.split('\n').length < _this5.config.code.maxShownLines + 2) $chroma.classList.add('open'); - - if (_this5.config.code.copyTitle) { - $copy.setAttribute('data-clipboard-text', code); - $copy.title = _this5.config.code.copyTitle; - var clipboard = new ClipboardJS($copy); - clipboard.on('success', function (_e) { - _this5.util.animateCSS($code, 'animate__flash'); + } else finish(search()); + } else if (searchConfig.type === 'algolia') { + this._algoliaIndex = this._algoliaIndex || algoliasearch(searchConfig.algoliaAppID, searchConfig.algoliaSearchKey).initIndex(searchConfig.algoliaIndex); + + this._algoliaIndex.search(query, { + offset: 0, + length: maxResultLength * 8, + attributesToHighlight: ['title'], + attributesToSnippet: [`content:${snippetLength}`], + highlightPreTag: `<${highlightTag}>`, + highlightPostTag: `` + }).then(({ + hits + }) => { + const results = {}; + hits.forEach(({ + uri, + date, + _highlightResult: { + title + }, + _snippetResult: { + content + } + }) => { + if (results[uri] && results[uri].context.length > content.value) return; + results[uri] = { + uri: uri, + title: title.value, + date: date, + context: content.value + }; + }); + finish(Object.values(results).slice(0, maxResultLength)); + }).catch(err => { + console.error(err); + finish([]); }); - $header.appendChild($copy); } - - $chroma.insertBefore($header, $chroma.firstChild); + }, + templates: { + suggestion: ({ + title, + date, + context + }) => `
${title}${date}
${context}
`, + empty: ({ + query + }) => `
${searchConfig.noResultsFound}: "${query}"
`, + footer: ({}) => { + const { + searchType, + icon, + href + } = searchConfig.type === 'algolia' ? { + searchType: 'algolia', + icon: '', + href: 'https://www.algolia.com/' + } : { + searchType: 'Lunr.js', + icon: '', + href: 'https://lunrjs.com/' + }; + return ``; + } } }); - } - }, { - key: "initTable", - value: function initTable() { - this.util.forEach(document.querySelectorAll('.content table'), function ($table) { - var $wrapper = document.createElement('div'); - $wrapper.className = 'table-wrapper'; - $table.parentElement.replaceChild($wrapper, $table); - $wrapper.appendChild($table); + autosearch.on('autocomplete:selected', (_event, suggestion, _dataset, _context) => { + window.location.assign(suggestion.uri); }); - } - }, { - key: "initHeaderLink", - value: function initHeaderLink() { - for (var num = 1; num <= 6; num++) { - this.util.forEach(document.querySelectorAll('.single .content > h' + num), function ($header) { - $header.classList.add('headerLink'); - $header.insertAdjacentHTML('afterbegin', "")); - }); + if (isMobile) this._searchMobile = autosearch;else this._searchDesktop = autosearch; + }; + + if (searchConfig.lunrSegmentitURL && !document.getElementById('lunr-segmentit')) { + const script = document.createElement('script'); + script.id = 'lunr-segmentit'; + script.type = 'text/javascript'; + script.src = searchConfig.lunrSegmentitURL; + script.async = true; + + if (script.readyState) { + script.onreadystatechange = () => { + if (script.readyState == 'loaded' || script.readyState == 'complete') { + script.onreadystatechange = null; + initAutosearch(); + } + }; + } else { + script.onload = () => { + initAutosearch(); + }; } - } - }, { - key: "initToc", - value: function initToc() { - var _this6 = this; - - var $tocCore = document.getElementById('TableOfContents'); - if ($tocCore === null) return; - - if (document.getElementById('toc-static').getAttribute('data-kept') || this.util.isTocStatic()) { - var $tocContentStatic = document.getElementById('toc-content-static'); - if ($tocCore.parentElement !== $tocContentStatic) { - $tocCore.parentElement.removeChild($tocCore); - $tocContentStatic.appendChild($tocCore); - } - - if (this._tocOnScroll) this.scrollEventSet.delete(this._tocOnScroll); - } else { - var $tocContentAuto = document.getElementById('toc-content-auto'); + document.body.appendChild(script); + } else initAutosearch(); + } - if ($tocCore.parentElement !== $tocContentAuto) { - $tocCore.parentElement.removeChild($tocCore); - $tocContentAuto.appendChild($tocCore); - } + initDetails() { + this.util.forEach(document.getElementsByClassName('details'), $details => { + const $summary = $details.getElementsByClassName('details-summary')[0]; + $summary.addEventListener('click', () => { + $details.classList.toggle('open'); + }, false); + }); + } - var $toc = document.getElementById('toc-auto'); - var $page = document.getElementsByClassName('page')[0]; - var rect = $page.getBoundingClientRect(); - $toc.style.left = "".concat(rect.left + rect.width + 20, "px"); - $toc.style.maxWidth = "".concat($page.getBoundingClientRect().left - 20, "px"); - $toc.style.visibility = 'visible'; - var $tocLinkElements = $tocCore.querySelectorAll('a:first-child'); - var $tocLiElements = $tocCore.getElementsByTagName('li'); - var $headerLinkElements = document.getElementsByClassName('headerLink'); - var headerIsFixed = document.body.getAttribute('data-header-desktop') !== 'normal'; - var headerHeight = document.getElementById('header-desktop').offsetHeight; - var TOP_SPACING = 20 + (headerIsFixed ? headerHeight : 0); - var minTocTop = $toc.offsetTop; - var minScrollTop = minTocTop - TOP_SPACING + (headerIsFixed ? 0 : headerHeight); - - this._tocOnScroll = this._tocOnScroll || function () { - var footerTop = document.getElementById('post-footer').offsetTop; - var maxTocTop = footerTop - $toc.getBoundingClientRect().height; - var maxScrollTop = maxTocTop - TOP_SPACING + (headerIsFixed ? 0 : headerHeight); - - if (_this6.newScrollTop < minScrollTop) { - $toc.style.position = 'absolute'; - $toc.style.top = "".concat(minTocTop, "px"); - } else if (_this6.newScrollTop > maxScrollTop) { - $toc.style.position = 'absolute'; - $toc.style.top = "".concat(maxTocTop, "px"); - } else { - $toc.style.position = 'fixed'; - $toc.style.top = "".concat(TOP_SPACING, "px"); - } + initLightGallery() { + if (this.config.lightgallery) lightGallery(document.getElementById('content'), { + plugins: [lgThumbnail, lgZoom], + selector: '.lightgallery', + speed: 400, + hideBarsDelay: 2000, + allowMediaOverlap: true, + exThumbImage: 'data-thumbnail', + toggleThumb: true, + thumbWidth: 80, + thumbHeight: '60px', + actualSize: false, + showZoomInOutIcons: true + }); + } - _this6.util.forEach($tocLinkElements, function ($tocLink) { - $tocLink.classList.remove('active'); + initHighlight() { + this.util.forEach(document.querySelectorAll('.highlight > pre.chroma'), $preChroma => { + const $chroma = document.createElement('div'); + $chroma.className = $preChroma.className; + const $table = document.createElement('table'); + $chroma.appendChild($table); + const $tbody = document.createElement('tbody'); + $table.appendChild($tbody); + const $tr = document.createElement('tr'); + $tbody.appendChild($tr); + const $td = document.createElement('td'); + $tr.appendChild($td); + $preChroma.parentElement.replaceChild($chroma, $preChroma); + $td.appendChild($preChroma); + }); + this.util.forEach(document.querySelectorAll('.highlight > .chroma'), $chroma => { + const $codeElements = $chroma.querySelectorAll('pre.chroma > code'); + + if ($codeElements.length) { + const $code = $codeElements[$codeElements.length - 1]; + const $header = document.createElement('div'); + $header.className = 'code-header ' + $code.className.toLowerCase(); + const $title = document.createElement('span'); + $title.classList.add('code-title'); + $title.insertAdjacentHTML('afterbegin', ''); + $title.addEventListener('click', () => { + $chroma.classList.toggle('open'); + }, false); + $header.appendChild($title); + const $ellipses = document.createElement('span'); + $ellipses.insertAdjacentHTML('afterbegin', ''); + $ellipses.classList.add('ellipses'); + $ellipses.addEventListener('click', () => { + $chroma.classList.add('open'); + }, false); + $header.appendChild($ellipses); + const $copy = document.createElement('span'); + $copy.insertAdjacentHTML('afterbegin', ''); + $copy.classList.add('copy'); + const code = $code.innerText; + if (this.config.code.maxShownLines < 0 || code.split('\n').length < this.config.code.maxShownLines + 2) $chroma.classList.add('open'); + + if (this.config.code.copyTitle) { + $copy.setAttribute('data-clipboard-text', code); + $copy.title = this.config.code.copyTitle; + const clipboard = new ClipboardJS($copy); + clipboard.on('success', _e => { + this.util.animateCSS($code, 'animate__flash'); }); + $header.appendChild($copy); + } - _this6.util.forEach($tocLiElements, function ($tocLi) { - $tocLi.classList.remove('has-active'); - }); + $chroma.insertBefore($header, $chroma.firstChild); + } + }); + } - var INDEX_SPACING = 20 + (headerIsFixed ? headerHeight : 0); - var activeTocIndex = $headerLinkElements.length - 1; + initTable() { + this.util.forEach(document.querySelectorAll('.content table'), $table => { + const $wrapper = document.createElement('div'); + $wrapper.className = 'table-wrapper'; + $table.parentElement.replaceChild($wrapper, $table); + $wrapper.appendChild($table); + }); + } - for (var i = 0; i < $headerLinkElements.length - 1; i++) { - var thisTop = $headerLinkElements[i].getBoundingClientRect().top; - var nextTop = $headerLinkElements[i + 1].getBoundingClientRect().top; + initHeaderLink() { + for (let num = 1; num <= 6; num++) { + this.util.forEach(document.querySelectorAll('.single .content > h' + num), $header => { + $header.classList.add('headerLink'); + $header.insertAdjacentHTML('afterbegin', ``); + }); + } + } - if (i == 0 && thisTop > INDEX_SPACING || thisTop <= INDEX_SPACING && nextTop > INDEX_SPACING) { - activeTocIndex = i; - break; - } - } + initToc() { + const $tocCore = document.getElementById('TableOfContents'); + if ($tocCore === null) return; - if (activeTocIndex !== -1) { - $tocLinkElements[activeTocIndex].classList.add('active'); - var $parent = $tocLinkElements[activeTocIndex].parentElement; + if (document.getElementById('toc-static').getAttribute('data-kept') || this.util.isTocStatic()) { + const $tocContentStatic = document.getElementById('toc-content-static'); - while ($parent !== $tocCore) { - $parent.classList.add('has-active'); - $parent = $parent.parentElement.parentElement; - } - } - }; + if ($tocCore.parentElement !== $tocContentStatic) { + $tocCore.parentElement.removeChild($tocCore); + $tocContentStatic.appendChild($tocCore); + } - this._tocOnScroll(); + if (this._tocOnScroll) this.scrollEventSet.delete(this._tocOnScroll); + } else { + const $tocContentAuto = document.getElementById('toc-content-auto'); - this.scrollEventSet.add(this._tocOnScroll); + if ($tocCore.parentElement !== $tocContentAuto) { + $tocCore.parentElement.removeChild($tocCore); + $tocContentAuto.appendChild($tocCore); } - } - }, { - key: "initMath", - value: function initMath() { - if (this.config.math) renderMathInElement(document.body, this.config.math); - } - }, { - key: "initMermaid", - value: function initMermaid() { - var _this7 = this; - - this._mermaidOnSwitchTheme = this._mermaidOnSwitchTheme || function () { - var $mermaidElements = document.getElementsByClassName('mermaid'); - - if ($mermaidElements.length) { - mermaid.initialize({ - startOnLoad: false, - theme: _this7.isDark ? 'dark' : 'neutral', - securityLevel: 'loose' - }); - _this7.util.forEach($mermaidElements, function ($mermaid) { - mermaid.render('svg-' + $mermaid.id, _this7.data[$mermaid.id], function (svgCode) { - $mermaid.innerHTML = svgCode; - }, $mermaid); - }); + const $toc = document.getElementById('toc-auto'); + const $page = document.getElementsByClassName('page')[0]; + const rect = $page.getBoundingClientRect(); + $toc.style.left = `${rect.left + rect.width + 20}px`; + $toc.style.maxWidth = `${$page.getBoundingClientRect().left - 20}px`; + $toc.style.visibility = 'visible'; + const $tocLinkElements = $tocCore.querySelectorAll('a:first-child'); + const $tocLiElements = $tocCore.getElementsByTagName('li'); + const $headerLinkElements = document.getElementsByClassName('headerLink'); + const headerIsFixed = document.body.getAttribute('data-header-desktop') !== 'normal'; + const headerHeight = document.getElementById('header-desktop').offsetHeight; + const TOP_SPACING = 20 + (headerIsFixed ? headerHeight : 0); + const minTocTop = $toc.offsetTop; + const minScrollTop = minTocTop - TOP_SPACING + (headerIsFixed ? 0 : headerHeight); + + this._tocOnScroll = this._tocOnScroll || (() => { + const footerTop = document.getElementById('post-footer').offsetTop; + const maxTocTop = footerTop - $toc.getBoundingClientRect().height; + const maxScrollTop = maxTocTop - TOP_SPACING + (headerIsFixed ? 0 : headerHeight); + + if (this.newScrollTop < minScrollTop) { + $toc.style.position = 'absolute'; + $toc.style.top = `${minTocTop}px`; + } else if (this.newScrollTop > maxScrollTop) { + $toc.style.position = 'absolute'; + $toc.style.top = `${maxTocTop}px`; + } else { + $toc.style.position = 'fixed'; + $toc.style.top = `${TOP_SPACING}px`; } - }; - this.switchThemeEventSet.add(this._mermaidOnSwitchTheme); - - this._mermaidOnSwitchTheme(); - } - }, { - key: "initEcharts", - value: function initEcharts() { - var _this8 = this; - - if (this.config.echarts) { - echarts.registerTheme('light', this.config.echarts.lightTheme); - echarts.registerTheme('dark', this.config.echarts.darkTheme); + this.util.forEach($tocLinkElements, $tocLink => { + $tocLink.classList.remove('active'); + }); + this.util.forEach($tocLiElements, $tocLi => { + $tocLi.classList.remove('has-active'); + }); + const INDEX_SPACING = 20 + (headerIsFixed ? headerHeight : 0); + let activeTocIndex = $headerLinkElements.length - 1; - this._echartsOnSwitchTheme = this._echartsOnSwitchTheme || function () { - _this8._echartsArr = _this8._echartsArr || []; + for (let i = 0; i < $headerLinkElements.length - 1; i++) { + const thisTop = $headerLinkElements[i].getBoundingClientRect().top; + const nextTop = $headerLinkElements[i + 1].getBoundingClientRect().top; - for (var i = 0; i < _this8._echartsArr.length; i++) { - _this8._echartsArr[i].dispose(); + if (i == 0 && thisTop > INDEX_SPACING || thisTop <= INDEX_SPACING && nextTop > INDEX_SPACING) { + activeTocIndex = i; + break; } + } - _this8._echartsArr = []; + if (activeTocIndex !== -1) { + $tocLinkElements[activeTocIndex].classList.add('active'); + let $parent = $tocLinkElements[activeTocIndex].parentElement; - _this8.util.forEach(document.getElementsByClassName('echarts'), function ($echarts) { - var chart = echarts.init($echarts, _this8.isDark ? 'dark' : 'light', { - renderer: 'svg' - }); - chart.setOption(JSON.parse(_this8.data[$echarts.id])); + while ($parent !== $tocCore) { + $parent.classList.add('has-active'); + $parent = $parent.parentElement.parentElement; + } + } + }); - _this8._echartsArr.push(chart); - }); - }; + this._tocOnScroll(); - this.switchThemeEventSet.add(this._echartsOnSwitchTheme); + this.scrollEventSet.add(this._tocOnScroll); + } + } - this._echartsOnSwitchTheme(); + initMath() { + if (this.config.math) renderMathInElement(document.body, this.config.math); + } - this._echartsOnResize = this._echartsOnResize || function () { - for (var i = 0; i < _this8._echartsArr.length; i++) { - _this8._echartsArr[i].resize(); - } - }; + initMermaid() { + this._mermaidOnSwitchTheme = this._mermaidOnSwitchTheme || (() => { + const $mermaidElements = document.getElementsByClassName('mermaid'); - this.resizeEventSet.add(this._echartsOnResize); + if ($mermaidElements.length) { + mermaid.initialize({ + startOnLoad: false, + theme: this.isDark ? 'dark' : 'neutral', + securityLevel: 'loose' + }); + this.util.forEach($mermaidElements, $mermaid => { + mermaid.render('svg-' + $mermaid.id, this.data[$mermaid.id], svgCode => { + $mermaid.innerHTML = svgCode; + }, $mermaid); + }); } - } - }, { - key: "initMapbox", - value: function initMapbox() { - var _this9 = this; - - if (this.config.mapbox) { - mapboxgl.accessToken = this.config.mapbox.accessToken; - mapboxgl.setRTLTextPlugin(this.config.mapbox.RTLTextPlugin); - this._mapboxArr = this._mapboxArr || []; - this.util.forEach(document.getElementsByClassName('mapbox'), function ($mapbox) { - var _this9$data$$mapbox$i = _this9.data[$mapbox.id], - lng = _this9$data$$mapbox$i.lng, - lat = _this9$data$$mapbox$i.lat, - zoom = _this9$data$$mapbox$i.zoom, - lightStyle = _this9$data$$mapbox$i.lightStyle, - darkStyle = _this9$data$$mapbox$i.darkStyle, - marked = _this9$data$$mapbox$i.marked, - navigation = _this9$data$$mapbox$i.navigation, - geolocate = _this9$data$$mapbox$i.geolocate, - scale = _this9$data$$mapbox$i.scale, - fullscreen = _this9$data$$mapbox$i.fullscreen; - var mapbox = new mapboxgl.Map({ - container: $mapbox, - center: [lng, lat], - zoom: zoom, - minZoom: .2, - style: _this9.isDark ? darkStyle : lightStyle, - attributionControl: false - }); + }); - if (marked) { - new mapboxgl.Marker().setLngLat([lng, lat]).addTo(mapbox); - } + this.switchThemeEventSet.add(this._mermaidOnSwitchTheme); - if (navigation) { - mapbox.addControl(new mapboxgl.NavigationControl(), 'bottom-right'); - } + this._mermaidOnSwitchTheme(); + } - if (geolocate) { - mapbox.addControl(new mapboxgl.GeolocateControl({ - positionOptions: { - enableHighAccuracy: true - }, - showUserLocation: true, - trackUserLocation: true - }), 'bottom-right'); - } + initEcharts() { + if (this.config.echarts) { + echarts.registerTheme('light', this.config.echarts.lightTheme); + echarts.registerTheme('dark', this.config.echarts.darkTheme); - if (scale) { - mapbox.addControl(new mapboxgl.ScaleControl()); - } + this._echartsOnSwitchTheme = this._echartsOnSwitchTheme || (() => { + this._echartsArr = this._echartsArr || []; - if (fullscreen) { - mapbox.addControl(new mapboxgl.FullscreenControl()); - } + for (let i = 0; i < this._echartsArr.length; i++) { + this._echartsArr[i].dispose(); + } - mapbox.addControl(new MapboxLanguage()); + this._echartsArr = []; + this.util.forEach(document.getElementsByClassName('echarts'), $echarts => { + const chart = echarts.init($echarts, this.isDark ? 'dark' : 'light', { + renderer: 'svg' + }); + chart.setOption(JSON.parse(this.data[$echarts.id])); - _this9._mapboxArr.push(mapbox); + this._echartsArr.push(chart); }); + }); - this._mapboxOnSwitchTheme = this._mapboxOnSwitchTheme || function () { - _this9.util.forEach(_this9._mapboxArr, function (mapbox) { - var $mapbox = mapbox.getContainer(); - var _this9$data$$mapbox$i2 = _this9.data[$mapbox.id], - lightStyle = _this9$data$$mapbox$i2.lightStyle, - darkStyle = _this9$data$$mapbox$i2.darkStyle; - mapbox.setStyle(_this9.isDark ? darkStyle : lightStyle); - mapbox.addControl(new MapboxLanguage()); - }); - }; + this.switchThemeEventSet.add(this._echartsOnSwitchTheme); - this.switchThemeEventSet.add(this._mapboxOnSwitchTheme); - } - } - }, { - key: "initTypeit", - value: function initTypeit() { - var _this10 = this; - - if (this.config.typeit) { - var typeitConfig = this.config.typeit; - var speed = typeitConfig.speed ? typeitConfig.speed : 100; - var cursorSpeed = typeitConfig.cursorSpeed ? typeitConfig.cursorSpeed : 1000; - var cursorChar = typeitConfig.cursorChar ? typeitConfig.cursorChar : '|'; - Object.values(typeitConfig.data).forEach(function (group) { - var typeone = function typeone(i) { - var id = group[i]; - var instance = new TypeIt("#".concat(id), { - strings: _this10.data[id], - speed: speed, - lifeLike: true, - cursorSpeed: cursorSpeed, - cursorChar: cursorChar, - waitUntilVisible: true, - afterComplete: function afterComplete() { - if (i === group.length - 1) { - if (typeitConfig.duration >= 0) window.setTimeout(function () { - instance.destroy(); - }, typeitConfig.duration); - return; - } + this._echartsOnSwitchTheme(); - instance.destroy(); - typeone(i + 1); - } - }).go(); - }; + this._echartsOnResize = this._echartsOnResize || (() => { + for (let i = 0; i < this._echartsArr.length; i++) { + this._echartsArr[i].resize(); + } + }); - typeone(0); - }); - } + this.resizeEventSet.add(this._echartsOnResize); } - }, { - key: "initComment", - value: function initComment() { - var _this11 = this; - - if (this.config.comment) { - if (this.config.comment.gitalk) { - this.config.comment.gitalk.body = decodeURI(window.location.href); - var gitalk = new Gitalk(this.config.comment.gitalk); - gitalk.render('gitalk'); + } + + initMapbox() { + if (this.config.mapbox) { + mapboxgl.accessToken = this.config.mapbox.accessToken; + mapboxgl.setRTLTextPlugin(this.config.mapbox.RTLTextPlugin); + this._mapboxArr = this._mapboxArr || []; + this.util.forEach(document.getElementsByClassName('mapbox'), $mapbox => { + const { + lng, + lat, + zoom, + lightStyle, + darkStyle, + marked, + navigation, + geolocate, + scale, + fullscreen + } = this.data[$mapbox.id]; + const mapbox = new mapboxgl.Map({ + container: $mapbox, + center: [lng, lat], + zoom: zoom, + minZoom: .2, + style: this.isDark ? darkStyle : lightStyle, + attributionControl: false + }); + + if (marked) { + new mapboxgl.Marker().setLngLat([lng, lat]).addTo(mapbox); } - if (this.config.comment.valine) new Valine(this.config.comment.valine); - - if (this.config.comment.utterances) { - var utterancesConfig = this.config.comment.utterances; - var script = document.createElement('script'); - script.src = 'https://utteranc.es/client.js'; - script.type = 'text/javascript'; - script.setAttribute('repo', utterancesConfig.repo); - script.setAttribute('issue-term', utterancesConfig.issueTerm); - if (utterancesConfig.label) script.setAttribute('label', utterancesConfig.label); - script.setAttribute('theme', this.isDark ? utterancesConfig.darkTheme : utterancesConfig.lightTheme); - script.crossOrigin = 'anonymous'; - script.async = true; - document.getElementById('utterances').appendChild(script); - - this._utterancesOnSwitchTheme = this._utterancesOnSwitchTheme || function () { - var message = { - type: 'set-theme', - theme: _this11.isDark ? utterancesConfig.darkTheme : utterancesConfig.lightTheme - }; - var iframe = document.querySelector('.utterances-frame'); - iframe.contentWindow.postMessage(message, 'https://utteranc.es'); - }; + if (navigation) { + mapbox.addControl(new mapboxgl.NavigationControl(), 'bottom-right'); + } - this.switchThemeEventSet.add(this._utterancesOnSwitchTheme); + if (geolocate) { + mapbox.addControl(new mapboxgl.GeolocateControl({ + positionOptions: { + enableHighAccuracy: true + }, + showUserLocation: true, + trackUserLocation: true + }), 'bottom-right'); } - } - } - }, { - key: "initCookieconsent", - value: function initCookieconsent() { - if (this.config.cookieconsent) cookieconsent.initialise(this.config.cookieconsent); - } - }, { - key: "onScroll", - value: function onScroll() { - var _this12 = this; - - var $headers = []; - if (document.body.getAttribute('data-header-desktop') === 'auto') $headers.push(document.getElementById('header-desktop')); - if (document.body.getAttribute('data-header-mobile') === 'auto') $headers.push(document.getElementById('header-mobile')); - - if (document.getElementById('comments')) { - var $viewComments = document.getElementById('view-comments'); - $viewComments.href = "#comments"; - $viewComments.style.display = 'block'; - } - var $fixedButtons = document.getElementById('fixed-buttons'); - var ACCURACY = 20, - MINIMUM = 100; - window.addEventListener('scroll', function () { - _this12.newScrollTop = _this12.util.getScrollTop(); - var scroll = _this12.newScrollTop - _this12.oldScrollTop; + if (scale) { + mapbox.addControl(new mapboxgl.ScaleControl()); + } - var isMobile = _this12.util.isMobile(); + if (fullscreen) { + mapbox.addControl(new mapboxgl.FullscreenControl()); + } - _this12.util.forEach($headers, function ($header) { - if (scroll > ACCURACY) { - $header.classList.remove('animate__fadeInDown'); + mapbox.addControl(new MapboxLanguage()); - _this12.util.animateCSS($header, ['animate__fadeOutUp', 'animate__faster'], true); - } else if (scroll < -ACCURACY) { - $header.classList.remove('animate__fadeOutUp'); + this._mapboxArr.push(mapbox); + }); - _this12.util.animateCSS($header, ['animate__fadeInDown', 'animate__faster'], true); - } + this._mapboxOnSwitchTheme = this._mapboxOnSwitchTheme || (() => { + this.util.forEach(this._mapboxArr, mapbox => { + const $mapbox = mapbox.getContainer(); + const { + lightStyle, + darkStyle + } = this.data[$mapbox.id]; + mapbox.setStyle(this.isDark ? darkStyle : lightStyle); + mapbox.addControl(new MapboxLanguage()); }); + }); - if (_this12.newScrollTop > MINIMUM) { - if (isMobile && scroll > ACCURACY) { - $fixedButtons.classList.remove('animate__fadeIn'); + this.switchThemeEventSet.add(this._mapboxOnSwitchTheme); + } + } - _this12.util.animateCSS($fixedButtons, ['animate__fadeOut', 'animate__faster'], true); - } else if (!isMobile || scroll < -ACCURACY) { - $fixedButtons.style.display = 'block'; - $fixedButtons.classList.remove('animate__fadeOut'); + initTypeit() { + if (this.config.typeit) { + const typeitConfig = this.config.typeit; + const speed = typeitConfig.speed ? typeitConfig.speed : 100; + const cursorSpeed = typeitConfig.cursorSpeed ? typeitConfig.cursorSpeed : 1000; + const cursorChar = typeitConfig.cursorChar ? typeitConfig.cursorChar : '|'; + Object.values(typeitConfig.data).forEach(group => { + const typeone = i => { + const id = group[i]; + const instance = new TypeIt(`#${id}`, { + strings: this.data[id], + speed: speed, + lifeLike: true, + cursorSpeed: cursorSpeed, + cursorChar: cursorChar, + waitUntilVisible: true, + afterComplete: () => { + if (i === group.length - 1) { + if (typeitConfig.duration >= 0) window.setTimeout(() => { + instance.destroy(); + }, typeitConfig.duration); + return; + } - _this12.util.animateCSS($fixedButtons, ['animate__fadeIn', 'animate__faster'], true); - } - } else { - if (!isMobile) { - $fixedButtons.classList.remove('animate__fadeIn'); + instance.destroy(); + typeone(i + 1); + } + }).go(); + }; - _this12.util.animateCSS($fixedButtons, ['animate__fadeOut', 'animate__faster'], true); - } + typeone(0); + }); + } + } - $fixedButtons.style.display = 'none'; - } + initComment() { + if (this.config.comment) { + if (this.config.comment.gitalk) { + this.config.comment.gitalk.body = decodeURI(window.location.href); + const gitalk = new Gitalk(this.config.comment.gitalk); + gitalk.render('gitalk'); + } - var _iterator2 = _createForOfIteratorHelper(_this12.scrollEventSet), - _step2; + if (this.config.comment.valine) new Valine(this.config.comment.valine); - try { - for (_iterator2.s(); !(_step2 = _iterator2.n()).done;) { - var event = _step2.value; - event(); - } - } catch (err) { - _iterator2.e(err); - } finally { - _iterator2.f(); - } + if (this.config.comment.utterances) { + const utterancesConfig = this.config.comment.utterances; + const script = document.createElement('script'); + script.src = 'https://utteranc.es/client.js'; + script.type = 'text/javascript'; + script.setAttribute('repo', utterancesConfig.repo); + script.setAttribute('issue-term', utterancesConfig.issueTerm); + if (utterancesConfig.label) script.setAttribute('label', utterancesConfig.label); + script.setAttribute('theme', this.isDark ? utterancesConfig.darkTheme : utterancesConfig.lightTheme); + script.crossOrigin = 'anonymous'; + script.async = true; + document.getElementById('utterances').appendChild(script); - _this12.oldScrollTop = _this12.newScrollTop; - }, false); + this._utterancesOnSwitchTheme = this._utterancesOnSwitchTheme || (() => { + const message = { + type: 'set-theme', + theme: this.isDark ? utterancesConfig.darkTheme : utterancesConfig.lightTheme + }; + const iframe = document.querySelector('.utterances-frame'); + iframe.contentWindow.postMessage(message, 'https://utteranc.es'); + }); + + this.switchThemeEventSet.add(this._utterancesOnSwitchTheme); + } } - }, { - key: "onResize", - value: function onResize() { - var _this13 = this; - - window.addEventListener('resize', function () { - if (!_this13._resizeTimeout) { - _this13._resizeTimeout = window.setTimeout(function () { - _this13._resizeTimeout = null; - - var _iterator3 = _createForOfIteratorHelper(_this13.resizeEventSet), - _step3; - - try { - for (_iterator3.s(); !(_step3 = _iterator3.n()).done;) { - var event = _step3.value; - event(); - } - } catch (err) { - _iterator3.e(err); - } finally { - _iterator3.f(); - } + } - _this13.initToc(); + initCookieconsent() { + if (this.config.cookieconsent) cookieconsent.initialise(this.config.cookieconsent); + } - _this13.initMermaid(); + onScroll() { + const $headers = []; + if (document.body.getAttribute('data-header-desktop') === 'auto') $headers.push(document.getElementById('header-desktop')); + if (document.body.getAttribute('data-header-mobile') === 'auto') $headers.push(document.getElementById('header-mobile')); - _this13.initSearch(); - }, 100); - } - }, false); + if (document.getElementById('comments')) { + const $viewComments = document.getElementById('view-comments'); + $viewComments.href = `#comments`; + $viewComments.style.display = 'block'; } - }, { - key: "onClickMask", - value: function onClickMask() { - var _this14 = this; - - document.getElementById('mask').addEventListener('click', function () { - var _iterator4 = _createForOfIteratorHelper(_this14.clickMaskEventSet), - _step4; - - try { - for (_iterator4.s(); !(_step4 = _iterator4.n()).done;) { - var event = _step4.value; - event(); - } - } catch (err) { - _iterator4.e(err); - } finally { - _iterator4.f(); + + const $fixedButtons = document.getElementById('fixed-buttons'); + const ACCURACY = 20, + MINIMUM = 100; + window.addEventListener('scroll', () => { + this.newScrollTop = this.util.getScrollTop(); + const scroll = this.newScrollTop - this.oldScrollTop; + const isMobile = this.util.isMobile(); + this.util.forEach($headers, $header => { + if (scroll > ACCURACY) { + $header.classList.remove('animate__fadeInDown'); + this.util.animateCSS($header, ['animate__fadeOutUp', 'animate__faster'], true); + } else if (scroll < -ACCURACY) { + $header.classList.remove('animate__fadeOutUp'); + this.util.animateCSS($header, ['animate__fadeInDown', 'animate__faster'], true); } + }); - document.body.classList.remove('blur'); - }, false); - } - }, { - key: "init", - value: function init() { - var _this15 = this; - - try { - this.initRaw(); - this.initSVGIcon(); - this.initTwemoji(); - this.initMenuMobile(); - this.initSwitchTheme(); - this.initSearch(); - this.initDetails(); - this.initLightGallery(); - this.initHighlight(); - this.initTable(); - this.initHeaderLink(); - this.initMath(); - this.initMermaid(); - this.initEcharts(); - this.initTypeit(); - this.initMapbox(); - this.initCookieconsent(); - } catch (err) { - console.error(err); + if (this.newScrollTop > MINIMUM) { + if (isMobile && scroll > ACCURACY) { + $fixedButtons.classList.remove('animate__fadeIn'); + this.util.animateCSS($fixedButtons, ['animate__fadeOut', 'animate__faster'], true); + } else if (!isMobile || scroll < -ACCURACY) { + $fixedButtons.style.display = 'block'; + $fixedButtons.classList.remove('animate__fadeOut'); + this.util.animateCSS($fixedButtons, ['animate__fadeIn', 'animate__faster'], true); + } + } else { + if (!isMobile) { + $fixedButtons.classList.remove('animate__fadeIn'); + this.util.animateCSS($fixedButtons, ['animate__fadeOut', 'animate__faster'], true); + } + + $fixedButtons.style.display = 'none'; } - window.setTimeout(function () { - _this15.initToc(); + for (let event of this.scrollEventSet) event(); + + this.oldScrollTop = this.newScrollTop; + }, false); + } + + onResize() { + window.addEventListener('resize', () => { + if (!this._resizeTimeout) { + this._resizeTimeout = window.setTimeout(() => { + this._resizeTimeout = null; + + for (let event of this.resizeEventSet) event(); - _this15.initComment(); + this.initToc(); + this.initMermaid(); + this.initSearch(); + }, 100); + } + }, false); + } - _this15.onScroll(); + onClickMask() { + document.getElementById('mask').addEventListener('click', () => { + for (let event of this.clickMaskEventSet) event(); - _this15.onResize(); + document.body.classList.remove('blur'); + }, false); + } - _this15.onClickMask(); - }, 100); + init() { + try { + this.initRaw(); + this.initSVGIcon(); + this.initTwemoji(); + this.initMenuMobile(); + this.initSwitchTheme(); + this.initSearch(); + this.initDetails(); + this.initLightGallery(); + this.initHighlight(); + this.initTable(); + this.initHeaderLink(); + this.initMath(); + this.initMermaid(); + this.initEcharts(); + this.initTypeit(); + this.initMapbox(); + this.initCookieconsent(); + } catch (err) { + console.error(err); } - }]); - return Theme; -}(); + window.setTimeout(() => { + this.initToc(); + this.initComment(); + this.onScroll(); + this.onResize(); + this.onClickMask(); + }, 100); + } + +} -var themeInit = function themeInit() { - var theme = new Theme(); +const themeInit = () => { + const theme = new Theme(); theme.init(); }; diff --git a/content/posts/theme-documentation-basics/index.en.md b/content/posts/theme-documentation-basics/index.en.md index addc9e03..ed628e9d 100644 --- a/content/posts/theme-documentation-basics/index.en.md +++ b/content/posts/theme-documentation-basics/index.en.md @@ -252,7 +252,7 @@ Please open the code block below to view the complete sample configuration :(far # ICP info only in China (HTML format is supported) icp = "" # license info (HTML format is supported) - license = 'CC BY-NC 4.0' + license = 'CC BY-NC 4.0' # {{< version 0.2.0 >}} Section (all posts) page config [params.section] diff --git a/exampleSite/config.toml b/exampleSite/config.toml index 90f6ac9b..bb1b4b32 100644 --- a/exampleSite/config.toml +++ b/exampleSite/config.toml @@ -119,7 +119,7 @@ enableEmoji = true # ICP info only in China (HTML format is supported) icp = "" # license info (HTML format is supported) - license= 'CC BY-NC 4.0' + license= 'CC BY-NC 4.0' # Section (all posts) page config [params.section] diff --git a/exampleSite/content/posts/theme-documentation-basics/index.en.md b/exampleSite/content/posts/theme-documentation-basics/index.en.md index addc9e03..ed628e9d 100644 --- a/exampleSite/content/posts/theme-documentation-basics/index.en.md +++ b/exampleSite/content/posts/theme-documentation-basics/index.en.md @@ -252,7 +252,7 @@ Please open the code block below to view the complete sample configuration :(far # ICP info only in China (HTML format is supported) icp = "" # license info (HTML format is supported) - license = 'CC BY-NC 4.0' + license = 'CC BY-NC 4.0' # {{< version 0.2.0 >}} Section (all posts) page config [params.section] diff --git a/exampleSite/content/posts/theme-documentation-basics/index.zh-cn.md b/exampleSite/content/posts/theme-documentation-basics/index.zh-cn.md index eceedb28..647fa656 100644 --- a/exampleSite/content/posts/theme-documentation-basics/index.zh-cn.md +++ b/exampleSite/content/posts/theme-documentation-basics/index.zh-cn.md @@ -254,7 +254,7 @@ hugo # ICP 备案信息,仅在中国使用 (支持 HTML 格式) icp = "" # 许可协议信息 (支持 HTML 格式) - license = 'CC BY-NC 4.0' + license = 'CC BY-NC 4.0' # {{< version 0.2.0 >}} Section (所有文章) 页面配置 [params.section] diff --git a/layouts/partials/footer.html b/layouts/partials/footer.html index 98dbf63d..d93a8eb5 100644 --- a/layouts/partials/footer.html +++ b/layouts/partials/footer.html @@ -11,8 +11,8 @@ {{- /* Hugo and KeepIt */ -}} {{- if ne .Site.Params.footer.hugo false -}} {{- end -}} diff --git a/layouts/partials/header.html b/layouts/partials/header.html index 10948a0a..339ac762 100644 --- a/layouts/partials/header.html +++ b/layouts/partials/header.html @@ -32,7 +32,7 @@ {{- with .Page -}} {{- $url = .RelPermalink -}} {{- end -}} - + {{- .Pre | safeHTML }} {{ .Name }} {{ .Post | safeHTML -}} {{- end -}} @@ -142,7 +142,7 @@ {{- with .Page -}} {{- $url = .RelPermalink -}} {{- end -}} - + {{- .Pre | safeHTML }}{{ .Name }}{{ .Post | safeHTML -}} {{- end -}} diff --git a/layouts/partials/home/profile.html b/layouts/partials/home/profile.html index b453fad3..7d4bad83 100644 --- a/layouts/partials/home/profile.html +++ b/layouts/partials/home/profile.html @@ -12,7 +12,7 @@ {{- with .Page -}} {{- $url = .RelPermalink -}} {{- end -}} - + {{- dict "Src" $avatar | partial "plugin/image.html" -}} {{- else -}} diff --git a/layouts/partials/plugin/link.html b/layouts/partials/plugin/link.html index 83da75fa..5039c830 100644 --- a/layouts/partials/plugin/link.html +++ b/layouts/partials/plugin/link.html @@ -1,5 +1,5 @@ {{- $rel := "" -}} - + {{- with .Icon -}} {{- partial "plugin/icon.html" . -}} {{- end -}} diff --git a/layouts/shortcodes/version.html b/layouts/shortcodes/version.html index 67ada16f..48b56abd 100644 --- a/layouts/shortcodes/version.html +++ b/layouts/shortcodes/version.html @@ -8,6 +8,6 @@ {{- $resource := resources.Get "svg/version.template.svg" -}} {{- $resource = $resource | resources.ExecuteAsTemplate $path (dict "version" $version "label" $label "color" $color) | minify -}} {{- $alt := printf "KeepIt %v | %v" $label $version -}} - + {{- dict "Src" $resource.RelPermalink "Alt" $alt "Class" "version" | partial "plugin/image.html" -}} \ No newline at end of file diff --git a/src/js/theme.js b/src/js/theme.js index a00bd28e..c45cfee5 100644 --- a/src/js/theme.js +++ b/src/js/theme.js @@ -284,7 +284,7 @@ class Theme { icon: '', href: 'https://lunrjs.com/', }; - return ``;}, + return ``;}, }, }); autosearch.on('autocomplete:selected', (_event, suggestion, _dataset, _context) => {