- loading...
[Trick] Live Version Numbers on your blog
There isn’t much connecting your open source projects – written in one language and possibly stored on a SourceForge/RubyForge server – to your blog – written in some other language and stored on a different server. Pity.
Sure, you can list your available projects/gems/plugins/libraries on your sidebar, and that’s great for new visitors but what about the old warhorses? What about the people who actually use your code? It would would be snazzy to inform them if a new version of your projects was available.
Sure you can spam your entire subscription list about every minor update. And during the lean weeks, you might just do that so people know you’re alive. But you’re a professional, and you want something cool. Something automatic and, dare I say it, magical.
Today, we’ll just do automatic. Tomorrow, soon maybe, we’ll all share a newer, improved magical version! Kazzam!
The version numbers are not stored at http://drnicwilliams.com – they are both stored at their respective websites: http://compositekeys.rubyforge.org and http://magicmodels.rubyforge.org. This is the super best part – once I start a new project and add it to the list on the sidebar, I never need to touch the blog templates again. Automatic. Almost magical.
Tourists and weary travellers can check if a new version of any project is available whenever they visit the site. If they don’t visit the site because they use feed readers, then now they have a reason to visit the site. Weird logic. Look, the next release of this idea will be so super cool that all your readers will just HAVE to come to your site. I promise. Perhaps you can flog some advertising. Anyway, your mother will be impressed.
How do I get sweet Live Version Numbering love for my projects?
What follows below will work for your 100k line mega-framework down to your 10 line Rails plugin. As long as you can create and modify one file on your project’s website.
Let’s call that file version.js, and give it the following innards:
var myproject_version = "0.7.1";
document.write(" - " + myproject_version);
This is a small Javascript program that you will run within your blog to generate the version number. Its separated on to two lines so that it will be super easy for you to change the version number whenever you need to in the future.
Let’s say you’ve saved this file at the web address: http://www.myproject.org/version.js
Now, modify your blog to include your homebrew wizardry. Go to the templates, and edit the sidebar, or wherever you already have your projects listed. NOTE: if you currently have the projects generated for you from a blog list (like in WordPress) then you’ll need to stop using the list generator, and hand craft the html yourself. Be a man, its only one time.
For me, my original html for the two projects was:
<li><h2>Open Source Projects</h2> <ul> <li><a href="http://compositekeys.rubyforge.org">Composite Primary Keys</a></li> <li><a href="http://magicmodels.rubyforge.org">Dr Nic's Magic Models</a></li> </ul> </li>
To get the Live Version Numbers working make the following changes:
<li><h2>Open Source Projects</h2> <ul> <li><a href="http://compositekeys.rubyforge.org">Composite Primary Keys</a><script src="http://compositekeys.rubyforge.org/version.js" type="text/javascript"></script></li> <li><a href="http://magicmodels.rubyforge.org">Dr Nic's Magic Models</a><script src="http://magicmodels.rubyforge.org/version.js" type="text/javascript"></script></li> </ul> </li>
Let’s call this Cross-Site Scripting; other people do. If the javascript wasn’t coming from a known site – your project site – it’d be considered a security problem.
So now you have Live Version Numbers working, what do you do if you release a new version of one of your projects? You change the version number in the version.js file. You score extra points if your release mechanism can automatically update this value for you.
The future of Live Version Numbers – the Magic Edition
What your readers really want is an “in your face” notification or dropdown box if they need to know about a new version. Yes you could do a dedicated RSS feed instead/as well, but we’re trying to impress people here. RSS isn’t impressing anyone: if they understand it, they’re not impressed; if they don’t understand it, they’re not impressed.
So, the future version will include cookie support and magical information boxes to inform each individual visitor about changes to projects. This will definitely be magical. Your mother will know her school fees did some good.
Welcome! Welcome! Welcome! Ladies and Gentlemen, today you shall be thrilled and dazzled by wonders of magical mystery. Dr Nic’s Magic Models will now be unveiled to all. Mystery and magic that you will be able to perform at home.