Personal System Iterate: Weekly Review Init
04/02/15
Last time I grabbed all my blogposts into an array and got the length of the array. This time, I want to do something a bit more complicated; I want to reduce the blogposts to the ones since my last weekly review.
Now, part of me thinks this is one of those things I should do synchronously, but I want to apply this ability to more than just a list of posts between points in time. However, I also want to keep the chronological order for each blog post that triggers correctly.
Hmmm.... Let's make a thing that does the thing and think about better construction after.
So... I don't know jQuery syntax very well. This is something I need to think about carefully.
This is something I need to research, actually.
And yet I still managed to hack something together that is slowly approximating what I want to do!
$ = cheerio.load(data, {
normalizeWhitespace: true
});
blogposts = [];
$('.blogpost').each(function (index) {
var that = this,
validPost = function () {
if (date && $(that).children("h2").text().search(date) === -1) {
return false;
}
if (!date) {
if ($(that).children("h1").text().replace(/\ /g,'') === "WeeklyReview") {
date = $(that).children("h2").text();
}
}
return true;
};
if (validPost()) {
return blogposts[index] = $(this).children("h1,h2").text();
}
return false;
});
console.log(blogposts.join('\n'));
This code outputs:
$ node blogpost.js ../public/diary/index.html
Plan Document 04/01/15
Log 04/01/15
Personal System Iterate: Weekly Review Init 04/01/15
Plan Document 04/01/15
Log 03/31/15
End of Day Review 03/31/15
End of Day Routine 03/31/15
Personal System Iterate: Weekly Review Init 03/31/15
Plan Document 03/31/15
Plan Document 03/30/15
End of Day Review 03/30/15
Weekly Review 03/30/15
UA Game Dev Club Meeting 03/30/15
Plan Document 03/30/15
Which is the title and date of each diary post of each day up until and including the day I wrote a post with a weekly review title.
Format it so it's html that links to the post refenced, and that's exactly what I want.
Next time?