Tech Blog :: Generate pager (previous/next) links for an old Blogspot blog using Node.js
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.
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. (Uses the xml2js library, after trying 3 others that didn’t work as well/easily.)
- 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.
- The client-side script depends on jQuery, so make sure your blog template is loading that:
<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.)
- Customize the generated HTML in the client-side
addPagerForPost()function or style with CSS.
- Only works with a blog export; if your blog is still getting new content, this won’t read the RSS.