Last active
November 5, 2021 01:12
-
-
Save odiak/12366336a0723d61d388962fc53f391e to your computer and use it in GitHub Desktop.
Convert Inkdrop's backup to plain Markdown files
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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