Generate pager (previous/next) links for an old Blogspot/Blogger blog using a Node.js app
by Ben Buckman (newleafdigital.com)
On an old blog from 2006 that still gets traffic (http://benb-xc-06.blogspot.com), I wanted to add Previous/Next links to each post (with their post titles) to help visitors navigate. But the old template didn’t have any tags available to make that happen within Blogger. So I wrote this node app to generate the links, loaded client-side via AJAX.
How it works
- Export your blog from Blogspot using the Export functionality. You’ll get a big XML file.
- Check out this code on a server with node.js installed.
- Put the exported XML file into the root of this app, as blog-export.xml; or change the path in app.js.
- Run the app (
node app.js, or with forever).
- The module in posts.js will parse the XML file and generate an in-memory array of all the post URLs and titles.
- The module in server.js will respond to HTTP requests (by default on port 3003, change as you wish):
- /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.
- [dependency] In your blog template, make sure jQuery is loaded if not already.
<script src='//ajax.googleapis.com/ajax/libs/jquery/1.X.X/jquery.min.js' />
- In your blog template, load the client-side script in this app, exposed at /js/blog-pager-client.js.
- Change the URL (
var url…) in the client-side script to the URL of your node app.
- Save the template, load a post page. (To debug, comment out the
bloggerPagerLog()and open the browser console.)
- Only works with a blog export; if your blog is still getting new content, this won’t read the RSS.
Enjoy! Feel free to contact me at ben at newleafdigital dot com.