mirror of
https://github.com/McShelby/hugo-theme-relearn.git
synced 2024-11-23 07:47:54 +00:00
theme: fix snyk code issues #633
This commit is contained in:
parent
82d3a9aabf
commit
e6b50128e4
2 changed files with 8 additions and 2 deletions
|
@ -158,7 +158,8 @@ function initLunrJs() {
|
||||||
function search(term) {
|
function search(term) {
|
||||||
// Find the item in our index corresponding to the Lunr one to have more info
|
// Find the item in our index corresponding to the Lunr one to have more info
|
||||||
// Remove Lunr special search characters: https://lunrjs.com/guides/searching.html
|
// Remove Lunr special search characters: https://lunrjs.com/guides/searching.html
|
||||||
var searchTerm = lunr.tokenizer(term.replace(/[*:^~+-]/, ' ')).reduce( function(a,token){return a.concat(searchPatterns(token.str))}, []).join(' ');
|
term = term.replace( /[*:^~+-]/g, ' ' );
|
||||||
|
var searchTerm = lunr.tokenizer( term ).reduce( function(a,token){return a.concat(searchPatterns(token.str))}, []).join(' ');
|
||||||
return !searchTerm || !lunrIndex ? [] : lunrIndex.search(searchTerm).map(function(result) {
|
return !searchTerm || !lunrIndex ? [] : lunrIndex.search(searchTerm).map(function(result) {
|
||||||
return { index: result.ref, matches: Object.keys(result.matchData.metadata) }
|
return { index: result.ref, matches: Object.keys(result.matchData.metadata) }
|
||||||
});
|
});
|
||||||
|
|
|
@ -37,6 +37,10 @@ var psm;
|
||||||
var pst;
|
var pst;
|
||||||
var elc = document.querySelector('#body-inner');
|
var elc = document.querySelector('#body-inner');
|
||||||
|
|
||||||
|
function regexEscape( s ){
|
||||||
|
return s.replace( /[-[\]{}()*+?.,\\^$|#\s]/g, '\\$&' );
|
||||||
|
}
|
||||||
|
|
||||||
function documentFocus(){
|
function documentFocus(){
|
||||||
elc.focus();
|
elc.focus();
|
||||||
psc && psc.scrollbarY.focus();
|
psc && psc.scrollbarY.focus();
|
||||||
|
@ -1082,6 +1086,7 @@ function scrollToPositions() {
|
||||||
|
|
||||||
var search = sessionStorage.getItem( baseUriFull+'search-value' );
|
var search = sessionStorage.getItem( baseUriFull+'search-value' );
|
||||||
if( search && search.length ){
|
if( search && search.length ){
|
||||||
|
search = regexEscape( search );
|
||||||
var found = elementContains( search, elc );
|
var found = elementContains( search, elc );
|
||||||
var searchedElem = found.length && found[ 0 ];
|
var searchedElem = found.length && found[ 0 ];
|
||||||
if( searchedElem ){
|
if( searchedElem ){
|
||||||
|
@ -1169,7 +1174,7 @@ function highlight( es, words, options ){
|
||||||
return word != '';
|
return word != '';
|
||||||
});
|
});
|
||||||
words = words.map( function( word, i ){
|
words = words.map( function( word, i ){
|
||||||
return word.replace(/[-[\]{}()*+?.,\\^$|#\s]/g, "\\$&");
|
return regexEscape( word );
|
||||||
});
|
});
|
||||||
if( words.length == 0 ){ return this; }
|
if( words.length == 0 ){ return this; }
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue