Apr 242016

IA Writer to WordPress

0. Wha?

With the coming of the new doggie into the house, perhaps I will again add more content to the bloggy thing that I have kinda sorta not really been keeping over the last little while.

Probably this has been done by someone else on the Intertubz, but ach, why not. I have some time on my hands, so here are running notes in IA Writer that will make its way to a WordPress post by some means or other. There’s nothing special about IA writer, by the way. Well, there is, but not for the purposes of the WordPress posting. The same code should work with any plain-ish text file coming from any editor.

Why bother? Well, I think that the primary reason a lot of my notes have not made it to the blog is that it is just such a PITA to go out of my way to make a blog posting. If it all just sorta “works” from my usual workflows than that would perhaps be a very different situation. Not that I think I have anything particularly interesting or unique to say

1. This file

Is written in markdown, with metadata at the head:

Title: IA Writer to Wordpress  
Author: yearlus  
Email: stephen@yearl.us  
Date: 2016-04-26  
Format: complete  
post_status: draft  
post_date: 2016-04-26
post_title: IA Writer to Wordpress  
category: tech  
post_tag: text, editors, Ruby, code, Wordpress, workflow  

# [%Title]

2. Markdown processors

Four Ruby processors for playing with markdown are briefly alluded to here: markdown-processing-ruby

And I went ahead and played with two of these:


$ gem install redcarpet -n /usr/local/bin


$ gem install kramdown -n /usr/local/bin

But neither of these processors support (yet!) the metadata blocks of MultiMarkdown. And kramdown does not recognise the back-tick code-fence (“` “`), only the tilda code-fence (~~~ ~~~)

So, install Fletcher Penney’s MultiMarkdown, and test:

$ brew install multimarkdown
$ multimarkdown ~/_scratch/IA-Writer-to-WP-Coleman-Notes.txt > ~/_scratch/IA-Writer-to-WP-Coleman-Notes.html

Gives some very nice HTML, including interpolation of the metadata (of this file), and writing of that metadata:

    <meta charset="utf-8"/>
    <title>IA Writer to Wordpress</title>
    <meta name="author" content="yearlus"/>
    <meta name="email" content="stephen@yearl.us"/>
    <meta name="date" content="2016-04-26"/>
    <meta name="format" content="complete"/>
    <meta name="post_status" content="draft"/>
    <meta name="post_date" content="2016-04-26"/>
    <meta name="post_title" content="IA Writer to Wordpress"/>
    <meta name="category" content="tech"/>
    <meta name="post_tag" content="text, editors, Ruby, code, Wordpress, workflow"/>

So the process for this exercise seems clear:
1. “~~shell out” to markdown and produce an html file~~
2. process that html with nokogiri
3. post to WordPress

No need to shell out, apparently. tillsc has already built a Ruby extension library around MultiMarkdown, Ruby MultiMarkdown 4, so
I guess the awkward bit would be how best to execute the ruby script that pulls all this together… from a services menu item, maybe? And then how to deal with edits… something in the metadata at the head of the file? A call to getPost call to XML RPC to see if an existing post “matching” (on what criterion?) that about to be posted exists? But what to check on? Is the old post deleted? I suppose when one starts thinking about these things then one might just as well produce an actual interface to WordPress, but why bother when there are so many such things anyway?

Maybe I will look into that… but I am reasonably happy with the fact that this post came from iA Writer, and without too much trouble either. Next up? A horror-show of a MultiMarkdown file in iA Writer to to see how much gets translated into a decent-ish looking post.

3. Code

Posting to WordPress is pretty straightforward. All the heavy lifting is done by the rubypress gem, which makes this sort of thing doggone simple (see what I did there!). Here a block of code from that thing I wrote a while ago that scraped a Koine Greek “Word of the Day” from Ἡ Καινὴ Διαθήκη. Last post here

# ========== Post to Wordpress ==========
if options[:wordpress_write] == 'yes'
  wp = Rubypress::Client.new(
    host:      "#{config['wp']['host']}",
    username:  "#{config['wp']['username']}",
    password:  "#{config['wp']['password']}",
    path:      "#{config['wp']['path']}")

    blog_id:    '0',
    content:    {
      post_status:   'draft',
      post_date:     Time.now,
      post_title:    "#{html_title}",
      terms_names:  {
        post_tag:     ['greek', 'koine', 'κοινή', 'language'],
        category:     ['Greek']
      post_content:  "#{wp_content}"
# ========== END WP Post ==========


posted with wpiawriter v. 0.1
Apr 022013

74111101– yes, my eldest insists on representing himself as the ASCII decimal code point values for his name– and I have been watching the History Channel’s The Universe. Below some of 74’s questions (typed verbatim from his notes) that he hopes to have answered after writing to some of the presenters in the series.



  • If the Universe keeps on expanding will it eventually rip apart the things that make up dark energy?
  • Is there a known limit to the repulsive effects of dark energy in the way that we know gravity does operate above or below certain distances?
  • Is dark enery strong enough to rip apart:
  • If there is antimatter, is there antiDARKmatter?
  • Once the sun becomes a white dwarf, is it possible to combine all the gas in the planetary nebula and the outer planets to form another sun?
  • Is it possible to use the sun’s energy to start nuclear fusion and as the sun gets cooler to add more hydrogen to make it hotter and launch it into space?
  • If dark energy is driving the expansion of the Universe will it eventually destroy the particles that cause dark matter? Will this then cause a big crunch and possibly a new big bang?


Enhanced by Zemanta

Feb 162013

The not-very-much-used-by-me Posterous is going offline on April 30th 2013, roughly 12 months after its acquisition by Twitter. I had a few on-and-off posts there, and I guess it would sort of be a shame to loose them, so this is an attempted replacement. The Posterous blog is copied here: http://sjy.yearl.us/sjy/posterous/blog.yearl.us/ … that was a simple 

wget -r -l inf -k -E -p -nc blog.yearl.us

but I thought I’d also try and group these pages into WordPress itself a lá http://en.support.wordpress.com/import/import-from-posterous/

Of course setting up WordPress was a breeze.

  • Set up a blank MySQL database with an admin user
  • Then on the server with the webserver (in my case Apacehe2)
mkdir sjy
cd sjy
wget http://wordpress.org/latest.tar.gz
tar xzf latest.tar.gz
cd wordpress
mv * ..
cd ..
rm -rf wordpress
mv wp-config-sample.php wp-config.php
vi wp-config

Setting the login details of the MySQL database. And that is that. Went on into install the Suffusion theme for WordPress (because although I do not intend to style this, my wife’s gluten-free cooking blog uses Suffusion) and the CodeColorer  plugin.



Jan 292012

Fsked the http://mary.yearl.us WP install last night whilst arsing with names. One single bloody typo in “site URL” and good luck getting back into the admin panel. WP does not even offer a warning that changing this might be a bad thing, or potentially so.

Fortunately having access to the database I could edit the value in-place in the tables… now all is well again with the world.

…except for the fact that I felt I had to sign up–finally– for a twitter account just so I could get an API key in order to explore some things on Mar’s blog. And it turns out another yearl.* has @yearlus as his handle. Grrr. for some reason this bothers me. Bothers me to the extent that I offerered him a free subdomain of his choosing under yearl.us. I’d take that deal if I were him.