Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

@goooooouwa
Created March 26, 2019 09:44
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save goooooouwa/6198cc24d0d187d87bf15779c187e520 to your computer and use it in GitHub Desktop.
Save goooooouwa/6198cc24d0d187d87bf15779c187e520 to your computer and use it in GitHub Desktop.
var fs = require('fs');
const contents = fs.readFileSync('CardDiary-JSON.json', 'utf8');
const obj = JSON.parse(contents);
for (const d of obj.diaryExports) {
const diary = JSON.parse(d.content);
const date = d.createDate.substring(0, 10);
const filename = `${date}-${diary.title || 'log'}`;
const fileContent = `---
title: ${diary.title || `${date}-log` }
layout: post
date: ${date}
category: log
published: false
---
${diary.content}`;
console.log(filename);
fs.writeFileSync(`./tmp/${filename}.md`, fileContent, function(err) {
if(err) {
return console.log(err);
}
console.log("File saved!");
});
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment