diff --git a/_config.yml b/_config.yml index 79a02f8..81bc72d 100755 --- a/_config.yml +++ b/_config.yml @@ -197,6 +197,7 @@ search: field: all # post, page, all path: /search.json # 搜索文件存放位置 content: true # 是否搜索内容 + skip_search: # 指定 path 中的内容不被搜索。 algolia_search: # Docsearch https://docsearch.algolia.com/apply/ 申请 appId: apiKey: diff --git a/scripts/generators/search.js b/scripts/generators/search.js index 3f349b1..eb999fa 100644 --- a/scripts/generators/search.js +++ b/scripts/generators/search.js @@ -60,8 +60,22 @@ hexo.extend.generator.register('search_json_generator', function (locals) { return temp_post } + function matchAndExit(path, patterns) { + for (let pattern of patterns) { + const regexPattern = new RegExp('^' + pattern.replace(/\*/g, '.*') + '$'); + if (path.match(regexPattern)) { + // console.log("Matched pattern:", pattern); + return true; + } + } + return false; + } + if (posts) { posts.each(function(post) { + var layout_list = ["post"] + if (!layout_list.includes(post.layout)) return + if (matchAndExit(post.path, cfg.skip_search)) return if (post.indexing == false) return let temp_post = generateJson(post) res.push(temp_post) @@ -69,6 +83,9 @@ hexo.extend.generator.register('search_json_generator', function (locals) { } if (pages) { pages.each(function(page) { + var layout_list = ["page", "wiki"] + if (!layout_list.includes(page.layout)) return + if (matchAndExit(page.path, cfg.skip_search)) return if (page.indexing == false) return let temp_post = generateJson(page) res.push(temp_post)