Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion layout/_partials/comments.njk
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
{{ partial(inject_item.layout, inject_item.locals, inject_item.options) }}
</div>
{%- endfor %}
{{- next_js('comments-buttons.js', { pjax: true }) }}
{{- next_js('comments-buttons.js', { pjax: true, async: true }) }}
{%- elif theme.comments.style == 'tabs' %}
<div class="tabs tabs-comment">
<ul class="nav-tabs">
Expand Down
4 changes: 2 additions & 2 deletions layout/_partials/head/head.njk
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@

{{ next_font() }}

{{ next_vendors('fontawesome') }}
{{ next_vendors('fontawesome', { async: true }) }}

{%- if theme.motion.enable %}
{{ next_vendors('animate_css') }}
Expand All @@ -60,7 +60,7 @@

{%- if theme.pace.enable %}
{{ next_vendors('pace_css') }}
{{ next_vendors('pace_js') }}
{{ next_vendors('pace_js', { async: true }) }}
{%- endif %}

{{ next_data('main', next_config()) }}
Expand Down
2 changes: 1 addition & 1 deletion layout/_partials/page/schedule.njk
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
<div class="event-list">
</div>
{{- next_js('schedule.js', { pjax: true }) }}
{{- next_js('schedule.js', { pjax: true, async: true }) }}
14 changes: 7 additions & 7 deletions layout/_scripts/index.njk
Original file line number Diff line number Diff line change
@@ -1,22 +1,22 @@
{%- include 'vendors.njk' -%}

{%- if theme.injects.comment.length > 1 %}
{{- next_js('comments.js') }}
{{- next_js('comments.js', { defer: true }) }}
{%- endif %}

{{- next_js('utils.js') }}
{{- next_js('utils.js', { defer: true }) }}
{%- if theme.motion.enable %}
{{- next_js('motion.js') }}
{{- next_js('motion.js', { defer: true }) }}
{%- endif %}

{%- if theme.sidebar.display !== 'remove' %}
{{- next_js('sidebar.js') }}
{{- next_js('sidebar.js', { defer: true }) }}
{%- endif %}

{{- next_js('next-boot.js') }}
{{- next_js('next-boot.js', { defer: true }) }}
{%- if theme.bookmark.enable %}
{{- next_js('bookmark.js') }}
{{- next_js('bookmark.js', { defer: true }) }}
{%- endif %}
{%- if theme.pjax %}
{{- next_js('pjax.js') }}
{{- next_js('pjax.js', { defer: true }) }}
{%- endif %}
4 changes: 2 additions & 2 deletions layout/_scripts/vendors.njk
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,6 @@
<script size="{{ theme.canvas_ribbon.size }}" alpha="{{ theme.canvas_ribbon.alpha }}" zIndex="{{ theme.canvas_ribbon.zIndex }}" src="{{ theme.vendors.canvas_ribbon.url }}" defer></script>
{%- endif %}

