chipzoller / hugo-clarity

A theme for Hugo based on VMware Clarity
Other
572 stars 263 forks source link

Issue 290 allow granular search by sections #301

Closed onweru closed 2 years ago

onweru commented 2 years ago

This PR fixes issue #290

Changes / fixes

  1. Searching within a section produce results only from that section. For example, if you have 2 mainSections 1/ vegetables 2/ fruits, searching in the fruits section will only produce results for that section.
  2. Searching outside a section will search the entire site. For example, with the above mainSections setup, searching from the homepage will produce results from both sections and other pages of the site.

    Future implementations may include a github-like feature i.e search all site. This PR will leave that to a future PR

    Screen Shot 2022-05-15 at 00 10 53

Screenshots (if applicable)

(prefer animated gif)

Checklist

Ensure you have checked off the following before submitting your PR.

chipzoller commented 2 years ago

How would a visitor to that site know that the search they were executing was in context of that mainSection and not site-global?

onweru commented 2 years ago

How would a visitor to that site know that the search they were executing was in context of that mainSection and not site-global?

🤔 interesting question. They wouldn't really know in most cases; at least in this current form. This implementation assumes that the user would most likely benefit from results from the section they are searching from.

I would like to clarify something though. The search function has no awareness of mainSections, only the site author has that knowledge. The function is only aware of the Section (scope), only when the user is in it. Perhaps fruits & vegetables are too rudimentary. A better example would be blog & docs. I assume it would be preferable to return docs results from the docs section. Even if the user doesn't know, they would benefit nonetheless.

This situation is still not quite ideal, hence 👇🏼

Future implementations may include a github-like feature i.e search all site

I think should read as "~may~ should include a github-like feature i.e search all site, search blog, search docs ..."

chipzoller commented 2 years ago

Ok, so with this change, would a user still be able to execute a global search if they weren't navigated to one of those sections, or does this essentially replace the current global search with section-scoped search?

onweru commented 2 years ago

Ok, so with this change, would a user still be able to execute a global search if they weren't navigated to one of those sections, or does this essentially replace the current global search with section-scoped search?

Yes, any search outside a section is a global search by default. Scope only applies within sections. For example, using neonmirrors searches from the homepage, about us or any other page that is outside the posts section will be global.

chipzoller commented 2 years ago

My suggestion would be one of two following options until a more advanced search can be implemented:

  1. Make search truly "global" without being confined to simply one mainSection entry.
  2. If section-scoped search is implemented, define a way to inform the user (perhaps as "shadow" text when clicking in the search box) this search will be isolated to the section where they are executing the search.

@rootwork what's your suggestion here?

onweru commented 2 years ago

Just to clarify,

Make search truly "global" without being confined to simply one mainSection entry.

The changes in this PR fix this very problem. On master, the active search scope is restrained to one mainSection. Else it was hardcoded to 'post' section. That's why in issue #290, specifying more than one entry threw the search off.

  1. Now, the search function has no awareness of mainSections entries, it doesn't use them at all. The Section scope is defined on the page level.
  2. the hardcoded post section is removed.
  3. In Hugo Section refers to the top-level folder in the content directory. Therefore, the search function doesn't treat nested sections as independent scope; only the topmost Section applies as valid scope, From what I have observed, most site authors use these top level folders to isolate 'apples' from 'oranges'; if they've more than one of this folder anyway. My sense is that unless searching from outside a section, it rarely benefits a user search for an orange from within a basket of apples. That's not to say that global search is entirely undesirable.
chipzoller commented 2 years ago

I see, thanks for Clarity (ha!). @rootwork what is your opinion?