Tech Blog :: Generate pager (previous/next) links for an old Blogspot blog using Node.js

Nov 25 '11 11:30am

Generate pager (previous/next) links for an old Blogspot blog using Node.js

I have an old Blogspot blog that still gets a lot of traffic, but it was very hard to navigate without links from post to post. The template uses an old version of their templating language, and doesn’t have any tags available to generate pager links within Blogger.

So I wrote a node app called Blogger Pager (code on Github) to generate the links, loaded client-side via AJAX.

How it works

  1. Export your blog from Blogspot using the Export functionality. You’ll get a big XML file.
  2. Check out this code on a server with node.js installed.
  3. Put the exported XML file into the root of this app, as blog-export.xml; or change the path in app.js.
  4. Run the app (node app.js, or with forever).
  5. The module in posts.js will parse the XML file and generate an in-memory array of all the post URLs and titles. (Uses the xml2js library, after trying 3 others that didn’t work as well/easily.)
  6. The module in server.js will respond to HTTP requests (by default on port 3003, set in server.js):
    • /pager handles JSONP requests with a ?url parameter, returning a JSON object of the surrounding posts.
    • /posts returns an HTML page of all the parsed posts.
  7. The client-side script depends on jQuery, so make sure your blog template is loading that:
    • e.g. <script src='//' />
  8. In your blog template, load the client-side script in this app, exposed at /js/blog-pager-client.js.
  9. Change the URL (var url…) in the client-side script to the URL of your node app.
  10. Save the template, load a post page. (To debug, comment out the return in bloggerPagerLog() and open the browser console.)
  11. Customize the generated HTML in the client-side addPagerForPost() function or style with CSS.

Known Limitations

  1. Only works with a blog export; if your blog is still getting new content, this won’t read the RSS.