mirror of
https://github.com/khoaliber/khoj.git
synced 2026-03-08 05:39:13 +00:00
Demarcate different results with a border box
- Add back support for searching by type Github - Remove custom class name in markdown js file
This commit is contained in:
10
src/khoj/interface/web/assets/markdown-it.min.js
vendored
10
src/khoj/interface/web/assets/markdown-it.min.js
vendored
@@ -3227,16 +3227,6 @@
|
|||||||
result += (token.nesting === -1 ? "</" : "<") + token.tag;
|
result += (token.nesting === -1 ? "</" : "<") + token.tag;
|
||||||
// Encode attributes, e.g. `<img src="foo"`
|
// Encode attributes, e.g. `<img src="foo"`
|
||||||
result += this.renderAttrs(token);
|
result += this.renderAttrs(token);
|
||||||
|
|
||||||
if (token.tag === "img" && token.attrs) {
|
|
||||||
for (var i = 0; i < token.attrs.length; i++) {
|
|
||||||
if (token.attrs[i][0] === "src") {
|
|
||||||
if (token.attrs[i][1].includes("avatar")) {
|
|
||||||
result += ' class="md-avatar"';
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
// Add a slash for self-closing tags, e.g. `<img src="foo" /`
|
// Add a slash for self-closing tags, e.g. `<img src="foo" /`
|
||||||
if (token.nesting === 0 && options.xhtmlOut) {
|
if (token.nesting === 0 && options.xhtmlOut) {
|
||||||
result += " /";
|
result += " /";
|
||||||
|
|||||||
@@ -36,11 +36,15 @@
|
|||||||
function render_markdown(query, data) {
|
function render_markdown(query, data) {
|
||||||
var md = window.markdownit();
|
var md = window.markdownit();
|
||||||
return data.map(function (item) {
|
return data.map(function (item) {
|
||||||
|
let rendered = "";
|
||||||
if (item.additional.file.startsWith("http")) {
|
if (item.additional.file.startsWith("http")) {
|
||||||
lines = item.entry.split("\n");
|
lines = item.entry.split("\n");
|
||||||
return md.render(`${lines[0]}\t[*](${item.additional.file})\n${lines.slice(1).join("\n")}`);
|
rendered = md.render(`${lines[0]}\t[*](${item.additional.file})\n${lines.slice(1).join("\n")}`);
|
||||||
}
|
}
|
||||||
return `<div class="results-markdown">` + md.render(`${item.entry}`) + `</div>`;
|
else {
|
||||||
|
rendered = md.render(`${item.entry}`);
|
||||||
|
}
|
||||||
|
return `<div class="results-markdown">` + rendered + `</div>`;
|
||||||
}).join("\n");
|
}).join("\n");
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -59,29 +63,22 @@
|
|||||||
}).join("\n");
|
}).join("\n");
|
||||||
}
|
}
|
||||||
|
|
||||||
function render_mutliple(query, data, type) {
|
function render_multiple(query, data, type) {
|
||||||
let org_files = data.filter((item) => item.additional.file.endsWith(".org"));
|
|
||||||
let md_files = data.filter((item) => item.additional.file.endsWith(".md"));
|
|
||||||
let pdf_files = data.filter((item) => item.additional.file.endsWith(".pdf"));
|
|
||||||
let issue_files = data.filter((item) => item.additional.file.includes("issues") && item.additional.file.includes("github.com"));
|
|
||||||
|
|
||||||
let html = "";
|
let html = "";
|
||||||
if (org_files.length > 0) {
|
data.forEach(item => {
|
||||||
html += render_org(query, org_files, type);
|
if (item.additional.file.endsWith(".org")) {
|
||||||
|
html += render_org(query, [item], "org-");
|
||||||
|
} else if (
|
||||||
|
item.additional.file.endsWith(".md") ||
|
||||||
|
item.additional.file.endsWith(".markdown") ||
|
||||||
|
(item.additional.file.includes("issues") && item.additional.file.includes("github.com"))
|
||||||
|
)
|
||||||
|
{
|
||||||
|
html += render_markdown(query, [item]);
|
||||||
|
} else if (item.additional.file.endsWith(".pdf")) {
|
||||||
|
html += render_pdf(query, [item]);
|
||||||
}
|
}
|
||||||
|
});
|
||||||
if (md_files.length > 0) {
|
|
||||||
html += render_markdown(query, md_files);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (issue_files.length > 0) {
|
|
||||||
html += render_markdown(query, issue_files);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (pdf_files.length > 0) {
|
|
||||||
html += render_pdf(query, pdf_files);
|
|
||||||
}
|
|
||||||
|
|
||||||
return html;
|
return html;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -100,11 +97,25 @@
|
|||||||
} else if (type === "pdf") {
|
} else if (type === "pdf") {
|
||||||
results = render_pdf(query, data);
|
results = render_pdf(query, data);
|
||||||
} else if (type === "github" || type === "all") {
|
} else if (type === "github" || type === "all") {
|
||||||
results = render_mutliple(query, data, type);
|
results = render_multiple(query, data, type);
|
||||||
} else {
|
} else {
|
||||||
results = data.map((item) => `<div class="results-plugin">` + `<p>${item.entry}</p>` + `</div>`).join("\n")
|
results = data.map((item) => `<div class="results-plugin">` + `<p>${item.entry}</p>` + `</div>`).join("\n")
|
||||||
}
|
}
|
||||||
return `<div id="results-${type}">${results}</div>`;
|
|
||||||
|
// Any POST rendering goes here.
|
||||||
|
|
||||||
|
let renderedResults = document.createElement("div");
|
||||||
|
renderedResults.id = `results-${type}`;
|
||||||
|
renderedResults.innerHTML = results;
|
||||||
|
|
||||||
|
// For all elements that are of type img in the results html and have a src with 'avatar' in the URL, add the class 'avatar'
|
||||||
|
// This is used to make the avatar images round
|
||||||
|
let images = renderedResults.querySelectorAll("img[src*='avatar']");
|
||||||
|
for (let i = 0; i < images.length; i++) {
|
||||||
|
images[i].classList.add("avatar");
|
||||||
|
}
|
||||||
|
|
||||||
|
return renderedResults.outerHTML;
|
||||||
}
|
}
|
||||||
|
|
||||||
function search(rerank=false) {
|
function search(rerank=false) {
|
||||||
@@ -277,7 +288,6 @@
|
|||||||
margin: 0px;
|
margin: 0px;
|
||||||
background: #f8fafc;
|
background: #f8fafc;
|
||||||
color: #475569;
|
color: #475569;
|
||||||
text-align: center;
|
|
||||||
font-family: roboto, karma, segoe ui, sans-serif;
|
font-family: roboto, karma, segoe ui, sans-serif;
|
||||||
font-size: 20px;
|
font-size: 20px;
|
||||||
font-weight: 300;
|
font-weight: 300;
|
||||||
@@ -388,12 +398,18 @@
|
|||||||
text-decoration: none;
|
text-decoration: none;
|
||||||
}
|
}
|
||||||
|
|
||||||
img.md-avatar {
|
img.avatar {
|
||||||
width: 20px;
|
width: 20px;
|
||||||
height: 20px;
|
height: 20px;
|
||||||
border-radius: 50%;
|
border-radius: 50%;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
div.results-markdown,
|
||||||
|
div.results-org,
|
||||||
|
div.results-pdf {
|
||||||
|
border: black 1px solid;
|
||||||
|
}
|
||||||
|
|
||||||
</style>
|
</style>
|
||||||
|
|
||||||
</html>
|
</html>
|
||||||
|
|||||||
@@ -1,6 +1,7 @@
|
|||||||
# Standard Packages
|
# Standard Packages
|
||||||
import logging
|
import logging
|
||||||
import time
|
import time
|
||||||
|
from datetime import datetime
|
||||||
from typing import Dict, List, Union
|
from typing import Dict, List, Union
|
||||||
|
|
||||||
# External Packages
|
# External Packages
|
||||||
@@ -235,7 +236,7 @@ class GithubToJsonl(TextToJsonl):
|
|||||||
return result
|
return result
|
||||||
|
|
||||||
for comment in raw_comments:
|
for comment in raw_comments:
|
||||||
created_at = comment["created_at"].split("T")[0]
|
created_at = datetime.strptime(comment["created_at"], "%Y-%m-%dT%H:%M:%SZ").strftime("%Y-%m-%d %H:%M")
|
||||||
commenter = comment["user"]["login"]
|
commenter = comment["user"]["login"]
|
||||||
commenter_url = comment["user"]["html_url"]
|
commenter_url = comment["user"]["html_url"]
|
||||||
comment_url = comment["html_url"]
|
comment_url = comment["html_url"]
|
||||||
|
|||||||
@@ -216,6 +216,20 @@ async def search(
|
|||||||
)
|
)
|
||||||
]
|
]
|
||||||
|
|
||||||
|
if (t == SearchType.Github or t == SearchType.All) and state.model.github_search:
|
||||||
|
# query github issues
|
||||||
|
search_futures += [
|
||||||
|
executor.submit(
|
||||||
|
text_search.query,
|
||||||
|
user_query,
|
||||||
|
state.model.github_search,
|
||||||
|
question_embedding=encoded_asymmetric_query,
|
||||||
|
rank_results=r or False,
|
||||||
|
score_threshold=score_threshold,
|
||||||
|
dedupe=dedupe or True,
|
||||||
|
)
|
||||||
|
]
|
||||||
|
|
||||||
if (t == SearchType.Pdf or t == SearchType.All) and state.model.pdf_search:
|
if (t == SearchType.Pdf or t == SearchType.All) and state.model.pdf_search:
|
||||||
# query pdf files
|
# query pdf files
|
||||||
search_futures += [
|
search_futures += [
|
||||||
|
|||||||
Reference in New Issue
Block a user