Skip to content

Commit d0decb2

Browse files
hustcc逍为
andauthored
feat: add pageTitle in userSiteSearch result (#1625)
Co-authored-by: 逍为 <[email protected]>
1 parent c7b15ff commit d0decb2

File tree

3 files changed

+7
-1
lines changed

3 files changed

+7
-1
lines changed

compiled/_internal/searchWorker.min.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/client/theme-api/useSiteSearch/index.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ export interface ISearchNavResult {
1616
type: 'page' | 'title' | 'demo' | 'content';
1717
link: string;
1818
priority: number;
19+
pageTitle: string;
1920
highlightTitleTexts: IHighlightText[];
2021
highlightTexts: IHighlightText[];
2122
}[];

src/client/theme-api/useSiteSearch/searchWorker.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -247,6 +247,7 @@ function generateSearchResult(metadata: ISearchMetadata, keywordsStr: string) {
247247

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

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

275277
// match at most once in the same section
@@ -297,6 +299,7 @@ function generateSearchResult(metadata: ISearchMetadata, keywordsStr: string) {
297299
sec.paragraphs[0] || '',
298300
keywords,
299301
)[0],
302+
pageTitle,
300303
});
301304
}
302305
});
@@ -323,6 +326,7 @@ function generateSearchResult(metadata: ISearchMetadata, keywordsStr: string) {
323326
}).reduce((acc, p) => acc + p, 0),
324327
highlightTitleTexts,
325328
highlightTexts,
329+
pageTitle,
326330
});
327331
}
328332
});
@@ -347,6 +351,7 @@ function generateSearchResult(metadata: ISearchMetadata, keywordsStr: string) {
347351
data.sections[0]?.paragraphs[0] || '',
348352
keywords,
349353
)[0],
354+
pageTitle,
350355
});
351356
}
352357

0 commit comments

Comments
 (0)