repos / neovimcraft

website that makes it easy to find neovim plugins
git clone https://github.com/neurosnap/neovimcraft.git

commit
4c18494
parent
c9663a4
author
Eric Bower
date
2021-08-23 19:34:52 +0000 UTC
data updates to search and repo view
5 files changed,  +62, -10
A src/lib/date.ts
+38, -0
 1@@ -0,0 +1,38 @@
 2+const zero = (num: number) => (num < 10 ? `0${num}` : `${num}`);
 3+export const format = (date: Date) => {
 4+  return `${date.getFullYear()}-${zero(date.getMonth() + 1)}-${zero(date.getDate())}`;
 5+};
 6+
 7+const units: { unit: Intl.RelativeTimeFormatUnit; ms: number }[] = [
 8+  { unit: 'year', ms: 31536000000 },
 9+  { unit: 'month', ms: 2628000000 },
10+  { unit: 'day', ms: 86400000 },
11+  { unit: 'hour', ms: 3600000 },
12+  { unit: 'minute', ms: 60000 },
13+  { unit: 'second', ms: 1000 },
14+];
15+const rtf = new Intl.RelativeTimeFormat('en', { numeric: 'auto' });
16+
17+/**
18+ * Get language-sensitive relative time message from Dates.
19+ * @param relative  - the relative dateTime, generally is in the past or future
20+ * @param pivot     - the dateTime of reference, generally is the current time
21+ */
22+export function relativeTimeFromDates(relative: Date | null, pivot: Date = new Date()): string {
23+  if (!relative) return '';
24+  const elapsed = relative.getTime() - pivot.getTime();
25+  return relativeTimeFromElapsed(elapsed);
26+}
27+
28+/**
29+ * Get language-sensitive relative time message from elapsed time.
30+ * @param elapsed   - the elapsed time in milliseconds
31+ */
32+export function relativeTimeFromElapsed(elapsed: number): string {
33+  for (const { unit, ms } of units) {
34+    if (Math.abs(elapsed) >= ms || unit === 'second') {
35+      return rtf.format(Math.round(elapsed / ms), unit);
36+    }
37+  }
38+  return '';
39+}
M src/lib/plugin-view.svelte
+17, -2
 1@@ -6,6 +6,7 @@
 2   import TagItem from './tag.svelte';
 3   import Icon from './icon.svelte';
 4   import Tooltip from '$lib/tooltip.svelte';
 5+  import { format, relativeTimeFromDates } from '$lib/date';
 6 
 7   export let plugin: Plugin;
 8   export let tags: Tag[];
 9@@ -40,8 +41,10 @@
10       <div class="metric"><Icon icon="git-branch" /> <span>{plugin.forks}</span></div>
11     </Tooltip>
12   </div>
13-  <div><div>Created</div><div>{plugin.createdAt}</div></div>
14-  <div><div>Last updated</div><div>{plugin.createdAt}</div></div>
15+  <div class="timestamps">
16+    <div><h5 class="ts-header">CREATED</h5><h2>{format(new Date(plugin.createdAt))}</h2></div>
17+    <div><h5 class="ts-header">UPDATED</h5><h2>{relativeTimeFromDates(new Date(plugin.updatedAt))}</h2></div>
18+  </div>
19   {#if isPlugin}
20     <div class="install">
21       <h3><a href="https://github.com/wbthomason/packer.nvim" target="_blank">packer</a></h3>
22@@ -66,6 +69,18 @@ end)</code></pre>
23     height: auto;
24   }
25 
26+  .timestamps {
27+    display: flex;
28+    justify-content: space-between;
29+    background-color: var(--primary-color);
30+    padding: 15px;
31+    margin: 15px 0;
32+  }
33+
34+  .ts-header {
35+    margin-bottom: 10px;
36+  }
37+
38   .meta {
39     margin-bottom: 20px;
40   }
M src/lib/plugin.svelte
+5, -2
 1@@ -14,6 +14,9 @@
 2       <a href="/plugin/{plugin.username}/{plugin.repo}">{plugin.repo}</a>
 3     </h2>
 4     <div class="metrics">
 5+      <Tooltip tip="github repo" bottom>
 6+        <a href={plugin.link} target="_blank"><Icon icon="github" /></a>
 7+      </Tooltip>
 8       <Tooltip tip="stars" bottom>
 9         <div class="metric-item"><Icon icon="star" /> <span>{plugin.stars}</span></div>
10       </Tooltip>
11@@ -61,8 +64,8 @@
12   }
13 
14   .metrics {
15-    width: 150px;
16-    min-width: 150px;
17+    width: 175px;
18+    min-width: 175px;
19     display: flex;
20     justify-content: space-between;
21   }
M src/lib/resources.json
+1, -1
 1@@ -1064,6 +1064,7 @@
 2       "repo": "vacuumline.nvim",
 3       "tags": ["statusline", "plugin"]
 4     },
 5+    { "type": "github", "username": "SmiteshP", "repo": "nvim-gps", "tags": ["plugin"] },
 6     {
 7       "type": "github",
 8       "username": "yamatsum",
 9@@ -1730,7 +1731,6 @@
10       "repo": "starlite-nvim",
11       "tags": ["plugin", "neovim-0.5"]
12     },
13-    { "type": "github", "username": "SmiteshP", "repo": "nvim-gps", "tags": ["plugin"] },
14     {
15       "type": "github",
16       "username": "Rasukarusan",
M src/routes/guides.svelte
+1, -5
 1@@ -36,11 +36,7 @@
 2 <script lang="ts">
 3   import Nav from '$lib/nav.svelte';
 4   import Tag from '$lib/tag.svelte';
 5-
 6-  const zero = (num: number) => (num < 10 ? `0${num}` : `${num}`);
 7-  const format = (date: Date) => {
 8-    return `${date.getFullYear()}-${zero(date.getMonth() + 1)}-${zero(date.getDate())}`;
 9-  };
10+  import { format } from '$lib/date';
11 
12   export let articles: Article[];
13 </script>