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)
51 if (entry.body.indexOf('@<') > -1) {
52 const data = entry.body.split('@<').pop().split('>')[0]
53 const mention = data.split(' ')
54 const name = mention[0]
55 const path = mention[1]
56 entry.body = entry.body.replace(`@<${data}>`, `<a href='${path}'>${name}</a>`)
59 return `<li class='entry'><span class='date'>${ago(date)}</span> <span class='author'>${entry.author}</span> <span class='body'>${entry.body}</span></li>`
64 this.findFeeds = function () {
65 console.log('Finding feeds..')
66 for (const id in sites) {
67 const site = sites[id]
68 if (site.feed && site.author) {
69 feeds[site.author] = { path: site.feed }
72 console.log(`Found ${Object.keys(feeds).length} feeds.`)
75 this.fetchFeeds = function () {
76 console.log(`Fetching ${Object.keys(feeds).length} feeds..`)
77 for (const id in feeds) {
78 this.fetchFeed(id, feeds[id])
82 this.fetchFeed = function (id, feed) {
83 console.log(`Fetching ${id}(${feed.path})..`)
84 Promise.all([ fetch(feed.path, { cache: 'no-store' }).then(x => x.text()) ]).then(([content]) => {
85 feeds[id].content = parseFeed(id, content)
92 this._footer = function () {
93 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 <a href="https://github.com/XXIIVV/Webring/">add it</a> to your entry in the webring.</p>'
98 function parseFeed (author, feed) {
99 const lines = feed.split('\n')
101 for (const id in lines) {
102 const line = lines[id]
103 const date = line.substr(0, 25).trim()
104 const body = line.substr(26).trim()
105 entries.push({ date, body, author })
110 function ago (days, cap = 9999) {
111 if (-days > cap) { return `${this.toString(true)}` }
112 if (days === -1) { return `yesterday` }
113 if (days === 1) { return 'tomorrow' }
114 if (days === 0) { return 'today' }
115 if (days < -365) { return `${Math.floor(days / -365)} years ago` }
116 if (days < 1) { return `${days * -1} days ago` }
117 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