on master help sign in
*
commite4cf4b576e92c1ebeafc3c296e616b473553e534 authorDevine Lu Linvega <aliceffekt@gmail.com> dateTue 2 Jul 2019, 09:06 (7 years ago) parent39efe03
1 file changed+12−2
scripts/hallway.js+12−2
scripts/hallway.js+12−2
@@ -47,7 +47,7 @@ function Hallway (sites) {
4747 const diff = (now - then)
4848 const date = Math.floor(diff / 86400000)
4949
50− return `<li class='entry'><span class='date'>${date}</span> <span class='author'>${entry.author}</span> <span class='body'>${entry.body}</span></li>`
50+ return `<li class='entry'><span class='date'>${ago(date)}</span> <span class='author'>${entry.author}</span> <span class='body'>${entry.body}</span></li>`
5151 }
5252
5353 // Feeds
@@ -72,7 +72,7 @@ function Hallway (sites) {
7272
7373 this.fetchFeed = function (id, feed) {
7474 console.log(`Fetching ${id}(${feed.path})..`)
75− Promise.all([ fetch(feed.path).then(x => x.text()) ]).then(([content]) => {
75+ Promise.all([ fetch(feed.path, { cache: 'no-store' }).then(x => x.text()) ]).then(([content]) => {
7676 feeds[id].content = parseFeed(id, content)
7777 this.refresh()
7878 })
@@ -97,4 +97,14 @@ function Hallway (sites) {
9797 }
9898 return entries
9999 }
100+
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`
109+ }
100110}