Skip to content

处理多语言时,生成的search_index.json 文件中会出现多种语言的字段在一个文件的问题 #20

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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
15 changes: 12 additions & 3 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@ var Entities = require('html-entities').AllHtmlEntities;
var Html = new Entities();

// Map of Lunr ref to document
var documentsStore = {};
var documentsStore = {}; // According to the language
var documentsStoreAll = {}; // all languages

module.exports = {
book: {
Expand Down Expand Up @@ -48,7 +49,11 @@ module.exports = {
body: text
};

documentsStore[doc.url] = doc;
if (!documentsStore[this.config.values.language]) {
documentsStore[this.config.values.language] = {};
}
documentsStore[this.config.values.language][doc.url] = doc;
documentsStoreAll[doc.url] = doc;

return page;
},
Expand All @@ -58,7 +63,11 @@ module.exports = {
if (this.output.name != 'website') return;

this.log.debug.ln('write search index');
return this.output.writeFile('search_plus_index.json', JSON.stringify(documentsStore));
if (this.config.values.language) {
return this.output.writeFile('search_plus_index.json', JSON.stringify(documentsStore[this.config.values.language]));
} else {
return this.output.writeFile('search_plus_index.json', JSON.stringify(documentsStoreAll));
}
}
}
};