on master help sign in
Limit sidebar content to 15 items each, fixes #198
commitfa7585159eabf2cec1b2b7218d2ec55ecc7e0d66 authorDevine Lu Linvega <aliceffekt@gmail.com> dateTue 23 Jul 2019, 16:26 (7 years ago) parentaf92c91
2 files changed+12−12
scripts/hallway.js+11−11 scripts/sites.js+1−1
scripts/hallway.js+11−11
@@ -11,7 +11,7 @@ function Hallway (sites) {
1111 this.el = document.createElement('div')
1212 this.el.id = 'hallway'
1313 const filterAndPage = window.location.hash.split('^')
14− this.finder = { filter: filterAndPage[0].trim().replace('#', ''), page: filterAndPage[1] || 1 }
14+ this.finder = { filter: filterAndPage[0].trim().replace('#', ''), page: filterAndPage[1] || 1 }
1515 this.cache = null
1616
1717 this.install = function (host) {
@@ -34,22 +34,22 @@ function Hallway (sites) {
3434 this.el.innerHTML = `
3535 <div id='entries'>
3636 <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', '')}
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', '')}
3838 </ul>
3939 <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>`, '')}
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>`, '')}
4141 </div>
4242 </div>
4343 <div id='sidebar'>
4444 <ul id='channels'>
4545 <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`, '')}
46+ ${Object.keys(channels).slice(0, 15).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`, '')}
4747 </ul>
4848 <ul id='users'>
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`, '')}
49+ ${Object.keys(users).slice(0, 15).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`, '')}
5050 </ul>
5151 <ul id='tags'>
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`, '')}
52+ ${Object.keys(tags).slice(0, 15).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`, '')}
5353 </ul>
5454 </div>
5555 <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>`
@@ -80,7 +80,7 @@ function Hallway (sites) {
8080 return users
8181 }
8282
83− this.findTags = function (entries){
83+ this.findTags = function (entries) {
8484 const tags = {}
8585 for (const id in entries) {
8686 const entry = entries[id]
@@ -98,7 +98,7 @@ function Hallway (sites) {
9898 a.push(feeds[id].content[i])
9999 }
100100 }
101− return a.sort( (a, b) => a.offset - b.offset )
101+ return a.sort((a, b) => a.offset - b.offset)
102102 }
103103
104104 this.findMention = function (found) {
@@ -154,7 +154,7 @@ function Hallway (sites) {
154154 // Utils
155155
156156 function parseFeed (author, feed) {
157− const lines = feed.split('\n').filter((line) => line.substr(0,1) !== '#')
157+ const lines = feed.split('\n').filter((line) => line.substr(0, 1) !== '#')
158158 const entries = []
159159 for (const id in lines) {
160160 const line = lines[id].trim()
@@ -163,7 +163,7 @@ function Hallway (sites) {
163163 const date = parts[0].trim()
164164 const body = escapeHtml(parts[1].trim()).trim()
165165 const channel = body.substr(0, 1) === '/' ? body.split(' ')[0].substr(1).toLowerCase() : body.substr(0, 1) === '@' ? 'veranda' : 'lobby'
166− const tags = (body.match(re_tag)||[]).map(a => a.substr(a.indexOf('#')+1).toLowerCase())
166+ const tags = (body.match(re_tag) || []).map(a => a.substr(a.indexOf('#') + 1).toLowerCase())
167167 const offset = new Date() - new Date(date)
168168 entries.push({ date, body, author, offset, channel, tags })
169169 }
@@ -205,6 +205,6 @@ function Hallway (sites) {
205205function filter (name) {
206206 window.location.hash = name
207207 const filterAndPage = window.location.hash.split('^')
208− hallway.finder = { filter: filterAndPage[0].trim().replace('#', ''), page: filterAndPage[1] || 1 }
208+ hallway.finder = { filter: filterAndPage[0].trim().replace('#', ''), page: filterAndPage[1] || 1 }
209209 hallway.refresh()
210210}
scripts/sites.js+1−1
@@ -9,7 +9,7 @@ const sites = [
99 { url: 'https://electro.pizza', title: 'electro pizza', type: 'blog', author: 'rho', rss: 'https://electro.pizza/feed.xml', feed: 'https://electro.pizza/twtxt.txt' },
1010 { url: 'https://ianjbattaglia.co' },
1111 { url: 'https://avanier.now.sh', title: 'Arachne', type: 'wiki', author: 'joshavanier', contact: 'joshavanier@protonmail.com' },
12− { url: 'http://kaemura.com', title: 'kaemura.com', type: 'blog', author: 'kaemura', contact: 'chimera1190@gmail.com', feed: 'https://kaemura.com/twttxt.txt'},
12+ { url: 'http://kaemura.com', title: 'kaemura.com', type: 'blog', author: 'kaemura', contact: 'chimera1190@gmail.com', feed: 'https://kaemura.com/twttxt.txt' },
1313 { url: 'https://liamcooke.com' },
1414 { url: 'https://electricgecko.de' },
1515 { url: 'https://wichniow.ski' },