Splitting | Top | Image References Fail |
Prev, Top, Next
There has been a great public outcry for links between the pages. Well, Brian Kelly, @spilth on Twitter, mentioned it. I told him to cool his jets, we’re only on version 0.0.1 or something but he called me on the “feedback welcome” typo I made in my initial announcement.
But it does seem to me that we should be able to put in some quick links with the new little splitter Ruby script. I’m going to break my own rules again, and not TDD this. Hold my beer.
#!/usr/bin/env ruby -wU
require 'tempfile'
SPLIT_MARKER = "----\n\n"
filenumber = 0
input = ARGF.read
chunks = input.split(SPLIT_MARKER)
# puts "Chunks length %d" % chunks.length
chunks.each do |chunk|
next if chunk.length < 1
title = chunk.split("\n")[0]
if filenumber == 0
filename = "index.md"
else
filename = sprintf("%02d", filenumber) + ".md"
end
puts filename + ": " + title
tf = File.new(filename, "w")
tf.print chunk
link = ""
if ( filenumber == 1 )
link += "[Prev](index.html) "
elsif filenumber > 1
link += "[Prev](%02d.html) " % (filenumber - 1) unless filenumber == 0
end
link += "[Top](index.html) "
link += "[Next](%02d.html)" % (filenumber + 1) unless filenumber >= chunks.length - 1
tf.puts
tf.puts
tf.puts link
tf.close
filenumber += 1
end
This is pretty rough, but it seems to work. A side lesson, though: when you don’t work to get your code clean, it winds up getting dirtier all the time. But now we have links between pages.
Splitting | Top | Image References Fail |