Change function results and relative locations of JavaScript files

This commit is contained in:
Ethan Yoo 2022-12-29 10:28:20 -05:00
parent 0ee02bbe37
commit 0fe00bf114
Signed by: ethan
GPG Key ID: 70596474C5D20F85
1 changed files with 7 additions and 11 deletions

View File

@ -1,4 +1,4 @@
// static/scripts/fixedsearch/fixedsearch.js // js/fixedsearch.js
/*-------------------------------------------------------------- /*--------------------------------------------------------------
fixedsearch Super fast, client side search for Hugo.io with Fusejs.io fixedsearch Super fast, client side search for Hugo.io with Fusejs.io
based on https://gist.github.com/cmod/5410eae147e4318164258742dd053993 based on https://gist.github.com/cmod/5410eae147e4318164258742dd053993
@ -67,7 +67,7 @@ fixedsearch = function(){
} }
// Use Enter (13) to move to the first result // Use Enter (13) to move to the first result
if (e.keyCode == 13) { if (e.keyCode == 13) {
if (results_available && document.activeElement == search_input) { if (results_available && document.activeElement == search_input) {
e.preventDefault(); // stop form from being submitted e.preventDefault(); // stop form from being submitted
first.focus(); first.focus();
@ -75,7 +75,7 @@ fixedsearch = function(){
} }
// Use Backspace (8) to switch back to the search input // Use Backspace (8) to switch back to the search input
if (e.keyCode == 8) { if (e.keyCode == 8) {
if (document.activeElement != search_input) { if (document.activeElement != search_input) {
e.preventDefault(); // stop browser from going back in history e.preventDefault(); // stop browser from going back in history
search_input.focus(); search_input.focus();
@ -173,10 +173,10 @@ fixedsearch = function(){
--------------------------------------------------------------*/ --------------------------------------------------------------*/
function search_init() { function search_init() {
if (first_run) { if (first_run) {
load_script(window.location.origin + '/scripts/fixedsearch/fuse.js').then(() => { load_script(window.location.origin + '/js/fuse.js').then(() => {
search_input.value = ""; // reset default value search_input.value = ""; // reset default value
first_run = false; // let's never do this again first_run = false; // let's never do this again
fetch_JSON(search_form.getAttribute('data-language-prefix') + '/index.json', function(data){ fetch_JSON('/index.json', function(data){
var options = { // fuse.js options; check fuse.js website for details var options = { // fuse.js options; check fuse.js website for details
shouldSort: true, shouldSort: true,
location: 0, location: 0,
@ -187,9 +187,7 @@ fixedsearch = function(){
'permalink', 'permalink',
'title', 'title',
'date', 'date',
'summary', 'description',
'section',
'categories',
'tags' 'tags'
] ]
}; };
@ -223,9 +221,7 @@ fixedsearch = function(){
`<li><a href="${results[item].item.permalink}" tabindex="0"> `<li><a href="${results[item].item.permalink}" tabindex="0">
<span class="title">${results[item].item.title}</span> <span class="title">${results[item].item.title}</span>
<span class="date">${results[item].item.date}</span> <span class="date">${results[item].item.date}</span>
<span class="summary">${results[item].item.summary}</span> <span class="description">${results[item].item.description}</span>
<span class="section">${results[item].item.section}</span>
<span class="categories">${results[item].item.categories.join(', ')}</span>
<span class="tags">${results[item].item.tags.join(', ')}</span> <span class="tags">${results[item].item.tags.join(', ')}</span>
</a></li>`; </a></li>`;
} }