hephaestus/heph.nvim/lua/heph/home.lua

27 lines
848 B
Lua
Raw Normal View History

--- The home / index page (tech-spec §8): a single designated `doc` that is the
--- base landing page of the knowledge base — a stable place to grow a map of
--- content. Open-or-create by title, so the first `:Heph home` mints it and
--- every later one returns the same doc.
local rpc = require("heph.rpc")
local M = {}
--- Open (creating if absent) the home page titled `title` (default "Home").
--- Returns the node.
function M.open(title)
title = (title and #title > 0) and title or "Home"
local node = rpc.call("node.resolve", { title = title })
if not node then
node = rpc.call("node.create", {
kind = "doc",
title = title,
body = "# " .. title .. "\n\n",
})
require("heph.util").notify("created home page [[" .. title .. "]]")
end
require("heph.node").open(node.id)
return node
end
return M