on master help sign in
add in pagination
commit83aeeb64bcba70b16da6c0a260ac47cce6f6db81 authorckipp01 <ckipp@pm.me> dateMon 22 Jul 2019, 16:05 (7 years ago) parentab3831d
2 files changed+25−14
links/main.css+6−2 scripts/hallway.js+19−12
links/main.css+6−2
@@ -1,7 +1,7 @@
11* { margin:0;padding:0;border:0;outline:0;text-decoration:none;font-weight:inherit;font-style:inherit;color:inherit;font-size:100%;font-family:inherit;vertical-align:baseline;list-style:none;border-collapse:collapse;border-spacing:0; -webkit-font-smoothing: antialiased;-moz-osx-font-smoothing: grayscale;}
22
33body { background:#f4f4f4; padding:0px; margin:0px; }
4−body div { display:block; background: #111;min-height: calc(100vh - 60px);width: calc(100vw - 60px);margin: 15px;color: #333;padding: 15px;font-family:'input_mono_regular', 'Monospaced','Courier New',courier;font-size:11px; position: relative; border-radius: 2px; color:white;}
4+body > div { display:block; background: #111;min-height: calc(100vh - 60px);width: calc(100vw - 60px);margin: 15px;color: #333;padding: 15px;font-family:'input_mono_regular', 'Monospaced','Courier New',courier;font-size:11px; position: relative; border-radius: 2px; color:white;}
55body div ul { max-width: 800px; border-bottom: 2px solid white;padding-bottom: 15px;margin-bottom:15px; overflow: hidden;}
66body div p { display:block; padding:0px 5px; line-height: 20px; max-width: 600px}
77body div p a { text-decoration: underline;}
@@ -12,7 +12,11 @@ body div p.readme { max-width:500px; }
1212/* Hallway */
1313
1414body #hallway #entries { width: calc(100vw - 300px) !important; }
15−body #hallway #sidebar { position: absolute;top: 0px;right: 0px;padding: 0px 15px;width: 200px; }
15+body #hallway #sidebar { position: absolute;top: 0px;right: 0px;padding: 15px;width: 200px; }
16+
17+body #hallway #pagination { margin: 10px; text-align: center; }
18+body #hallway #pagination span { padding: 3px; margin: 2px; cursor: pointer; }
19+body #hallway #pagination span.selected { background: white; color:black; }
1620
1721body #hallway #sidebar > * { border-bottom: 0px; line-height: 16px; padding-bottom: 0px }
1822body #hallway #sidebar > * li { text-transform: lowercase; }
scripts/hallway.js+19−12
@@ -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}