This repository was archived by the owner on Aug 16, 2025. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathplugin.ergo.js
More file actions
60 lines (49 loc) · 1.53 KB
/
plugin.ergo.js
File metadata and controls
60 lines (49 loc) · 1.53 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
var l = function() { } //function(str) { console.log('next/prev: '+str); }
function _find(data, direction) {
var uri = data.uri;
var post_type = data.post_type;
if (!uri || !post_type) {
l(uri + ' not found: post_type='+post_type)
return null;
}
//l('data is:\n' + (require('util').inspect(data, {colors:true})))
var all = data[post_type]; // this relies upon collate plugin
if (!all) {
l('list of post_types not found for ' + uri)
return null;
}
var idx = all.findIndex(function(p) { return p.uri == uri; })
if (idx<0) {
l(uri + ' not found in current list')
return null;
}
idx += direction;
if (idx<0 || idx>=all.length) {
l(uri + ' + ' + direction +' == bof/eof')
return null;
}
var post = all[idx];
l(uri + ' + ' + direction + ' ==> ' + post.uri)
post.isFirst = idx===0; // stop calling back into our 'isFirst/isLast', by providing the extra info now, directly
post.isLast = idx===all.length-1;
return post;
}
module.exports = {
name: "Ergo Next/Prev Plugin",
url: "https://github.com/ergo-cms/plugin-nextprev",
active: true,
version: "1.0.0",
default_fields: {
has_nextprev: true, // a simple signal to themes that we're available
next: function() { return _find(this, 1); },
prev: function() { return _find(this, -1); },
/*isFirst: function() { // this can interfere when iterating a section. Usematch also defines 'isFirst' & 'isLast'
var p = _find(this, 0);
return !!p ? p.isFirst : false;
},
isLast: function() {
var p = _find(this, 0);
return !!p ? p.isLast : false;
},*/
}
}