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: [email protected]  
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:

Redcarpet


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

Kramdown


$ 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:


<head>
    <meta charset="utf-8"/>
    <title>IA Writer to Wordpress</title>
    <meta name="author" content="yearlus"/>
    <meta name="email" content="[email protected]"/>
    <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"/>
</head>

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']}")

  wp.newPost(
    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
# ========== END WP Post ==========

 


posted with wpiawriter v. 0.1
Mar 302015
 

I never really did manage to get into the swing of things with Sublime Text everyone’s favourite general-purpose editor since, well TextMate fell out of favour ca. 2009-ish, and generally stuck to TextMate. Sure there’s VIM (and it is awesome), but really? Life _is_ better with a pretty and functional editor.

And then along came Atom… as well as a few others: Brackets and Light Table to name the other two newbies, all better described at SitePoint. Suffice to say that Atom won for me. Despite it being very Sublime-like, I felt comfortable with it. So here, culled from .zsh_history, those Themes and Packages that I have installed and not uninstalled over the last eight months or so:

Themes (used under bright ambient light, also Atom’s built-in “One Light” UI)

❯ apm install unity-ui
❯ apm install pen-paper-coffee-syntax

Themes (used under bright ambient light, also Atom’s built in “One Dark” UI)

❯ apm install isotope-ui
❯ apm install zenburn

Themes (basically unused; railscasts for nostalgia; github, because wihout it there would be no Atom)

❯ apm install inspired-github
❯ apm install railscasts-theme

Packages

❯ apm install open-in-browser
❯ apm install color-picker
❯ apm install csslint
❯ apm install linter-rubocop
❯ apm install linter-csslint
❯ apm install emmet
❯ apm install autocomplete-plus
❯ apm install atom-beautify
❯ apm install latex
❯ apm install language-latex
❯ apm install fancy-new-file
❯ apm install file-icons
❯ apm install filetype-color
Feb 172013
 

For whatever reason, I’ve bumped into a number of in-browser [latex]\LaTeX[/latex] editing tools recently. I guess these are mostly useful for collaborative efforts, and I can see a reason why one would not want to use Subversion or Git. I mean Eldest is just coming of an age where he’s seeing computers as tools for his own use rather than just vectors of games/educational materials/movies. Because I am a benevolent father-dictator, he’s already familiar with [latex]\LaTeX[/latex] (and actually loves Computer Modern), and has decided to set all his writings in [latex]\LaTeX[/latex] prior to submission. Good for him. I love the fact that he was complaining about fonts on the MacBook Airs at school, and the pain of writing in MS Word. Good boy!

So, rather than having him use my tool chain, which is very much tied to my laptop and TeXstudio, we could use one of these. I might even be able to persuade his Grade IV teacher that [latex]\LaTeX[/latex] is something worth introducing to the kids in its own right. She was, after all, blown away by 74111101’s Christmas writing piece that we set in [latex]\LaTeX[/latex]. I guess I’ll make notes as I evaluate each below and add them here.

[latex]\LaTeX[/latex] can, apparently, be embedded in WP using shortcodes <http://en.support.wordpress.com/latex/>, but neither of the below “codes”, for example appear to work out-of-the-box on self-hosted WP sites:

[latex]\LaTeX[/latex]
$latex \LaTeX$

So I installed two WP LaTex plugins: Easy WP LaTeX and QuickLaTeX (also http://quicklatex.com/).

QuickLaTeX is *by far* the crisper of the two, and is what is used for the LaTeX symbol on this page.

[latex]\LaTeX[/latex] rendered w/ QuickLaTeX
\LaTeX rendered w/ Easy WP LaTeX

The online editors

http://SpanDeX.io/
https://www.sharelatex.com/
http://www.scribtex.com/
https://www.writelatex.com/
http://code.google.com/p/latex-lab/

 

 

Social Widgets powered by AB-WebLog.com.