This commit is contained in:
GitJournal 2024-01-10 05:52:16 +08:00
parent 8f8ff4d595
commit 26382832f2
2 changed files with 25 additions and 3 deletions

View File

@ -1,5 +1,6 @@
<!DOCTYPE html>
<html lang="en">
<!-- TODO: add debug flag to pop up alert window when error occurs -->
<head>
<meta charset="UTF-8">
@ -395,6 +396,7 @@
// const RESULT_LIMIT = 50;
const progressOverlay = document.getElementById('progress-overlay');
const progressBar = document.querySelector('.progress');
var isDebugMode = false;
function navigateToPage(base_filepath, language_id, project_id, detail_filepath = "") {
// Use a relative path to navigate to a specific page
let page_param = "codeview.html";
@ -580,6 +582,7 @@
const field = result.field; // "content"
const ids = result.result;
ids.forEach(id => {
id = id - 0 // to integer.
const data_type = data[id].type;
const file_id = data[id].file_id;
if (searchResultItems[file_id] === undefined) {
@ -594,7 +597,11 @@
if (detail_types.indexOf(data_type) != -1) {
const pair_id = ((data_type === "code") ? id : (id - 1));
if (searchResultItems[file_id].pairs[pair_id] === undefined) {
searchResultItems[file_id].pairs[pair_id] = { "left": data[pair_id].content, "right": data[pair_id - 1].content, "location": data[pair_id].location };
// console.log(pair_id, pair_id+1, data_type, data[pair_id].location)
let mit = { "left": data[pair_id].content, "right": data[pair_id + 1].content, "location": data[pair_id].location }
// let mit = { "left": data[pair_id].content, "right": data[pair_id - 1].content, "location": data[pair_id].location }
// console.log(mit)
searchResultItems[file_id].pairs[pair_id] = mit;
}
}
// listItem.textContent = `[${field}][${data_type}] ${data[id][field]}`;
@ -717,7 +724,20 @@
hasInputEvent = false;
if (!isSearchRunning) {
isSearchRunning = true;
searchInputEventListener();
try {
searchInputEventListener();
} catch (error) {
// Print exception info
console.error(error);
if (isDebugMode) {
// Show alert window in debug mode
console.log(error.message);
alert("An error occurred when searching: " + error.message);
} else {
// Raise exception when not in debug mode
throw error;
}
}
isSearchRunning = false;
}
}
@ -747,6 +767,8 @@
const queryParams = getQueryParams(window.location.search);
const query_from_url = queryParams.q;
const file_path_from_url = queryParams.file;
isDebugMode = queryParams.debug == 'true';
if (isDebugMode){console.log("You are in debug mode.")}
if (query_from_url != null || query_from_url != undefined) {
setTextAndTriggerInputEvent(query_from_url)
} else if (file_path_from_url != null || file_path_from_url != undefined) {

View File

@ -7,7 +7,7 @@
"0": {
"filepath": "/README.md",
"entry_id": 0,
"language_id": "plain-text"
"language_id": "markdown"
},
"1": {
"filepath": "/hubconf.py",