File Titles with Deno
Deno was created by the inventor of Nodejs.
After getting frustrated with a few different markdown editors I decided to just start using VS Codium for notes. This is mostly awesome.
One small obstacle was ordering notes by date. I decided I can include the date in the filename. The convention I chose was "yy-mm-dd-" + "article-title". This was a pain to write, and I even got it wrong a couple times 😅. Enter Deno
I wanted to try Deno on something trivial anyway. So I made this snippet with Deno to generate a file with the title and formatted date:
let today = new Date();
let titleDate =
String(today.getFullYear()).slice(2) +
"-" +
String(today.getMonth() + 1).padStart(2, 0) +
"-" +
String(today.getDate()).padStart(2, 0);
let fileTitle = titleDate + "-" + Deno.args.join("-");
console.log(fileTitle);
const encoder = new TextEncoder();
const data = encoder.encode(`# ${Deno.args.join(" ")}
## ${today.getMonth() + 1}/${today.getDate()}/${today.getFullYear()}`);
Deno.writeFileSync(`${fileTitle}.md`, data); // overwrite "fileTitle.txt" or create it
It's great and it makes note taking a much cleaner experience. Way smoother to do with Deno than Nodejs because I can just have a single .js file in my root notes folder without disturbing the peace and initiating npm and everything.