on master help sign in
Make links clickable.
commit9d85e837ab3d68f51b830988ffdf1e121f80064e authorDevine Lu Linvega <aliceffekt@gmail.com> dateWed 3 Jul 2019, 20:03 (7 years ago) parent3a5d267
1 file changed+7−2
scripts/hallway.js+7−2
scripts/hallway.js+7−2
@@ -72,12 +72,14 @@ function Hallway (sites) {
7272 const users = []
7373 const channels = []
7474 const tags = []
75+ const links = []
7576
7677 // Channels
7778 for (const id in words) {
7879 if (words[id].substr(0, 1) === '@') { users.push(words[id]) }
7980 if (words[id].substr(0, 1) === '/') { channels.push(words[id]) }
8081 if (words[id].substr(0, 1) === '#') { tags.push(words[id]) }
82+ if (words[id].substr(0, 4) === 'http') { links.push(words[id]) }
8183 }
8284
8385 for (const id in users) {
@@ -89,6 +91,9 @@ function Hallway (sites) {
8991 for (const id in tags) {
9092 entry.body = entry.body.replace(tags[id], `<span class='tag'>${tags[id]}</span>`)
9193 }
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+ }
9297
9398 const filter = window.location.hash.substr(1).replace(/\+/g, ' ').toLowerCase()
9499 const highlight = filter === entry.author.toLowerCase()
@@ -176,7 +181,7 @@ function Hallway (sites) {
176181 return `${Math.floor(minutes / 1440)} days ago`
177182 }
178183
179− function escapeHtml(unsafe) {
180− return unsafe.replace(/&/g, "&amp;").replace(/</g, "&lt;").replace(/>/g, "&gt;").replace(/"/g, "&quot;").replace(/'/g, "&#039;");
184+ function escapeHtml (unsafe) {
185+ return unsafe.replace(/&/g, '&amp;').replace(/</g, '&lt;').replace(/>/g, '&gt;').replace(/"/g, '&quot;').replace(/'/g, '&#039;')
181186 }
182187}