-
-
Notifications
You must be signed in to change notification settings - Fork 70
fix: Fix Orama search not working on /docs #361
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
Merged
Merged
Changes from 7 commits
Commits
Show all changes
13 commits
Select commit
Hold shift + click to select a range
2f8d548
Fix Orama search version filter on docs
smith558 ebfd89a
Format SearchBar override
smith558 d7a008b
Add @orama/react-components dependency
smith558 3debc17
Resolve Orama react components import
smith558 cb5797e
Use direct path for Orama react components
smith558 993e37f
Use static path for Orama react components
smith558 eeebda2
Revert "Use static path for Orama react components"
smith558 0e99069
Patch fix Orama search with Docusaurus v3
smith558 e1bde14
Update orama patch for version name handling
smith558 ce80636
Ensure patch-package runs during build
smith558 b33bbe6
Update config and lockfile
smith558 3919688
Revert previous changes
smith558 d93db37
Updates @orama/plugin-docusaurus-v3 to 3.1.18
smith558 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,127 @@ | ||
| import React, { lazy } from 'react' | ||
| import { useLocation } from '@docusaurus/router' | ||
| import BrowserOnly from '@docusaurus/BrowserOnly' | ||
| import { useActiveVersion, useVersions } from '@docusaurus/plugin-content-docs/client' | ||
| import { usePluginData } from '@docusaurus/useGlobalData' | ||
|
|
||
| // Reuse Orama's theme helpers but ensure the search filter receives a version name string. | ||
| import useOrama from '@orama/plugin-docusaurus-v3/dist/theme/SearchBar/useOrama.js' | ||
| import { getColorMode, getPreferredVersion } from '@orama/plugin-docusaurus-v3/dist/theme/SearchBar/utils.js' | ||
|
|
||
| const oramaComponentsPath = '../../node_modules/@orama/react-components/dist/index.js' | ||
|
|
||
| const OramaSearchButton = lazy(() => | ||
| import(oramaComponentsPath).then((module) => ({ | ||
| default: module.OramaSearchButton, | ||
| })), | ||
| ) | ||
|
|
||
| const OramaSearchBox = lazy(() => | ||
| import(oramaComponentsPath).then((module) => ({ | ||
| default: module.OramaSearchBox, | ||
| })), | ||
| ) | ||
|
|
||
| // Add `where` when collectionManager is provided. Handles different query APIs. | ||
| function formatSearchParams(versionName, collectionManager) { | ||
| if (collectionManager) { | ||
| return { | ||
| version: versionName, | ||
| } | ||
| } | ||
|
|
||
| return { | ||
| version: { eq: versionName }, | ||
| } | ||
| } | ||
|
|
||
| function resolveVersionName({ activeVersionName, preferredVersionName, versions }) { | ||
| // Plugin passes the whole version object; Orama expects a string. Keep this override until upstream fixes it. | ||
| return activeVersionName || preferredVersionName || versions?.[0]?.name || 'latest' | ||
| } | ||
|
|
||
| export function OramaSearchNoDocs() { | ||
| const colorMode = getColorMode() | ||
| const { | ||
| searchBoxConfig, | ||
| searchBtnConfig = { | ||
| text: 'Search', | ||
| }, | ||
| } = useOrama() | ||
| const collectionManager = searchBoxConfig.basic?.collectionManager | ||
|
|
||
| return ( | ||
| <> | ||
| <OramaSearchButton colorScheme={colorMode} className="DocSearch-Button" {...searchBtnConfig}> | ||
| {searchBtnConfig?.text} | ||
| </OramaSearchButton> | ||
| <OramaSearchBox | ||
| {...(collectionManager ? {} : searchBoxConfig.basic)} | ||
| {...searchBoxConfig.custom} | ||
| oramaCoreClientInstance={collectionManager} | ||
| colorScheme={colorMode} | ||
| searchParams={{ | ||
| where: formatSearchParams('latest', collectionManager), | ||
| }} | ||
| /> | ||
| </> | ||
| ) | ||
| } | ||
|
|
||
| export function OramaSearchWithDocs({ pluginId }) { | ||
| const colorMode = getColorMode() | ||
| const { searchBoxConfig, searchBtnConfig } = useOrama() | ||
| const collectionManager = searchBoxConfig.basic?.collectionManager | ||
| const versions = useVersions(pluginId) | ||
| const activeVersion = useActiveVersion(pluginId) | ||
| const preferredVersion = getPreferredVersion(searchBoxConfig.basic?.clientInstance) | ||
|
|
||
| // Ensure the filter receives a string version name, not a full version object. | ||
| const currentVersionName = resolveVersionName({ | ||
| activeVersionName: activeVersion?.name, | ||
| preferredVersionName: preferredVersion, | ||
| versions, | ||
| }) | ||
|
|
||
| const searchParams = currentVersionName | ||
| ? { | ||
| where: formatSearchParams(currentVersionName, collectionManager), | ||
| } | ||
| : {} | ||
|
|
||
| return ( | ||
| <> | ||
| <OramaSearchButton colorScheme={colorMode} className="DocSearch-Button" {...searchBtnConfig}> | ||
| {searchBtnConfig?.text || 'Search'} | ||
| </OramaSearchButton> | ||
| <OramaSearchBox | ||
| {...(collectionManager ? {} : searchBoxConfig.basic)} | ||
| {...searchBoxConfig.custom} | ||
| oramaCoreClientInstance={collectionManager} | ||
| colorScheme={colorMode} | ||
| searchParams={searchParams} | ||
| /> | ||
| </> | ||
| ) | ||
| } | ||
|
|
||
| export default function OramaSearchWrapper() { | ||
| const { pathname } = useLocation() | ||
| const { docsInstances } = usePluginData('@orama/plugin-docusaurus-v3') | ||
| let pluginId | ||
|
|
||
| if (docsInstances) { | ||
| pluginId = docsInstances.find((id) => pathname.includes(id)) || docsInstances?.[0] | ||
| } | ||
|
|
||
| return ( | ||
| <BrowserOnly fallback={<div>Loading Search...</div>}> | ||
| {() => { | ||
| if (pluginId) { | ||
| return <OramaSearchWithDocs pluginId={pluginId} /> | ||
| } | ||
| return <OramaSearchNoDocs /> | ||
| }} | ||
| </BrowserOnly> | ||
| ) | ||
| } | ||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.