Rory's Diary
Home
Blog
Projects
Facebook
Google+
Github
RSS

Personal System Iterate: Weekly Review Init

04/01/15

Let's continue where I left off and feed in an html file as a commandline argument.

/*jslint node: true */
(function () {
    "use strict";
    var args = process.argv.slice(2),
        fs = require('fs'),
        cheerio = require('cheerio'),
        $,
        usage;

    usage = function () {
        console.log("Need a single input HTML file to read.");
    };

    if (args.length !== 1) {
        return usage();
    }

    fs.readFile(args[0], "utf-8", function (err, data) {
        if (err) {
            return usage();
        }
        $ = cheerio.load(data);

        console.log($.html());
    });
}());

Running this on my homepage's index.html file spits out... my homepage's html.

From here, I think I should play a bit. Could I count the number of blogposts in my blog area?

fs.readFile(args[0], "utf-8", function (err, data) {
    if (err) {
        return usage();
    }
    $ = cheerio.load(data);

    console.log($('.blogpost').length);
});

And running it gets me?

$ node blogpost.js public/blog/index.html
239

Only 239? I figured it'd be more by now. How many did I have at the beginning of the year?

Internal Distraction: Checking blog post from beginning of the year.

I had 150 blogposts at the end of last year according to my last post of last year (interesting, it seems my css link for that post is an abosolute path, still got some stuff to fix there).

So, I'm pretty close to 90 blogposts for this year, which considering my average of one per day, I feel confident that my little script there works.

Nice.

And that's all the time I have for today.