'use strict' function Hallway (sites) { const feeds = {} this.sites = sites this.el = document.createElement('div') this.el.id = 'hallway' this.install = function (host) { host.appendChild(this.el) // Find feeds this.findFeeds() } this.start = function () { this.el.innerHTML = 'hello' this.fetchFeeds() // this.fetch('https://wiki.xxiivv.com/twtxt.txt') } this.refresh = function () { const entries = this.sortEntries() let html = '' for (const id in entries) { html += `${this.templateEntry(entries[id])}\n` } this.el.innerHTML = `
The Hallway is a decentralized forum, to join the conversation, simply create yourself a twtxt feed and add it to your entry in the webring.
' } // Utils function parseFeed (author, feed) { const lines = feed.split('\n') const entries = [] for (const id in lines) { const line = lines[id] const date = line.substr(0, 25).trim() const body = line.substr(26).trim() entries.push({ date, body, author }) } return entries } function ago (days, cap = 9999) { if (-days > cap) { return `${this.toString(true)}` } if (days === -1) { return `yesterday` } if (days === 1) { return 'tomorrow' } if (days === 0) { return 'today' } if (days < -365) { return `${Math.floor(days / -365)} years ago` } if (days < 1) { return `${days * -1} days ago` } return `in ${days} days` } }