-- Função para gerar páginas recentes (versão DOM vertical)
function miniPaginasRecentesV(nPaginas)
nPanPaginas = nPaginas or 12
-- Buscar últimas 10 páginas modificadas
local recentPages = query[[
from index.tag "page"
order by lastModified desc
limit nPaginas
]]
-- Array para as páginas
local pagesContainer = {}
-- Gerar cada página como item vertical
for i, page in ipairs(recentPages) do
local pageName = page.name or ""
local displayName = string.match(pageName or "", "([^/]+)$") or pageName or ""
-- Calcular horas desde última modificação
local hoursAgo = ""
if page.lastModified then
local now = os.time()
-- Converter string ISO "yyyy-mm-ddThh:mm:ss.mmm" para timestamp
local year, month, day, hour, min, sec, msec = string.match(
page.lastModified,
"(%d+)%-(%d+)%-(%d+)T(%d+):(%d+):(%d+).(%d+)"
)
if year then
local modifiedTime = os.time({
year = tonumber(year),
month = tonumber(month),
day = tonumber(day),
hour = tonumber(hour),
min = tonumber(min),
sec = tonumber(sec)
})
local hoursDiff = math.floor(os.difftime(now, modifiedTime) / 3600)
if hoursDiff >= 0 then
hoursAgo = tostring(hoursDiff)
end
end
end
-- Criar item da página
local pageItem = dom.div {
style = [[
padding: 5px 9px;
background-color: #f8f9fa;
color: #666;
cursor: pointer;
font-size: 12px;
border-bottom: 1px solid #eee;
white-space: nowrap;
]],
["data-page"] = pageName,
onclick = function()
editor.navigate(pageName)
end,
["xonclick"] = string.format("syscall('editor.navigate','%s')", pageName),
title = pageName,
-- Nome da página com expoente de horas
displayName,
dom.sup {
style = "font-size: 0.7em; vertical-align: super; margin-left: 3px; color: #999;",
hoursAgo..'h'
}
}
table.insert(pagesContainer, pageItem)
end
-- Container principal
local html = dom.div {
style = "padding: 5px; font-family: sans-serif;",
dom.h3 {
style = "margin: 0 0 10px 0; font-size: 14px;",
"✍🏻 Páginas Recentes"
},
unpack(pagesContainer)
}
html = js.tojs(html).outerHTML
html = html:gsub('xonclick=', 'onclick=')
editor.showPanel("rhs", 0.1, html, script)
my.print('showRHSPanelDinamico carregado')
end