backstage / mkdocs-techdocs-core

The core MkDocs plugin used by Backstage's TechDocs as a wrapper around multiple MkDocs plugins and Python Markdown extensions
Apache License 2.0
82 stars 61 forks source link

Duplicate search index entries #192

Open zerok opened 1 month ago

zerok commented 1 month ago

Hi ๐Ÿ™‚

With the current setup this plugin uses the original mkdocs search plugin. Unfortunately, this produces duplicate content for pages that have a h1 element as both, the whole page and the h1 section, will be included in the index:

    {
      "location": "",
      "text": "Welcome to MkDocs For full documentation visit mkdocs.org . Commands mkdocs new [dir-name] - Create a new project. mkdocs serve - Start the live-reloading docs server. mkdocs build - Build the documentation site. mkdocs -h - Print help message and exit. Project layout mkdocs.yml # The configuration fil
e. docs/ index.md # The documentation homepage. ... # Other markdown pages, images and other files.",
      "title": "Welcome to MkDocs"
    },
    {
      "location": "#welcome-to-mkdocs",
      "text": "For full documentation visit mkdocs.org .",
      "title": "Welcome to MkDocs"
    }

As far as I can tell, the search plugin in mkdocs-material does not do that and so we don't have duplicate entries in the index:

    {
      "location": "",
      "title": "Welcome to MkDocs",
      "text": "<p>For full documentation visit mkdocs.org.</p>"
    },
    {
      "location": "#commands",
      "title": "Commands",
      "text": "<ul> <li><code>mkdocs new [dir-name]</code> - Create a new project.</li> <li><code>mkdocs serve</code> - Start the live-reloading docs server.</li> <li><code>mkdocs build</code> - Build the documentation site.</li> <li><code>mkdocs -h</code> - Print help message and exit.</li> </ul>"
    }

Looking through https://github.com/mkdocs/mkdocs/blob/master/mkdocs/contrib/search/search_index.py I also don't see a way that this behaviour could be replicated. Is there perhaps a way other than forking the original search plugin?

alexef commented 1 day ago

I would make mkdocs-material search an option in mkdocs.yml config to use either standard search or theme search in: https://github.com/backstage/mkdocs-techdocs-core/blob/main/src/core.py#L22

awanlin commented 2 hours ago

Hi @alexef, is this something that you would be willing to submit a PR for?

alexef commented 1 hour ago

@awanlin already did: https://github.com/backstage/mkdocs-techdocs-core/pull/202 - but I'm trying to figure out ways to test it.

awanlin commented 1 hour ago

Thanks! Left a comment ๐Ÿ‘