Support absolute path for search DB

This commit is contained in:
Mimi 2020-10-01 21:56:39 +08:00
parent 460087d6f0
commit c1a2073a10
2 changed files with 5 additions and 6 deletions

View File

@ -8,12 +8,12 @@ const { parse } = require('url');
* Export theme config to js
*/
hexo.extend.helper.register('next_config', function() {
const { config, theme, next_version, __ } = this;
const { config, theme, __ } = this;
const exportConfig = {
hostname : parse(config.url).hostname || config.url,
root : config.root,
scheme : theme.scheme,
version : next_version,
version : this.next_version,
exturl : theme.exturl,
sidebar : theme.sidebar,
copycode : theme.codeblock.copy_button.enable,
@ -41,7 +41,7 @@ hexo.extend.helper.register('next_config', function() {
};
}
if (config.search && theme.local_search && theme.local_search.enable) {
exportConfig.path = config.search.path;
exportConfig.path = this.url_for(config.search.path);
exportConfig.localsearch = theme.local_search;
}
return `<script class="hexo-configurations">

View File

@ -2,6 +2,7 @@
document.addEventListener('DOMContentLoaded', () => {
if (!CONFIG.path) {
// Search DB path
console.warn('`hexo-generator-searchdb` plugin is not installed!');
return;
}
@ -196,10 +197,8 @@ document.addEventListener('DOMContentLoaded', () => {
};
const fetchData = () => {
// Search DB path
const searchPath = CONFIG.root + CONFIG.path;
const isXml = !CONFIG.path.endsWith('json');
fetch(searchPath)
fetch(CONFIG.path)
.then(response => response.text())
.then(res => {
// Get the contents from search data