on master help sign in
Make links clickable.
9d85e83Devine Lu Linvega
scripts/hallway.js+7−2
@@ -72,12 +72,14 @@ function Hallway (sites) {
72 const users = []
72 const users = []
73 const channels = []
73 const channels = []
74 const tags = []
74 const tags = []
75+ const links = []
75
76
76 // Channels
77 // Channels
77 for (const id in words) {
78 for (const id in words) {
78 if (words[id].substr(0, 1) === '@') { users.push(words[id]) }
79 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) === '/') { channels.push(words[id]) }
80 if (words[id].substr(0, 1) === '#') { tags.push(words[id]) }
81 if (words[id].substr(0, 1) === '#') { tags.push(words[id]) }
82+ if (words[id].substr(0, 4) === 'http') { links.push(words[id]) }
81 }
83 }
82
84
83 for (const id in users) {
85 for (const id in users) {
@@ -89,6 +91,9 @@ function Hallway (sites) {
89 for (const id in tags) {
91 for (const id in tags) {
90 entry.body = entry.body.replace(tags[id], `<span class='tag'>${tags[id]}</span>`)
92 entry.body = entry.body.replace(tags[id], `<span class='tag'>${tags[id]}</span>`)
91 }
93 }
94+ for (const id in links) {
95+ entry.body = entry.body.replace(links[id], `<a href='${links[id]}'>${links[id].replace('https://', '').replace('http://', '')}</a>`)
96+ }
92
97
93 const filter = window.location.hash.substr(1).replace(/\+/g, ' ').toLowerCase()
98 const filter = window.location.hash.substr(1).replace(/\+/g, ' ').toLowerCase()
94 const highlight = filter === entry.author.toLowerCase()
99 const highlight = filter === entry.author.toLowerCase()
@@ -176,7 +181,7 @@ function Hallway (sites) {
176 return `${Math.floor(minutes / 1440)} days ago`
181 return `${Math.floor(minutes / 1440)} days ago`
177 }
182 }
178
183
179− function escapeHtml(unsafe) {
184+ function escapeHtml (unsafe) {
180− return unsafe.replace(/&/g, "&amp;").replace(/</g, "&lt;").replace(/>/g, "&gt;").replace(/"/g, "&quot;").replace(/'/g, "&#039;");
185+ return unsafe.replace(/&/g, '&amp;').replace(/</g, '&lt;').replace(/>/g, '&gt;').replace(/"/g, '&quot;').replace(/'/g, '&#039;')
181 }
186 }
182}
187}