mirror of
https://github.com/jakejarvis/jarv.is.git
synced 2025-07-03 17:06:37 -04:00
move some cruft from serverless API to client
This commit is contained in:
@ -1,4 +1,5 @@
|
||||
import fetch from "cross-fetch";
|
||||
import numeral from "numeral";
|
||||
import * as queryString from "query-string";
|
||||
|
||||
// don't continue if there isn't a span#meta-hits element on this page
|
||||
@ -18,14 +19,17 @@ if (wrapper) {
|
||||
fetch(queryString.stringifyUrl({ url: "/api/hits/", query: { slug: slug } }))
|
||||
.then((response) => response.json())
|
||||
.then((data) => {
|
||||
if (typeof data.hits !== "undefined") {
|
||||
if (data.hits) {
|
||||
// finally inject the hits and hide the loading spinner
|
||||
const spinner = document.getElementById("hit-spinner");
|
||||
const counter = document.getElementById("hit-counter");
|
||||
|
||||
const hitsComma = numeral(data.hits).format("0,0");
|
||||
const hitsPlural = data.hits === 1 ? "hit" : "hits";
|
||||
|
||||
if (spinner) spinner.style.display = "none";
|
||||
if (counter) counter.appendChild(document.createTextNode(data.pretty_hits));
|
||||
wrapper.title = data.pretty_hits + " " + data.pretty_unit;
|
||||
if (counter) counter.appendChild(document.createTextNode(hitsComma));
|
||||
wrapper.title = hitsComma + " " + hitsPlural;
|
||||
} else {
|
||||
// something went horribly wrong, initiate coverup
|
||||
wrapper.style.display = "none";
|
||||
|
@ -1,9 +1,14 @@
|
||||
import fetch from "cross-fetch";
|
||||
import numeral from "numeral";
|
||||
import dayjs from "dayjs";
|
||||
import relativeTime from "dayjs/plugin/relativeTime.js";
|
||||
|
||||
// don't continue if there isn't a span#meta-hits element on this page
|
||||
const wrapper = document.getElementById("github-cards");
|
||||
|
||||
if (wrapper) {
|
||||
dayjs.extend(relativeTime);
|
||||
|
||||
fetch("/api/projects/?top")
|
||||
.then((response) => response.json())
|
||||
.then((data) => {
|
||||
@ -24,7 +29,7 @@ if (wrapper) {
|
||||
html += `
|
||||
<div class="repo-meta">
|
||||
<svg viewBox="0 0 16 16" height="16" width="16"><path fill-rule="evenodd" d="M8 .25a.75.75 0 01.673.418l1.882 3.815 4.21.612a.75.75 0 01.416 1.279l-3.046 2.97.719 4.192a.75.75 0 01-1.088.791L8 12.347l-3.766 1.98a.75.75 0 01-1.088-.79l.72-4.194L.818 6.374a.75.75 0 01.416-1.28l4.21-.611L7.327.668A.75.75 0 018 .25zm0 2.445L6.615 5.5a.75.75 0 01-.564.41l-3.097.45 2.24 2.184a.75.75 0 01.216.664l-.528 3.084 2.769-1.456a.75.75 0 01.698 0l2.77 1.456-.53-3.084a.75.75 0 01.216-.664l2.24-2.183-3.096-.45a.75.75 0 01-.564-.41L8 2.694v.001z"></path></svg>
|
||||
<span>${repo.stargazerCount_pretty}</span>
|
||||
<span>${numeral(repo.stargazerCount).format("0,0")}</span>
|
||||
</div>`;
|
||||
}
|
||||
|
||||
@ -32,13 +37,13 @@ if (wrapper) {
|
||||
html += `
|
||||
<div class="repo-meta">
|
||||
<svg viewBox="0 0 16 16" height="16" width="16"><path fill-rule="evenodd" d="M5 3.25a.75.75 0 11-1.5 0 .75.75 0 011.5 0zm0 2.122a2.25 2.25 0 10-1.5 0v.878A2.25 2.25 0 005.75 8.5h1.5v2.128a2.251 2.251 0 101.5 0V8.5h1.5a2.25 2.25 0 002.25-2.25v-.878a2.25 2.25 0 10-1.5 0v.878a.75.75 0 01-.75.75h-4.5A.75.75 0 015 6.25v-.878zm3.75 7.378a.75.75 0 11-1.5 0 .75.75 0 011.5 0zm3-8.75a.75.75 0 100-1.5.75.75 0 000 1.5z"></path></svg>
|
||||
<span>${repo.forkCount_pretty}</span>
|
||||
<span>${numeral(repo.forkCount).format("0,0")}</span>
|
||||
</div>`;
|
||||
}
|
||||
|
||||
html += `
|
||||
<div class="repo-meta">
|
||||
<span title="${repo.pushedAt}">Updated ${repo.pushedAt_relative}</span>
|
||||
<span title="${dayjs(repo.pushedAt).format("MMM D, YYYY h:mm A")}">Updated ${dayjs(repo.pushedAt).fromNow()}</span>
|
||||
</div>`;
|
||||
|
||||
const div = document.createElement("div");
|
||||
|
Reference in New Issue
Block a user