Skip to content

feat(search): resultSource option shows where results come from#2767

Open
piecioshka wants to merge 3 commits into
docsifyjs:developfrom
piecioshka:feat/search-result-page-title
Open

feat(search): resultSource option shows where results come from#2767
piecioshka wants to merge 3 commits into
docsifyjs:developfrom
piecioshka:feat/search-result-page-title

Conversation

@piecioshka

@piecioshka piecioshka commented Jul 22, 2026

Copy link
Copy Markdown

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 resultSource option 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 sidebar
window.$docsify = {
  search: {
    resultSource: 'breadcrumb', // 'none' | 'page' | 'breadcrumb'
  },
};

Implementation notes:

  • genIndex() stamps every index entry with the title of its page (pageTitle), and search() exposes it on results as page
  • the breadcrumb is computed at render time by walking the rendered .sidebar-nav tree from the link matching the result URL up to the root
  • emoji in sidebar labels and page titles are stripped so the source line stays plain text; the label is right-aligned, slightly muted (--color-mono-7) and the page segment renders in <strong>
  • default 'none' keeps the current behavior, so nothing changes for existing sites

Preview (resultSource: 'breadcrumb' on the docsify docs):

Search results with breadcrumb source labels

Related issue, if any:

None.

What kind of change does this PR introduce?

  • Bugfix
  • Feature
  • Code style update (formatting, renaming)
  • Refactoring (no functional changes, no api changes)
  • Build related changes
  • Documentation content changes
  • Other (please describe):

For any code change,

  • Related documentation has been updated, if needed
  • Related tests have been added or updated, if needed

Does this PR introduce a breaking change?

  • Yes
  • No

Tested in the following browsers:

  • Chrome
  • Firefox
  • Safari
  • Edge

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.
Copilot AI review requested due to automatic review settings July 22, 2026 18:53
@vercel

vercel Bot commented Jul 22, 2026

Copy link
Copy Markdown

@piecioshka is attempting to deploy a commit to the Docsify Team on Vercel.

A member of the Team first needs to authorize it.

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.resultSource config ('none' | 'page' | 'breadcrumb') and propagate it through the plugin.
  • Stamp search index entries with pageTitle and expose it on search results as page.
  • 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.

Comment thread src/plugins/search/component.js
Comment thread src/plugins/search/index.js
Comment thread test/e2e/search.test.js
- 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
@vercel

vercel Bot commented Jul 23, 2026

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated (UTC)
docsify-preview Ready Ready Preview, Comment Jul 23, 2026 8:59am

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants