wpsync – Markdown to WP

wpsync is a command-line tool to sync a local directory of markdown files to your WordPress.

I really like markdown and vim. My publishing process was:

  1. Create a draft in markdown,
  2. When ready to publish v1.0 copy-paste to WordPress; the editor converts markdown nicely, and then publish
  3. However, when a revision is needed, it must be done in WordPress not in my markdown/vim tools.

After publishing my Working with Vim tutorial, there was a lot of revisions and additions I needed to make, and I couldn’t use vim. This seemed wrong writing a tutorial for vim, not in vim.

So I wrote the wpsync program which reads a directory of markdown files, and uses the WordPresss API to publish and update posts, pages, and media.

Here’s a demo:

wpsync demo

Install and Setup

The program is written in Go, I probably should have written it in JavaScript so I could use some of the markdown libraries that WordPress uses, but this is a personal project and I like writing Golang. I even use wpsync to publish my Working with Go tutorial.

You can view the code and download binary releases at github.com/mkaz/wpsync

Authentication on the command-line is the tricky bit. The JWT Authentication plugin is required and what makes it possible. For now this does not work for WordPress.com sites. For wpcom, it is possible to use a similar token for authentication, however I don’t haven’t setup a way to retrieve this token via the command-line.

Usage

Create a directory for your site, and sub-directories posts, media or pages. Any files in these directories will be uploaded.

Run wpsync --init for initial setup

Run wpsync -confirm to confirm each upload

See the readme in Github for full documentation.

Usage: wpsync [args]

Arguments:

  -confirm
        Confirm prompt before upload
  -debug
        Display debug messages
  -dryrun
        Test run, shows what will happen
  -help
        Display help and quit
  -init
        Create settings for blog and auth
  -quiet
        Do not display info messages
  -test
        Test config and authentication
  -version
        Display version and quit

Next Steps

I’ll probably keep tweaking away on this, right now there is only one-way sync from local to remote. It would be nice to be able to pull down existing posts, edit, and publish.

Any feedback, comments, issues, or even pull requests are welcome.