Skip to content

Commit

Permalink
feat: zen quote
Browse files Browse the repository at this point in the history
  • Loading branch information
yetone committed Jul 23, 2024
1 parent afcc2a4 commit 07870ac
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 0 deletions.
2 changes: 2 additions & 0 deletions lua/layers/ui/configs.lua
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
local utils = require('layers.ui.utils')
local configs = {}

function configs.web_devicons()
Expand Down Expand Up @@ -162,6 +163,7 @@ function configs.dashboard()
db.setup({
theme = 'doom',
config = {
footer = { utils.get_quote() },
center = {
{
icon = '',
Expand Down
29 changes: 29 additions & 0 deletions lua/layers/ui/utils.lua
Original file line number Diff line number Diff line change
Expand Up @@ -20,4 +20,33 @@ M.hide_statusline = function()
api.nvim_set_option('laststatus', 3)
end

---Make a HTTP request to https://zenquotes.io to get a random quote
---@return string
M.get_quote = function()
local found_curl, curl = pcall(require, 'plenary.curl')
if not found_curl then
error('plenary not found')
return ''
end

local response = curl.get('https://zenquotes.io/api/random', {
headers = {
['User-Agent'] = 'curl/7.68.0',
},
})

if response.status ~= 200 then
error('Http failed with ' .. response.status, 1)
return ''
end

local json_data = vim.json.decode(response.body, {})
if json_data == {} or json_data == nil then
error('empty json from quotes API decoded')
return ''
end

return '󰟶 ' .. json_data[1].q .. ' - ' .. json_data[1].a
end

return M

0 comments on commit 07870ac

Please sign in to comment.