From 0005c0367f5695c9762f4d63611989e3830cf247 Mon Sep 17 00:00:00 2001 From: Mimi <1119186082@qq.com> Date: Wed, 8 Sep 2021 11:16:31 +0800 Subject: [PATCH] Do not restart Pace on every pushState event * See: https://github.com/next-theme/hexo-theme-next/issues/362 --- layout/_third-party/index.njk | 2 ++ layout/_third-party/pace.njk | 3 +++ scripts/filters/minify.js | 4 ++++ source/js/third-party/pace.js | 7 +++++++ 4 files changed, 16 insertions(+) create mode 100644 layout/_third-party/pace.njk create mode 100644 source/js/third-party/pace.js diff --git a/layout/_third-party/index.njk b/layout/_third-party/index.njk index 4b7ccce..a6afcc8 100644 --- a/layout/_third-party/index.njk +++ b/layout/_third-party/index.njk @@ -18,3 +18,5 @@ {%- include 'tags/mermaid.njk' -%} {%- include 'fancybox.njk' -%} + +{%- include 'pace.njk' -%} diff --git a/layout/_third-party/pace.njk b/layout/_third-party/pace.njk new file mode 100644 index 0000000..ffbadcd --- /dev/null +++ b/layout/_third-party/pace.njk @@ -0,0 +1,3 @@ +{%- if theme.pace.enable %} + {{ next_js('third-party/pace.js') }} +{%- endif %} diff --git a/scripts/filters/minify.js b/scripts/filters/minify.js index f977816..9ac33ae 100644 --- a/scripts/filters/minify.js +++ b/scripts/filters/minify.js @@ -137,6 +137,10 @@ hexo.extend.filter.register('after_generate', () => { hexo.route.remove('js/third-party/fancybox.js'); } + if (!theme.pace.enable) { + hexo.route.remove('js/third-party/pace.js'); + } + if (!theme.quicklink.enable) { hexo.route.remove('js/third-party/quicklink.js'); } diff --git a/source/js/third-party/pace.js b/source/js/third-party/pace.js new file mode 100644 index 0000000..c22d59f --- /dev/null +++ b/source/js/third-party/pace.js @@ -0,0 +1,7 @@ +/* global Pace */ + +Pace.options.restartOnPushState = false; + +document.addEventListener('pjax:send', () => { + Pace.restart(); +});