Skip to content

Instantly share code, notes, and snippets.

@joshcanhelp
Created October 18, 2021 23:56
Show Gist options
  • Save joshcanhelp/9d57c388f6419904064ed2658def44ee to your computer and use it in GitHub Desktop.
Save joshcanhelp/9d57c388f6419904064ed2658def44ee to your computer and use it in GitHub Desktop.
Convert Roam daily exports to Obsidian default date format
const { opendir, writeFile, readFile } = require('fs/promises');
const uniqueMonth = [];
(async () => {
const dir = await opendir('./_in');
for await (const dirent of dir) {
const namePieces = dirent.name
.replace("st,", "")
.replace("nd,", "")
.replace("rd,", "")
.replace("th,", "")
.replace(".md", "")
.split(" ")
if (!uniqueMonth.includes(namePieces[0])) {
uniqueMonth.push(namePieces[0]);
}
const monthNumber = convertMonthToNumber[namePieces[0]];
const newName = namePieces[2] + "-" + monthNumber + "-" + namePieces[1] + ".md";
const contents = await readFile('./_in/' + dirent.name);
await writeFile('./_out/' + newName, contents);
console.log(newName);
}
})();
const convertMonthToNumber = {
'January': 1,
'February': 2,
'March': 3,
'April': 4,
'May': 5,
'June': 6,
'July': 7,
'August': 8,
'September': 9,
'October': 10,
'November': 11,
'December': 12,
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment