Created
September 19, 2013 21:49
-
-
Save ruemic/6630337 to your computer and use it in GitHub Desktop.
Calendar extension for organizing entries into past and future by month
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Use <pop:calendar:months> within the scope of entries to generate | |
// a timeline array of all the months which have entries | |
exports.months = function() { | |
if (!section) return null; | |
var result = site.search({ | |
all: true, | |
filters: {section: section, date: "future" }, | |
timeline: {date: "month"} | |
}).timeline; | |
return result; | |
// Returns a simple array of months with 'start' & 'end' atrributes | |
}; | |
// Use <pop:entries_for start="<pop:start/>" end="<pop:end/>"> inside of <pop:calendar:months> | |
// to render a collection of entries with a date between the specified 'start' and 'end' date. | |
exports.entries_between = function(options) { | |
if (!section) return null; | |
var start = new Date(options.start); | |
var end = new Date(options.end); | |
if ( new Date() > start ) | |
start = new Date() | |
var results = site.search({ | |
all: true, | |
filters: {section: section, date: {from: start, to: end}}, | |
order: "date ASC" | |
}).results; | |
log(JSON.stringify(results)); | |
return results; | |
// Returns an array of entries which you can render out | |
// in your templates like a regular <pop:entries> tag. | |
}; | |
exports.past_months = function(options) { | |
if (!section) return null; | |
var result = site.search({ | |
all: true, | |
filters: {section: section, date: "past" }, | |
timeline: {date: "month"} | |
}).timeline; | |
return result; | |
// Returns a simple array of months with 'start' & 'end' atrributes | |
}; | |
// Generates an array of entries who's 'date' field falls | |
// within the specified 'start' and 'end' date. | |
exports.past_entries_between = function(options) { | |
if (!section) return null; | |
var start = new Date(options.start), end = new Date(options.end); | |
if ( new Date() < end ) | |
end = new Date() | |
var results = site.search({ | |
all: true, | |
filters: {section: section, date: {from: start, to: end}}, | |
order: "date DESC" | |
}).results; | |
return results; | |
// Returns an array of tour dates which you can render out | |
// in your templates like a regular collection tag. | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment