Skip to content

Commit

Permalink
Add filter to SearchIndexPlugin
Browse files Browse the repository at this point in the history
  • Loading branch information
joshwooding committed Aug 29, 2024
1 parent d138bcf commit b75cd3f
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 2 deletions.
5 changes: 5 additions & 0 deletions .changeset/cool-ads-carry.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@jpmorganchase/mosaic-plugins': minor
---

Add a `filter` option to SearchIndexPlugin, which allows you to exclude pages from the search index.
8 changes: 6 additions & 2 deletions packages/plugins/src/SearchIndexPlugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,10 @@ interface SearchIndexPluginOptions {
maxLineCount?: number;
keys?: string[];
relevancy?: SearchRelevancy;
/**
* An array of glob patterns to exclude pages from the search index.
*/
filter?: string[];
}

interface Optimization {
Expand Down Expand Up @@ -145,13 +149,13 @@ const SearchIndexPlugin: PluginType<Page, SearchIndexPluginOptions> = {
async $beforeSend(
mutableFilesystem,
{ config, serialiser, ignorePages },
{ maxLineLength, maxLineCount, keys: optionKeys }
{ maxLineLength, maxLineCount, keys: optionKeys, filter }
) {
const pages = await Promise.all(
(
(await mutableFilesystem.promises.glob('**', {
onlyFiles: true,
ignore: ignorePages.map(ignore => `**/${ignore}`),
ignore: ignorePages.map(ignore => `**/${ignore}`).concat(filter),
cwd: '/'
})) as string[]
).map(async pagePath => {
Expand Down

0 comments on commit b75cd3f

Please sign in to comment.