Skip to content

Filter the command reference to a category when its menu link is clicked - #30

Open
madolson wants to merge 1 commit into
promote/docs-modern-sidebarfrom
command-category-filter
Open

madolson wants to merge 1 commit into
promote/docs-modern-sidebarfrom
command-category-filter

Conversation

@madolson

Copy link
Copy Markdown
Owner

Clicking a command category in the docs menu now fills the search box with the category name and shows just that category's commands, on /commands/ and from command pages. Editing the box goes back to the normal command name search across all categories and drops the category from the URL. One decision for review: typing a category name by hand stays a name search, so "set" still finds the SET command rather than switching to the Set category. Stacks on valkey-io#773.

AI generated details

Problem

The search box matches command names only (templates/commands.html:95), so filling it with "Hash" would find almost nothing and "Set" would match SET, HSET and CONFIG SET across groups. The page has to know the text came from a category.

Fix

All in templates/commands.html.

  • Each .command-group carries data-group (the groups.json key, same as the heading id) and data-group-name (its display name), :65.
  • showGroupFromHash(), :115, runs on load and on hashchange. If the hash names a group it puts the display name in the box, shows only that group with all its entries, hides the no-results message, and scrolls the box into view. On load it scrolls again, :156, because the browser's own fragment scroll runs after the inline script and puts the heading at the top, hiding the box (measured: box at -69px without it). A hash that names no group does nothing, except an empty hash after a category was active (back button), which clears the filter.
  • The box now uses oninput instead of onkeyup, :15. Keyup also fires for keys that don't edit the box (Tab into it, arrows), which would drop a category filter for no reason; setting .value from script fires neither.
  • onSearchInput(), :143, drops the hash with history.replaceState and dispatches a hashchange so the menu's markCurrent() (from Put the docs menu above the content on phones and add previous/next topic links valkey-io/valkey-io.github.io#773) moves to "All commands". showGroupFromHash() ignores that event because no category is active by then.
  • No change without JavaScript: the hash still jumps to the heading. The menu macro is unchanged.

Alternative considered: matching an exact category name typed by hand. Rejected per the decision above, since "set", "list" and "string" are also command names or substrings people search for.

Screenshots (1440x900)

/commands/#hash, before (valkey-io#773 head):

before

/commands/#hash, after:

after

/commands/ after typing "get":

get

Browser evidence

Headless Chrome over CDP, full command content, Zola 0.23.6. Clicks are Input.dispatchMouseEvent on the menu anchor; typing is Input.dispatchKeyEvent.

Load /commands/#hash:

"url": "/commands/#hash", "box": "Hash", "visibleGroups": ["hash 28/28"], "visibleEntries": 28,
"noResults": "none", "menuCurrent": ["Hash /commands/#hash"], "boxTop": 0, "firstGroupHeadingTop": 69
hash group entry count in DOM: 28

Then click the menu's Sorted Set link:

"url": "/commands/#sorted-set", "box": "Sorted Set", "visibleGroups": ["sorted-set 35/35"],
"menuCurrent": ["Sorted Set /commands/#sorted-set"]

Then type "get":

"url": "/commands/", "box": "get",
"visibleGroups": ["bitmap 1/7","cluster 3/38","connection 2/28","hash 5/28","json 3/23","server 6/82","string 6/25"],
"menuCurrent": ["All commands /commands/"]
entries in DOM whose name contains 'get': 26 visible: 26
location.href: http://127.0.0.1:18732/commands/

From /commands/set/, expand the menu's Command reference and click Hash:

"url": "/commands/#hash", "box": "Hash", "visibleGroups": ["hash 28/28"], "menuCurrent": ["Hash /commands/#hash"]

No hash and an unknown hash, valkey-io#773 head against this branch:

e. identical visible entries before/after for /commands/ : True 440
e. identical visible entries before/after for /commands/#not-a-group : True 440

Type "set" by hand:

f. SET entry's group, visible: ['string', True, True]
f. after: typed 'set': ... total entries 31   (31 before as well)

Back button from #sorted-set to #hash to the plain URL:

back to #hash: ['#hash', 'Hash', ['hash']]
back to /commands/ (no hash): ['http://127.0.0.1:18732/commands/', '', 19]

Try it

Open /commands/ on the preview, click Hash in the menu's Command reference, then Sorted Set, then type in the box.

This was generated by AI but verified, with love, by a human.

Opening /commands/#<group> (a category link in the docs menu) puts the
group's name in the search box and shows only that group. Editing the box
is the usual command name search over all groups and drops the hash.

Signed-off-by: Madelyn Olson <madelyneolson@gmail.com>
@madolson madolson added the needs-review Staged work waiting on madolson's review label Nov 17, 2026

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

needs-review Staged work waiting on madolson's review

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant