mkdocs-techdocs-core icon indicating copy to clipboard operation
mkdocs-techdocs-core copied to clipboard

Duplicate search index entries

Open zerok opened this issue 1 year ago • 4 comments

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?

zerok avatar May 24 '24 06:05 zerok

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

alexef avatar Jul 01 '24 05:07 alexef

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

awanlin avatar Jul 02 '24 12:07 awanlin

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

alexef avatar Jul 02 '24 12:07 alexef

Thanks! Left a comment 👍

awanlin avatar Jul 02 '24 12:07 awanlin