Skip to content

Commit 63c3302

Browse files
committed
add a sorting option
1 parent d4f4d19 commit 63c3302

File tree

3 files changed

+15
-3
lines changed

3 files changed

+15
-3
lines changed

README.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -286,6 +286,12 @@ const default_options = {
286286

287287
count: 20,
288288

289+
// optional sorting function for the entries.
290+
// Gets the array entries as the input, expects the sorted array
291+
// as its output.
292+
// e.g.: sort: entries => _.reverse( _.sortBy( entries, 'date' ) ),
293+
sort: entries => entries,
294+
289295
// ---------------------------------------------------------------------------
290296

291297
// supported - use in config as needed

index.js

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -226,6 +226,12 @@ PLUGIN.get_options_defaults = ( context ) =>
226226

227227
count: 20,
228228

229+
// optional sorting function for the entries.
230+
// Gets the array entries as the input, expects the sorted array
231+
// as its output.
232+
// e.g.: sort: entries => _.reverse( _.sortBy( entries, 'date' ) ),
233+
sort: entries => entries, // defaults to just returning it as it is
234+
229235
// -------------------------------------------------------------------------
230236

231237
// supported - use in config as needed

lib/Generator.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -84,9 +84,9 @@ class Generator
8484
{
8585

8686
try {
87-
88-
const pages = this.pages.slice( 0, this.options.count );
89-
87+
88+
const pages = this.options.sort(this.pages).slice( 0, this.options.count );
89+
9090
LIB.LOG.wait('Adding pages/posts as feed items...');
9191

9292
const out = [];

0 commit comments

Comments
 (0)