twbs / bootstrap

The most popular HTML, CSS, and JavaScript framework for developing responsive, mobile first projects on the web.
https://getbootstrap.com
MIT License
170.43k stars 78.82k forks source link

Potentially unintended text in search on docs #37312

Open morganarnel opened 2 years ago

morganarnel commented 2 years ago

Prerequisites

Describe the issue

Go to the docs page at: https://getbootstrap.com/docs/5.2/customize/overview/ Press / to open the Algolia search, when searching for Modal what are presumably supposed to be results are displayed as a heading.

image

Reduced test cases

NA

What operating system(s) are you seeing the problem on?

Windows, macOS, Android, iOS, Linux

What browser(s) are you seeing the problem on?

Chrome, Firefox, Microsoft Edge

What version of Bootstrap are you using?

NA

julien-deramond commented 2 years ago

Apparently, all the <h1>s in the Modal page are gathered and appear in the results as a title in violet.

WinterSilence commented 2 years ago

customize widget

mdo commented 1 year ago

@patrickhlauke We may want to revisit the h1 move in modal headers. Or at least see if there's a fix for this with Algolia.

patrickhlauke commented 1 year ago

so is there no way to get the silly algolia thing to exclude certain types of headings with a particular .modal-title class? would hate to have to compromise correct structure/markup just for this...

julien-deramond commented 1 year ago

I'm not confortable about compromising the correct structure. We could create an issue in their repo so they use only the first h1 of the page for this part 🤷

WinterSilence commented 1 year ago

in search.js:

...
transformItems(items) {
  return items.map(item => {
    item._highlightResult.hierarchy.lvl0.value = '' // Added
    const liveUrl = 'https://getbootstrap.com/'
    ...
  })
}
...
julien-deramond commented 1 year ago

Hum. If we do it, we'll lose some information in the results (violet titles).

Before:

Screenshot 2022-10-17 at 11 24 17

With the proposed patch:

Screenshot 2022-10-17 at 11 24 28
WinterSilence commented 1 year ago

@julien-deramond it's rude solution just for example

I explode default configs and find solution in config.js:

  ...
  actions: [
    {
      recordExtractor: ({ helpers }) => {
        return helpers.docsearch({
          recordProps: {
            lvl1: ['header h1', 'article h1', 'main h1', 'h1', 'head > title'],
            content: ['article p, article li', 'main p, main li', 'p, li'],
            lvl0: {
              selectors: '',
              defaultValue: 'Documentation',
            },
            lvl2: ['article h2', 'main h2', 'h2'],
            lvl3: ['article h3', 'main h3', 'h3'],
            lvl4: ['article h4', 'main h4', 'h4'],
            lvl5: ['article h5', 'main h5', 'h5'],
            lvl6: ['article h6', 'main h6', 'h6'],
          },
        });
      },
    },
  ],
  ...
julien-deramond commented 1 year ago

Yes this syntax could provide a solution:

recordExtractor: ({ $, helpers }) => {
  // Removing DOM elements we don't want to crawl
  $(".modal-title").remove();

  return helpers.docsearch({
    // ...
  });
},
bastienmoulia commented 1 year ago

Same with ti (would like to find titles) : image