How do I get the uuid of a page?

I have tried reading the uuid property of getPage but that doesn’t seem to be it (it seems to be the uuid of the last block on the page).

What do you mean? The uuid entry in the result of calling getPage ?

This doesn’t make sense. Could you provide some code?

var linkedPage = await logseq.Editor.getPage(linkedPageName);
logseq.App.pushState('page', { name: linkedPage?.uuid });

This does not work, I believe because the uuid is not the page uuid. The reason that I don’t think it is the page uuid is that I tried inserting a block after it, and the block got inserted after the last block on the page.

logseq.Editor.insertBlock(linkedPage!.uuid, "A new block.", {
        before: false
});

If there are no blocks on the page this works, however not if there are blocks.

  • This is the correct uuid.
  • What confuses you is the (admittedly confusing) semantics of insertBlock.
    • i.e. to insert means to append
  • This is the behavior for all blocks.
    • Pages are simply root-level blocks.
  • In order to prepend, should:
    • get the first child
    • insert with both options before and sibling

That explains the code that I was able to get working:

var linkedPage = await logseq.Editor.getPage(linkedPageName);
var linkedPageBlocksTree = await logseq.Editor.getPageBlocksTree(linkedPageName);
if (linkedPageBlocksTree[0] !== undefined) {
  logseq.Editor.insertBlock(linkedPageBlocksTree[0]!.uuid, currentPageProperties, {
    before: true
  });
} 
else {
  logseq.Editor.insertBlock(linkedPage!.uuid, currentPageProperties, {
    before: false
  });
}