Skip to content

Commit

Permalink
feat: add pageTitle in userSiteSearch result (#1625)
Browse files Browse the repository at this point in the history
Co-authored-by: 逍为 <xiaowei.wzw@antgroup.com>
  • Loading branch information
hustcc and 逍为 committed Apr 24, 2023
1 parent c7b15ff commit d0decb2
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 1 deletion.
2 changes: 1 addition & 1 deletion compiled/_internal/searchWorker.min.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions src/client/theme-api/useSiteSearch/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ export interface ISearchNavResult {
type: 'page' | 'title' | 'demo' | 'content';
link: string;
priority: number;
pageTitle: string;
highlightTitleTexts: IHighlightText[];
highlightTexts: IHighlightText[];
}[];
Expand Down
5 changes: 5 additions & 0 deletions src/client/theme-api/useSiteSearch/searchWorker.ts
Original file line number Diff line number Diff line change
Expand Up @@ -247,6 +247,7 @@ function generateSearchResult(metadata: ISearchMetadata, keywordsStr: string) {

// traverse metadata from all routes
metadata.forEach((data) => {
const pageTitle = data.title;
const hints: ISearchResult[0]['hints'] = [];

// find content & section hints
Expand All @@ -270,6 +271,7 @@ function generateSearchResult(metadata: ISearchMetadata, keywordsStr: string) {
}).reduce((acc, p) => acc + p, 0),
highlightTitleTexts,
highlightTexts,
pageTitle,
});

// match at most once in the same section
Expand Down Expand Up @@ -297,6 +299,7 @@ function generateSearchResult(metadata: ISearchMetadata, keywordsStr: string) {
sec.paragraphs[0] || '',
keywords,
)[0],
pageTitle,
});
}
});
Expand All @@ -323,6 +326,7 @@ function generateSearchResult(metadata: ISearchMetadata, keywordsStr: string) {
}).reduce((acc, p) => acc + p, 0),
highlightTitleTexts,
highlightTexts,
pageTitle,
});
}
});
Expand All @@ -347,6 +351,7 @@ function generateSearchResult(metadata: ISearchMetadata, keywordsStr: string) {
data.sections[0]?.paragraphs[0] || '',
keywords,
)[0],
pageTitle,
});
}

Expand Down

0 comments on commit d0decb2

Please sign in to comment.