Skip to content

Implement page search URL + Opensearch XML#2143

Open
ian-h-chamberlain wants to merge 2 commits intonushell:mainfrom
ian-h-chamberlain:feat/search-url
Open

Implement page search URL + Opensearch XML#2143
ian-h-chamberlain wants to merge 2 commits intonushell:mainfrom
ian-h-chamberlain:feat/search-url

Conversation

@ian-h-chamberlain
Copy link
Copy Markdown

Closes #1093

I tend to create a lot of shortcuts to doc searches in my browser, so I wanted the same thing for Nushell! I decided to take a crack at implementing the search URL logic I've seen used by many other docs websites.

Screen.Recording.2026-03-28.at.01.25.37.mov

Also set up Opensearch XML so some browsers can more easily add a search engine:

image

Implementation

  • Wrap the DocSearch component provided by the docsearchPlugin, and override its registration with our custom component

In the new URLDocSearch component:

  • Prefill and execute search when a page loads with the search param set, at onMounted

  • Add an input event handler, which updates the URL bar when the search bar is updated. Use a 500ms debounce to avoid flooding the user's browser history with partial searches

There are two pieces to this:
- Prefill and execute search when a page loads with the `search` param set
- Update the URL bar when a search is executed, with 500ms debounce
Also fixup some TS lint errors in the new component, language server
wasn't working before.
@fdncred
Copy link
Copy Markdown
Contributor

fdncred commented Mar 28, 2026

sounds cool!

function handleSearchInput(event: InputEvent) {
const target = event.target as HTMLInputElement | undefined;
const searchQuery = target?.value;
if (target?.id !== 'docsearch-input' || !searchQuery) {
Copy link
Copy Markdown
Contributor

@hustcer hustcer Mar 31, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think If the input value is empty it's better to delete the search param here. Returning early when the input is cleared means the existing ?search= parameter is not removed. As a result, after the user clears the search and closes the modal, the URL may still retains the old query.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hmm, good point, I think that probably makes sense. I'm not sure how easy it will be to detect the modal being dismissed (since that logic is implemented in a nested child), but it's probably doable with some kind of global event listener at least.

I will try to get to implementing this next week when I should have some time!

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

FR: Generate search URL

3 participants