Created
March 12, 2017 22:23
-
-
Save casprwang/089fc7d78e0cc7c1c31f6ca64777a8b6 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
/* eslint-disable */ | |
import prompt from 'prompt'; | |
import mkdirp from 'mkdirp'; | |
import moment from 'moment'; | |
import yaml from 'js-yaml'; | |
/* eslint-enable */ | |
import snakeCase from 'lodash/snakeCase'; | |
import fs from 'fs'; | |
prompt.start(); | |
/*eslint-disable */ | |
prompt.get(['title'], (err, result) => { | |
'use strict' | |
const dir = `./pages/blog/${ moment().format('YYYY-MM-DD') }-${ snakeCase(result.title) }` | |
mkdirp.sync(dir) | |
let postFileStr = '---\n' | |
const frontmatter = { | |
title: result.title, | |
date: moment().toJSON(), | |
layout: 'post', | |
draft: true, | |
place: 'blog', | |
tags: null, | |
categories: null, | |
coverPhoto: null | |
} | |
postFileStr += yaml.safeDump(frontmatter) | |
postFileStr += '---\n' | |
fs.writeFileSync(`${ dir }/index.md`, postFileStr, { | |
encoding: 'utf-8', | |
}) | |
return console.log(dir); | |
}) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment