Skip to content

Instantly share code, notes, and snippets.

@odiak
Last active November 5, 2021 01:12
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 odiak/12366336a0723d61d388962fc53f391e to your computer and use it in GitHub Desktop.
Save odiak/12366336a0723d61d388962fc53f391e to your computer and use it in GitHub Desktop.
Convert Inkdrop's backup to plain Markdown files
// read notes from `data/note` directory and export to `md` directory
const fs = require('fs/promises')
;(async () => {
fs.mkdir('md', { recursive: true })
const list = await fs.readdir('data/note')
const usedNames = new Set()
for (const fileName of list) {
if (!/\.json$/.test(fileName)) continue
const file = await fs.open(`data/note/${fileName}`, 'r')
const content = await file.readFile({ encoding: 'utf-8' })
await file.close()
const { title, body } = JSON.parse(content)
console.log(title)
let newFileName = title
let i = 1
while (usedNames.has(newFileName)) {
newFileName = `${title} (${i})`
i++
}
usedNames.add(newFileName)
const newFile = await fs.open(`md/${newFileName}.md`, 'w')
await newFile.writeFile(body, { encoding: 'utf-8' })
await newFile.close()
}
})()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment