From 60d846d0c82e8312f66910d52b22c2978da0def2 Mon Sep 17 00:00:00 2001 From: Paul Schaefer Date: Thu, 14 Feb 2019 10:39:54 -0500 Subject: [PATCH] Added `timeago` for quickly converting a Date object into '3 days ago' or similar. --- index.js | 8 +++++++- package-lock.json | 5 +++++ package.json | 8 ++++++-- public/index.jade | 4 +++- 4 files changed, 21 insertions(+), 4 deletions(-) diff --git a/index.js b/index.js index 5400992..9fb8bda 100644 --- a/index.js +++ b/index.js @@ -1,4 +1,5 @@ const fs = require('fs'); +const timeago = require('timeago.js'); const repos = require('github-user-repos'); const opts = { 'token': process.env.GITHUB_TOKEN, @@ -16,9 +17,14 @@ function callback(error, results, info) { if (error) { throw new Error(error.message); } - console.log(JSON.stringify(results)); + // console.log(JSON.stringify(results)); // returns + // Converts a DateTime value to '3 days ago' or similar, adds it to data file. + results.forEach(element => { + element['updated_at_timeago'] = timeago.format(element['updated_at']); + }); + fs.mkdir('public/repos', { recursive: true }, (err) => { // if (err) throw err; }); diff --git a/package-lock.json b/package-lock.json index 627c052..77cf9d1 100644 --- a/package-lock.json +++ b/package-lock.json @@ -6009,6 +6009,11 @@ "xtend": "~4.0.1" } }, + "timeago.js": { + "version": "4.0.0-beta.2", + "resolved": "https://registry.npmjs.org/timeago.js/-/timeago.js-4.0.0-beta.2.tgz", + "integrity": "sha512-MQkHiYGoB6qZC4DNWsLc9bav+L9hpdulL6sL7okzKR8r1Ipask/tXKAio8T+4jeby8FbpbDvbnCKGrh1bLop3g==" + }, "timed-out": { "version": "3.1.3", "resolved": "https://registry.npmjs.org/timed-out/-/timed-out-3.1.3.tgz", diff --git a/package.json b/package.json index e046162..23001d5 100644 --- a/package.json +++ b/package.json @@ -13,7 +13,10 @@ }, "keywords": [ "harp", - "harpjs" + "harpjs", + "github-user-repos", + "timeago", + "timeago.js" ], "author": "Paul Schaefer", "license": "MIT", @@ -23,6 +26,7 @@ "homepage": "https://github.com/pschfr/labs#readme", "dependencies": { "github-user-repos": "^1.0.2", - "harp": "^0.29.0" + "harp": "^0.29.0", + "timeago.js": "^4.0.0-beta.2" } } diff --git a/public/index.jade b/public/index.jade index 3e78d4d..9fc3837 100644 --- a/public/index.jade +++ b/public/index.jade @@ -17,5 +17,7 @@ ul | Description: #{repo['description']}
if repo['homepage'] | URL: - a(href="#{repo['homepage']}")= repo['homepage'] + a(href="#{repo['homepage']}") #{repo['homepage']}
+ | Last updated: + time(datetime="#{repo['updated_at']}") #{repo['updated_at_timeago']} br