on master help sign in
Remove code duplicate
26680f2Devine Lu Linvega
scripts/hallway.js+6−17
@@ -26,8 +26,8 @@ function Hallway (sites) {
26
26
27 this.refresh = function (feeds = this.cache) {
27 this.refresh = function (feeds = this.cache) {
28 const entries = this.findEntries(feeds)
28 const entries = this.findEntries(feeds)
29− const channels = this.findChannels(entries)
29+ const channels = this.find(entries, 'channel')
30− const users = this.findUsers(entries)
30+ const users = this.find(entries, 'author')
31 const tags = this.findTags(entries)
31 const tags = this.findTags(entries)
32 const relevantEntries = entries.filter(val => !this.finder.filter || (val.author === this.finder.filter || val.channel === this.finder.filter || val.tags.includes(this.finder.filter)))
32 const relevantEntries = entries.filter(val => !this.finder.filter || (val.author === this.finder.filter || val.channel === this.finder.filter || val.tags.includes(this.finder.filter)))
33
33
@@ -61,23 +61,12 @@ function Hallway (sites) {
61
61
62 // Entries
62 // Entries
63
63
64− this.findChannels = function (entries) {
64+ this.find = function (entries, p) {
65− const channels = {}
65+ const h = {}
66 for (const id in entries) {
66 for (const id in entries) {
67− const entry = entries[id]
67+ if (entries[id] && entries[id][p]) { h[entries[id][p]] = h[entries[id][p]] ? h[entries[id][p]] + 1 : 1 }
68− if (!entry.channel) { continue }
69− channels[entry.channel] = channels[entry.channel] ? channels[entry.channel] + 1 : 1
70− }
71− return channels
72− }
73−
74− this.findUsers = function (entries) {
75− const users = {}
76− for (const id in entries) {
77− const entry = entries[id]
78− users[entry.author] = users[entry.author] ? users[entry.author] + 1 : 1
79 }
68 }
80− return users
69+ return h
81 }
70 }
82
71
83 this.findTags = function (entries) {
72 this.findTags = function (entries) {