return undefined;
}
+ const searchResultPage: SearchResult['page'] = {
+ id: page.id,
+ text: (page.html || '').replace(/<(?:.|\n)*?>/gm, '').replace(/<(?:.|\n)*?>/gm, ''),
+ title: getMarkdownRemarkTitle(page) || '',
+ url: getMarkdownRemarkUrl(page) || ''
+ };
+
const highlights: { [field: string]: [number, number][] } = {};
let longestTerm = '';
let exactMatch = false;
});
return {
- page: {
- id: page.id,
- text: (page.html || '')
- .replace(/<(?:.|\n)*?>/gm, '')
- .replace(/<(?:.|\n)*?>/gm, ''),
- title: getMarkdownRemarkTitle(page) || '',
- url: getMarkdownRemarkUrl(page) || ''
- },
+ page: searchResultPage,
exactMatch,
highlights,
query,
import lunr, { LunrBuilder, LunrIndex, LunrToken } from 'lunr';
import { sortBy } from 'lodash';
import { DocNavigationItem } from 'Docs/@types/types';
-import SearchResultEntry, { SearchResult } from './SearchResultEntry';
+import SearchResultEntry from './SearchResultEntry';
import { getUrlsList } from '../navTreeUtils';
import { DocumentationEntry } from '../utils';
+import { isDefined } from '../../../helpers/types';
interface Props {
navigation: DocNavigationItem[];
)
.map(match => {
const page = this.props.pages.find(page => page.relativeName === match.ref);
+
+ if (!page) {
+ return null;
+ }
+
const highlights: T.Dict<[number, number][]> = {};
let longestTerm = '';
let exactMatch = false;
return { exactMatch, highlights, longestTerm, page, query };
})
- .filter(result => result.page) as SearchResult[];
+ .filter(isDefined);
// Re-order results by the length of the longest matched term and by exact
// match (if applicable). The longer the matched term is, the higher the