-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathissue-navigation.js
More file actions
60 lines (50 loc) · 1.85 KB
/
issue-navigation.js
File metadata and controls
60 lines (50 loc) · 1.85 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
59
60
// issue-navigation.js - Issue navigation helper
class IssueNavigation {
static generateIssueSelector() {
if (!window.journalData || !window.journalData.issues) {
console.warn('Journal data not available for issue selector');
return [];
}
return Object.entries(window.journalData.issues)
.map(([issueId, issue]) => ({
id: issueId,
title: issue.title,
year: issue.year,
volume: issue.volume,
number: issue.number,
url: `issues.html?issue=${issueId}`
}))
.sort((a, b) => {
if (b.year !== a.year) return b.year - a.year;
if (b.volume !== a.volume) return b.volume - a.volume;
return b.number - a.number;
});
}
static getIssueUrl(issueId) {
return `issues.html?issue=${issueId}`;
}
static getPreviousIssue(currentIssueId) {
const issues = this.generateIssueSelector();
const currentIndex = issues.findIndex(issue => issue.id === currentIssueId);
if (currentIndex > 0) {
return {
...issues[currentIndex - 1],
url: this.getIssueUrl(issues[currentIndex - 1].id)
};
}
return null;
}
static getNextIssue(currentIssueId) {
const issues = this.generateIssueSelector();
const currentIndex = issues.findIndex(issue => issue.id === currentIssueId);
if (currentIndex >= 0 && currentIndex < issues.length - 1) {
return {
...issues[currentIndex + 1],
url: this.getIssueUrl(issues[currentIndex + 1].id)
};
}
return null;
}
}
// Make available globally
window.IssueNavigation = IssueNavigation;