Skip to content

Instantly share code, notes, and snippets.

@duckbrain
Created August 12, 2016 19:16
Show Gist options
  • Save duckbrain/87c5d84eb63d8a6046b8db4c19d51739 to your computer and use it in GitHub Desktop.
Save duckbrain/87c5d84eb63d8a6046b8db4c19d51739 to your computer and use it in GitHub Desktop.
A quick script I used to convert my Red Notebook data files to plain Markdown (needs changes to apply elsewhere)
#!/usr/bin/node
const Promise = require('bluebird');
const fs = Promise.promisifyAll(require('fs'));
const moment = require('moment');
const YAML = require('yamljs');
let today = moment();
function readJournal(dir, date) {
return fs.readFileAsync(dir + '/' + date.format('YYYY-MM') + '.txt', 'utf8')
.catch(()=>null)
.then(d=>{
if (!d) return d;
try { return YAML.parse(d)[date.format('D')]; }
catch(ex) { return null; }
});
}
// Change start date to an approparite date
for (let d = moment([2013, 1, 1]); d.isBefore(today); d.add(1, 'day')) {
let date = d.clone();
Promise.all([
Promise.resolve(date),
// Put the folder names of your journals here
readJournal('data', date),
readJournal('dream-journal', date)
]).then(a=>{
// Modify to join them into one file how you like
let date = a[0];
let data = a[1];
let dream = a[2];
let content = '\n';
if (data) {
content += '# Journal\n\n' + data.text;
}
if (dream) {
content += '# Dream Journal\n\n' + dream.text;
}
if (content == '\n') return;
a[0] = date.toString();
fs.writeFile('out/journal-' + date.format('YYYY-MM-DD') + '.md', content);
});
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment