Skip to content

Instantly share code, notes, and snippets.

@ejkarne
Created December 23, 2025 21:32
Show Gist options
  • Select an option

  • Save ejkarne/c75ab3fa1eca4685f966baec7c6cec39 to your computer and use it in GitHub Desktop.

Select an option

Save ejkarne/c75ab3fa1eca4685f966baec7c6cec39 to your computer and use it in GitHub Desktop.
local userpatch = require("userpatch")
local function patchCoverBrowser(plugin)
local BookInfoManager = require("bookinfomanager")
local DocSettings = require("docsettings")
local doc_pages_cache = {}
local orig_getBookInfo = BookInfoManager.getBookInfo
function BookInfoManager:getBookInfo(filepath, do_cover_image, ...)
local bookinfo = orig_getBookInfo(self, filepath, do_cover_image, ...)
if not bookinfo then
return bookinfo
end
if bookinfo.pages == nil then
local cached = doc_pages_cache[filepath]
if cached ~= nil then
if cached > 0 then
bookinfo.pages = cached
end
return bookinfo
end
local pages = 0
local sidecar = DocSettings:findSidecarFile(filepath)
if sidecar then
local ok, docsettings = pcall(DocSettings.openSettingsFile, sidecar)
if ok and docsettings then
local n = tonumber(docsettings:readSetting("doc_pages"))
if n and n > 0 then
pages = n
end
end
end
doc_pages_cache[filepath] = pages
if pages > 0 then
bookinfo.pages = pages
end
end
return bookinfo
end
end
userpatch.registerPatchPluginFunc("coverbrowser", patchCoverBrowser)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment