mirror of
https://github.com/khoaliber/khoj.git
synced 2026-03-09 21:29:11 +00:00
Add Basic HTML Rendering of Org-Mode Results
This commit is contained in:
@@ -3,6 +3,7 @@
|
|||||||
<meta charset="utf-8">
|
<meta charset="utf-8">
|
||||||
<title>Khoj</title>
|
<title>Khoj</title>
|
||||||
</head>
|
</head>
|
||||||
|
<script type="text/javascript" src="static/org.js"></script>
|
||||||
|
|
||||||
<script>
|
<script>
|
||||||
function render_image(item) {
|
function render_image(item) {
|
||||||
@@ -14,8 +15,24 @@
|
|||||||
</a>`
|
</a>`
|
||||||
}
|
}
|
||||||
|
|
||||||
function render_json(data) {
|
function render_org(query, data) {
|
||||||
return `<pre id="json">${JSON.stringify(data, null, 2)}</pre>`
|
var orgCode = `Query: ${query}\n` + data.map(function (item) {
|
||||||
|
return `${item.entry}`
|
||||||
|
}).join("\n")
|
||||||
|
var orgParser = new Org.Parser();
|
||||||
|
var orgDocument = orgParser.parse(orgCode);
|
||||||
|
var orgHTMLDocument = orgDocument.convert(Org.ConverterHTML);
|
||||||
|
return orgHTMLDocument.toString();
|
||||||
|
}
|
||||||
|
|
||||||
|
function render_json(data, query, type) {
|
||||||
|
if (type === "org") {
|
||||||
|
return render_org(query, data);
|
||||||
|
} else if (type === "image") {
|
||||||
|
return data.map(render_image).join('');
|
||||||
|
} else {
|
||||||
|
return `<pre id="json">${JSON.stringify(data, null, 2)}</pre>`;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
function search(rerank=false) {
|
function search(rerank=false) {
|
||||||
@@ -23,16 +40,16 @@
|
|||||||
type = document.getElementById("type").value;
|
type = document.getElementById("type").value;
|
||||||
console.log(query, type);
|
console.log(query, type);
|
||||||
url = type === "image"
|
url = type === "image"
|
||||||
? `/search?q=${query}&t=${type}&n=6`
|
? `/search?q=${query}&t=${type}&n=6`
|
||||||
: `/search?q=${query}&t=${type}&n=6&r=${rerank}`;
|
: `/search?q=${query}&t=${type}&n=6&r=${rerank}`;
|
||||||
fetch(url)
|
fetch(url)
|
||||||
.then(response => response.json())
|
.then(response => response.json())
|
||||||
.then(data => {
|
.then(data => {
|
||||||
console.log(data);
|
console.log(data);
|
||||||
document.getElementById("results").innerHTML =
|
document.getElementById("results").innerHTML =
|
||||||
type === "image"
|
`<div id=result-${type}>`
|
||||||
? data.map(render_image).join('')
|
+ render_json(data, query, type)
|
||||||
: render_json(data);
|
+ `</div>`;
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -127,7 +144,7 @@
|
|||||||
border-radius: 5px;
|
border-radius: 5px;
|
||||||
border: 1px solid #ccc;
|
border: 1px solid #ccc;
|
||||||
}
|
}
|
||||||
#results {
|
#results-image {
|
||||||
display: grid;
|
display: grid;
|
||||||
grid-template-columns: repeat(3, 1fr);
|
grid-template-columns: repeat(3, 1fr);
|
||||||
}
|
}
|
||||||
|
|||||||
1816
src/interface/web/org.js
Normal file
1816
src/interface/web/org.js
Normal file
File diff suppressed because it is too large
Load Diff
Reference in New Issue
Block a user