{%- for name in js_vendors() %}
{{ next_vendors(name) }}
{%- for name, options in js_vendors() %}
{{ next_vendors(name, options) }}
{%- endfor %}
2 changes: 1 addition & 1 deletion layout/_third-party/addtoany.njk
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
{%- if theme.addtoany.enable %}
{{ next_js('third-party/addtoany.js') }}
{{ next_js('third-party/addtoany.js', { defer: true }) }}
{%- endif %}
2 changes: 1 addition & 1 deletion layout/_third-party/analytics/baidu-analytics.njk
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
{%- if theme.baidu_analytics %}
{{ next_js('third-party/analytics/baidu-analytics.js') }}
{{ next_js('third-party/analytics/baidu-analytics.js', { async: true }) }}
<script async src="https://hm.baidu.com/hm.js?{{ theme.baidu_analytics }}"></script>
{%- endif %}
2 changes: 1 addition & 1 deletion layout/_third-party/analytics/google-analytics.njk
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,5 @@
<script async src="https://www.googletagmanager.com/gtag/js?id={{ theme.google_analytics.tracking_id }}"></script>
{%- endif %}
{{ next_data('google_analytics', theme.google_analytics) }}
{{ next_js('third-party/analytics/google-analytics.js') }}
{{ next_js('third-party/analytics/google-analytics.js', { async: true }) }}
{%- endif %}
2 changes: 1 addition & 1 deletion layout/_third-party/analytics/growingio.njk
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{%- if theme.growingio_analytics %}
<script async src="//assets.growingio.com/2.1/gio.js"></script>
{{ next_data('growingio_analytics', theme.growingio_analytics) }}
{{ next_js('third-party/analytics/growingio.js') }}
{{ next_js('third-party/analytics/growingio.js', { async: true }) }}
{%- endif %}
2 changes: 1 addition & 1 deletion layout/_third-party/analytics/matomo.njk
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
{%- if theme.matomo.enable %}
{{ next_data('matomo', theme.matomo) }}
{{ next_js('third-party/analytics/matomo.js') }}
{{ next_js('third-party/analytics/matomo.js', { async: true }) }}
{%- endif %}
2 changes: 1 addition & 1 deletion layout/_third-party/chat/chatra.njk
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
{{ next_data('chatra', theme.chatra) }}
{{ next_js('third-party/chat/chatra.js') }}
{{ next_js('third-party/chat/chatra.js', { defer: true }) }}
<script{{ ' async' if theme.chatra.async }} src="https://call.chatra.io/chatra.js"></script>
2 changes: 1 addition & 1 deletion layout/_third-party/chat/tidio.njk
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
<script src="//code.tidio.co/{{ theme.tidio.key }}.js"></script>
{{ next_js('third-party/chat/tidio.js') }}
{{ next_js('third-party/chat/tidio.js', { defer: true }) }}
2 changes: 1 addition & 1 deletion layout/_third-party/comments/changyan.njk
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
{{ next_data('changyan', theme.changyan) }}
{{ next_js('third-party/comments/changyan.js') }}
{{ next_js('third-party/comments/changyan.js', { defer: true }) }}
2 changes: 1 addition & 1 deletion layout/_third-party/comments/disqus.njk
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,4 @@
disqus: __('disqus')
}
}) }}
{{ next_js('third-party/comments/disqus.js') }}
{{ next_js('third-party/comments/disqus.js', { defer: true }) }}
2 changes: 1 addition & 1 deletion layout/_third-party/comments/disqusjs.njk
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,4 @@
{{ next_data('disqusjs', theme.disqusjs, {
js: theme.vendors.disqusjs_js
}) }}
{{ next_js('third-party/comments/disqusjs.js') }}
{{ next_js('third-party/comments/disqusjs.js', { defer: true }) }}
2 changes: 1 addition & 1 deletion layout/_third-party/comments/gitalk.njk
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,4 @@
js: theme.vendors.gitalk_js,
path_md5: gitalk_md5(page.path)
}) }}
{{ next_js('third-party/comments/gitalk.js') }}
{{ next_js('third-party/comments/gitalk.js', { defer: true }) }}
2 changes: 1 addition & 1 deletion layout/_third-party/comments/isso.njk
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
{{ next_data('isso', theme.isso) }}
{{ next_js('third-party/comments/isso.js') }}
{{ next_js('third-party/comments/isso.js', { defer: true }) }}
2 changes: 1 addition & 1 deletion layout/_third-party/comments/livere.njk
Original file line number Diff line number Diff line change
@@ -1 +1 @@
{{ next_js('third-party/comments/livere.js') }}
{{ next_js('third-party/comments/livere.js', { defer: true }) }}
2 changes: 1 addition & 1 deletion layout/_third-party/comments/utterances.njk
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
{{ next_data('utterances', theme.utterances) }}
{{ next_js('third-party/comments/utterances.js') }}
{{ next_js('third-party/comments/utterances.js', { defer: true }) }}
2 changes: 1 addition & 1 deletion layout/_third-party/fancybox.njk
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
{%- if theme.fancybox %}
{{ next_js('third-party/fancybox.js') }}
{{ next_js('third-party/fancybox.js', { defer: true }) }}
{%- endif %}
4 changes: 2 additions & 2 deletions layout/_third-party/math/katex.njk
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{{ next_vendors('katex') }}
{{ next_vendors('katex', { defer: true }) }}
{%- if theme.math.katex.copy_tex %}
{{ next_data('katex', {
copy_tex_js: theme.vendors.copy_tex_js
}) }}
{{ next_js('third-party/math/katex.js') }}
{{ next_js('third-party/math/katex.js', { defer: true }) }}
{%- endif %}
2 changes: 1 addition & 1 deletion layout/_third-party/math/mathjax.njk
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
{{ next_data('mathjax', theme.math.mathjax, {
js: theme.vendors.mathjax
}) }}
{{ next_js('third-party/math/mathjax.js') }}
{{ next_js('third-party/math/mathjax.js', { defer: true }) }}
2 changes: 1 addition & 1 deletion layout/_third-party/pace.njk
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
{%- if theme.pace.enable %}
{{ next_js('third-party/pace.js') }}
{{ next_js('third-party/pace.js', { defer: true }) }}
{%- endif %}
4 changes: 2 additions & 2 deletions layout/_third-party/quicklink.njk
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{%- if theme.quicklink.enable %}
{{ next_vendors('quicklink') }}
{{ next_vendors('quicklink', { defer: true }) }}
{{ next_data('quicklink', page.quicklink, {
url: url | replace(r/index\.html$/, '')
}) }}
{{ next_js('third-party/quicklink.js') }}
{{ next_js('third-party/quicklink.js', { defer: true }) }}
{%- endif %}
5 changes: 2 additions & 3 deletions layout/_third-party/search/algolia-search.njk
Original file line number Diff line number Diff line change
@@ -1,3 +1,2 @@
{{ next_vendors('algolia_search') }}

