@@ -10,7 +10,8 @@ function Hallway (sites) {
10 this.sites = sites
10 this.sites = sites
11 this.el = document.createElement('div')
11 this.el = document.createElement('div')
12 this.el.id = 'hallway'
12 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 }
14 this.cache = null
15 this.cache = null
16 this.install = function (host) {
17 this.install = function (host) {
@@ -28,21 +29,27 @@ function Hallway (sites) {
28 const channels = this.findChannels(entries)
29 const channels = this.findChannels(entries)
29 const users = this.findUsers(entries)
30 const users = this.findUsers(entries)
30 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 this.el.innerHTML = `
34 this.el.innerHTML = `
33− <ul id='entries'>
35+ <div 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' }, '')}
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', '')}
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>`, '')}
36 <div id='sidebar'>
43 <div id='sidebar'>
37 <ul id='channels'>
44 <ul id='channels'>
38− <li onclick='filter("")' class='${hallway.filter === '' ? 'selected' : ''}'><a href='#'>hallway <span class='right'>${entries.length}</span></a></li>
45+ <li onclick='filter("")' class='${hallway.finder.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` }, '')}
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`, '')}
41 <ul id='users'>
48 <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`, '')}
44 <ul id='tags'>
51 <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`, '')}
48 <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>`
55 <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) {
120 this.findFeeds = function () {
127 this.findFeeds = function () {
121 console.log('Finding feeds..')
128 console.log('Finding feeds..')
122− for (const id in sites) {
129+ for (const site of sites) {
123− const site = sites[id]
124 if (site.feed && site.author) {
130 if (site.feed && site.author) {
125 feeds[site.author] = { path: site.feed }
131 feeds[site.author] = { path: site.feed }
@@ -148,7 +154,7 @@ function Hallway (sites) {
150 function parseFeed (author, feed) {
156 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) !== '#')
152 const entries = []
158 const entries = []
153 for (const id in lines) {
159 for (const id in lines) {
154 const line = lines[id].trim()
160 const line = lines[id].trim()
@@ -198,6 +204,7 @@ function Hallway (sites) {
199function filter (name) {
205function filter (name) {
200 window.location.hash = name
206 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 }
202 hallway.refresh()
209 hallway.refresh()