mirror of
https://github.com/next-theme/hexo-theme-next.git
synced 2026-01-18 18:33:42 +00:00
Subresource Integrity (#247)
This commit is contained in:
parent
f21fff4f8c
commit
54b32d7f4b
@ -38,19 +38,19 @@
|
|||||||
|
|
||||||
{{ next_font() }}
|
{{ next_font() }}
|
||||||
|
|
||||||
<link rel="stylesheet" href="{{ theme.vendors.fontawesome }}">
|
{{ next_vendors('fontawesome') }}
|
||||||
|
|
||||||
{%- if theme.motion.enable %}
|
{%- if theme.motion.enable %}
|
||||||
<link rel="stylesheet" href="{{ theme.vendors.animate_css }}">
|
{{ next_vendors('animate_css') }}
|
||||||
{%- endif %}
|
{%- endif %}
|
||||||
|
|
||||||
{%- if theme.fancybox %}
|
{%- if theme.fancybox %}
|
||||||
<link rel="stylesheet" href="{{ theme.vendors.fancybox_css }}">
|
{{ next_vendors('fancybox_css') }}
|
||||||
{%- endif %}
|
{%- endif %}
|
||||||
|
|
||||||
{%- if theme.nprogress.enable %}
|
{%- if theme.nprogress.enable %}
|
||||||
<link rel="stylesheet" href="{{ theme.vendors.nprogress_css }}">
|
{{ next_vendors('nprogress_css') }}
|
||||||
<script src="{{ theme.vendors.nprogress_js }}"></script>
|
{{ next_vendors('nprogress_js') }}
|
||||||
{%- endif %}
|
{%- endif %}
|
||||||
|
|
||||||
{{ next_data('main', next_config()) }}
|
{{ next_data('main', next_config()) }}
|
||||||
|
|||||||
@ -1,7 +1,7 @@
|
|||||||
{%- if theme.canvas_ribbon.enable %}
|
{%- if theme.canvas_ribbon.enable %}
|
||||||
<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="{{ theme.vendors.canvas_ribbon.url }}"></script>
|
||||||
{%- endif %}
|
{%- endif %}
|
||||||
|
|
||||||
{%- for name in js_vendors() %}
|
{%- for name in js_vendors() %}
|
||||||
<script src="{{ url_for(theme.vendors[name]) }}"></script>
|
{{ next_vendors(name) }}
|
||||||
{%- endfor %}
|
{%- endfor %}
|
||||||
|
|||||||
2
layout/_third-party/comments/disqusjs.njk
vendored
2
layout/_third-party/comments/disqusjs.njk
vendored
@ -1,4 +1,4 @@
|
|||||||
<link rel="stylesheet" href="{{ theme.vendors.disqusjs_css }}">
|
{{ next_vendors('disqusjs_css') }}
|
||||||
|
|
||||||
{{ next_data('disqusjs', theme.disqusjs, {
|
{{ next_data('disqusjs', theme.disqusjs, {
|
||||||
js: theme.vendors.disqusjs_js
|
js: theme.vendors.disqusjs_js
|
||||||
|
|||||||
2
layout/_third-party/comments/gitalk.njk
vendored
2
layout/_third-party/comments/gitalk.njk
vendored
@ -1,4 +1,4 @@
|
|||||||
<link rel="stylesheet" href="{{ theme.vendors.gitalk_css }}">
|
{{ next_vendors('gitalk_css') }}
|
||||||
|
|
||||||
{{ next_data('gitalk', theme.gitalk, {
|
{{ next_data('gitalk', theme.gitalk, {
|
||||||
js: theme.vendors.gitalk_js,
|
js: theme.vendors.gitalk_js,
|
||||||
|
|||||||
4
layout/_third-party/math/katex.njk
vendored
4
layout/_third-party/math/katex.njk
vendored
@ -1,6 +1,6 @@
|
|||||||
<link rel="stylesheet" href="{{ theme.vendors.katex }}">
|
{{ next_vendors('katex') }}
|
||||||
{%- if theme.math.katex.copy_tex %}
|
{%- if theme.math.katex.copy_tex %}
|
||||||
<link rel="stylesheet" href="{{ theme.vendors.copy_tex_css }}">
|
{{ next_vendors('copy_tex_css') }}
|
||||||
{{ next_data('katex', {
|
{{ next_data('katex', {
|
||||||
copy_tex_js: theme.vendors.copy_tex_js
|
copy_tex_js: theme.vendors.copy_tex_js
|
||||||
}) }}
|
}) }}
|
||||||
|
|||||||
2
layout/_third-party/quicklink.njk
vendored
2
layout/_third-party/quicklink.njk
vendored
@ -1,5 +1,5 @@
|
|||||||
{%- if theme.quicklink.enable %}
|
{%- if theme.quicklink.enable %}
|
||||||
<script src="{{ theme.vendors.quicklink }}"></script>
|
{{ next_vendors('quicklink') }}
|
||||||
{{ next_data('quicklink', page.quicklink, {
|
{{ next_data('quicklink', page.quicklink, {
|
||||||
url: url | replace(r/index\.html$/, '')
|
url: url | replace(r/index\.html$/, '')
|
||||||
}) }}
|
}) }}
|
||||||
|
|||||||
@ -1,4 +1,4 @@
|
|||||||
<script src="{{ theme.vendors.algolia_search }}"></script>
|
{{ next_vendors('algolia_search') }}
|
||||||
<script src="{{ theme.vendors.instant_search }}"></script>
|
{{ next_vendors('instant_search') }}
|
||||||
|
|
||||||
{{- next_js('third-party/search/algolia-search.js') }}
|
{{- next_js('third-party/search/algolia-search.js') }}
|
||||||
|
|||||||
4
layout/_third-party/statistics/firestore.njk
vendored
4
layout/_third-party/statistics/firestore.njk
vendored
@ -1,6 +1,6 @@
|
|||||||
{%- if theme.firestore.enable %}
|
{%- if theme.firestore.enable %}
|
||||||
<script src="{{ theme.vendors.firebase_app }}"></script>
|
{{ next_vendors('firebase_app') }}
|
||||||
<script src="{{ theme.vendors.firebase_firestore }}"></script>
|
{{ next_vendors('firebase_firestore') }}
|
||||||
{{ next_data('firestore', theme.firestore) }}
|
{{ next_data('firestore', theme.firestore) }}
|
||||||
{{ next_js('third-party/statistics/firestore.js') }}
|
{{ next_js('third-party/statistics/firestore.js') }}
|
||||||
{%- endif %}
|
{%- endif %}
|
||||||
|
|||||||
@ -19,7 +19,9 @@ module.exports = hexo => {
|
|||||||
}
|
}
|
||||||
for (const [key, value] of Object.entries(dependencies)) {
|
for (const [key, value] of Object.entries(dependencies)) {
|
||||||
if (vendors[key]) {
|
if (vendors[key]) {
|
||||||
vendors[key] = url_for.call(hexo, vendors[key]);
|
vendors[key] = {
|
||||||
|
url: url_for.call(hexo, vendors[key])
|
||||||
|
};
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
const { name, version, file, alias, unavailable } = value;
|
const { name, version, file, alias, unavailable } = value;
|
||||||
@ -32,6 +34,9 @@ module.exports = hexo => {
|
|||||||
let { plugins = 'jsdelivr' } = vendors;
|
let { plugins = 'jsdelivr' } = vendors;
|
||||||
if (plugins === 'cdnjs' && unavailable && unavailable.includes('cdnjs')) plugins = 'jsdelivr';
|
if (plugins === 'cdnjs' && unavailable && unavailable.includes('cdnjs')) plugins = 'jsdelivr';
|
||||||
if (plugins === 'local' && typeof internal === 'undefined') plugins = 'jsdelivr';
|
if (plugins === 'local' && typeof internal === 'undefined') plugins = 'jsdelivr';
|
||||||
vendors[key] = links[plugins] || links.jsdelivr;
|
vendors[key] = {
|
||||||
|
url : links[plugins] || links.jsdelivr,
|
||||||
|
integrity: value.integrity
|
||||||
|
};
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|||||||
@ -29,6 +29,17 @@ hexo.extend.helper.register('next_js', function(file, pjax = false) {
|
|||||||
return `<script ${pjax ? 'data-pjax ' : ''}src="${src}"></script>`;
|
return `<script ${pjax ? 'data-pjax ' : ''}src="${src}"></script>`;
|
||||||
});
|
});
|
||||||
|
|
||||||
|
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) {
|
hexo.extend.helper.register('next_data', function(name, ...data) {
|
||||||
const { escape_html } = this;
|
const { escape_html } = this;
|
||||||
const json = data.length === 1 ? data[0] : Object.assign({}, ...data);
|
const json = data.length === 1 ? data[0] : Object.assign({}, ...data);
|
||||||
|
|||||||
@ -337,9 +337,9 @@ NexT.utils = {
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
getScript: function(url, options = {}, legacyCondition) {
|
getScript: function(src, options = {}, legacyCondition) {
|
||||||
if (typeof options === 'function') {
|
if (typeof options === 'function') {
|
||||||
return this.getScript(url, {
|
return this.getScript(src, {
|
||||||
condition: legacyCondition
|
condition: legacyCondition
|
||||||
}).then(options);
|
}).then(options);
|
||||||
}
|
}
|
||||||
@ -373,7 +373,16 @@ NexT.utils = {
|
|||||||
script.onload = resolve;
|
script.onload = resolve;
|
||||||
script.onerror = reject;
|
script.onerror = reject;
|
||||||
|
|
||||||
|
if (typeof src === 'object') {
|
||||||
|
const { url, integrity } = src;
|
||||||
script.src = url;
|
script.src = url;
|
||||||
|
if (integrity) {
|
||||||
|
script.integrity = integrity;
|
||||||
|
script.crossOrigin = 'anonymous';
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
script.src = src;
|
||||||
|
}
|
||||||
(parentNode || document.head).appendChild(script);
|
(parentNode || document.head).appendChild(script);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user