From 08fc82abfd307b286210accfdc9a7ec0ed4111bd Mon Sep 17 00:00:00 2001 From: Sam Carlton Date: Sat, 21 Nov 2020 14:21:16 -0600 Subject: [PATCH 1/5] Ignore stored commits data --- .gitignore | 1 + 1 file changed, 1 insertion(+) diff --git a/.gitignore b/.gitignore index b7ce690..313eec5 100644 --- a/.gitignore +++ b/.gitignore @@ -86,3 +86,4 @@ dist /README-temp.md /game-list.json .DS_Store +/commits-data.json From 25f5343b25b4fe50d1e771a2d17b19fefd3fcc01 Mon Sep 17 00:00:00 2001 From: Sam Carlton Date: Sat, 21 Nov 2020 15:36:59 -0600 Subject: [PATCH 2/5] Add commit dates to apps --- helpers/build-app-list.js | 66 ++++++++++++++++++++++++++++++++++-- helpers/parse-github-date.js | 33 ++++++++++++++++++ 2 files changed, 97 insertions(+), 2 deletions(-) create mode 100644 helpers/parse-github-date.js diff --git a/helpers/build-app-list.js b/helpers/build-app-list.js index a066682..8e2e224 100644 --- a/helpers/build-app-list.js +++ b/helpers/build-app-list.js @@ -2,6 +2,9 @@ import { promises as fs } from 'fs' import MarkdownIt from 'markdown-it' import slugify from 'slugify' +import axios from 'axios' + +import parseGithubDate from './parse-github-date' const md = new MarkdownIt() @@ -14,6 +17,7 @@ export const statuses = { '🚫': 'no' } + const getTokenLinks = function ( childTokens ) { const tokenList = [] @@ -53,12 +57,60 @@ const getTokenLinks = function ( childTokens ) { return tokenList } + +const lookForLastUpdated = function (app, commits) { + + for (const { node: commit } of commits) { + + // console.log('commit', commit) + + // $$ If message body contains endpoint + if (commit.messageBody.includes(app.endpoint)) { + // console.log('Found', app.name ,commit.committedDate) + return commit.committedDate + } + + // $$ If message body contains App Name + if (commit.messageBody.includes(app.name)) { + // console.log('Found', app.name ,commit.committedDate) + return commit.committedDate + } + + // $$ If message headline contains App Name + if (commit.messageHeadline.includes(app.name)) { + // console.log('Found', app.name ,commit.committedDate) + return commit.committedDate + } + + // $$$ If commits comments contains endpoint + for (const { node: comment } of commit.comments.edges) { + if (comment.body.includes(app.endpoint)) { + // console.log('Found', app.name ,commit.committedDate) + return commit.committedDate + } + } + + } + + return null +} + + export default async function () { const readmeContent = await fs.readFile('./README-temp.md', 'utf8') - // console.log('readmeContent', readmeContent) + // Fetch Commits + const response = await axios.get(process.env.COMMITS_SOURCE) + // Extract commit from response data + const commits = response.data.data.viewer.repository.defaultBranchRef.target.history.edges + // console.log('commits', commits) + + // Save commits to file just in case + await fs.writeFile('./commits-data.json', JSON.stringify(commits)) + + // Parse markdown const result = md.parse(readmeContent) @@ -119,6 +171,8 @@ export default async function () { strict: true }) + const endpoint = `/app/${appSlug}` + let status = 'unknown' for (const statusKey in statuses) { @@ -128,14 +182,22 @@ export default async function () { } } + const lastUpdatedRaw = lookForLastUpdated({ name, endpoint }, commits) + + const lastUpdated = (lastUpdatedRaw) ? { + raw: lastUpdatedRaw, + timestamp: parseGithubDate(lastUpdatedRaw).timestamp, + } : null + appList.push({ name, status, + lastUpdated, url, text, slug: appSlug, - endpoint: `/app/${appSlug}`, + endpoint, section: { label: sectionTitle, slug: sectionSlug diff --git a/helpers/parse-github-date.js b/helpers/parse-github-date.js new file mode 100644 index 0000000..f051c50 --- /dev/null +++ b/helpers/parse-github-date.js @@ -0,0 +1,33 @@ +// in miliseconds +const units = { + year : 24 * 60 * 60 * 1000 * 365, + month : 24 * 60 * 60 * 1000 * 365/12, + day : 24 * 60 * 60 * 1000, + hour : 60 * 60 * 1000, + minute: 60 * 1000, + second: 1000 +} + +const rtf = new Intl.RelativeTimeFormat('en', { numeric: 'auto' }) + +const getRelativeTime = function (d1, d2 = new Date()) { + var elapsed = d1 - d2 + + // "Math.abs" accounts for both "past" & "future" scenarios + for (var u in units) + if (Math.abs(elapsed) > units[u] || u == 'second') + return rtf.format(Math.round(elapsed/units[u]), u) + +} + +export default function (rawDate) { + + const date = new Date(rawDate) + + return { + date, + raw: rawDate, + timestamp: date.getTime(), + relative: getRelativeTime(date) + } +} From 38c2954d2318f75582eda65f12e84a649fc5b16f Mon Sep 17 00:00:00 2001 From: Sam Carlton Date: Sat, 21 Nov 2020 15:37:35 -0600 Subject: [PATCH 3/5] Show relative dates on search list --- components/relative-time.vue | 24 ++++++++++++++++++++++++ components/search.vue | 17 ++++++++++++++--- 2 files changed, 38 insertions(+), 3 deletions(-) create mode 100644 components/relative-time.vue diff --git a/components/relative-time.vue b/components/relative-time.vue new file mode 100644 index 0000000..4fc4f9a --- /dev/null +++ b/components/relative-time.vue @@ -0,0 +1,24 @@ + + + diff --git a/components/search.vue b/components/search.vue index 0ce1171..8070f45 100644 --- a/components/search.vue +++ b/components/search.vue @@ -62,16 +62,25 @@
{{ app.name.charAt(0) }}
-
+
🕹 {{ app.name }}
-
+
{{ app.text }}
+ + + + + +
Date: Sat, 21 Nov 2020 15:37:52 -0600 Subject: [PATCH 4/5] Sort apps by date then null --- pages/index.vue | 23 ++++++++++++++++++++++- 1 file changed, 22 insertions(+), 1 deletion(-) diff --git a/pages/index.vue b/pages/index.vue index 14fa595..7074869 100644 --- a/pages/index.vue +++ b/pages/index.vue @@ -40,6 +40,27 @@ import LinkButton from '~/components/link-button.vue' import appList from '~/app-list.json' import gameList from '~/game-list.json' +// console.log('appList.length', appList.length) +// console.log('gameList.length', gameList.length) + +function byTimeThenNull (appA, appB) { + console.log('appA.lastUpdated', appA.lastUpdated) + + // equal items sort equally + if (appA.lastUpdated === appB.lastUpdated) { + return 0; + } + // nulls sort after anything else + else if (appA.lastUpdated === null) { + return 1; + } + else if (appB.lastUpdated === null) { + return -1; + } + + return appB.lastUpdated.timestamp - appA.lastUpdated.timestamp +} + export default { components: { Search, @@ -53,7 +74,7 @@ export default { computed: { appList() { return [ - ...appList, + ...appList.sort(byTimeThenNull), ...gameList ] } From 3ddd96ae1df100951a71ab0b280af9fc9ab4122f Mon Sep 17 00:00:00 2001 From: Sam Carlton Date: Sat, 21 Nov 2020 15:48:00 -0600 Subject: [PATCH 5/5] Add dates to app pages --- pages/app/_slug.vue | 24 ++++++++++++++++++++++-- 1 file changed, 22 insertions(+), 2 deletions(-) diff --git a/pages/app/_slug.vue b/pages/app/_slug.vue index 63ad65a..dc2a95b 100644 --- a/pages/app/_slug.vue +++ b/pages/app/_slug.vue @@ -24,12 +24,19 @@ >{{ (i === 0) ? 'View' : link.label }}
-