on master help sign in
Added date formatting
20c9a81Devine Lu Linvega
links/main.css+4−4
@@ -11,13 +11,13 @@ body div p.readme { max-width:500px; }
11
11
12/* Hallway */
12/* Hallway */
13
13
14−body #hallway .entry { line-height: 16px; display: block; position: relative; padding-left:200px; }
14+body #hallway .entry { line-height: 16px; display: block; position: relative; padding-left:140px; }
15−body #hallway .entry .date { color: #555;display: block;position: absolute;left: 0px; }
15+body #hallway .entry .date { color: #555;display: block;float:right; margin-left:20px;}
16−body #hallway .entry .date:after { content: ")" }
17−body #hallway .entry .author { font-family: 'input_mono_medium'; position: absolute;left: 60px; }
16+body #hallway .entry .author { font-family: 'input_mono_medium'; position: absolute;left: 0px; }
18body #hallway .entry .author:after { content:":"; }
17body #hallway .entry .author:after { content:":"; }
19body #hallway .entry .body { max-width: 400px }
18body #hallway .entry .body { max-width: 400px }
20body #hallway .entry .body a { text-decoration: underline; }
19body #hallway .entry .body a { text-decoration: underline; }
20+body #hallway p { padding-left: 60px;background-image: url(../icon.white.svg);background-size: 40px;background-repeat: no-repeat;background-position: 0px 0px; }
21
21
22/* Portal */
22/* Portal */
23
23
scripts/hallway.js+30−15
@@ -42,11 +42,6 @@ function Hallway (sites) {
42 }
42 }
43
43
44 this.templateEntry = function (entry) {
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)
49−
50 // Find mention
45 // Find mention
51 if (entry.body.indexOf('@<') > -1) {
46 if (entry.body.indexOf('@<') > -1) {
52 const data = entry.body.split('@<').pop().split('>')[0]
47 const data = entry.body.split('@<').pop().split('>')[0]
@@ -56,7 +51,7 @@ function Hallway (sites) {
56 entry.body = entry.body.replace(`@<${data}>`, `<a href='${path}'>${name}</a>`)
51 entry.body = entry.body.replace(`@<${data}>`, `<a href='${path}'>${name}</a>`)
57 }
52 }
58
53
59− return `<li class='entry'><span class='date'>${ago(date)}</span> <span class='author'>${entry.author}</span> <span class='body'>${entry.body}</span></li>`
54+ return `<li class='entry'><span class='date'>${timeAgo(Date.parse(entry.date))}</span> <span class='author'>${entry.author}</span> <span class='body'>${entry.body}</span></li>`
60 }
55 }
61
56
62 // Feeds
57 // Feeds
@@ -81,7 +76,7 @@ function Hallway (sites) {
81
76
82 this.fetchFeed = function (id, feed) {
77 this.fetchFeed = function (id, feed) {
83 console.log(`Fetching ${id}(${feed.path})..`)
78 console.log(`Fetching ${id}(${feed.path})..`)
84− Promise.all([ fetch(feed.path, { cache: 'no-store' }).then(x => x.text()) ]).then(([content]) => {
79+ Promise.all([ fetch(feed.path + '?v=1', { cache: 'no-store' }).then(x => x.text()) ]).then(([content]) => {
85 feeds[id].content = parseFeed(id, content)
80 feeds[id].content = parseFeed(id, content)
86 this.refresh()
81 this.refresh()
87 })
82 })
@@ -107,13 +102,33 @@ function Hallway (sites) {
107 return entries
102 return entries
108 }
103 }
109
104
110− function ago (days, cap = 9999) {
105+ function timeAgo (dateParam) {
111− if (-days > cap) { return `${this.toString(true)}` }
106+ if (!dateParam) {
112− if (days === -1) { return `yesterday` }
107+ return null
108+ }
109+
110+ const date = typeof dateParam === 'object' ? dateParam : new Date(dateParam)
111+ const DAY_IN_MS = 86400000 // 24 * 60 * 60 * 1000
112+ const today = new Date()
113+ const yesterday = new Date(today - DAY_IN_MS)
114+ const seconds = Math.round((today - date) / 1000)
115+ const minutes = Math.round(seconds / 60)
116+ const isToday = today.toDateString() === date.toDateString()
117+ const isYesterday = yesterday.toDateString() === date.toDateString()
118+
119+ if (seconds < 5) {
113− if (days === 1) { return 'tomorrow' }
120+ return 'now'
114− if (days === 0) { return 'today' }
121+ } else if (seconds < 60) {
115− if (days < -365) { return `${Math.floor(days / -365)} years ago` }
122+ return `${seconds} seconds ago`
116− if (days < 1) { return `${days * -1} days ago` }
123+ } else if (seconds < 90) {
124+ return 'about a minute ago'
125+ } else if (minutes < 60) {
126+ return `${minutes} minutes ago`
127+ } else if (isToday) {
128+ return `${Math.floor(minutes / 60)} hours ago`
129+ } else if (isYesterday) {
130+ return 'yesterday'
131+ }
117− return `in ${days} days`
132+ return `${Math.floor(minutes / 1440)} days ago`
118 }
133 }
119}
134}