hexo-theme-next
Advanced tools
Comparing version 8.4.0 to 8.5.0
@@ -17,3 +17,3 @@ <div align="right"> | ||
[![NPM version](https://img.shields.io/npm/v/hexo-theme-next?color=red&logo=npm&style=flat-square)](https://www.npmjs.com/package/hexo-theme-next) | ||
[![Required Hexo version](https://img.shields.io/badge/hexo-%3E=5.0.0-blue?style=flat-square&logo=hexo)](https://hexo.io) | ||
[![Required Hexo version](https://img.shields.io/badge/hexo-%3E=5.3.0-blue?style=flat-square&logo=hexo)](https://hexo.io) | ||
[![License](https://img.shields.io/badge/license-%20AGPL-orange?style=flat-square&logo=gnu)](https://github.com/next-theme/hexo-theme-next/blob/master/LICENSE.md) | ||
@@ -20,0 +20,0 @@ [![Build Status](https://img.shields.io/github/workflow/status/next-theme/hexo-theme-next/Linter?label=test&logo=github&style=flat-square)](https://github.com/next-theme/hexo-theme-next/actions?query=workflow%3ALinter) |
@@ -17,3 +17,3 @@ <div align="right"> | ||
[![NPM version](https://img.shields.io/npm/v/hexo-theme-next?color=red&logo=npm&style=flat-square)](https://www.npmjs.com/package/hexo-theme-next) | ||
[![Required Hexo version](https://img.shields.io/badge/hexo-%3E=5.0.0-blue?style=flat-square&logo=hexo)](https://hexo.io) | ||
[![Required Hexo version](https://img.shields.io/badge/hexo-%3E=5.3.0-blue?style=flat-square&logo=hexo)](https://hexo.io) | ||
[![License](https://img.shields.io/badge/license-%20AGPL-orange?style=flat-square&logo=gnu)](https://github.com/next-theme/hexo-theme-next/blob/master/LICENSE.md) | ||
@@ -20,0 +20,0 @@ [![Build Status](https://img.shields.io/github/workflow/status/next-theme/hexo-theme-next/Linter?label=test&logo=github&style=flat-square)](https://github.com/next-theme/hexo-theme-next/actions?query=workflow%3ALinter) |
{ | ||
"name": "hexo-theme-next", | ||
"version": "8.4.0", | ||
"version": "8.5.0", | ||
"description": "Elegant and powerful theme for Hexo.", | ||
@@ -20,3 +20,3 @@ "main": "package.json", | ||
"test": "mocha test/index.js", | ||
"test-cov": "nyc --reporter=lcovonly npm run test" | ||
"test-cov": "nyc npm test" | ||
}, | ||
@@ -38,7 +38,7 @@ "repository": "next-theme/hexo-theme-next", | ||
"chai": "4.3.4", | ||
"eslint": "7.25.0", | ||
"eslint": "7.27.0", | ||
"hexo": "5.4.0", | ||
"hexo-renderer-marked": "4.0.0", | ||
"js-yaml": "4.1.0", | ||
"mocha": "8.3.2", | ||
"mocha": "8.4.0", | ||
"nyc": "15.1.0", | ||
@@ -45,0 +45,0 @@ "stylint": "2.0.0" |
@@ -17,3 +17,3 @@ <div align="right"> | ||
[![NPM version](https://img.shields.io/npm/v/hexo-theme-next?color=red&logo=npm&style=flat-square)](https://www.npmjs.com/package/hexo-theme-next) | ||
[![Required Hexo version](https://img.shields.io/badge/hexo-%3E=5.0.0-blue?style=flat-square&logo=hexo)](https://hexo.io) | ||
[![Required Hexo version](https://img.shields.io/badge/hexo-%3E=5.3.0-blue?style=flat-square&logo=hexo)](https://hexo.io) | ||
[![License](https://img.shields.io/badge/license-%20AGPL-orange?style=flat-square&logo=gnu)](https://github.com/next-theme/hexo-theme-next/blob/master/LICENSE.md) | ||
@@ -20,0 +20,0 @@ [![Build Status](https://img.shields.io/github/workflow/status/next-theme/hexo-theme-next/Linter?label=test&logo=github&style=flat-square)](https://github.com/next-theme/hexo-theme-next/actions?query=workflow%3ALinter) |
@@ -9,3 +9,3 @@ 'use strict'; | ||
if (data.next) { | ||
hexo.log.warn('`next.yml` is deprecated. Please upgrade to Hexo 5.0 and use `_config.next.yml` instead.'); | ||
hexo.log.warn('`next.yml` is deprecated. Please upgrade to Hexo 5 or later and use `_config.next.yml` instead.'); | ||
hexo.log.warn('Documentation: https://theme-next.js.org/docs/getting-started/configuration.html'); | ||
@@ -12,0 +12,0 @@ } |
@@ -7,2 +7,3 @@ 'use strict'; | ||
const { url_for } = require('hexo-util'); | ||
let internal; | ||
@@ -17,3 +18,3 @@ try { | ||
module.exports = hexo => { | ||
const { vendors } = hexo.theme.config; | ||
const { vendors, creative_commons } = hexo.theme.config; | ||
if (typeof internal === 'function') { | ||
@@ -23,6 +24,13 @@ internal(hexo, dependencies); | ||
for (const [key, value] of Object.entries(dependencies)) { | ||
if (vendors[key]) { | ||
vendors[key] = url_for.call(hexo, vendors[key]); | ||
// This script will be executed repeatedly when Hexo listens file changes | ||
// But the variable vendors[key] only needs to be modified once | ||
if (vendors[key] && typeof vendors[key] === 'string') { | ||
vendors[key] = { | ||
url: url_for.call(hexo, vendors[key]) | ||
}; | ||
continue; | ||
} | ||
if (key === 'creative_commons') { | ||
value.file = `${value.dir}/${creative_commons.size}/${creative_commons.license.replace(/-/g, '_')}.svg`; | ||
} | ||
const { name, version, file, alias, unavailable } = value; | ||
@@ -38,4 +46,7 @@ const links = { | ||
if (plugins === 'local' && typeof internal === 'undefined') plugins = 'jsdelivr'; | ||
vendors[key] = links[plugins] || links.jsdelivr; | ||
vendors[key] = { | ||
url : links[plugins] || links.jsdelivr, | ||
integrity: value.integrity | ||
}; | ||
} | ||
}; |
@@ -24,3 +24,3 @@ /* global hexo */ | ||
// Creative Commons | ||
locals.ccURL = 'https://creativecommons.org/' + (theme.creative_commons.license === 'zero' ? 'publicdomain/zero/1.0/' : 'licenses/' + theme.creative_commons.license + '/4.0/') + (theme.creative_commons.language || ''); | ||
locals.ccURL = 'https://creativecommons.org/' + (theme.creative_commons.license === 'cc-zero' ? 'publicdomain/zero/1.0/' : 'licenses/' + theme.creative_commons.license + '/4.0/') + (theme.creative_commons.language || ''); | ||
// PJAX | ||
@@ -27,0 +27,0 @@ locals.pjax = theme.pjax ? ' data-pjax' : ''; |
@@ -32,2 +32,13 @@ /* global hexo */ | ||
hexo.extend.helper.register('next_vendors', function(name) { | ||
const { url, integrity } = this.theme.vendors[name]; | ||
const type = url.endsWith('css') ? 'css' : 'js'; | ||
if (type === 'css') { | ||
if (integrity) return `<link rel="stylesheet" href="${url}" integrity="${integrity}" crossorigin="anonymous">`; | ||
return `<link rel="stylesheet" href="${url}">`; | ||
} | ||
if (integrity) return `<script src="${url}" integrity="${integrity}" crossorigin="anonymous"></script>`; | ||
return `<script src="${url}"></script>`; | ||
}); | ||
hexo.extend.helper.register('next_data', function(name, ...data) { | ||
@@ -34,0 +45,0 @@ const { escape_html } = this; |
@@ -39,6 +39,2 @@ 'use strict'; | ||
if (attrs.class && Array.isArray(attrs.class)) { | ||
attrs.class = attrs.class.join(' '); | ||
} | ||
// If it's external link, rewrite attributes. | ||
@@ -45,0 +41,0 @@ if (data.protocol && data.hostname !== siteHost) { |
@@ -29,3 +29,3 @@ /* global CONFIG */ | ||
// Scroll event | ||
window.addEventListener('scroll', () => link.classList.toggle('book-mark-link-fixed', window.scrollY === 0)); | ||
window.addEventListener('scroll', () => link.classList.toggle('book-mark-link-fixed', window.scrollY === 0), { passive: true }); | ||
// Register beforeunload event when the trigger is auto | ||
@@ -32,0 +32,0 @@ if (trigger === 'auto') { |
@@ -39,16 +39,27 @@ if (!window.NexT) window.NexT = {}; | ||
let override = overrideConfig[name]; | ||
if (override === undefined && typeof existing === 'object') { | ||
override = {}; | ||
overrideConfig[name] = override; | ||
// For unset override and mixable existing | ||
if (!(name in overrideConfig) && typeof existing === 'object') { | ||
// Get ready to mix. | ||
overrideConfig[name] = {}; | ||
} | ||
if (typeof override === 'object') { | ||
return new Proxy({...existing, ...override}, { | ||
set(target, prop, value) { | ||
override[prop] = value; | ||
return true; | ||
} | ||
}); | ||
if (name in overrideConfig) { | ||
const override = overrideConfig[name]; | ||
// When mixable | ||
if (typeof override === 'object' && typeof existing === 'object') { | ||
// Mix, proxy changes to the override. | ||
return new Proxy({...existing, ...override}, { | ||
set(target, prop, value) { | ||
target[prop] = value; | ||
override[prop] = value; | ||
return true; | ||
} | ||
}); | ||
} | ||
return override; | ||
} | ||
// Only when not mixable and override hasn't been set. | ||
return existing; | ||
@@ -55,0 +66,0 @@ } |
@@ -60,3 +60,3 @@ /* global CONFIG */ | ||
window.addEventListener('resize', updateFooterPosition); | ||
window.addEventListener('scroll', updateFooterPosition); | ||
window.addEventListener('scroll', updateFooterPosition, { passive: true }); | ||
}); |
@@ -17,3 +17,5 @@ /* global NexT, CONFIG, DISQUS */ | ||
if (CONFIG.page.comments) { | ||
const disqus_config = function() { | ||
// `disqus_config` should be a global variable | ||
// See https://help.disqus.com/en/articles/1717084-javascript-configuration-variables | ||
window.disqus_config = function() { | ||
this.page.url = CONFIG.page.permalink; | ||
@@ -30,3 +32,3 @@ this.page.identifier = CONFIG.page.path; | ||
reload: true, | ||
config: disqus_config | ||
config: window.disqus_config | ||
}); | ||
@@ -33,0 +35,0 @@ } else { |
@@ -1,2 +0,2 @@ | ||
/* global instantsearch, algoliasearch, CONFIG */ | ||
/* global instantsearch, algoliasearch, CONFIG, pjax */ | ||
@@ -16,5 +16,7 @@ document.addEventListener('DOMContentLoaded', () => { | ||
window.pjax && search.on('render', () => { | ||
window.pjax.refresh(document.querySelector('.algolia-hits')); | ||
}); | ||
if (typeof pjax === 'object') { | ||
search.on('render', () => { | ||
pjax.refresh(document.querySelector('.algolia-hits')); | ||
}); | ||
} | ||
@@ -21,0 +23,0 @@ // Registering Widgets |
@@ -1,2 +0,2 @@ | ||
/* global CONFIG */ | ||
/* global CONFIG, pjax */ | ||
@@ -195,3 +195,3 @@ document.addEventListener('DOMContentLoaded', () => { | ||
<ul class="search-result-list">${resultItems.map(result => result.item).join('')}</ul>`; | ||
window.pjax && window.pjax.refresh(container); | ||
if (typeof pjax === 'object') pjax.refresh(container); | ||
} | ||
@@ -207,9 +207,7 @@ }; | ||
isfetched = true; | ||
datas = isXml ? [...new DOMParser().parseFromString(res, 'text/xml').querySelectorAll('entry')].map(element => { | ||
return { | ||
title : element.querySelector('title').textContent, | ||
content: element.querySelector('content').textContent, | ||
url : element.querySelector('url').textContent | ||
}; | ||
}) : JSON.parse(res); | ||
datas = isXml ? [...new DOMParser().parseFromString(res, 'text/xml').querySelectorAll('entry')].map(element => ({ | ||
title : element.querySelector('title').textContent, | ||
content: element.querySelector('content').textContent, | ||
url : element.querySelector('url').textContent | ||
})) : JSON.parse(res); | ||
// Only match articles with non-empty titles | ||
@@ -216,0 +214,0 @@ datas = datas.filter(data => data.title).map(data => { |
@@ -192,3 +192,3 @@ /* global NexT, CONFIG */ | ||
this.activateNavByIndex(index); | ||
}); | ||
}, { passive: true }); | ||
@@ -341,5 +341,5 @@ backToTop && backToTop.addEventListener('click', () => { | ||
getScript: function(url, options = {}, legacyCondition) { | ||
getScript: function(src, options = {}, legacyCondition) { | ||
if (typeof options === 'function') { | ||
return this.getScript(url, { | ||
return this.getScript(src, { | ||
condition: legacyCondition | ||
@@ -378,3 +378,12 @@ }).then(options); | ||
script.src = url; | ||
if (typeof src === 'object') { | ||
const { url, integrity } = src; | ||
script.src = url; | ||
if (integrity) { | ||
script.integrity = integrity; | ||
script.crossOrigin = 'anonymous'; | ||
} | ||
} else { | ||
script.src = src; | ||
} | ||
(parentNode || document.head).appendChild(script); | ||
@@ -381,0 +390,0 @@ } |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
3018
443621
266