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

RSS Description in Post File Plans

09/15/15

I have finally decided to get around to messing with blog scripts again. Part of it is due to me having made a bunch of helper scripts at work and getting a lot out of it. Part of it is that I am still doing the RSS updating by hand everyday, and it's finally getting on my nerves again.

I mean, I first mentioned wanting to make the RSS thing smarter back in April. And it kinda trailed off shortly after that. Where does the time go? If I was better at documenting my stuff, I could answer that question, Stephan.

Anyways, right now I'm in the process of cooking a script that will first fix all the files I currently have, and I can then think further from there. Right now, it looks like:

/*jslint node: true */
(function () {
    "use strict";
    var cheerio = require('cheerio'),
        fs = require('fs');

    fs.readFile('public/basic.rss', 'utf-8', function (err, data) {
        var rss;

        if (err) {
            return console.trace(err);
        }

        rss = cheerio.load(data, {xmlMode: true});

        // TODO: sync up every RSS item with its post
        rss('item').each(function (index, element) {
            var htmlname;

            htmlname = rss(element).find('guid').text().trim()
                .replace('http://www.ksionda.me', 'public');

            //console.log(rss(element).html());
            //console.log(htmlname);

            fs.readFile(htmlname, 'utf-8', function (err, data) {
                var post,
                    viewname,
                    viewtext;

                if (err) {
                    return console.trace(err);
                }

                post = cheerio.load(data);

                viewtext = (
                    '    <div id="content">'
                    + post('#content,#temp').html()
                    + '</div>'
                );

                if (index === 0) {
                    console.log(viewtext);
                }

                viewname = htmlname.replace('public', 'views');
            });

        });
    });


    // TODO: Generate a file with an RSS section and blog post section

    // TODO: create copy of indexGenerate that updates the blog index file
    // and each blog post url that doesn't currently exist and updates the
    // rss file
}());

Right now this just grabs the blog content of each post in the RSS file, and prints that content if the RSS item index is 0. Soon, I'll have a bunch of files in views/blog that contain a content div and a description div, and from there I'll generate the rendered htmlpages and also the RSS file. I'll have to have a special case for posts that do not have RSS items.

I'm glad I'm finally getting around to this properly.