Browse Source

Server: fix duration string, add verbose option

resume-pdf-2
Kevin Mok 5 years ago
parent
commit
ae2e8100fd
Signed by: Kevin-Mok GPG Key ID: AEA75288DC135CF5
  1. 1
      .gitignore
  2. 3
      assets/sass/main.scss
  3. 10
      content/server/_index.md
  4. 78
      static/server-apps.json
  5. 39
      static/server-table.js

1
.gitignore

@ -4,3 +4,4 @@ resources/_gen/
themes/base16*
commit-msg.txt
static/server-apps.json

3
assets/sass/main.scss

@ -722,7 +722,8 @@ article.single section.body h4 { color: #f2777a; }
article.single section.body h5 { color: #515151; }
article.single section.body h6 { color: #747369; }
article.single section.body a,a:visited { color: #a06700; }
// article.single section.body a,a:visited { color: #a06700; }
article.single section.body a,a:visited { color: $base-sky-blue; }
/* Article Elements */

10
content/server/_index.md

@ -6,9 +6,11 @@ layout: single
js: ["server-table"]
---
Here is a list of apps that I am running a my [DigitalOcean
droplet][do-droplet] along with their statuses, which are updated
every hour using [this Node.js script][update-script].
droplet][do-droplet]. Their [statuses] are updated every hour using a
[Node.js script][update-script] and a [systemd service]/[timer].
[do-droplet]: https://www.digitalocean.com/products/droplets/
[update-script]:
https://git.kevin-mok.com/Kevin-Mok/server-pages/src/branch/master/server-status.js
[statuses]: https://kevin-mok.com/server-apps.json
[systemd service]: https://git.kevin-mok.com/Kevin-Mok/server-pages/src/branch/master/server-pages.service
[timer]: https://git.kevin-mok.com/Kevin-Mok/server-pages/src/branch/master/server-pages.timer
[update-script]: https://git.kevin-mok.com/Kevin-Mok/server-pages/src/branch/master/server-status.js

78
static/server-apps.json

@ -1,78 +0,0 @@
{
"sites": [
{
"shortUrl": "kevin-mok.com",
"url": "https://kevin-mok.com",
"siteTitle": " Kevin Mok ",
"description": "Personal site (this site).",
"repo": "Kevin-Mok/my-site",
"repoUrl": "https://git.kevin-mok.com/Kevin-Mok/my-site",
"status": "up"
},
{
"shortUrl": "git.kevin-mok.com",
"url": "https://git.kevin-mok.com",
"siteTitle": "Kevin Mok's Gitea",
"description": "Lightweight Git server.",
"repo": "go-gitea/gitea",
"repoUrl": "https://github.com/go-gitea/gitea",
"status": "up"
},
{
"shortUrl": "cal.khkm.tk",
"url": "https://cal.khkm.tk",
"siteTitle": "Baïkal server",
"description": "CalDAV/CardDAV server.",
"repo": "sabre-io/Baikal",
"repoUrl": "https://github.com/sabre-io/Baikal",
"status": "up"
},
{
"shortUrl": "matrix.ataraxy.tk",
"url": "https://matrix.ataraxy.tk/.well-known/matrix/server",
"siteTitle": "",
"description": "Matrix chat server. Only accessible through Riot client.",
"repo": "matrix-org/synapse",
"repoUrl": "https://github.com/matrix-org/synapse",
"status": "up"
},
{
"shortUrl": "mnpd.gq",
"url": "https://mnpd.gq/test",
"siteTitle": "test",
"description": "Minimalistic live web notepad.",
"repo": "pereorga/minimalist-web-notepad",
"repoUrl": "https://github.com/pereorga/minimalist-web-notepad",
"status": "up"
},
{
"shortUrl": "pste.gq",
"url": "https://pste.gq",
"siteTitle": "hastebin",
"description": "Pastebin.",
"repo": "seejohnrun/haste-server",
"repoUrl": "https://github.com/seejohnrun/haste-server",
"status": "up"
},
{
"shortUrl": "smol.gq",
"url": "https://smol.gq",
"siteTitle": "Kevin's URL Shortener",
"description": "URL shortener.",
"repo": "132ikl/liteshort",
"repoUrl": "https://github.com/132ikl/liteshort",
"status": "up"
},
{
"shortUrl": "taskd.khkm.tk",
"url": "taskd.khkm.tk:53589",
"siteTitle": "",
"description": "Taskwarrior (task manager) server. No web interface.",
"repo": "GothenburgBitFactory/taskserver",
"repoUrl": "https://github.com/GothenburgBitFactory/taskserver",
"status": "up"
}
],
"updateTime": 1569204723194,
"upSince": "2019-09-22 19:30:10"
}

39
static/server-table.js

@ -50,17 +50,42 @@ const generateTable = (table, data) => {
})
}
const getDurationSince = date => {
const getDurationSince = (date, verbose) => {
const milli = Math.abs(Date.now() - date)
let mins = Math.floor(milli/1000/60)
const days = Math.floor(mins/60/24)
mins %= 60*24
const hours = Math.floor(mins/60)
mins %= 60
let durationString = (days > 0) ? `${days}d ` : ''
durationString += (hours > 0) ? `${hours} hours, ` : ''
durationString += (mins > 0) ? `${mins} minutes` : '0m'
return durationString
let dayString = ''
let hourString = ''
let minString = ''
if (days > 0) {
dayString += days
if (!verbose) {
dayString += 'd '
} else {
dayString += (days == 1) ? ' day' : ' days'
dayString += ', '
}
}
if (hours > 0) {
hourString += hours
if (!verbose) {
hourString += 'h '
} else {
hourString += (hours == 1) ? ' hour' : ' hours'
hourString += ', '
}
}
minString += (mins > 0) ? mins: '0'
if (!verbose) {
minString += 'm'
} else {
minString += (mins == 1) ? ' minute' : ' minutes'
}
return dayString + hourString + minString
}
fetch("/server-apps.json")
@ -70,7 +95,7 @@ fetch("/server-apps.json")
generateTable(table, json['sites']);
generateTableHead(table);
document.querySelector('#last-updated-time').textContent =
getDurationSince(new Date(json['updateTime'])) + ' ago.'
getDurationSince(new Date(json['updateTime']), false) + ' ago.'
document.querySelector('#server-uptime-time').textContent =
getDurationSince(new Date(json['upSince'])) + '.'
getDurationSince(new Date(json['upSince']), true) + '.'
});
Loading…
Cancel
Save