Shortcuts for / commands?

I use /today, /cloze, and some others a lot, but because I have to switch keyboard layouts from different languages - I can’t type in English conveniently, and fast enough. The workflow is slow af.

At least for /today, I added this to config.js (doesn’t exist by default so you have to create it in the logseq folder).

Now I can press Cmd+T and it inserts the current date.

function getOrdinalSuffix(day) {
  if (day > 3 && day < 21) return 'th';
  switch (day % 10) {
    case 1:  return "st";
    case 2:  return "nd";
    case 3:  return "rd";
    default: return "th";
  }
}

function formatDateLikeLogseq() {
  const today = new Date();
  const day = today.getDate();
  let month = today.toLocaleString('default', { month: 'short' });
  month = month[0].toUpperCase() + month.slice(1);
  const year = today.getFullYear();
  const ordinalSuffix = getOrdinalSuffix(day);
  return `${month} ${day}${ordinalSuffix}, ${year}`;
}

document.addEventListener("keydown", (e) => {
  if (e.metaKey && e.key === "t") {
    e.stopPropagation();
    const date = formatDateLikeLogseq();
    logseq.api.insert_at_editing_cursor(`[[${date}]]`);
  }
});

Could simplify formatDateLikeLogseq with this code.

1 Like