glasserc / rst2wp

Post to Wordpress using ReStructuredText
11 stars 10 forks source link

:title: rst2wp: a ReStructuredText to Wordpress uploader

rst2wp is a Wordpress blogging client. It uses XML-RPC to upload posts.

The basic use case is to enable faster and more automatic blogging than is possible with the HTML/JS interface to Wordpress. To that end, you can use your favorite editor <http://www.gnu.org/software/emacs/>_ to write your posts, and then run rst2wp post.rst to get them online.

NOTE: rst2wp is not exactly deprecated but something close to it. If you are trying to pick a tool to use on your cool new blog idea, it would be hard for me to recommend this one. When this program was first written (in 2009), Wordpress seemed like a good way to publish a blog-like site with features like tags, RSS feeds, and search. In that environment, using rst2wp to facilitate writing posts as plain text in a git repository made perfect sense. In 2020, the landscape looks a lot different and it's hard to justify tying your site to Wordpress as an implementation choice. There's a whole category of "static site generators" and any of them will be better-maintained than rst2wp, to say nothing of whether your site really needs to be running Wordpress on the backend. In particular I've heard good things about Pelican <https://blog.getpelican.com/>_. The rest of the documentation is targeted at existing users of rst2wp who are not motivated to move their entire site to something else.

Requirements

Features

Shortcomings

Getting started

  1. git clone https://github.com/glasserc/rst2wp.git
  2. cd rst2wp
  3. python setup.py install

Then just run rst2wp once to create ~/.config/rst2wp/wordpressrc. Account settings and configuration stuff goes in there.

Usage

Run rst2wp with the name of a post as its argument. The post is just an ordinary RST file, except that the (normally optional) bibliographic fields at the top of the file are required in order to provide a title to the post.

Here's a sample post::

:title: This is a brand new test!

This is just a test, of course. Here's an image:

|my_image|

I'd like to close with a quote:

    Four score and seven years ago..

.. |my_image| image:: http://travelogue.betacantrips.com/wp-content/uploads/2009/09/tumblr_kqlgm7DjDq1qz59y9o1_500.gif
   :target: http://travelogue.betacantrips.com/

Once you run rst2wp on this file, the file will be modified. Particularly, you'll see::

:id: 362

in the bibliographic fields at the top, and in the image:: directive, you'll see::

:saved_as: http://travelogue.betacantrips.com/wp-content/uploads/2009/09/tumblr_kqlgm7DjDq1qz59y9o1_500.gif

In the future, this blog post will be altered instead of new ones being uploaded, and the uploaded image won't be re-uploaded.

You might find this annoying because you might have to re-load the file in your text editor, so this information is also saved in ~/.config/rst2wp. You can choose one or the other by editing config.data_storage.

Options

Config

The configuration file (by default $HOME/.config/rst2wp/wordpressrc) has several parameters:

Publishing

Wordpress supports having posts that aren't yet published. There are many reasons you might do this -- for one, you might want to make sure rst2wp didn't make a hash of your post. Thus, rst2wp can mark a post "published" or not. This is controlled in several ways.

  1. If either of the --publish\ /\ --no-publish arguments are present, this has priority (--publish marks the post published; --no-publish marks the post as "unpublished").

  2. Otherwise, if the post has a bibliographic field called :publish: and it is set to "yes", the post is marked published.

  3. Otherwise, if the configuration parameter publish_default is set, the value of the parameter is used: "yes" marks the post published, "no" marks it as unpublished.

  4. Otherwise, the post is marked as unpublished.

Known Links

Over time you may find that you refer to some sites over and over again. ReST has a perfectly effective technique for this: defining external link targets. If you define a known_links file with the format::

[http://www.example.com/]
link = example link

Then you can use it freely in all your posts::

This is a link to `example link`_. Isn't ReST lovely?

Why ReStructuredText?

Because I like ReStructuredText.

Some people like Markdown. You can tell because they write about functions like gtk\ window\ new. Markdown started as a giant ball of regular expressions to create HTML and it hasn't changed much. It has grown extensions to address some shortcomings, but it isn't very extensible.

Additionally, I like the docutils codebase a lot -- it makes the kinds of customizations I made here very easy.

Notes on changing Wordpress's themes

Some CSS styles you might want to drop into your theme's style.css.

::

.line {
    min-height: 1em;
}