-
-
Notifications
You must be signed in to change notification settings - Fork 83
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix: Search bar, update styles (#264)
Style Fix: Last minute touch up
- Loading branch information
1 parent
9b49e54
commit 77127ca
Showing
7 changed files
with
295 additions
and
103 deletions.
There are no files selected for viewing
This file contains 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 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,53 @@ | ||
//copied from https://github.com/cmfcmf/docusaurus-search-local | ||
import Mark from "mark.js"; | ||
import { useEffect, useState } from "react"; | ||
import { useLocation } from "@docusaurus/router"; | ||
import useDocusaurusContext from "@docusaurus/useDocusaurusContext"; | ||
import { useHistory } from "@docusaurus/router"; | ||
|
||
export function HighlightSearchResults() { | ||
const location = useLocation(); | ||
const history = useHistory(); | ||
const { | ||
siteConfig: { baseUrl }, | ||
} = useDocusaurusContext(); | ||
|
||
const [highlightData, setHighlightData] = useState({ wordToHighlight: '', isTitleSuggestion: false , titleText: '' }); | ||
|
||
useEffect(() => { | ||
if ( | ||
!location.state?.highlightState || | ||
location.state.highlightState.wordToHighlight.length === 0 | ||
) { | ||
return; | ||
} | ||
setHighlightData(location.state.highlightState); | ||
|
||
const { highlightState, ...state } = location.state; | ||
history.replace({ | ||
...location, | ||
state, | ||
}); | ||
}, [location.state?.highlightState, history, location]); | ||
|
||
useEffect(() => { | ||
if (highlightData.wordToHighlight.length === 0) { | ||
return; | ||
} | ||
|
||
// Make sure to also adjust parse.js if you change the top element here. | ||
const root = document.getElementsByTagName("article")[0] ?? document.getElementsByTagName("main")[0] ; | ||
if (!root) { | ||
return; | ||
} | ||
|
||
const mark = new Mark(root); | ||
const options = { | ||
ignoreJoiners: true, | ||
}; | ||
mark.mark(highlightData.wordToHighlight , options); | ||
return () => mark.unmark(options); | ||
}, [highlightData, baseUrl]); | ||
|
||
return null; | ||
} |
This file contains 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 was deleted.
Oops, something went wrong.
Oops, something went wrong.