function sendYearListing(request, response) {
    var year = request.params.slug;
    var retVal = '<div class="center"><h1>' + year + '</h1></div>';
    var currentMonth = null;
    var anyFound = false;

    allPostsSortedAndGrouped(function (postsByDay) {
        postsByDay.each(function (day) {
            var thisDay = Date.create(day.date);
            if (thisDay.is(year)) {
                // Date.isBetween() is not inclusive, so back the from date up one
                var thisMonth = new Date(Number(year), Number(currentMonth)).addDays(-1);
                // ...and advance the to date by two (one to offset above, one to genuinely add).
                var nextMonth = Date.create(thisMonth).addMonths(1).addDays(2);

                //console.log(thisMonth.short() + ' <-- ' + thisDay.short() + ' --> ' + nextMonth.short() + '?   ' + (thisDay.isBetween(thisMonth, nextMonth) ? 'YES' : 'NO'));
                if (currentMonth === null || !thisDay.isBetween(thisMonth, nextMonth)) {
                    // If we've started a month list, end it, because we're on a new month now.
                    if (currentMonth >= 0) {
                        retVal += '</ul>';
                    }

					anyFound = true;
                    currentMonth = thisDay.getMonth();
                    retVal += '<h2><a href="/' + year + '/' + (currentMonth + 1) + '/">' + thisDay.format('{Month}') + '</a></h2>\n<ul>';
                }

                day.articles.each(function (article) {
                    retVal += '<li><a href="' + externalFilenameForFile(article.file) + '">' + article.metadata.Title + '</a></li>';
                });
            }
        });

        if (!anyFound) {
			retVal += "<i>No posts found.</i>";
        }

		var updatedSource = performMetadataReplacements(siteMetadata, headerSource);
		var header = updatedSource.replace(metadataMarker + 'Title' + metadataMarker, 'Posts for ' + year);
        response.status(200).send(header + retVal + footerSource);
    });

}
// Sends a listing of an entire year's posts.
Sends a listing of an entire year's posts.
Sends a listing of an entire year ' s posts .
function sendYearListing(request, response) {
    var year = request.params.slug;
    var retVal = '<div class="center"><h1>' + year + '</h1></div>';
    var currentMonth = null;
    var anyFound = false;
    allPostsSortedAndGrouped(function (postsByDay) {
        postsByDay.each(function (day) {
            var thisDay = Date.create(day.date);
            if (thisDay.is(year)) {
                var thisMonth = new Date(Number(year), Number(currentMonth)).addDays(-1);
                var nextMonth = Date.create(thisMonth).addMonths(1).addDays(2);
                if (currentMonth === null || !thisDay.isBetween(thisMonth, nextMonth)) {
                    if (currentMonth >= 0) {
                        retVal += '</ul>';
                    }
					anyFound = true;
                    currentMonth = thisDay.getMonth();
                    retVal += '<h2><a href="/' + year + '/' + (currentMonth + 1) + '/">' + thisDay.format('{Month}') + '</a></h2>\n<ul>';
                }
                day.articles.each(function (article) {
                    retVal += '<li><a href="' + externalFilenameForFile(article.file) + '">' + article.metadata.Title + '</a></li>';
                });
            }
        });
        if (!anyFound) {
			retVal += "<i>No posts found.</i>";
        }
		var updatedSource = performMetadataReplacements(siteMetadata, headerSource);
		var header = updatedSource.replace(metadataMarker + 'Title' + metadataMarker, 'Posts for ' + year);
        response.status(200).send(header + retVal + footerSource);
    });
}
function sendYearListing ( request , response ) { var year = request . params . slug ; var retVal = '<div class="center"><h1>' + year + '</h1></div>' ; var currentMonth = null ; var anyFound = false ; allPostsSortedAndGrouped ( function ( postsByDay ) { postsByDay . each ( function ( day ) { var thisDay = Date . create ( day . date ) ; if ( thisDay . is ( year ) ) { var thisMonth = new Date ( Number ( year ) , Number ( currentMonth ) ) . addDays ( - 1 ) ; var nextMonth = Date . create ( thisMonth ) . addMonths ( 1 ) . addDays ( 2 ) ; if ( currentMonth === null || ! thisDay . isBetween ( thisMonth , nextMonth ) ) { if ( currentMonth >= 0 ) { retVal += '</ul>' ; } anyFound = true ; currentMonth = thisDay . getMonth ( ) ; retVal += '<h2><a href="/' + year + '/' + ( currentMonth + 1 ) + '/">' + thisDay . format ( '{Month}' ) + '</a></h2>\n<ul>' ; } day . articles . each ( function ( article ) { retVal += '<li><a href="' + externalFilenameForFile ( article . file ) + '">' + article . metadata . Title + '</a></li>' ; } ) ; } } ) ; if ( ! anyFound ) { retVal += "<i>No posts found.</i>" ; } var updatedSource = performMetadataReplacements ( siteMetadata , headerSource ) ; var header = updatedSource . replace ( metadataMarker + 'Title' + metadataMarker , 'Posts for ' + year ) ; response . status ( 200 ) . send ( header + retVal + footerSource ) ; } ) ; }
Sends a listing of an entire year's posts.
Sends a listing of an entire year ' s posts .
// Date.isBetween() is not inclusive, so back the from date up one // ...and advance the to date by two (one to offset above, one to genuinely add). //console.log(thisMonth.short() + ' <-- ' + thisDay.short() + ' --> ' + nextMonth.short() + '?   ' + (thisDay.isBetween(thisMonth, nextMonth) ? 'YES' : 'NO')); // If we've started a month list, end it, because we're on a new month now.