Personal System Iterate: Weekly Review Init
04/05/15
Last time, I listed out all my diary posts not before 04/04/15, which happened to be just one post because yesterday was 04/04/15. But the point was that my linkText and beforeDate functions worked.
With that verified, now I want to grab the date of the last weekly review, so I can feed it into this functionality and get a link to all posts since my last weekly review.
And so I've made a bunch of changes again to accomodate this:
/*jslint node: true */
(function () {
'use strict';
var fs = require('fs'),
$ = require('cheerio'),
before,
linkText,
last,
date,
title;
date = function (blogpost) {
return blogpost.children('h2').text().trim();
};
title = function (blogpost) {
return blogpost.children('h1').text().trim();
};
linkText = function (postList) {
return function () {
var link,
blogpost = $(this);
link = function (blogpost) {
var ahref = blogpost.find('h1 a').attr('href');
if (ahref) {
return ahref.trim();
}
return '';
};
postList.push(
'<h3>\n <a href="'
+ link(blogpost)
+ '">\n '
+ title(blogpost)
+ '('
+ date(blogpost)
+ ')'
+ '</a>\n</h3>'
);
};
};
before = function (givenDate) {
var compareDates,
givenMonthDayYear;
givenMonthDayYear = givenDate.split('/');
compareDates = function (date) {
var monthDayYear = date.split('/');
if (monthDayYear[2] !== givenMonthDayYear[2]) {
// Compare years
return monthDayYear[2] < givenMonthDayYear[2];
}
if (monthDayYear[0] !== givenMonthDayYear[0]) {
// Compare months
return monthDayYear[0] < givenMonthDayYear[0];
}
if (monthDayYear[1] !== givenMonthDayYear[1]) {
// Compare days
return monthDayYear[1] < givenMonthDayYear[1];
}
// Default compare strings
return date < givenDate;
};
return function () {
var blogpost = $(this);
return compareDates(date(blogpost));
};
};
last = function (blogposts) {
return date($(blogposts.get(0)));
};
fs.readFile('public/diary/index.html', 'utf-8', function (err, data) {
var diaryPost = [],
weeklyReviews;
if (err) {
return;
}
weeklyReviews = $('.blogpost', data)
.filter(function () {
var blogpost = $(this);
return title(blogpost) === 'Weekly Review';
});
// Just this once, I want the weekly review before last
// This is a quick hack that filters out the most-recent weekly review
weeklyReviews = $(weeklyReviews).slice(1);
$('.blogpost', data)
.not(before(last(weeklyReviews)))
.each(linkText(diaryPost));
fs.readFile('public/blog/index.html', 'utf-8', function (err, data) {
if (err) {
return;
}
$('.blogpost', data)
.not(before(last(weeklyReviews)))
.each(linkText(diaryPost));
console.log(diaryPost.reverse().join('\n'));
});
});
}());
Which gave me an output of:
<h3>
<a href="death_note_fanfic_outline.html">
Death Note Fanfic Outline(03/23/15)</a>
</h3>
<h3>
<a href="magical_mundane.html">
Magical Mundane(03/24/15)</a>
</h3>
<h3>
<a href="frozen_shouldnt_have_had_bad_guy.html">
Frozen Shouldn't Have a Bad Guy(03/25/15)</a>
</h3>
<h3>
<a href="vim_functions.html">
Vim: Functions(03/26/15)</a>
</h3>
<h3>
<a href="functional_javascript.html">
Functional Javascript?(03/27/15)</a>
</h3>
<h3>
<a href="uagamejam_20150327.html">
UA Game Jam!(03/28/15)</a>
</h3>
<h3>
<a href="impressjs_the_beginning_draft.html">
()</a>
</h3>
<h3>
<a href="modular_development_environment.html">
Modular Development Environment(03/30/15)</a>
</h3>
<h3>
<a href="findReplace_js_is_back.html">
FindReplace.js is Back(03/31/15)</a>
</h3>
<h3>
<a href="iterating_my_system.html">
Iterating My System(04/01/15)</a>
</h3>
<h3>
<a href="training_everyday_plan.html">
Training Everyday Plan(04/02/15)</a>
</h3>
<h3>
<a href="javascript_cheerio_and_the_return_of_jquery.html">
Javascript: Cheerio and the Return of jQuery(04/03/15)</a>
</h3>
<h3>
<a href="css_digging_deeper.html">
CSS Digging Deeper(04/04/15)</a>
</h3>
<h3>
<a href="vim_tags.html">
Vim: Tags(04/05/15)</a>
</h3>
<h3>
<a href="diary_reposts.html">
Diary Reposts(04/06/15)</a>
</h3>
<h3>
<a href="gamedev_gamejam_invitation_talk_prep.html">
Game Dev Game Jam Invitation Talk Prep(03/23/15)</a>
</h3>
<h3>
<a href="building_plan_150323.html">
Building Plan(03/23/15)</a>
</h3>
<h3>
<a href="plan_document_150323.html">
Plan Document(03/23/15)</a>
</h3>
<h3>
<a href="ua_game_dev_javascript_talk_prep.html">
UA Game Dev Javascript Talk Prep(03/23/15)</a>
</h3>
<h3>
<a href="weekly_review_150323.html">
Weekly Review(03/23/15)</a>
</h3>
<h3>
<a href="end_of_day_routine_150323.html">
End of Day Routine(03/23/15)</a>
</h3>
<h3>
<a href="review_150323.html">
Review(03/23/15)</a>
</h3>
<h3>
<a href="log_150323.html">
Log(03/23/15)</a>
</h3>
<h3>
<a href="plan_document_150324.html">
Plan Document(03/24/15)</a>
</h3>
<h3>
<a href="morning_routine_150324.html">
Morning Routine(03/24/15)</a>
</h3>
<h3>
<a href="review_150324.html">
Review(03/24/15)</a>
</h3>
<h3>
<a href="log_150324.html">
Log(03/24/15)</a>
</h3>
<h3>
<a href="end_of_day_routine150324.html">
End of Day Routine(03/24/15)</a>
</h3>
<h3>
<a href="plan_document_150325.html">
Plan Document(03/25/15)</a>
</h3>
<h3>
<a href="review_150325.html">
Review(03/25/15)</a>
</h3>
<h3>
<a href="log_150325.html">
Log(03/25/15)</a>
</h3>
<h3>
<a href="end_of_day_routine_150325.html">
End of Day Routine(03/25/15)</a>
</h3>
<h3>
<a href="plan_document_150326.html">
Plan Document(03/26/15)</a>
</h3>
<h3>
<a href="plan_document_150326.html">
Plan Document(03/26/15)</a>
</h3>
<h3>
<a href="review_150326.html">
Review(03/27/15)</a>
</h3>
<h3>
<a href="log_150326.html">
Log(03/26/15)</a>
</h3>
<h3>
<a href="end_of_day_routine_150326.html">
End of Day Routine(03/27/15)</a>
</h3>
<h3>
<a href="building_plan_150328.html">
Building Plan(03/28/15)</a>
</h3>
<h3>
<a href="plan_document_150328.html">
Plan Document(03/28/15)</a>
</h3>
<h3>
<a href="impressjs_the_beginning_draft_150328.html">
()</a>
</h3>
<h3>
<a href="development_tools_improvement_vim_setup_150328.html">
Development Tools Improvement: Vim Setup(03/28/15)</a>
</h3>
<h3>
<a href="log_150328.html">
Log(03/28/15)</a>
</h3>
<h3>
<a href="end_of_day_review_150329.html">
End of Day Review(03/29/15)</a>
</h3>
<h3>
<a href="plan_document_150330.html">
Plan Document(03/30/15)</a>
</h3>
<h3>
<a href="gamedevclub_150330.html">
UA Game Dev Club Meeting(03/30/15)</a>
</h3>
<h3>
<a href="weekly_review_150330.html">
Weekly Review(03/30/15)</a>
</h3>
<h3>
<a href="end_of_day_review_150330.html">
End of Day Review(03/30/15)</a>
</h3>
<h3>
<a href="log_150330.html">
Plan Document(03/30/15)</a>
</h3>
<h3>
<a href="plan_document_150331.html">
Plan Document(03/31/15)</a>
</h3>
<h3>
<a href="personal_system_iterate_weekly_review_init_150331.html">
Personal System Iterate: Weekly Review Init(03/31/15)</a>
</h3>
<h3>
<a href="end_of_day_routine_150331.html">
End of Day Routine(03/31/15)</a>
</h3>
<h3>
<a href="end_of_day_review_150331.html">
End of Day Review(03/31/15)</a>
</h3>
<h3>
<a href="log_150331.html">
Log(03/31/15)</a>
</h3>
<h3>
<a href="plan_document_150401.html">
Plan Document(04/01/15)</a>
</h3>
<h3>
<a href="personal_system_iterate_weekly_review_init_150401.html">
Personal System Iterate: Weekly Review Init(04/01/15)</a>
</h3>
<h3>
<a href="log_150401.html">
Log(04/01/15)</a>
</h3>
<h3>
<a href="plan_document_150402.html">
Plan Document(04/02/15)</a>
</h3>
<h3>
<a href="personal_system_iterate_weekly_review_init_150402.html">
Personal System Iterate: Weekly Review Init(04/02/15)</a>
</h3>
<h3>
<a href="log_150402.html">
Log(04/01/15)</a>
</h3>
<h3>
<a href="plan_document_150403.html">
Plan Document(04/03/15)</a>
</h3>
<h3>
<a href="personal_system_iterate_weekly_review_init_150403.html">
Personal System Iterate: Weekly Review Init(04/03/15)</a>
</h3>
<h3>
<a href="log_150403.html">
Plan Document(04/03/15)</a>
</h3>
<h3>
<a href="plan_document_150404.html">
Plan Document(04/04/15)</a>
</h3>
<h3>
<a href="personal_system_iterate_weekly_review_init_150404.html">
Personal System Iterate: Weekly Review Init(04/04/15)</a>
</h3>
<h3>
<a href="end_of_day_review_150405.html">
End of Day Review(04/05/15)</a>
</h3>
<h3>
<a href="end_of_day_routine_150405.html">
End of Day Routine(04/05/15)</a>
</h3>
<h3>
<a href="log_150404.html">
Plan Document(04/04/15)</a>
</h3>
<h3>
<a href="plan_document_150405.html">
Plan Document(04/05/15)</a>
</h3>
Which will be something I plop right into my weekly review file tomorrow for prepping through the review of my last two weeks of blog posts (I may have covered a good portion of some of these last week, but I can easily erase the links I don't need to review).
And now, finally, I have a workable thing for initing my weekly review. I can defintely do more, but for now this is the most valuable part that I want to implement for now.
It might be good to switch my focus on other things for a bit, now. We'll see.