The TreeView plug by joekrill shows your pages as a tree in a side panel. On a phone that panel takes over the screen. This setup keeps it as a sidebar on a desktop and makes it a pop-up on the phone, opened from a button in the top bar. On the phone, the pop-up closes by itself after you pick a page. System pages are left out of the tree.

Setup

  1. Open your CONFIG page.
  2. Add a space-lua code block (three backticks followed by space-lua) and paste this code inside it. If you already have a plugs list, add the TreeView line to it instead of making a second one.
-- true on a phone-sized screen (700px wide or less)
function treeviewIsPhone()
  return js.window.innerWidth <= 700
end

config.set {
  plugs = {
    "github:joekrill/silverbullet-treeview/treeview.plug.js"
  },
  treeview = {
    position = treeviewIsPhone() and "modal" or "lhs",
    exclusions = {
      { type = "regex", rule = "^(?:CONFIG|STYLES|Library|Repositories).*$" }
    }
  }
}
  1. Add a second space-lua block with the button and the auto close:
actionButton.define {
  icon = "sidebar",
  description = "Toggle Tree View",
  mobile = true,
  run = function()
    editor.invokeCommand("Tree View: Toggle")
  end
}

event.listen {
  name = "editor:pageLoaded",
  run = function()
    -- only the phone pop-up closes; the desktop sidebar stays open
    if not treeviewIsPhone() then return end
    -- wait a moment: the Tree View plug reopens itself on page load,
    -- so hiding at the same instant loses the race
    js.window.setTimeout(function()
      system.invokeFunction("treeview.hide")
    end, 400)
  end
}
  1. Run the command Plugs: Update to install the plug, then System: Reload.

Use

  • On a desktop, the tree is a sidebar on the left. The sidebar button in the top bar opens and closes it.
  • On the phone, the same button is in the top bar's overflow menu. It opens the tree as a pop-up, which closes once you pick a page.
  • The phone check runs when a page loads. If you resize a desktop window, reload to switch.
  • To hide more pages from the tree, add their names to the list in the rule line, separated by |.