Wednesday, September 1, 2010

Moved!

So I ported all the content from my old blog, and started one here hosted by Google. I have been so impressed by Google, and all their online services. They are good to their customers, and really good to developers, what with all the libraries.

  • Gdata
  • Appengine
  • Online services (gmail, calendar, contacts, map, blogger, etc)

I converted all my previous posts from html to markdown. Markdown is a nice readable markup language in its default state, which is easily converted into other formats. While I trust Google with a lot of things, I always like to have physical backups of all my posts.

So I store all my posts in my personal git repo, in multiple markdown files. Cool enough. There is a really nice webapp with javascript Markdown to html conversion, called Showdown. I could paste my markdown, convert it, then copy and paste the converted html into Blogger.

But I am a developer, who is also very lazy. I wrote a small script that transforms a markdown file into html, and loads the converted text into my clipboard for pasting into Blogger.

For those interested, the code for this script is below:

package com.calico.blogger.BlogBot

...
import com.petebevin.markdown.MarkdownProcessor
import scala.io.Source.{fromFile => open}
import grizzled.util.{withCloseable => withc}

object BlogBot {
  def writeToClipboard(text: String) {
    val clipboard = Toolkit.getDefaultToolkit.getSystemClipboard
    val str = new StringSelection(text)
    clipboard.setContents(str, null)
  }

  def main(args: Array[String]) {
    if(args.size < 1) {
      println("Please provide me a text file to convert from markdown to html")
    }   

    // Remove the <code></code> protions
    val regex = """<code>|</code>""".r

    // Add syntax highlighting
    val brush = """<pre>""".r

    val m = new MarkdownProcessor
    val markdown = m.markdown(open(args(0)).getLines.mkString("\n"))

    val nocode = regex.replaceAllIn(markdown, "") 
    val ret = brush.replaceAllIn(nocode, """<pre class="brush: scala; toolbar: false;">""")

    // Write to file
    println("Writing conversion to file: out.html ....")
    withc(new FileWriter("out.html")) { w =>
      w.write(ret)
    }   

    // Write to clipboard
    println("Writing conversion to your clipboard ....")
    try {
      writeToClipboard(ret)
      println("Done.")
    } catch {
      case e: Exception => println("Failed ... " + e.getMessage)
    }   
  }
}

So the process is made quite simple with scala, sbt, vim, and screen. I like working in pure command-line these days.

This is a post to inform people that I am still alive, and doing development on the side.

-- Philip

No comments:

Post a Comment