{{- next_js('third-party/search/algolia-search.js') }}
{{ next_vendors('algolia_search', { defer: true }) }}
{{- next_js('third-party/search/algolia-search.js', { defer: true }) }}
4 changes: 2 additions & 2 deletions layout/_third-party/search/localsearch.njk
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
{{ next_vendors('local_search') }}
{{ next_js('third-party/search/local-search.js') }}
{{ next_vendors('local_search', { defer: true }) }}
{{ next_js('third-party/search/local-search.js', { defer: true }) }}
6 changes: 3 additions & 3 deletions layout/_third-party/statistics/firestore.njk
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{%- if theme.firestore.enable %}
{{ next_vendors('firebase_app') }}
{{ next_vendors('firebase_firestore') }}
{{ next_vendors('firebase_app', { defer: true }) }}
{{ next_vendors('firebase_firestore', { defer: true }) }}
{{ next_data('firestore', theme.firestore) }}
{{ next_js('third-party/statistics/firestore.js') }}
{{ next_js('third-party/statistics/firestore.js', { defer: true }) }}
{%- endif %}
2 changes: 1 addition & 1 deletion layout/_third-party/statistics/lean-analytics.njk
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
{%- if theme.leancloud_visitors.enable %}
{{ next_data('leancloud_visitors', theme.leancloud_visitors) }}
{{ next_js('third-party/statistics/lean-analytics.js') }}
{{ next_js('third-party/statistics/lean-analytics.js', { defer: true }) }}
{%- endif %}
2 changes: 1 addition & 1 deletion layout/_third-party/tags/mermaid.njk
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,5 @@
{{ next_data('mermaid', theme.mermaid, {
js: theme.vendors.mermaid
}) }}
{{ next_js('third-party/tags/mermaid.js') }}
{{ next_js('third-party/tags/mermaid.js', { defer: true }) }}
{%- endif %}
2 changes: 1 addition & 1 deletion layout/_third-party/tags/pdf.njk
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,5 @@
object_url: theme.vendors.pdfobject,
url: url_for('lib/pdf/web/viewer.html')
}) }}
{{ next_js('third-party/tags/pdf.js') }}
{{ next_js('third-party/tags/pdf.js', { defer: true }) }}
{%- endif %}
2 changes: 1 addition & 1 deletion layout/_third-party/tags/wavedrom.njk
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,5 @@
{{ next_data('wavedrom_skin', theme.wavedrom, {
js: theme.vendors.wavedrom_skin
}) }}
{{ next_js('third-party/tags/wavedrom.js') }}
{{ next_js('third-party/tags/wavedrom.js', { defer: true }) }}
{%- endif %}
23 changes: 18 additions & 5 deletions scripts/helpers/engine.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,9 @@ hexo.extend.helper.register('next_inject', function(point) {

hexo.extend.helper.register('next_js', function(file, {
pjax = false,
module = false
module = false,
defer = false,
async = false
} = {}) {
Comment thread
wherewhere marked this conversation as resolved.
Comment thread
wherewhere marked this conversation as resolved.
Comment thread
wherewhere marked this conversation as resolved.
const { next_version } = this;
const { internal, custom_cdn_url } = this.theme.vendors;
Expand All @@ -32,18 +34,29 @@ hexo.extend.helper.register('next_js', function(file, {
custom : custom_cdn_url
});
const src = links[internal] || links.local;
return `<script ${pjax ? 'data-pjax ' : ''}${module ? 'type="module" ' : ''}src="${src}" defer></script>`;
if (defer && async) {
hexo.log.warn('Both `defer` and `async` are set to true for', file, 'in next_js helper. `defer` will be ignored.');
defer = false;
}
return `<script ${pjax ? 'data-pjax ' : ''}${module ? 'type="module" ' : ''}${defer ? 'defer ' : ''}${async ? 'async ' : ''}src="${src}"></script>`;
Comment thread
wherewhere marked this conversation as resolved.
Comment thread
wherewhere marked this conversation as resolved.
});

hexo.extend.helper.register('next_vendors', function(name) {
hexo.extend.helper.register('next_vendors', function(name, {
defer = false,
async = false
} = {}) {
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" defer></script>`;
return `<script src="${url}" defer></script>`;
if (defer && async) {
hexo.log.warn('Both `defer` and `async` are set to true for', name, 'in next_vendors helper. `defer` will be ignored.');
defer = false;
}
if (integrity) return `<script ${defer ? 'defer ' : ''}${async ? 'async ' : ''}src="${url}" integrity="${integrity}" crossorigin="anonymous"></script>`;
return `<script ${defer ? 'defer ' : ''}${async ? 'async ' : ''}src="${url}"></script>`;
Comment thread
wherewhere marked this conversation as resolved.
Comment thread
wherewhere marked this conversation as resolved.
});
Comment on lines +37 to 60

hexo.extend.helper.register('next_data', function(name, ...data) {
Expand Down
17 changes: 9 additions & 8 deletions scripts/helpers/next-vendors.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,27 +4,28 @@

hexo.extend.helper.register('js_vendors', function() {
const { config, theme } = this;
const vendors = ['anime'];
const vendors = { anime: {} };
if (theme.prism.enable && !config.prismjs.preprocess) {
vendors.push('prism', 'prism_autoloader');
vendors.prism = {};
vendors.prism_autoloader = {};
if (config.prismjs.line_number) {
vendors.push('prism_line_numbers');
vendors.prism_line_numbers = {};
}
}
if (theme.pjax) {
vendors.push('pjax');
vendors.pjax = { defer: true };
}
if (theme.fancybox) {
vendors.push('fancybox_js');
vendors.fancybox_js = {};
}
if (theme.mediumzoom) {
vendors.push('mediumzoom');
vendors.mediumzoom = {};
}
if (theme.lazyload) {
vendors.push('lazyload');
vendors.lazyload = { defer: true };
}
if (theme.pangu) {
vendors.push('pangu');
vendors.pangu = {};
}
return vendors;
});
Loading