on master help sign in
Added tags
036a371Devine Lu Linvega
scripts/hallway.js+23−21
@@ -21,23 +21,19 @@ function Hallway (sites) {
21 const channels = this.findChannels(entries)
21 const channels = this.findChannels(entries)
22 const users = this.findUsers(entries)
22 const users = this.findUsers(entries)
23
23
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−
28 this.el.innerHTML = `
24 this.el.innerHTML = `
29 <ul id='entries'>
25 <ul id='entries'>
30− ${_entries}
26+ ${entries.filter((val, id) => { return id < 50 }).reduce((acc, val, id) => { return acc + this.templateEntry(val) + '\n' }, '')}
31 </ul>
27 </ul>
32 <div id='sidebar'>
28 <div id='sidebar'>
33 <ul id='channels'>
29 <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` }, '')}
35 </ul>
31 </ul>
36 <ul id='users'>
32 <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` }, '')}
38 </ul>
34 </ul>
39 </div>
35 </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>`
41 }
37 }
42
38
43 // Entries
39 // Entries
@@ -72,18 +68,30 @@ function Hallway (sites) {
72 }
68 }
73
69
74 this.templateEntry = function (entry) {
70 this.templateEntry = function (entry) {
75− if (entry.body.substr(0, 1) === '@') {
76− const user = entry.body.split(' ')[0]
71+ const words = entry.body.split(' ')
77− entry.body = entry.body.replace(user, `<span class='user'>${user.toLowerCase()}</span>`)
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]) }
78 }
81 }
79
82
80− if (entry.body.substr(0, 1) === '/') {
83+ for (const id in users) {
81− const channel = entry.body.split(' ')[0]
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) {
82− entry.body = entry.body.replace(channel, `<span class='channel'>${channel.toLowerCase()}</span>`)
90+ entry.body = entry.body.replace(tags[id], `<span class='tag'>${tags[id]}</span>`)
83 }
91 }
84
92
85 const filter = window.location.hash.substr(1).replace(/\+/g, ' ').toLowerCase()
93 const filter = window.location.hash.substr(1).replace(/\+/g, ' ').toLowerCase()
86− const highlight = filter == entry.author.toLowerCase()
94+ const highlight = filter === entry.author.toLowerCase()
87
95
88 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>`
96 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>`
89 }
97 }
@@ -118,12 +126,6 @@ function Hallway (sites) {
118 })
126 })
119 }
127 }
120
128
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−
127 // Utils
129 // Utils
128
130
129 function compare (a, b) {
131 function compare (a, b) {