-
Notifications
You must be signed in to change notification settings - Fork 57
fix: search exiting, markdown rendering #955
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,5 @@ | ||
| --- | ||
| '@node-core/doc-kit': patch | ||
| --- | ||
|
|
||
| Close Orama search when the target link is on the same page |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,5 @@ | ||
| --- | ||
| '@node-core/doc-kit': patch | ||
| --- | ||
|
|
||
| Render markdown `code` snippets in the sidebar |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -11,6 +11,45 @@ import styles from './index.module.css'; | |
| import useOrama from '../../hooks/useOrama.mjs'; | ||
| import { relativeOrAbsolute } from '../../utils/relativeOrAbsolute.mjs'; | ||
|
|
||
| /** | ||
| * Dismisses the search modal the clicked hit sits in | ||
| * | ||
| * @param {MouseEvent} event | ||
| */ | ||
| const followSearchHit = event => { | ||
| if (event.ctrlKey || event.metaKey || event.shiftKey || event.altKey) { | ||
| return; | ||
| } | ||
|
|
||
| const target = new URL(event.currentTarget.href); | ||
|
|
||
| event.preventDefault(); | ||
|
|
||
| // Escape is the only dismissal `SearchModal` exposes to the hits it renders. | ||
| event.currentTarget.dispatchEvent( | ||
| new KeyboardEvent('keydown', { key: 'Escape', bubbles: true }) | ||
| ); | ||
|
|
||
| requestAnimationFrame(() => { | ||
| if (target.pathname !== window.location.pathname) { | ||
| window.location.href = target.href; | ||
| return; | ||
| } | ||
|
|
||
| requestAnimationFrame(() => | ||
| document | ||
| .getElementById(decodeURIComponent(target.hash.slice(1))) | ||
| ?.scrollIntoView() | ||
| ); | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Same-page search omits URL hashMedium Severity
Reviewed by Cursor Bugbot for commit 6e7b974. Configure here. |
||
| }); | ||
| }; | ||
|
|
||
| /** | ||
| * A search hit link that dismisses the modal when followed. | ||
| * @param {Object} props - Anchor props, as passed by `SearchHit`. | ||
| */ | ||
| const SearchHitLink = props => <a {...props} onClick={followSearchHit} />; | ||
|
|
||
| const SearchBox = ({ pathname }) => { | ||
| const client = useOrama(pathname); | ||
|
|
||
|
|
@@ -21,6 +60,7 @@ const SearchBox = ({ pathname }) => { | |
| noResultsTitle="No results found for" | ||
| onHit={hit => ( | ||
| <SearchHit | ||
| as={SearchHitLink} | ||
| document={{ | ||
| ...hit.document, | ||
| href: relativeOrAbsolute(hit.document.href, pathname), | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,26 @@ | ||
| /** | ||
| * Renders a raw Markdown heading. We intentionally | ||
| * only account for backticks, since running a full | ||
| * markdown parse is much slower (and there's never | ||
| * a case where'd have extremely complex markdown | ||
| * within a sidebar like this) | ||
| * | ||
| * @param {string} label - Raw heading text. | ||
| * @returns {import('preact').ComponentChildren} | ||
| */ | ||
| export const renderLabel = label => { | ||
| const segments = label.split('`'); | ||
|
|
||
| if (segments.length === 1) { | ||
| return label; | ||
| } | ||
|
|
||
| // Odd-indexed segments sat between a pair of backticks. | ||
| return segments.map((segment, index) => | ||
| index % 2 ? ( | ||
| <code key={`code:${segment}`}>{segment}</code> | ||
| ) : ( | ||
| <span key={`text:${segment}`}>{segment}</span> | ||
| ) | ||
| ); | ||
| }; |


Uh oh!
There was an error while loading. Please reload this page.