July 16, 2005
Added Some Links
Long overdue, but I've added links to some blogs that I read regularly, and would recommend to others. You can find the list on the upper right side of my main page.
Being the lazy programmer that I am, I couldn't just simply add the links to the page. No, I had to make it easy to add new ones, and also (this was truly lethargic) import all the entries I wanted in one go (so I didn't have type each one in using the easy method).
To make it easy to enter new links, I leveraged the approached that I use for the "Currently Reading" and "Recently Read" sections of my main page: I added a new category for blog links, and then I can enter each blog link as an otherwise normal MovableType Entry.
The title of the entry is the text you see on the link (this is true for the "reading lists too) and then the url becomes the entry body (for the reading lists its the ISBN). Then I use MovableTypes entry template tags to select the appropriate category, and then apply the relevant formatting (with the reading lists, it also means I can enter the book once, and then by changing the category from 'reading' to 'read' book titles move from one list to the other).
The movabletype template text for the blog links looks like this:
<MTEntries lastn="200" category="bloglink" sort_by="title" sort_order="ascend">
<div class="side">
<a href="<$MTEntryBody convert_breaks="0"$>"><$MTEntryTitle$></a>
</div>
</MTEntries>
For future blog links I simply add a new entry with the title of the blog, and the url as the only text (no newline), save and done (no rebuilding templates, or any other special processing -- its as easy as adding any other entry).
The other goal (getting the initial list imported all at once) was a bit trickier. I went down a dead end for a while by trying to write directly to the MT data store, but finally settled on leveraging the MT import mechanism. Here's how I finally got it to work:
- Exported my list of blogs into an OPML (i.e. XML) file
- Imported that into MS Excel
- Copied the two columns I wanted (Title and URL) to a new worksheet
- Added a column for the creation time
- Exported that to a comma delimited file
- Created a ruby script to read the CSV and write out each link in the MT export entry format
- Imported the resulting list using MT's import feature
Here's the ruby code in its entirety:
def make_entries() File.open("blogentries.csv") do |file| file.each do |line| title, text, created = line.chomp.split(/\s*\,\s*/) write_entry(title, text, created) end end end def write_entry(title, entry, created) #2005-07-16 11:00:24 date, time = created.split(' ') year,month,day = date.split('-') string = <<END_OF_STRING AUTHOR: (scrubbed) TITLE: #{title} STATUS: Publish ALLOW COMMENTS: 0 CONVERT BREAKS: __default__ ALLOW PINGS: 0 PRIMARY CATEGORY: bloglink CATEGORY: bloglink DATE: #{month}/#{day}/#{year} #{time} AM ----- BODY: #{entry} ----- EXTENDED BODY: ----- EXCERPT: ----- KEYWORDS: ----- -------- END_OF_STRING puts string end make_entries
Too easy -- i.e. it only took about 2 hours longer than entering them manually :-). But! when I got them imported the first time, I realized I had copied the wrong URL's (for some reason I was thinking people would want the syndication feed). Updating it to the right entries took about 4 minutes. Classic laziness ala Larry Wall
Spending a Saturday Morning writing ruby and watching the Open Championship on Tivo -- nothing finer. :-)
Posted by wcaputo at July 16, 2005 02:29 PMBad Links (January 19, 2006)
Visual Studio Team System Jumpstart (January 18, 2006)
Aligining Value (January 17, 2006)
Lisp Again (January 16, 2006)
Getting It Right (January 13, 2006)
Efficiency vs Productivity (January 12, 2006)
Stubbornness (January 10, 2006)
Writing To Annoy Yourself (January 9, 2006)
Due Process In The Workplace (January 5, 2006)
(All Entries...)