3function Hallway (sites) {
6 this.el = document.createElement('div')
9 this.install = function (host) {
10 host.appendChild(this.el)
15 this.start = function () {
16 this.el.innerHTML = 'hello'
18 // this.fetch('https://wiki.xxiivv.com/twtxt.txt')
21 this.refresh = function () {
22 const entries = this.sortEntries()
24 for (const id in entries) {
25 html += `${this.templateEntry(entries[id])}\n`
27 this.el.innerHTML = `<ul>${html}</ul>${this._footer()}`
32 this.sortEntries = function () {
34 for (const id in feeds) {
35 const feed = feeds[id]
36 for (const i in feed.content) {
37 const entry = feed.content[i]
44 this.templateEntry = function (entry) {
45 const now = new Date()
46 const then = Date.parse(entry.date)
47 const diff = (now - then)
48 const date = Math.floor(diff / 86400000)
50 return `<li class='entry'><span class='date'>${ago(date)}</span> <span class='author'>${entry.author}</span> <span class='body'>${entry.body}</span></li>`
55 this.findFeeds = function () {
56 console.log('Finding feeds..')
57 for (const id in sites) {
58 const site = sites[id]
59 if (site.feed && site.author) {
60 feeds[site.author] = { path: site.feed }
63 console.log(`Found ${Object.keys(feeds).length} feeds.`)
66 this.fetchFeeds = function () {
67 console.log(`Fetching ${Object.keys(feeds).length} feeds..`)
68 for (const id in feeds) {
69 this.fetchFeed(id, feeds[id])
73 this.fetchFeed = function (id, feed) {
74 console.log(`Fetching ${id}(${feed.path})..`)
75 Promise.all([ fetch(feed.path, { cache: 'no-store' }).then(x => x.text()) ]).then(([content]) => {
76 feeds[id].content = parseFeed(id, content)
83 this._footer = function () {
84 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 add it to your entry in the webring.</p>'
89 function parseFeed (author, feed) {
90 const lines = feed.split('\n')
92 for (const id in lines) {
93 const line = lines[id]
94 const date = line.substr(0, 25).trim()
95 const body = line.substr(26).trim()
96 entries.push({ date, body, author })
101 function ago (days, cap = 9999) {
102 if (-days > cap) { return `${this.toString(true)}` }
103 if (days === -1) { return `yesterday` }
104 if (days === 1) { return 'tomorrow' }
105 if (days === 0) { return 'today' }
106 if (days < -365) { return `${Math.floor(days / -365)} years ago` }
107 if (days < 1) { return `${days * -1} days ago` }
108 return `in ${days} days`
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