3const re_channel = /(\s|^)\/([a-zA-Z0-9]+)/g
4const re_user = /((\s|^)@<[a-zA-Z0-9./:\-_\+~#= ]*>)/g
5const re_tag = /([^&]|^)\#([a-zA-Z0-9]+)/g
6const re_url = /((https?):\/\/(([-a-zA-Z0-9@:%._\+~#=]{2,256}\.[a-z]{2,6}\b)([-a-zA-Z0-9@:%_\+.~#?&//=]*)))/g
8function Hallway (sites) {
11 this.el = document.createElement('div')
12 this.el.id = 'hallway'
13 const filterAndPage = window.location.hash.split('^')
14 this.finder = { filter: filterAndPage[0].trim().replace('#', ''), page: filterAndPage[1] || 1 }
17 this.install = function (host) {
18 host.appendChild(this.el)
22 this.start = function () {
23 this.el.innerHTML = 'hello.'
27 this.refresh = function (feeds = this.cache) {
28 const entries = this.findEntries(feeds)
29 const channels = this.find(entries, 'channel')
30 const users = this.find(entries, 'author')
31 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)))
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', '')}
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>`, '')}
45 <li onclick='filter("")' class='${hallway.finder.filter === '' ? 'selected' : ''}'><a href='#'>hallway <span class='right'>${entries.length}</span></a></li>
46 ${Object.keys(channels).slice(0, 15).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`, '')}
49 ${Object.keys(users).slice(0, 15).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`, '')}
52 ${Object.keys(tags).slice(0, 15).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`, '')}
55 <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>`
64 this.find = function (entries, p) {
66 for (const id in entries) {
67 if (entries[id] && entries[id][p]) { h[entries[id][p]] = h[entries[id][p]] ? h[entries[id][p]] + 1 : 1 }
72 this.findTags = function (entries) {
74 for (const id in entries) {
75 const entry = entries[id]
76 entry.tags.map(tag => {
77 tags[tag] = tags[tag] ? tags[tag] + 1 : 1
83 this.findEntries = function (feeds) {
85 for (const id in feeds) {
86 for (const i in feeds[id].content) {
87 a.push(feeds[id].content[i])
90 return a.sort((a, b) => a.offset - b.offset)
93 this.findMention = function (found) {
94 const mention = Object.keys(feeds).filter(user => found.indexOf(feeds[user].path) > -1)
95 return mention.length === 1 ? ` <span class='user'>@${mention[0]}</span>` : ` <span class='user'>${found}</span>`
98 this.templateEntry = function (entry) {
99 entry.html = entry.body
100 .replace(re_channel, `$1<span class='channel'>/$2</span>`)
101 .replace(re_user, this.findMention)
102 .replace(re_tag, `$1<span class='tag'>#$2</span>`)
103 .replace(re_url, `<a target="_blank" href='$1'>$1</a>`)
105 const filter = window.location.hash.substr(1).replace(/\+/g, ' ').toLowerCase()
106 const highlight = filter === entry.author.toLowerCase()
107 const origin = feeds[entry.author].path
109 return `<li class='entry ${highlight ? 'highlight' : ''}'><span class='date'>${timeAgo(Date.parse(entry.date))}</span> <a class='author' href='${origin}' target='_blank'>${entry.author}</a> <span class='body'>${entry.html}</span></li>`
114 this.findFeeds = function () {
115 console.log('Finding feeds..')
116 for (const site of sites) {
117 if (site.feed && site.author) {
118 feeds[site.author] = { path: site.feed }
121 console.log(`Found ${Object.keys(feeds).length} feeds.`)
124 this.fetchFeeds = function () {
125 console.log(`Fetching ${Object.keys(feeds).length} feeds..`)
126 for (const id in feeds) {
127 this.fetchFeed(id, feeds[id])
131 this.fetchFeed = function (id, feed) {
132 console.log(`Fetching ${id}(${feed.path})..`)
133 fetch(feed.path, { cache: 'no-store' }).then(x => x.text()).then((content) => {
134 feeds[id].content = parseFeed(id, content)
137 console.warn(`${id}`, err)
143 function parseFeed (author, feed) {
144 const lines = feed.split('\n').filter((line) => line.substr(0, 1) !== '#')
146 for (const id in lines) {
147 const line = lines[id].trim()
148 if (line === '') { continue }
149 const parts = line.replace(' ', '\t').split('\t')
150 const date = parts[0].trim()
151 const body = escapeHtml(parts[1].trim()).trim()
152 const channel = body.substr(0, 1) === '/' ? body.split(' ')[0].substr(1).toLowerCase() : body.substr(0, 1) === '@' ? 'veranda' : 'lobby'
153 const tags = (body.match(re_tag) || []).map(a => a.substr(a.indexOf('#') + 1).toLowerCase())
154 const offset = new Date() - new Date(date)
155 entries.push({ date, body, author, offset, channel, tags })
160 function timeAgo (dateParam) {
161 const date = typeof dateParam === 'object' ? dateParam : new Date(dateParam)
162 const today = new Date()
163 const yesterday = new Date(today - 86400000)
164 const seconds = Math.round((today - date) / 1000)
165 const minutes = Math.round(seconds / 60)
166 const isToday = today.toDateString() === date.toDateString()
167 const isYesterday = yesterday.toDateString() === date.toDateString()
171 } else if (seconds < 60) {
172 return `${seconds} seconds ago`
173 } else if (seconds < 90) {
174 return 'a minute ago'
175 } else if (minutes < 60) {
176 return `${minutes} minutes ago`
177 } else if (isToday) {
178 return `${Math.floor(minutes / 60)} hours ago`
179 } else if (isYesterday) {
183 return `${Math.floor(minutes / 1440)} days ago`
187function escapeHtml (unsafe) {
188 return unsafe.replace(/&/g, '&').replace(/</g, '<').replace(/>/g, '>').replace(/"/g, '"').replace(/'/g, ''')
191function filter (name) {
192 window.location.hash = name
193 const filterAndPage = window.location.hash.split('^')
194 hallway.finder = { filter: filterAndPage[0].trim().replace('#', ''), page: filterAndPage[1] || 1 }
keysesc to close
- j k
- move down, up
- enter
- open
- esc
- back, or up a level
- 1 2 3 4
- readme, files, commits, refs
- /
- filter
- y
- copy the clone command
- c
- compare the chosen commit with another (or shift-click both)
- ?
- show or hide this list