Feature: Display full article path in search results
Description
In large MkDocs sites there could be multiple pages with similar title residing under different navigation paths or sections. It is difficult to see from the search results in which section the particular article is located in.
Expected behavior
Search results should display the full navigation path to the pages just like in the header of the website, for example:
- My First Section / My Page
- My Second Section / My Page
This could be an optional configurable feature, toggled on or off.
Actual behavior
Only title is displayed in the search results:
- My Page
- My Page
Steps to reproduce the bug
- Search for a term which appreas in multiple pages with similar name
- Multiple pages with same title appear in the search results with no apparent clue in which section the page resides
Package versions
- Python:
2.7.5 - MkDocs:
0.16.3 - Material:
1.6.4
Project configuration
site_name: My Test Docs
site_description: Test documentation
copyright: 'Copyright © 2017 My Company'
theme: material
repo_url: https://git.mytestcompany.com/tech/docs
edit_uri: edit/master/docs/
site_favicon: 'img/favicon.ico'
theme_dir: 'theme'
markdown_extensions:
- admonition
- codehilite:
linenums: False
guess_lang: True
pygments_style: 'native'
noclasses: True
- toc:
permalink: True
separator: "_"
extra:
feature:
tabs: true
logo: 'img/logo.png'
palette:
primary: 'light blue'
accent: 'indigo'
font:
text: 'Roboto'
code: 'Roboto Mono'
pages:
- 'Start': 'index.md'
- 'FAQ': 'faq.md'
- My First Section:
- 'My Page': 'section1/mypage.md'
- 'Some Page': 'section1/somepage.md'
- My Second Section:
- 'My Page': 'section2/mypage.md'
- 'Other Page': 'section2/otherpage.md'
System information
- OS: not relevant
- Browser: not relevant
Not possible, because this information is missing from the search index MkDocs exposes. The only thing that could be used is the URL, because the path information is also encoded in the URL.
OK, I would be interested in at least displaying the URL in the results but not sure how to customize the results. Thank you.
The search results are generated dynamically inside the Search/Result.jsx class/file. You could include the URL below here:
https://github.com/squidfunk/mkdocs-material/blob/master/src/assets/javascripts/components/Material/Search/Result.jsx#L228
(doc.location)
and here:
https://github.com/squidfunk/mkdocs-material/blob/master/src/assets/javascripts/components/Material/Search/Result.jsx#L243
(section.location)
Then you need to set the styles for your changes which can be done through extra_css
Hi @squidfunk, I am interested in implementing showing the URL in the search result and formatting it to show the full article path.
Can you provide more information on what needs to be added to the lines you mention for doc.location/section.location. I am not proficient in javascript and JS class files.
@squidfunk Hello, I am referencing this legacy issue and notice that your links in above comment seem to be out of date (it seems you updated the .jsx files to .ts?). Would you please be able to provide updated insight on how to display full article path in search results.
Any and all information would be extremely appreciated and your work on this app has been top tier. Thanks for everything.
Search results are rendered here: https://github.com/squidfunk/mkdocs-material/blob/master/src/assets/javascripts/templates/search/index.tsx
Other than that, I recommend checking the source - it's quite extensively documented.
Thanks for the recommendations @squidfunk . To clarify, when you say "the source" do you mean this section of doc? https://squidfunk.github.io/mkdocs-material/setup/setting-up-site-search/#query-transformation ?
Nope, I meant everything that's under the src directory in this repository 😊 The section you linked talks about custom-transforming the query before sending it to the index.