From e0ee1d81984b76ba9d77c4e74099ee9d80664d31 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E9=92=9F=E6=84=8F?= Date: Mon, 13 Feb 2023 10:03:17 +0800 Subject: [PATCH] =?UTF-8?q?[fix]=20=E5=AD=90=E7=9B=AE=E5=BD=95=E9=83=A8?= =?UTF-8?q?=E7=BD=B2=20loadScript,=20search=20(#264)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * 优化子目录部署资源问题 --------- Co-authored-by: 钟意 --- layout/_partial/scripts/index.ejs | 4 ++++ source/js/main.js | 5 +++-- 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/layout/_partial/scripts/index.ejs b/layout/_partial/scripts/index.ejs index 8eabc29..02cdded 100644 --- a/layout/_partial/scripts/index.ejs +++ b/layout/_partial/scripts/index.ejs @@ -62,6 +62,9 @@ // 从 butterfly 和 volantis 获得灵感 loadScript: (src, opt) => new Promise((resolve, reject) => { var script = document.createElement('script'); + if (src.startsWith('/')){ + src = stellar.config.root + src.substring(1); + } script.src = src; if (opt) { for (let key of Object.keys(opt)) { @@ -100,6 +103,7 @@ day: '<%- __('meta.date_suffix.day') %>', month: '<%- __('meta.date_suffix.month') %>', }, + root : '<%- config.root %>', }; // required plugins (only load if needs) diff --git a/source/js/main.js b/source/js/main.js index 4196ff6..0ad4eed 100644 --- a/source/js/main.js +++ b/source/js/main.js @@ -334,9 +334,10 @@ if (stellar.search.service) { var $resultArea = document.querySelector("div#search-result"); $inputArea.focus(function() { var path = stellar.search[stellar.search.service]?.path || '/search.json'; - if (!path.startsWith('/')) { - path = '/' + path; + if (path.startsWith('/')) { + path = path.substring(1); } + path = stellar.config.root + path; const filter = $inputArea.attr('data-filter') || ''; searchFunc(path, filter, 'search-input', 'search-result'); });