Refactor vendors (#72)

* Compatibility with `@next-theme/plugins`

* Update test cases
This commit is contained in:
Mimi 2020-08-02 11:04:04 +08:00 committed by GitHub
parent 04da779212
commit d248a3f9a6
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
26 changed files with 223 additions and 169 deletions

1
.gitattributes vendored
View File

@ -1,2 +1 @@
source/lib/* linguist-vendored
test/* linguist-vendored test/* linguist-vendored

5
.gitignore vendored
View File

@ -8,8 +8,3 @@ node_modules/
# Ignore optional external libraries # Ignore optional external libraries
source/lib/* source/lib/*
# Track internal libraries & Ignore unused verdors files
!source/lib/font-awesome/
!source/lib/anime.min.js
!source/lib/animate-css/

View File

@ -853,126 +853,86 @@ canvas_ribbon:
#! See: https://theme-next.js.org/docs/advanced-settings #! See: https://theme-next.js.org/docs/advanced-settings
#! ============================================================== #! ==============================================================
# Script Vendors. Set a CDN address for the vendor you want to customize. # It's recommended to use the same version as in `_vendors.yml` to avoid potential problems.
# CDN URLs from UNPKG and CDNJS are provided in the comments for selection. # Remember to use the https protocol of CDN links when you enable https on your site.
# If left blank, jsDelivr will be used as the default CDN provider.
# It's recommended to use the same version as internal ones to avoid potential problems.
# Remember to use the https protocol of CDN files when you enable https on your site.
vendors: vendors:
# The CDN provider of NexT internal scripts.
# Available values: local, jsdelivr, unpkg # Available values: local, jsdelivr, unpkg
internal: local internal: local
# The default CDN provider of third-party plugins.
# Available values: local, jsdelivr, unpkg, cdnjs
# Dependencies for `plugins: local`: https://github.com/next-theme/plugins
plugins: jsdelivr
# Internal version: 3.1.0 # In the following settings, you can specify the CDN link for each plugin.
# anime: //cdn.jsdelivr.net/npm/animejs@3.2.0/lib/anime.min.js # If left blank, the default CDN provider set by `plugins` option will be used.
# anime: //unpkg.com/animejs@3.2.0/lib/anime.min.js
# anime: //cdnjs.cloudflare.com/ajax/libs/animejs/3.2.0/anime.min.js # Anime.js
anime: anime:
# Internal version: 5.13.0 # Font Awesome
# fontawesome: //cdn.jsdelivr.net/npm/@fortawesome/fontawesome-free@5/css/all.min.css
# fontawesome: //unpkg.com/@fortawesome/fontawesome-free@5/css/all.min.css
# fontawesome: //cdnjs.cloudflare.com/ajax/libs/font-awesome/5.14.0/css/all.min.css
fontawesome: fontawesome:
# Prism # Prism
# prism: //unpkg.com/prismjs@1/components/prism-core.min.js
# prism_autoloader: //unpkg.com/prismjs@1/plugins/autoloader/prism-autoloader.min.js
# prism_line_numbers: //unpkg.com/prismjs@1/plugins/line-numbers/prism-line-numbers.min.js
prism: prism:
prism_autoloader: prism_autoloader:
prism_line_numbers: prism_line_numbers:
# MathJax # MathJax
# mathjax: //unpkg.com/mathjax@3/es5/tex-mml-chtml.js
# mathjax: //cdnjs.cloudflare.com/ajax/libs/mathjax/3.0.5/es5/tex-mml-chtml.js
mathjax: mathjax:
# KaTeX # KaTeX
# katex: //unpkg.com/katex@0/dist/katex.min.css
# katex: //cdnjs.cloudflare.com/ajax/libs/KaTeX/0.11.1/katex.min.css
# copy_tex_js: //unpkg.com/katex@0/dist/contrib/copy-tex.min.js
# copy_tex_css: //unpkg.com/katex@0/dist/contrib/copy-tex.min.css
katex: katex:
copy_tex_js: copy_tex_js:
copy_tex_css: copy_tex_css:
# Recommended version: 0.4.0 # Pjax
# pjax: //cdn.jsdelivr.net/gh/next-theme/pjax@0/pjax.min.js
pjax: pjax:
# FancyBox # FancyBox
# jquery: //unpkg.com/jquery@3/dist/jquery.min.js
# fancybox: //unpkg.com/@fancyapps/fancybox@3/dist/jquery.fancybox.min.js
# fancybox_css: //unpkg.com/@fancyapps/fancybox@3/dist/jquery.fancybox.min.css
jquery: jquery:
fancybox: fancybox:
fancybox_css: fancybox_css:
# Medium-zoom # Medium-zoom
# mediumzoom: //unpkg.com/medium-zoom@1/dist/medium-zoom.min.js
# mediumzoom: //cdnjs.cloudflare.com/ajax/libs/medium-zoom/1.0.5/medium-zoom.min.js
mediumzoom: mediumzoom:
# Lazyload # Lazyload
# lazyload: //unpkg.com/lozad@1/dist/lozad.min.js
# lazyload: //cdnjs.cloudflare.com/ajax/libs/lozad.js/1.15.0/lozad.min.js
lazyload: lazyload:
# Pangu # Pangu
# pangu: //unpkg.com/pangu@4/dist/browser/pangu.min.js
# pangu: //cdnjs.cloudflare.com/ajax/libs/pangu/4.0.7/pangu.min.js
pangu: pangu:
# Quicklink # Quicklink
# quicklink: //unpkg.com/quicklink@2/dist/quicklink.umd.js
# quicklink: //cdnjs.cloudflare.com/ajax/libs/quicklink/2.0.0/quicklink.umd.js
quicklink: quicklink:
# DisqusJS # DisqusJS
# disqusjs_js: //unpkg.com/disqusjs@1/dist/disqus.js
# disqusjs_css: //unpkg.com/disqusjs@1/dist/disqusjs.css
disqusjs_js: disqusjs_js:
disqusjs_css: disqusjs_css:
# Valine # Valine
# valine: //unpkg.com/valine@1/dist/Valine.min.js
# valine: //cdnjs.cloudflare.com/ajax/libs/valine/1.4.14/Valine.min.js
valine: valine:
# Gitalk # Gitalk
# gitalk_js: //unpkg.com/gitalk@1/dist/gitalk.min.js
# gitalk_css: //unpkg.com/gitalk@1/dist/gitalk.min.css
gitalk_js: gitalk_js:
gitalk_css: gitalk_css:
# Algolia Search # Algolia Search
# algolia_search: //unpkg.com/algoliasearch@4/dist/algoliasearch-lite.umd.js
# instant_search: //unpkg.com/instantsearch.js@4/dist/instantsearch.production.min.js
algolia_search: algolia_search:
instant_search: instant_search:
# Mermaid # Mermaid
# mermaid: //unpkg.com/mermaid@8/dist/mermaid.min.js
# mermaid: //cdnjs.cloudflare.com/ajax/libs/mermaid/8.6.3/mermaid.min.js
mermaid: mermaid:
# Internal version: 3.1.1 # Animate.css
# Warning: motion won't work with animate.css version 3.2.0 or later # Warning: motion won't work with animate.css version 3.2.0 or later
# animate_css: //cdn.jsdelivr.net/npm/animate.css@3.1.1/animate.min.css
# animate_css: //unpkg.com/animate.css@3.1.1/animate.min.css
# animate_css: //cdnjs.cloudflare.com/ajax/libs/animate.css/3.1.1/animate.min.css
animate_css: animate_css:
# Internal version: 1.0.2 # Pace.js
# pace: //unpkg.com/pace-js@1/pace.min.js
# pace: //cdnjs.cloudflare.com/ajax/libs/pace/1.0.2/pace.min.js
# pace_css: //unpkg.com/pace-js@1/themes/blue/pace-theme-minimal.css
# pace_css: //cdnjs.cloudflare.com/ajax/libs/pace/1.0.2/themes/blue/pace-theme-minimal.min.css
pace: pace:
pace_css: pace_css:
# Canvas ribbon # Canvas ribbon
# canvas_ribbon: //unpkg.com/ribbon.js@1/dist/ribbon.min.js
canvas_ribbon: canvas_ribbon:
# Assets # Assets

132
_vendors.yml Normal file
View File

@ -0,0 +1,132 @@
anime:
name: animejs
version: 3.2.0
file: lib/anime.min.js
fontawesome:
name: '@fortawesome/fontawesome-free'
version: 5.14.0
file: css/all.min.css
alias: font-awesome
prism:
name: prismjs
version: 1.20.0
file: components/prism-core.min.js
alias: prism
prism_autoloader:
name: prismjs
version: 1.20.0
file: plugins/autoloader/prism-autoloader.min.js
alias: prism
prism_line_numbers:
name: prismjs
version: 1.20.0
file: plugins/line-numbers/prism-line-numbers.min.js
alias: prism
mathjax:
name: mathjax
version: 3.0.5
file: es5/tex-mml-chtml.js
katex:
name: katex
version: 0.11.1
file: dist/katex.min.css
alias: KaTeX
copy_tex_js:
name: katex
version: 0.11.1
file: dist/contrib/copy-tex.min.js
alias: KaTeX
copy_tex_css:
name: katex
version: 0.11.1
file: dist/contrib/copy-tex.min.css
alias: KaTeX
pjax:
name: '@next-theme/pjax'
version: 0.4.0
file: pjax.min.js
unavailable: [cdnjs]
jquery:
name: jquery
version: 3.5.1
file: dist/jquery.min.js
fancybox:
name: '@fancyapps/fancybox'
version: 3.5.7
file: dist/jquery.fancybox.min.js
alias: fancybox
fancybox_css:
name: '@fancyapps/fancybox'
version: 3.5.7
file: dist/jquery.fancybox.min.css
alias: fancybox
mediumzoom:
name: medium-zoom
version: 1.0.6
file: dist/medium-zoom.min.js
lazyload:
name: lozad
version: 1.15.0
file: dist/lozad.min.js
alias: lozad.js
pangu:
name: pangu
version: 4.0.7
file: dist/browser/pangu.min.js
quicklink:
name: quicklink
version: 2.0.0
file: dist/quicklink.umd.js
disqusjs_js:
name: disqusjs
version: 1.3.0
file: dist/disqus.js
unavailable: [cdnjs]
disqusjs_css:
name: disqusjs
version: 1.3.0
file: dist/disqusjs.css
unavailable: [cdnjs]
valine:
name: valine
version: 1.4.14
file: dist/Valine.min.js
gitalk_js:
name: gitalk
version: 1.6.2
file: dist/gitalk.min.js
gitalk_css:
name: gitalk
version: 1.6.2
file: dist/gitalk.css
algolia_search:
name: algoliasearch
version: 4.3.1
file: dist/algoliasearch-lite.umd.js
instant_search:
name: instantsearch.js
version: 4.7.0
file: dist/instantsearch.production.min.js
mermaid:
name: mermaid
version: 8.6.4
file: dist/mermaid.min.js
animate_css:
name: animate.css
version: 3.1.1
file: animate.min.css
pace:
name: pace-js
version: 1.0.2
file: pace.min.js
alias: pace
pace_css:
name: pace-js
version: 1.0.2
file: themes/blue/pace-theme-minimal.css
alias: pace
canvas_ribbon:
name: ribbon.js
version: 1.0.2
file: dist/ribbon.min.js
unavailable: [cdnjs]

View File

@ -43,24 +43,19 @@
{{ next_font() }} {{ next_font() }}
{%- set font_awesome_uri = theme.vendors.fontawesome or 'lib/font-awesome/css/all.min.css' %} <link rel="stylesheet" href="{{ theme.vendors.fontawesome }}">
<link rel="stylesheet" href="{{ url_for(font_awesome_uri) }}">
{%-if theme.motion.enable %} {%-if theme.motion.enable %}
{% set animate_css_uri = theme.vendors.animate_css or 'lib/animate-css/animate.min.css' %} <link rel="stylesheet" href="{{ theme.vendors.animate_css }}">
<link rel="stylesheet" href="{{ url_for(animate_css_uri) }}">
{%- endif %} {%- endif %}
{%- if theme.fancybox %} {%- if theme.fancybox %}
{%- set fancybox_css_uri = theme.vendors.fancybox_css or '//cdn.jsdelivr.net/npm/@fancyapps/fancybox@3/dist/jquery.fancybox.min.css' %} <link rel="stylesheet" href="{{ theme.vendors.fancybox_css }}">
<link rel="stylesheet" href="{{ url_for(fancybox_css_uri) }}">
{%- endif %} {%- endif %}
{%- if theme.pace.enable %} {%- if theme.pace.enable %}
{%- set pace_css_uri = theme.vendors.pace_css or '//cdn.jsdelivr.net/npm/pace-js@1/themes/blue/pace-theme-' + theme.pace.theme + '.min.css' %} <link rel="stylesheet" href="{{ theme.vendors.pace_css }}">
{%- set pace_js_uri = theme.vendors.pace or '//cdn.jsdelivr.net/npm/pace-js@1/pace.min.js' %} <script src="{{ theme.vendors.pace }}"></script>
<link rel="stylesheet" href="{{ url_for(pace_css_uri) }}">
<script src="{{ url_for(pace_js_uri) }}"></script>
{%- endif %} {%- endif %}
{{ next_config() }} {{ next_config() }}

View File

@ -1,8 +1,7 @@
{%- if theme.canvas_ribbon.enable %} {%- if theme.canvas_ribbon.enable %}
{%- set canvas_ribbon_uri = theme.vendors.canvas_ribbon or '//cdn.jsdelivr.net/npm/ribbon.js@1/dist/ribbon.min.js' %} <script size="{{ theme.canvas_ribbon.size }}" alpha="{{ theme.canvas_ribbon.alpha }}" zIndex="{{ theme.canvas_ribbon.zIndex }}" src="{{ theme.vendors.canvas_ribbon }}"></script>
<script size="{{ theme.canvas_ribbon.size }}" alpha="{{ theme.canvas_ribbon.alpha }}" zIndex="{{ theme.canvas_ribbon.zIndex }}" src="{{ url_for(canvas_ribbon_uri) }}"></script>
{%- endif %} {%- endif %}
{%- for name, internal in js_vendors() %} {%- for name in js_vendors() %}
<script src="{{ url_for(theme.vendors[name] or internal) }}"></script> <script src="{{ url_for(theme.vendors[name]) }}"></script>
{%- endfor %} {%- endfor %}

View File

@ -1,12 +1,9 @@
{%- if page.comments %} {%- if page.comments %}
{%- set disqusjs_css_uri = theme.vendors.disqusjs_css or '//cdn.jsdelivr.net/npm/disqusjs@1/dist/disqusjs.css' %} <link rel="stylesheet" href="{{ theme.vendors.disqusjs_css }}">
<link rel="stylesheet" href="{{ url_for(disqusjs_css_uri) }}">
{%- set disqusjs_js_uri = theme.vendors.disqusjs_js or '//cdn.jsdelivr.net/npm/disqusjs@1/dist/disqus.js' %}
<script> <script>
NexT.utils.loadComments('#disqus_thread', () => { NexT.utils.loadComments('#disqus_thread', () => {
NexT.utils.getScript('{{ url_for(disqusjs_js_uri) }}', () => { NexT.utils.getScript('{{ theme.vendors.disqusjs_js }}', () => {
window.dsqjs = new DisqusJS({ window.dsqjs = new DisqusJS({
api : '{{ theme.disqusjs.api }}' || 'https://disqus.com/api/', api : '{{ theme.disqusjs.api }}' || 'https://disqus.com/api/',
apikey : '{{ theme.disqusjs.apikey }}', apikey : '{{ theme.disqusjs.apikey }}',

View File

@ -1,12 +1,9 @@
{%- if page.comments %} {%- if page.comments %}
{%- set gitalk_css_uri = theme.vendors.gitalk_css or '//cdn.jsdelivr.net/npm/gitalk@1/dist/gitalk.min.css' %} <link rel="stylesheet" href="{{ theme.vendors.gitalk_css }}">
<link rel="stylesheet" href="{{ url_for(gitalk_css_uri) }}">
{%- set gitalk_js_uri = theme.vendors.gitalk_js or '//cdn.jsdelivr.net/npm/gitalk@1/dist/gitalk.min.js' %}
<script> <script>
NexT.utils.loadComments('#gitalk-container', () => { NexT.utils.loadComments('#gitalk-container', () => {
NexT.utils.getScript('{{ url_for(gitalk_js_uri) }}', () => { NexT.utils.getScript('{{ theme.vendors.gitalk_js }}', () => {
var gitalk = new Gitalk({ var gitalk = new Gitalk({
clientID : '{{ theme.gitalk.client_id }}', clientID : '{{ theme.gitalk.client_id }}',
clientSecret: '{{ theme.gitalk.client_secret }}', clientSecret: '{{ theme.gitalk.client_secret }}',

View File

@ -1,8 +1,6 @@
{%- set valine_uri = theme.vendors.valine or '//cdn.jsdelivr.net/npm/valine@1/dist/Valine.min.js' %}
<script> <script>
NexT.utils.loadComments('#valine-comments', () => { NexT.utils.loadComments('#valine-comments', () => {
NexT.utils.getScript('{{ url_for(valine_uri) }}', () => { NexT.utils.getScript('{{ theme.vendors.valine }}', () => {
new Valine(Object.assign({ new Valine(Object.assign({
el : '#valine-comments', el : '#valine-comments',
path: location.pathname, path: location.pathname,

View File

@ -1,8 +1,5 @@
{%- set katex_uri = theme.vendors.katex or '//cdn.jsdelivr.net/npm/katex@0/dist/katex.min.css' %} <link rel="stylesheet" href="{{ theme.vendors.katex }}">
<link rel="stylesheet" href="{{ url_for(katex_uri) }}">
{%- if theme.math.katex.copy_tex %} {%- if theme.math.katex.copy_tex %}
{%- set copy_tex_js_uri = theme.vendors.copy_tex_js or '//cdn.jsdelivr.net/npm/katex@0/dist/contrib/copy-tex.min.js' %} <script src="{{ theme.vendors.copy_tex_js }}"></script>
{%- set copy_tex_css_uri = theme.vendors.copy_tex_css or '//cdn.jsdelivr.net/npm/katex@0/dist/contrib/copy-tex.min.css' %} <link rel="stylesheet" href="{{ theme.vendors.copy_tex_css }}">
<script src="{{ url_for(copy_tex_js_uri) }}"></script>
<link rel="stylesheet" href="{{ url_for(copy_tex_css_uri) }}">
{%- endif %} {%- endif %}

View File

@ -1,5 +1,3 @@
{%- set mathjax_uri = theme.vendors.mathjax or '//cdn.jsdelivr.net/npm/mathjax@3/es5/tex-mml-chtml.js' %}
<script> <script>
if (typeof MathJax === 'undefined') { if (typeof MathJax === 'undefined') {
window.MathJax = { window.MathJax = {
@ -39,7 +37,7 @@
}; };
(function () { (function () {
const script = document.createElement('script'); const script = document.createElement('script');
script.src = '{{ url_for(mathjax_uri) }}'; script.src = '{{ theme.vendors.mathjax }}';
script.defer = true; script.defer = true;
document.head.appendChild(script); document.head.appendChild(script);
})(); })();

View File

@ -1,6 +1,5 @@
{%- if page.quicklink.enable %} {%- if page.quicklink.enable %}
{%- set quicklink_uri = theme.vendors.quicklink or '//cdn.jsdelivr.net/npm/quicklink@2/dist/quicklink.umd.js' %} <script src="{{ theme.vendors.quicklink }}"></script>
<script src="{{ url_for(quicklink_uri) }}"></script>
<script> <script>
{%- if page.quicklink.delay %} {%- if page.quicklink.delay %}
window.addEventListener('load', () => { window.addEventListener('load', () => {

View File

@ -1,6 +1,4 @@
{%- set algolia_search_uri = theme.vendors.algolia_search or '//cdn.jsdelivr.net/npm/algoliasearch@4/dist/algoliasearch-lite.umd.js' %} <script src="{{ theme.vendors.algolia_search }}"></script>
{%- set instant_search_uri = theme.vendors.instant_search or '//cdn.jsdelivr.net/npm/instantsearch.js@4/dist/instantsearch.production.min.js' %} <script src="{{ theme.vendors.instant_search }}"></script>
<script src="{{ url_for(algolia_search_uri) }}"></script>
<script src="{{ url_for(instant_search_uri) }}"></script>
{{- next_js('algolia-search.js') }} {{- next_js('algolia-search.js') }}

View File

@ -1,8 +1,7 @@
{%- if theme.mermaid.enable %} {%- if theme.mermaid.enable %}
{%- set mermaid_uri = theme.vendors.mermaid or '//cdn.jsdelivr.net/npm/mermaid@8/dist/mermaid.min.js' %}
<script{{ pjax }}> <script{{ pjax }}>
if (document.querySelectorAll('pre.mermaid').length) { if (document.querySelectorAll('pre.mermaid').length) {
NexT.utils.getScript('{{ url_for(mermaid_uri) }}', () => { NexT.utils.getScript('{{ theme.vendors.mermaid }}', () => {
mermaid.init({ mermaid.init({
theme : '{{ theme.mermaid.theme }}', theme : '{{ theme.mermaid.theme }}',
logLevel : 3, logLevel : 3,

View File

@ -3,8 +3,10 @@
'use strict'; 'use strict';
hexo.extend.filter.register('before_generate', () => { hexo.extend.filter.register('before_generate', () => {
// Merge config. // Merge config
require('./lib/config')(hexo); require('./lib/config')(hexo);
// Set vendors
require('./lib/vendors')(hexo);
// Add filter type `theme_inject` // Add filter type `theme_inject`
require('./lib/injects')(hexo); require('./lib/injects')(hexo);
// Highlight // Highlight

View File

@ -1,11 +1,6 @@
'use strict'; 'use strict';
const merge = require('hexo-util').deepMerge || require('lodash/merge'); const merge = require('hexo-util').deepMerge || require('lodash/merge');
let plugins;
try {
plugins = require('@next-theme/plugins');
} catch (error) {
}
module.exports = hexo => { module.exports = hexo => {
const data = hexo.locals.get('data'); const data = hexo.locals.get('data');
@ -28,13 +23,6 @@ module.exports = hexo => {
hexo.log.warn('Since caching is turned on, the `relative_link` option in Hexo `_config.yml` is set to `false` to avoid potential hazards.'); hexo.log.warn('Since caching is turned on, the `relative_link` option in Hexo `_config.yml` is set to `false` to avoid potential hazards.');
hexo.config.relative_link = false; hexo.config.relative_link = false;
} }
if (typeof plugins === 'function') {
const { vendors, generator } = plugins();
Object.keys(vendors).forEach(key => {
hexo.theme.config.vendors[key] = hexo.theme.config.vendors[key] || vendors[key];
});
hexo.extend.generator.register('next_vendors', () => generator);
}
hexo.config.meta_generator = false; hexo.config.meta_generator = false;
// Custom languages support. Introduced in NexT v6.3.0. // Custom languages support. Introduced in NexT v6.3.0.

View File

@ -0,0 +1,37 @@
'use strict';
const fs = require('fs');
const path = require('path');
const yaml = require('js-yaml');
const { url_for } = require('hexo-util');
let internal;
try {
internal = require('@next-theme/plugins');
} catch (error) {
}
const vendorsFile = fs.readFileSync(path.join(__dirname, '../../../_vendors.yml'));
const dependencies = yaml.safeLoad(vendorsFile);
module.exports = hexo => {
const { vendors } = hexo.theme.config;
if (typeof internal === 'function') {
internal(hexo, dependencies);
}
for (const [key, value] of Object.entries(dependencies)) {
if (vendors[key]) {
vendors[key] = url_for.call(hexo, vendors[key]);
continue;
}
const { name, version, file, alias, unavailable } = value;
const links = {
local : url_for.call(hexo, `lib/${name}/${file}`),
jsdelivr: `//cdn.jsdelivr.net/npm/${name}@${version}/${file}`,
unpkg : `//unpkg.com/${name}@${version}/${file}`,
cdnjs : `//cdnjs.cloudflare.com/ajax/libs/${alias || name}/${version}/${file.replace(/^(dist|lib|)\/(browser\/|)/, '')}`
};
let { plugins = 'jsdelivr' } = vendors;
if (plugins === 'cdnjs' && unavailable && unavailable.includes('cdnjs')) plugins = 'jsdelivr';
if (plugins === 'local' && typeof internal === 'undefined') plugins = 'jsdelivr';
vendors[key] = links[plugins];
}
};

View File

@ -12,20 +12,6 @@ hexo.extend.filter.register('after_generate', () => {
if (!theme.motion.enable) { if (!theme.motion.enable) {
hexo.route.remove('js/motion.js'); hexo.route.remove('js/motion.js');
hexo.route.remove('lib/animate-css/animate.min.css');
} else if (theme.vendors.animate_css) {
hexo.route.remove('lib/animate-css/animate.min.css');
}
if (theme.vendors.fontawesome) {
const lists = hexo.route.list();
lists.forEach(path => {
if (path.startsWith('lib/font-awesome')) hexo.route.remove(path);
});
}
if (theme.vendors.anime) {
hexo.route.remove('lib/anime.min.js');
} }
if (!theme.algolia_search.enable) { if (!theme.algolia_search.enable) {

View File

@ -4,31 +4,27 @@
hexo.extend.helper.register('js_vendors', function() { hexo.extend.helper.register('js_vendors', function() {
const { config, theme } = this; const { config, theme } = this;
const vendors = { const vendors = ['anime'];
anime: 'lib/anime.min.js'
};
if (config.prismjs.enable && !config.prismjs.preprocess) { if (config.prismjs.enable && !config.prismjs.preprocess) {
vendors.prism = '//cdn.jsdelivr.net/npm/prismjs@1/components/prism-core.min.js'; vendors.push('prism', 'prism_autoloader');
vendors.prism_autoloader = '//cdn.jsdelivr.net/npm/prismjs@1/plugins/autoloader/prism-autoloader.min.js';
if (config.prismjs.line_number) { if (config.prismjs.line_number) {
vendors.prism_line_numbers = '//cdn.jsdelivr.net/npm/prismjs@1/plugins/line-numbers/prism-line-numbers.min.js'; vendors.push('prism_line_numbers');
} }
} }
if (theme.pjax) { if (theme.pjax) {
vendors.pjax = '//cdn.jsdelivr.net/gh/next-theme/pjax@0/pjax.min.js'; vendors.push('pjax');
} }
if (theme.fancybox) { if (theme.fancybox) {
vendors.jquery = '//cdn.jsdelivr.net/npm/jquery@3/dist/jquery.min.js'; vendors.push('jquery', 'fancybox');
vendors.fancybox = '//cdn.jsdelivr.net/npm/@fancyapps/fancybox@3/dist/jquery.fancybox.min.js';
} }
if (theme.mediumzoom) { if (theme.mediumzoom) {
vendors.mediumzoom = '//cdn.jsdelivr.net/npm/medium-zoom@1/dist/medium-zoom.min.js'; vendors.push('mediumzoom');
} }
if (theme.lazyload) { if (theme.lazyload) {
vendors.lazyload = '//cdn.jsdelivr.net/npm/lozad@1/dist/lozad.min.js'; vendors.push('lazyload');
} }
if (theme.pangu) { if (theme.pangu) {
vendors.pangu = '//cdn.jsdelivr.net/npm/pangu@4/dist/browser/pangu.min.js'; vendors.push('pangu');
} }
return vendors; return vendors;
}); });

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

View File

@ -13,6 +13,13 @@ describe('Validate', () => {
}); });
}); });
it('vendors', () => {
const vendorsFile = fs.readFileSync(path.join(__dirname, '../../_vendors.yml'));
should.not.throw(() => {
yaml.safeLoad(vendorsFile);
});
});
it('language', () => { it('language', () => {
const languagesPath = path.join(__dirname, '../../languages'); const languagesPath = path.join(__dirname, '../../languages');
should.not.throw(() => { should.not.throw(() => {