From 3d7381446d695353b5b315065afa602e2202a0ed Mon Sep 17 00:00:00 2001 From: Andrew Spott Date: Tue, 17 Oct 2023 12:26:06 -0600 Subject: [PATCH] =?UTF-8?q?Changed=20globbing.=20=20Now=20doesn't=20clobbe?= =?UTF-8?q?r=20a=20users=20glob=20if=20they=20want=20to=20a=E2=80=A6=20(#4?= =?UTF-8?q?96)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * Changed globbing. Now doesn't clobber a users glob if they want to add it, but will (if just given a directory), add a recursive glob. Note: python's glob engine doesn't support `{}` globing, a future option is to warn if that is included. * Fix typo in globformat variable * Use older glob pattern for plaintext files --------- Co-authored-by: Saba --- .../interface/web/content_type_input.html | 26 +++++++++++++------ 1 file changed, 18 insertions(+), 8 deletions(-) diff --git a/src/khoj/interface/web/content_type_input.html b/src/khoj/interface/web/content_type_input.html index 3ef512f8..1f0dfa76 100644 --- a/src/khoj/interface/web/content_type_input.html +++ b/src/khoj/interface/web/content_type_input.html @@ -34,7 +34,7 @@ {% else %} {% for input_filter in current_config['input_filter'] %} - + {% endfor %} {% endif %} @@ -106,17 +106,18 @@ submit.addEventListener("click", function(event) { event.preventDefault(); - let globFormat = "**/*." + let globFormat = "**/*" let suffixes = []; if ('{{content_type}}' == "markdown") - suffixes = ["md", "markdown"] + suffixes = [".md", ".markdown"] else if ('{{content_type}}' == "org") - suffixes = ["org"] + suffixes = [".org"] else if ('{{content_type}}' === "pdf") - suffixes = ["pdf"] + suffixes = [".pdf"] else if ('{{content_type}}' === "plaintext") - suffixes = ['*'] + suffixes = ['.*'] + let globs = suffixes.map(x => `${globFormat}${x}`) var inputFileNodes = document.getElementsByName("input-files"); var inputFiles = getValidInputNodes(inputFileNodes).map(node => node.value); @@ -124,10 +125,19 @@ var inputFilter = []; var nodes = getValidInputNodes(inputFilterNodes); + + // A regex that checks for globs in the path. If they exist, + // we are going to just not add our own globing. If they don't, + // then we will assume globbing should be done. + const glob_regex = /([*?\[\]])/; if (nodes.length > 0) { for (var i = 0; i < nodes.length; i++) { - for (var j = 0; j < suffixes.length; j++) { - inputFilter.push(nodes[i].value + globFormat + suffixes[j]); + for (var j = 0; j < globs.length; j++) { + if (glob_regex.test(nodes[i].value)) { + inputFilter.push(nodes[i].value); + } else { + inputFilter.push(nodes[i].value + globs[j]); + } } } }