From b820c4c28cad5ab55ff152aedd0ee37d64edbbaa Mon Sep 17 00:00:00 2001 From: D-Sketon <2055272094@qq.com> Date: Thu, 19 Oct 2023 17:32:48 +0800 Subject: [PATCH] feat: Support Chinese search --- package.json | 2 ++ scripts/helpers.js | 4 ++++ themes/navy/layout/partial/after_footer.njk | 2 ++ 3 files changed, 8 insertions(+) diff --git a/package.json b/package.json index a810e7db59..65b0721015 100644 --- a/package.json +++ b/package.json @@ -11,6 +11,7 @@ "prepare": "husky install" }, "dependencies": { + "@node-rs/jieba": "^1.7.2", "cheerio": "^0.22.0", "hexo": "7.0.0-rc1", "hexo-clean-css": "^2.0.0", @@ -25,6 +26,7 @@ "hexo-tag-embed": "^1.0.0-rc.1", "hexo-uglify": "^2.0.0", "lunr": "2.3.9", + "lunr-languages": "^1.14.0", "sharp": "^0.32.0" }, "devDependencies": { diff --git a/scripts/helpers.js b/scripts/helpers.js index 0336a9eb1c..75867bc565 100644 --- a/scripts/helpers.js +++ b/scripts/helpers.js @@ -5,6 +5,9 @@ const { basename } = require('path'); const cheerio = require('cheerio'); const lunr = require('lunr'); +require('lunr-languages/lunr.stemmer.support.js')(lunr); +require('lunr-languages/lunr.zh.js')(lunr); +require('lunr-languages/lunr.multi.js')(lunr); const full_url_for = hexo.extend.helper.get('full_url_for').bind(hexo); const localizedPath = ['docs', 'api']; @@ -143,6 +146,7 @@ hexo.extend.helper.register('plugin_list', function() { hexo.extend.helper.register('lunr_index', data => { const index = lunr(function() { + this.use(lunr.multiLanguage('en', 'zh')); this.field('name', {boost: 10}); this.field('tags', {boost: 50}); this.field('description'); diff --git a/themes/navy/layout/partial/after_footer.njk b/themes/navy/layout/partial/after_footer.njk index 55750cda29..af0b54d64b 100644 --- a/themes/navy/layout/partial/after_footer.njk +++ b/themes/navy/layout/partial/after_footer.njk @@ -8,6 +8,8 @@ {% if page.layout === 'plugins' %} + +