logseq / plugins

Documentation site of Logseq plugins
https://plugins-doc.logseq.com/
20 stars 2 forks source link

🧩 logseq.Editor.getPage #10

Open utterances-bot opened 1 year ago

utterances-bot commented 1 year ago

https://plugins-doc.logseq.com/logseq/Editor/getPage

YU000jp commented 1 year ago

Get journalDay as Date (For TypeScript)

const getJournalDayDate = (str: string): Date => new Date(
  Number(str.slice(0, 4)), //year
  Number(str.slice(4, 6)) - 1, //month 0-11
  Number(str.slice(6)) //day
);

const { journalDay } = await logseq.Editor.getCurrentPage() as PageEntity;
if (!journalDay) {
  console.error('journalDay is undefined');
  return;
}
const targetDate:Date = getJournalDayDate(String(journalDay)) as Date;

getCurrentPage() or getPage(uuid)