feat(search): resultSource option shows where results come from#2767
Open
piecioshka wants to merge 3 commits into
Open
feat(search): resultSource option shows where results come from#2767piecioshka wants to merge 3 commits into
piecioshka wants to merge 3 commits into
Conversation
Search results for matches inside a section only showed the section heading, with no hint of which page it belongs to. Index entries now carry the title of their page (first heading) and a new search config option, resultSource, controls what renders below the excerpt: - 'none' (default): current behavior, nothing extra - 'page': the page title, e.g. "Guide", omitted when the matched title is the page title itself - 'breadcrumb': the sidebar path to the page, e.g. "Basics › Guide", falling back to the page title for pages not present in the sidebar Emoji in sidebar labels and page titles are stripped so the source line stays plain text.
|
@piecioshka is attempting to deploy a commit to the Docsify Team on Vercel. A member of the Team first needs to authorize it. |
There was a problem hiding this comment.
Pull request overview
This PR enhances the Docsify search plugin UX by adding a resultSource option that displays the originating page context for each search result (none/page title/sidebar breadcrumb), helping users distinguish similarly named sections across pages.
Changes:
- Add
search.resultSourceconfig ('none' | 'page' | 'breadcrumb') and propagate it through the plugin. - Stamp search index entries with
pageTitleand expose it on search results aspage. - Render and style a per-result “source” line (page title or computed sidebar breadcrumb), and add e2e coverage for the new option.
Reviewed changes
Copilot reviewed 6 out of 6 changed files in this pull request and generated 3 comments.
Show a summary per file
| File | Description |
|---|---|
| test/e2e/search.test.js | Adds e2e tests for resultSource modes (default/page/breadcrumb). |
| src/plugins/search/style.css | Styles the new .search-breadcrumb line under each result. |
| src/plugins/search/search.js | Captures pageTitle during indexing and exposes it on search results. |
| src/plugins/search/index.js | Adds the resultSource config option and wires it into plugin config. |
| src/plugins/search/component.js | Renders source info for results; computes breadcrumb from the sidebar DOM. |
| docs/plugins.md | Documents the new resultSource option in plugin docs. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
- mark resultSource as optional in the CONFIG JSDoc - decode URLs via a safe helper so malformed percent-encoding in user-authored sidebar links cannot break result rendering - cover the breadcrumb fallback (page absent from the sidebar) in e2e
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Search results for matches inside a section only show the section heading, with no hint of which page the result belongs to. On docs sites where many pages share similar section names ("Usage", "Options", "Examples"), it is hard to tell the results apart.
This PR adds a
resultSourceoption to the search plugin that renders, below each result excerpt, where the result comes from:'none'(default): current behavior, nothing extra renders'page': the title of the page (its first heading), omitted when the matched title is the page title itself'breadcrumb': the sidebar path to the page, e.g. "Getting started › Cover page", falling back to the page title for pages not present in the sidebarImplementation notes:
genIndex()stamps every index entry with the title of its page (pageTitle), andsearch()exposes it on results aspage.sidebar-navtree from the link matching the result URL up to the root--color-mono-7) and the page segment renders in<strong>'none'keeps the current behavior, so nothing changes for existing sitesPreview (
resultSource: 'breadcrumb'on the docsify docs):Related issue, if any:
None.
What kind of change does this PR introduce?
For any code change,
Does this PR introduce a breaking change?
Tested in the following browsers: