-
Notifications
You must be signed in to change notification settings - Fork 79
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
255eb43
commit 426e313
Showing
8 changed files
with
3,208 additions
and
3,241 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
Large diffs are not rendered by default.
Oops, something went wrong.
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
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 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