mirror of
https://github.com/khoj-ai/khoj.git
synced 2024-11-27 17:35:07 +01:00
Improve rendering search results of plugin content types in khoj.el
Render only the entry from plugin search response instead of raw json
This commit is contained in:
parent
f3f24387ec
commit
c2814fce58
1 changed files with 13 additions and 1 deletions
|
@ -244,6 +244,18 @@ Use `which-key` if available, else display simple message in echo area"
|
|||
;; remove trailing (, ) or SPC from extracted entries string
|
||||
(replace-regexp-in-string "[\(\) ]$" ""))))
|
||||
|
||||
(defun khoj--extract-entries (json-response query)
|
||||
"Convert JSON-RESPONSE, QUERY from API to text entries."
|
||||
(thread-last json-response
|
||||
;; extract and render entries from API response
|
||||
(mapcar (lambda (args) (format "%s\n\n" (cdr (assoc 'entry args)))))
|
||||
;; Set query as heading in rendered results buffer
|
||||
(format "# Query: %s\n\n%s\n" query)
|
||||
;; remove leading (, ) or SPC from extracted entries string
|
||||
(replace-regexp-in-string "^[\(\) ]" "")
|
||||
;; remove trailing (, ) or SPC from extracted entries string
|
||||
(replace-regexp-in-string "[\(\) ]$" "")))
|
||||
|
||||
(defun khoj--buffer-name-to-content-type (buffer-name)
|
||||
"Infer content type based on BUFFER-NAME."
|
||||
(let ((enabled-content-types (khoj--get-enabled-content-types))
|
||||
|
@ -296,7 +308,7 @@ Use `which-key` if available, else display simple message in echo area"
|
|||
((equal content-type "markdown") (khoj--extract-entries-as-markdown json-response query))
|
||||
((equal content-type "ledger") (khoj--extract-entries-as-ledger json-response query))
|
||||
((equal content-type "image") (khoj--extract-entries-as-images json-response query))
|
||||
(t (format "%s" json-response))))
|
||||
(t (khoj--extract-entries json-response query))))
|
||||
(cond ((equal content-type "org") (progn (org-mode)
|
||||
(visual-line-mode)))
|
||||
((equal content-type "markdown") (progn (markdown-mode)
|
||||
|
|
Loading…
Reference in a new issue