-
-
Notifications
You must be signed in to change notification settings - Fork 8.5k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
fix(search-algolia): pass custom transformItems function to SearchBar #8462
Conversation
✅ [V2]
To edit notification comments on pull requests, go to your Netlify site settings. |
⚡️ Lighthouse report for the deploy preview of this PR
|
props.transformItems | ||
? props.transformItems | ||
: (items) => | ||
items.map((item) => { | ||
// If Algolia contains a external domain, we should navigate without | ||
// relative URL | ||
if (isRegexpStringMatch(externalUrlRegex, item.url)) { | ||
return item; | ||
} | ||
|
||
// We transform the absolute URL into a relative URL. | ||
const url = new URL(item.url); | ||
return { | ||
...item, | ||
url: withBaseUrl(`${url.pathname}${url.hash}`), | ||
}; | ||
}), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Extract the arrow to a new variable and write useRef(props.transformItems ?? defaultTransformItems)
.
This PR references itself (instead of an external issue) and does not really give much context into what you are trying to achieve (although I have an idea, I'd like you to explain) This is also doing to conflict with #8428, which may already solve your use-case? Note: make sure your use-case also works on the SearchPage? https://docusaurus.io/search |
Found the original issue 🤪 #8461 Using a wrapper to provide a custom transformItems prop is exactly what I had in mind, so feel free to go ahead. Still wonder if the newly introduced code does not solve your use-case? cf #8428
Why do you want to transform those items? |
# Conflicts: # packages/docusaurus-theme-search-algolia/src/theme/SearchBar/index.tsx
Sorry @slorber @Josh-Cena. I was on a Christmas holiday but seems like you guys took care of this PR already.
Oops, my bad.
Not really. I wanted to tweak the search results and reorder them the way I want. The linked issue allows only changing the results pathname if I could understand correctly. |
Pre-flight checklist
Motivation
Closes #8462
Test Plan
Manual
Test links
Deploy preview: https://deploy-preview-_____--docusaurus-2.netlify.app/
Related issues/PRs
Closes #8461