on master help sign in
Added tags
commit036a371468a11e3c639bdb28b008dec2edeec69b authorDevine Lu Linvega <aliceffekt@gmail.com> dateWed 3 Jul 2019, 17:40 (7 years ago) parentb45dda1
1 file changed+23−21
scripts/hallway.js+23−21
scripts/hallway.js+23−21
@@ -21,23 +21,19 @@ function Hallway (sites) {
2121 const channels = this.findChannels(entries)
2222 const users = this.findUsers(entries)
2323
24− const _entries = entries.filter((val,id) => { return id < 50 }).reduce((acc, val, id) => { return acc + this.templateEntry(val) + '\n' }, '')
25− const _channels = Object.keys(channels).reduce((acc, val, id) => { return acc + `<li>${val} <span class='right'>${channels[val]}</span></li>\n` }, '')
26− const _users = Object.keys(users).reduce((acc, val, id) => { return acc + `<li>${val} <span class='right'>${users[val]}</span></li>\n` }, '')
27−
2824 this.el.innerHTML = `
2925 <ul id='entries'>
30− ${_entries}
26+ ${entries.filter((val, id) => { return id < 50 }).reduce((acc, val, id) => { return acc + this.templateEntry(val) + '\n' }, '')}
3127 </ul>
3228 <div id='sidebar'>
3329 <ul id='channels'>
34− ${_channels}
30+ ${Object.keys(channels).reduce((acc, val, id) => { return acc + `<li>${val} <span class='right'>${channels[val]}</span></li>\n` }, '')}
3531 </ul>
3632 <ul id='users'>
37− ${_users}
33+ ${Object.keys(users).reduce((acc, val, id) => { return acc + `<li>${val} <span class='right'>${users[val]}</span></li>\n` }, '')}
3834 </ul>
3935 </div>
40− ${this._footer()}`
36+ <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>`
4137 }
4238
4339 // Entries
@@ -72,18 +68,30 @@ function Hallway (sites) {
7268 }
7369
7470 this.templateEntry = function (entry) {
75− if (entry.body.substr(0, 1) === '@') {
76− const user = entry.body.split(' ')[0]
77− entry.body = entry.body.replace(user, `<span class='user'>${user.toLowerCase()}</span>`)
71+ const words = entry.body.split(' ')
72+ const users = []
73+ const channels = []
74+ const tags = []
75+
76+ // Channels
77+ for (const id in words) {
78+ if (words[id].substr(0, 1) === '@') { users.push(words[id]) }
79+ if (words[id].substr(0, 1) === '/') { channels.push(words[id]) }
80+ if (words[id].substr(0, 1) === '#') { tags.push(words[id]) }
7881 }
7982
80− if (entry.body.substr(0, 1) === '/') {
81− const channel = entry.body.split(' ')[0]
82− entry.body = entry.body.replace(channel, `<span class='channel'>${channel.toLowerCase()}</span>`)
83+ for (const id in users) {
84+ entry.body = entry.body.replace(users[id], `<span class='user'>${users[id]}</span>`)
85+ }
86+ for (const id in channels) {
87+ entry.body = entry.body.replace(channels[id], `<span class='user'>${channels[id]}</span>`)
88+ }
89+ for (const id in tags) {
90+ entry.body = entry.body.replace(tags[id], `<span class='tag'>${tags[id]}</span>`)
8391 }
8492
8593 const filter = window.location.hash.substr(1).replace(/\+/g, ' ').toLowerCase()
86− const highlight = filter == entry.author.toLowerCase()
94+ const highlight = filter === entry.author.toLowerCase()
8795
8896 return `<li class='entry ${highlight ? 'highlight' : ''}'><span class='date'>${timeAgo(Date.parse(entry.date))}</span> <a class='author' href=''>${entry.author}</a> <span class='body'>${entry.body}</span></li>`
8997 }
@@ -118,12 +126,6 @@ function Hallway (sites) {
118126 })
119127 }
120128
121− // Extras
122−
123− this._footer = function () {
124− return '<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>'
125− }
126−
127129 // Utils
128130
129131 function compare (a, b) {