@@ -10,7 +10,8 @@ function Hallway (sites) {
1010 this.sites = sites
1111 this.el = document.createElement('div')
1212 this.el.id = 'hallway'
13− this.filter = window.location.hash.replace('#', '').trim()
13+ const filterAndPage = window.location.hash.split('^')
14+ this.finder = { filter: filterAndPage[0].trim().replace('#', ''), page: filterAndPage[1] || 1 }
1415 this.cache = null
1516
1617 this.install = function (host) {
@@ -28,21 +29,27 @@ function Hallway (sites) {
2829 const channels = this.findChannels(entries)
2930 const users = this.findUsers(entries)
3031 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)))
3133
3234 this.el.innerHTML = `
33− <ul id='entries'>
34− ${entries.filter((val) => { return !this.filter || (val.author === this.filter || val.channel === this.filter || val.tags.includes(this.filter)) }).filter((_, id) => { return id < 50 }).reduce((acc, val) => { return acc + this.templateEntry(val) + '\n' }, '')}
35− </ul>
35+ <div id='entries'>
36+ <ul>
37+ ${entries.filter((val) => !this.finder.filter || (val.author === this.finder.filter || val.channel === this.finder.filter || val.tags.includes(this.finder.filter))).filter((_, id) => id < Number(this.finder.page) * 20 && id >= (Number(this.finder.page) -1) * 20).reduce((acc, val) => acc + this.templateEntry(val) + '\n', '')}
38+ </ul>
39+ <div id='pagination'>
40+ ${[...Array(Math.ceil(relevantEntries.length / 20)).keys()].reduce((acc, num) => `${acc}<span class='${Number(hallway.finder.page) === num + 1 ? "selected" : ""}' onclick='filter("${this.finder.filter}^${num + 1}")'>${num + 1}</span>`, '')}
41+ </div>
42+ </div>
3643 <div id='sidebar'>
3744 <ul id='channels'>
38− <li onclick='filter("")' class='${hallway.filter === '' ? 'selected' : ''}'><a href='#'>hallway <span class='right'>${entries.length}</span></a></li>
39− ${Object.keys(channels).reduce((acc, val) => { return acc + `<li onclick='filter("${val}")' class='${hallway.filter === val ? 'selected' : ''}'><a href='#${val}'>${val} <span class='right'>${channels[val]}</span></a></li>\n` }, '')}
45+ <li onclick='filter("")' class='${hallway.finder.filter === '' ? 'selected' : ''}'><a href='#'>hallway <span class='right'>${entries.length}</span></a></li>
46+ ${Object.keys(channels).reduce((acc, val) => acc + `<li onclick='filter("${val}")' class='${hallway.finder.filter === val ? 'selected' : ''}'><a href='#${val}'>${val} <span class='right'>${channels[val]}</span></a></li>\n`, '')}
4047 </ul>
4148 <ul id='users'>
42− ${Object.keys(users).reduce((acc, val) => { return acc + `<li onclick='filter("${val}")' class='${hallway.filter === val ? 'selected' : ''}' href='#${val}'>${val} <span class='right'>${users[val]}</span></li>\n` }, '')}
49+ ${Object.keys(users).reduce((acc, val) => acc + `<li onclick='filter("${val}")' class='${hallway.finder.filter === val ? 'selected' : ''}' href='#${val}'>${val} <span class='right'>${users[val]}</span></li>\n`, '')}
4350 </ul>
4451 <ul id='tags'>
45− ${Object.keys(tags).reduce((acc, val) => { return acc + `<li onclick='filter("${val}")' class='${hallway.filter === val ? 'selected' : ''}' href='#${val}'>#${val} <span class='right'>${tags[val]}</span></li>\n` }, '')}
52+ ${Object.keys(tags).reduce((acc, val) => acc + `<li onclick='filter("${val}")' class='${hallway.finder.filter === val ? 'selected' : ''}' href='#${val}'>#${val} <span class='right'>${tags[val]}</span></li>\n`, '')}
4653 </ul>
4754 </div>
4855 <p>The <b>Hallway</b> is a decentralized forum, to join the conversation, simply create yourself a <a href="https://twtxt.readthedocs.io/en/stable/user/twtxtfile.html">twtxt</a> feed and <a href="https://github.com/XXIIVV/Webring/">add it</a> to your entry in the <a href="index.html">webring</a>.</p>`
@@ -119,8 +126,7 @@ function Hallway (sites) {
119126
120127 this.findFeeds = function () {
121128 console.log('Finding feeds..')
122− for (const id in sites) {
123− const site = sites[id]
129+ for (const site of sites) {
124130 if (site.feed && site.author) {
125131 feeds[site.author] = { path: site.feed }
126132 }
@@ -148,7 +154,7 @@ function Hallway (sites) {
148154 // Utils
149155
150156 function parseFeed (author, feed) {
151− const lines = feed.split('\n').filter((line) => { return line.substr(0,1) !== '#' })
157+ const lines = feed.split('\n').filter((line) => line.substr(0,1) !== '#')
152158 const entries = []
153159 for (const id in lines) {
154160 const line = lines[id].trim()
@@ -198,6 +204,7 @@ function Hallway (sites) {
198204
199205function filter (name) {
200206 window.location.hash = name
201− hallway.filter = window.location.hash.replace('#', '').trim()
207+ const filterAndPage = window.location.hash.split('^')
208+ hallway.finder = { filter: filterAndPage[0].trim().replace('#', ''), page: filterAndPage[1] || 1 }
202209 hallway.refresh()
203210}