├── bin └── index.js ├── .gitignore ├── src ├── utils │ └── index.js └── index.js ├── .eslintrc ├── .vscode └── launch.json ├── LICENSE ├── README.md ├── package.json └── CODE_OF_CONDUCT.md /bin/index.js: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env node 2 | 3 | require('../src') 4 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | # Project dependencies 2 | # https://www.npmjs.org/doc/misc/npm-faq.html#should-i-check-my-node_modules-folder-into-git 3 | node_modules 4 | .cache/ 5 | # Build directory 6 | public/ 7 | .DS_Store 8 | entries 9 | dayone 10 | -------------------------------------------------------------------------------- /src/utils/index.js: -------------------------------------------------------------------------------- 1 | const fs = require('fs') 2 | const mkdirp = require('mkdirp') 3 | 4 | module.exports.ensureDirectoriesExist = function(dirnames) { 5 | if (!Array.isArray(dirnames)) { 6 | dirnames = [dirnames] 7 | } 8 | dirnames.forEach(dirname => { 9 | if (fs.existsSync(dirname)) { 10 | return true 11 | } 12 | mkdirp.sync(dirname) 13 | }) 14 | } 15 | -------------------------------------------------------------------------------- /.eslintrc: -------------------------------------------------------------------------------- 1 | { 2 | "env": { 3 | "browser": true, 4 | "node": true, 5 | "commonjs": true, 6 | "es6": true 7 | }, 8 | "extends": ["eslint:recommended", "plugin:node/recommended"], 9 | "plugins": ["node"], 10 | "rules": { 11 | "no-console": 0, 12 | "no-debugger": 0, 13 | "no-undef": 0, 14 | "indent": ["error", 4], 15 | "linebreak-style": ["error", "unix"], 16 | "quotes": ["error", "single"], 17 | "semi": ["error", "never"], 18 | "node/exports-style": ["error", "module.exports"] 19 | } 20 | } 21 | -------------------------------------------------------------------------------- /.vscode/launch.json: -------------------------------------------------------------------------------- 1 | { 2 | "version": "0.2.0", 3 | "configurations": [ 4 | { 5 | "type": "node", 6 | "request": "launch", 7 | "name": "Run Current File", 8 | "protocol": "legacy", 9 | "program": "${file}" 10 | }, 11 | { 12 | "type": "node", 13 | "request": "launch", 14 | "name": "Launch via NPM", 15 | "runtimeExecutable": "dayone-to-md", 16 | "protocol": "legacy", 17 | "runtimeArgs": [], 18 | "port": 5858 19 | } 20 | ] 21 | } 22 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | Copyright 2017 Dan Seethaler 2 | 3 | Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: 4 | 5 | The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. 6 | 7 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 8 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # dayone-to-markdown 2 | 3 | ## The Problem 4 | 5 | You love using the DayOne journaling app to record all your amazing thoughts! But you want to get those entries into a markdown format so you can publish them to your own blog or website. 6 | 7 | ## The Solution 8 | 9 | The DayOne app currently allows an export of entries to a JSON format. This package will unzip the DayOne output and convert all the entries in `Journal.json` into individual markdown files. By default some metadata from the entry is added as frontmatter to the top of each `.md` file. The photos and links to other entries are also converted into a relative markdown link. 10 | 11 | ## Usage 12 | 13 | First [make sure you have NPM installed](https://www.npmjs.com/package/dayone-to-md/tutorial), create a folder for this project, open command line interface there, install dayone-to-md with `npm install dayone-to-md` and initialize with `npm init`. Add the output zip file from _DayOne->Export to JSON_ into a folder titled `dayone` at the root of the project. Then add an npm script with the `dayone-to-md` bin i.e. `"scripts": {"convert": "dayone-to-md"}` to `package.json`. Now you can run `npm run convert`! The markdown files get output to `src/entries` and the photos are put in the `public/static` directory by default. 14 | -------------------------------------------------------------------------------- /package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "dayone-to-md", 3 | "version": "0.0.3", 4 | "description": "Convert the DayOne JSON export to markdown files.", 5 | "bin": "bin/index.js", 6 | "scripts": { 7 | "build": "babel --out-dir bin --ignore *.test.js src", 8 | "format": "prettier --trailing-comma es5 --no-semi --single-quote --write 'src/**/*.{js,json}'", 9 | "test": "jest" 10 | }, 11 | "repository": { 12 | "type": "git", 13 | "url": "git+https://github.com/danseethaler/dayone-to-md.git" 14 | }, 15 | "keywords": [ 16 | "dayone", 17 | "journaling", 18 | "json" 19 | ], 20 | "author": "Dan Seethaler (https://danseethaler.com/)", 21 | "license": "MIT", 22 | "bugs": { 23 | "url": "https://github.com/danseethaler/dayone-to-md/issues" 24 | }, 25 | "homepage": "https://github.com/danseethaler/dayone-to-md#readme", 26 | "devDependencies": { 27 | "eslint-config-airbnb": "^15.1.0", 28 | "eslint-plugin-import": "^2.7.0", 29 | "eslint-plugin-jsx-a11y": "^5.1.1", 30 | "eslint-plugin-node": "^5.1.1", 31 | "eslint-plugin-react": "^7.3.0", 32 | "jest": "^21.1.0", 33 | "prettier": "^1.7.0" 34 | }, 35 | "dependencies": { 36 | "adm-zip": "^0.4.7", 37 | "commander": "^2.11.0", 38 | "date-fns": "^1.28.5", 39 | "eslint": "^4.7.2", 40 | "mkdirp": "^0.5.1", 41 | "moment": "^2.19.2", 42 | "sanitize-filename": "^1.6.1" 43 | }, 44 | "engines": { 45 | "node": ">=6.0.0" 46 | } 47 | } 48 | -------------------------------------------------------------------------------- /CODE_OF_CONDUCT.md: -------------------------------------------------------------------------------- 1 | # Contributor Covenant Code of Conduct 2 | 3 | ## Our Pledge 4 | 5 | In the interest of fostering an open and welcoming environment, we as 6 | contributors and maintainers pledge to making participation in our project and 7 | our community a harassment-free experience for everyone, regardless of age, body 8 | size, disability, ethnicity, gender identity and expression, level of experience, 9 | nationality, personal appearance, race, religion, or sexual identity and 10 | orientation. 11 | 12 | ## Our Standards 13 | 14 | Examples of behavior that contributes to creating a positive environment 15 | include: 16 | 17 | * Using welcoming and inclusive language 18 | * Being respectful of differing viewpoints and experiences 19 | * Gracefully accepting constructive criticism 20 | * Focusing on what is best for the community 21 | * Showing empathy towards other community members 22 | 23 | Examples of unacceptable behavior by participants include: 24 | 25 | * The use of sexualized language or imagery and unwelcome sexual attention or 26 | advances 27 | * Trolling, insulting/derogatory comments, and personal or political attacks 28 | * Public or private harassment 29 | * Publishing others' private information, such as a physical or electronic 30 | address, without explicit permission 31 | * Other conduct which could reasonably be considered inappropriate in a 32 | professional setting 33 | 34 | ## Our Responsibilities 35 | 36 | Project maintainers are responsible for clarifying the standards of acceptable 37 | behavior and are expected to take appropriate and fair corrective action in 38 | response to any instances of unacceptable behavior. 39 | 40 | Project maintainers have the right and responsibility to remove, edit, or 41 | reject comments, commits, code, wiki edits, issues, and other contributions 42 | that are not aligned to this Code of Conduct, or to ban temporarily or 43 | permanently any contributor for other behaviors that they deem inappropriate, 44 | threatening, offensive, or harmful. 45 | 46 | ## Scope 47 | 48 | This Code of Conduct applies both within project spaces and in public spaces 49 | when an individual is representing the project or its community. Examples of 50 | representing a project or community include using an official project e-mail 51 | address, posting via an official social media account, or acting as an appointed 52 | representative at an online or offline event. Representation of a project may be 53 | further defined and clarified by project maintainers. 54 | 55 | ## Enforcement 56 | 57 | Instances of abusive, harassing, or otherwise unacceptable behavior may be 58 | reported by contacting the project team at dan@seethalers.com. All 59 | complaints will be reviewed and investigated and will result in a response that 60 | is deemed necessary and appropriate to the circumstances. The project team is 61 | obligated to maintain confidentiality with regard to the reporter of an incident. 62 | Further details of specific enforcement policies may be posted separately. 63 | 64 | Project maintainers who do not follow or enforce the Code of Conduct in good 65 | faith may face temporary or permanent repercussions as determined by other 66 | members of the project's leadership. 67 | 68 | ## Attribution 69 | 70 | This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 1.4, 71 | available at https://www.contributor-covenant.org/version/1/4/code-of-conduct/ 72 | 73 | [homepage]: https://www.contributor-covenant.org 74 | -------------------------------------------------------------------------------- /src/index.js: -------------------------------------------------------------------------------- 1 | const path = require('path') 2 | const fs = require('fs') 3 | const AdmZip = require('adm-zip') 4 | const formatDate = require('date-fns').format 5 | const moment = require('moment') 6 | var sanitize = require('sanitize-filename') 7 | const { ensureDirectoriesExist } = require('./utils') 8 | 9 | getDayoneFolderPath() 10 | .then(getDayoneZips) 11 | .then(unpackDayone) 12 | .catch(err => { 13 | throw new Error(err) 14 | }) 15 | 16 | function getDayoneFolderPath() { 17 | return new Promise((res, reject) => { 18 | const dayonePath = path.resolve('dayone') 19 | 20 | fs.stat(dayonePath, (err, stat) => { 21 | if (err || !stat.isDirectory()) { 22 | return reject('No `dayone` folder found.`') 23 | } 24 | return res(dayonePath) 25 | }) 26 | }) 27 | } 28 | 29 | function getDayoneZips(dayonePath) { 30 | return new Promise((res, reject) => { 31 | fs.readdir(dayonePath, (err, files) => { 32 | if (err) { 33 | return reject(err) 34 | } 35 | const zipFiles = files.reduce((prev, current) => { 36 | if (current.indexOf('.zip') === current.length - 4) { 37 | prev.push(path.join(dayonePath, current)) 38 | } 39 | return prev 40 | }, []) 41 | if (!zipFiles.length) { 42 | return reject('No zip files found in `dayone` folder.') 43 | } 44 | 45 | res(zipFiles) 46 | }) 47 | }) 48 | } 49 | 50 | function unpackDayone(zipDirectories) { 51 | let entriesProcess = 0 52 | 53 | zipDirectories.map(unpack) 54 | 55 | function unpack(directory) { 56 | // Make sure the output directories exist 57 | const entriesDirectory = path.resolve('./src/entries') 58 | const photosDirectory = path.resolve('./public/static') 59 | ensureDirectoriesExist([photosDirectory, entriesDirectory]) 60 | 61 | var zip = new AdmZip(directory) 62 | var zipEntries = zip.getEntries() // an array of ZipEntry records 63 | 64 | zipEntries.forEach(function(zipEntry) { 65 | // Main json file 66 | if (zipEntry.entryName === 'Journal.json') { 67 | const fullData = JSON.parse(zip.readAsText(zipEntry.entryName)) 68 | const mdEntries = fullData.entries.map(entryToMarkdown) 69 | 70 | entriesProcess += mdEntries.length 71 | 72 | saveEntries(mdEntries, entriesDirectory) 73 | } 74 | // Photos 75 | if (zipEntry.entryName.indexOf('photos/') === 0) { 76 | zip.extractEntryTo( 77 | /*entry name*/ zipEntry.entryName, 78 | /*target path*/ photosDirectory, 79 | /*maintainEntryPath*/ false, 80 | /*overwrite*/ true 81 | ) 82 | } 83 | }) 84 | } 85 | 86 | console.log(`${entriesProcess} entries processed!`) 87 | } 88 | 89 | function entryToMarkdown(entry) { 90 | let title = entry.text.slice(0, entry.text.indexOf('\n')).trim() 91 | let text = entry.text.slice(entry.text.indexOf('\n')).trim() 92 | 93 | if (entry.photos) { 94 | entry.photos.map(photo => { 95 | text = text.replace( 96 | `dayone-moment://${photo.identifier}`, 97 | `./static/${photo.md5}.${photo.type}` 98 | ) 99 | }) 100 | } 101 | 102 | let formattedEntry = { 103 | id: entry.uuid, 104 | date: formatDate(new Date(entry.creationDate), 'D MMM, YYYY'), 105 | title, 106 | location: entry.location ? entry.location.placeName : '', 107 | starred: entry.starred, 108 | tags: entry.tags 109 | } 110 | 111 | formattedEntry.md = [getFrontMatter(formattedEntry), text].join('\n\n') 112 | 113 | return formattedEntry 114 | } 115 | 116 | function saveEntries(entries, location) { 117 | entries.map(({ md, date, title }) => { 118 | const fileDate = moment(date, 'D MMM, YYYY').format('YYYY-MM-DD') 119 | const fileName = sanitize(title) 120 | var saveTo = path.join(location, `${fileDate} - ${fileName}.md`) 121 | fs.writeFileSync(saveTo, md, { 122 | encoding: 'utf8' 123 | }) 124 | }) 125 | } 126 | 127 | function getFrontMatter(entry) { 128 | var frontMatter = '---\n' 129 | for (var prop in entry) { 130 | if (entry.hasOwnProperty(prop)) { 131 | let item = entry[prop] || '' 132 | if (Array.isArray(item)) { 133 | item = item.join(', ') 134 | } 135 | frontMatter = `${frontMatter}${prop}: ${JSON.stringify(item)}\n` 136 | } 137 | } 138 | return frontMatter + '---' 139 | } 140 | --------------------------------------------------------------------------------