@@ -2663,27 +2663,30 @@ function ZoteroSource:get_name()
26632663end
26642664
26652665function ZoteroSource:get_items()
2666- -- Replace 0 with your numeric Zotero user ID if needed.
2667- local url = 'http://localhost:23119/api/users/0/items?format=json'
2668- local ok, result = pcall(vim.fn.system, { 'curl', '-s', url })
2669- if not ok or vim.v.shell_error ~= 0 then
2670- return {}
2671- end
2672- local data = vim.json.decode(result or '') or {}
2673- local items = {}
2674- for _, entry in ipairs(data) do
2675- local d = entry.data or {}
2676- if d.citationKey then
2677- local creators = d.creators or {}
2678- local author = (creators[1] or {}).lastName or ''
2679- local year = (d.date or ''):match('%d%d%d%d') or ''
2680- table.insert(items, {
2681- key = d.citationKey,
2682- description = author .. year .. ' ' .. (d.title or ''),
2683- })
2666+ local curl = require('plenary.curl')
2667+ local res = curl.get {
2668+ url = 'http://localhost:23119/api/users/0/items?format=json',
2669+ accept = 'application/json',
2670+ }
2671+ if res.status == 200 then
2672+ local data = vim.json.decode(res.body or '') or {}
2673+ local items = {}
2674+ for _, entry in ipairs(data) do
2675+ local d = entry.data or {}
2676+ if d.citationKey then
2677+ local creators = d.creators or {}
2678+ local author = (creators[1] or {}).lastName or ''
2679+ local year = (d.date or ''):match('%d%d%d%d') or ''
2680+ table.insert(items, {
2681+ key = d.citationKey,
2682+ description = author .. year .. ' ' .. (d.title or ''),
2683+ })
2684+ end
26842685 end
2686+ return items
2687+ else
2688+ return {}
26852689 end
2686- return items
26872690end
26882691
26892692require('orgmode').setup({
0 commit comments