diff --git a/doc/tags b/doc/tags index 45bc78e..f9493f3 100644 --- a/doc/tags +++ b/doc/tags @@ -1,5 +1,6 @@ drash-drash.nvim drash.txt /*drash-drash.nvim* drash-drash.nvim-development drash.txt /*drash-drash.nvim-development* +drash-drash.nvim-installation drash.txt /*drash-drash.nvim-installation* drash-links drash.txt /*drash-links* drash-table-of-contents drash.txt /*drash-table-of-contents* drash.txt drash.txt /*drash.txt* diff --git a/lua/drash/sefaria.lua b/lua/drash/sefaria.lua index 4974887..b8b6d79 100644 --- a/lua/drash/sefaria.lua +++ b/lua/drash/sefaria.lua @@ -1,5 +1,5 @@ local plenary_curl = require('plenary.curl') -local drash_util = require('drash.util') +local drash_utils = require('drash.util') local M = {} @@ -14,7 +14,6 @@ M.get_calendar = function() local body = response.body local data = vim.json.decode(body) - return data end @@ -25,9 +24,10 @@ M.post_search = function(query) local url = 'https://www.sefaria.org/api/search-wrapper' local response = plenary_curl.post(url, { - body = '{ "query":"' .. query .. '" }', + body = '{ "query":"' .. query .. '", "source_proj":true }', headers = { ['Content-Type'] = 'application/json', + accept = 'application/json', }, }) @@ -35,28 +35,40 @@ M.post_search = function(query) return nil end - local body = response.body + local data = vim.fn.json_decode(response.body) + return data +end - local data = vim.json.decode(body) +M.post_find_refs = function(title, body) + local url = 'https://www.sefaria.org/api/find-refs' + local response = plenary_curl.post(url, { + body = '{ "text": {"title":"' .. title .. '", "body":"' .. body .. '"}, "lang":"en" }', + headers = { + ['Content-Type'] = 'application/json', + }, + }) + + if response.status ~= 200 then + return nil + end + + local data = vim.fn.json_decode(response.body) return data end M.get_text = function(id) - id = drash_util.url_encode(id) - local url = 'https://www.sefaria.org/api/v3/texts/' - .. id - .. '?version=english&return_format=text_only' - print(url) + id = drash_utils.url_encode(id) + local url = 'https://www.sefaria.org/api/v3/texts/' .. id - local response = plenary_curl.get(url) + local response = plenary_curl.get(url, { + query = { version = 'english', return_format = 'text_only' }, + }) if response.status ~= 200 then return nil end - local body = response.body - local data = vim.json.decode(body) - + local data = vim.fn.json_decode(response.body) return data end diff --git a/lua/telescope/_extensions/drash.lua b/lua/telescope/_extensions/drash.lua index c98c6b6..95d651c 100644 --- a/lua/telescope/_extensions/drash.lua +++ b/lua/telescope/_extensions/drash.lua @@ -5,15 +5,12 @@ local finders = require('telescope.finders') local actions = require('telescope.actions') local action_state = require('telescope.actions.state') local previewers = require('telescope.previewers') -local make_entry = require('telescope.make_entry') local conf = require('telescope.config').values local M = {} M.search_sefaria = function(opts) opts = opts or { prompt = '' } - opts.entry_maker = make_entry.gen_from_string(opts) - print(opts.prompt) local searcher = function(prompt) if not prompt or prompt == '' then @@ -25,12 +22,7 @@ M.search_sefaria = function(opts) return {} end - local hits = search_list.hits.hits - for i, hit in ipairs(search_list.hits.hits) do - hits[i] = hit._id - end - - return hits + return search_list.hits.hits end pickers @@ -38,18 +30,25 @@ M.search_sefaria = function(opts) prompt_title = 'Search Sefaria', finder = finders.new_table({ results = searcher(opts.prompt), - entry_maker = opts.entry_maker, + entry_maker = function(entry) + return { + value = entry, + display = entry._id or entry.id, + ordinal = entry._id or entry.id, + } + end, }), attach_mappings = function(prompt_bufnr) actions.select_default:replace(function() local selected = action_state.get_selected_entry() - print(vim.inspect(selected)) actions.close(prompt_bufnr) if selected == nil then return end - local response = require('drash.sefaria').get_text(selected[1]) + local response = require('drash.sefaria').get_text( + selected.value._source.ref or selected.value.source.ref + ) local text = {} if response == nil then text = { 'Error fetching text' } @@ -68,7 +67,8 @@ M.search_sefaria = function(opts) end, previewer = previewers.new_buffer_previewer({ define_preview = function(self, entry) - local response = require('drash.sefaria').get_text(entry[1]) + local response = + require('drash.sefaria').get_text(entry.value._source.ref or entry.value.source.ref) local text = {} if response == nil then text = { 'Error fetching text' }