Using Emacs to write WriteFreely articles

It is possible to use Emacs and markdown to write and publish articles on a WriteFreely server. First Markdown mode should be installed

M-x package-install RET markdown RET

Install then the specific Emacs package to interact with WriteFreely servers. It is available in MELPA and depend on ox-hugo

M-x package-install RET writefreely RET

When the packages are ready Emacs need to be confgured to access the target server: In the Emacs init file

~/emacs.d/init.el

add:

(require 'writefreely)
(setq writefreely-instance-url "https://yourblog.com")
(setq writefreely-instance-api-endpoint "https://yourblog.com/api")
(load-file expand-file-name "~/.emacs.d/secrets/writefreely-auth-token.el")

In the last raw there is a file we need to create because it is a good practice not to paste the access token in plain text but encrypt it.

  1. Get an access token:
curl -X POST "https://yourblog.com/api/auth/login" -H "Content-Type: application/json" -d '{"alias":"YOUR-USERNAME","pass":"YOUR-PASSWORD"}'
  1. Store the token in an encripted file

Create the dir for storing it

kdir -p ~/.emacs.d/secrets
chmod 700 ~/emacs.d/secrets

Create the token file:

nano ~/.emacs.d/secrets/writefreely-auth-token.el

Insert:

(setq writefreely-auth-token "YOUR-ACCESS-TOKEN")

Encript the file with GPG:

gpg --symmetric --cipher-algo AES256 ~/.emacs.d/secrets/writefreely-auth-token.el

GPG will ask for an encryption passphrase

Now it is possible to post: 1 – Save the post in Emacs 2 – M-x write-freely-publish-or-update 3 – Select the collection 4 – Done!