Add Basic HTML Rendering of Org-Mode Results

This commit is contained in:
Debanjum Singh Solanky
2022-07-28 05:29:26 +04:00
parent 1da44d4dfe
commit 965a93a2f2
2 changed files with 1841 additions and 8 deletions

View File

@@ -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) {
@@ -30,9 +47,9 @@
.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

File diff suppressed because it is too large Load Diff