1
mirror of https://github.com/jakejarvis/jarv.is.git synced 2025-07-03 18:46:40 -04:00

harder/better/faster/stronger deps

This commit is contained in:
2021-07-07 09:34:57 -04:00
parent dd0a2b01d2
commit 0adf03d969
7 changed files with 306 additions and 298 deletions

View File

@ -4,9 +4,12 @@ import * as Sentry from "@sentry/node";
import * as Tracing from "@sentry/tracing"; // eslint-disable-line @typescript-eslint/no-unused-vars
import { VercelRequest, VercelResponse } from "@vercel/node";
import { Client, query as q } from "faunadb";
import numeral from "numeral";
import fetch from "node-fetch";
import pluralize from "pluralize";
import rssParser from "rss-parser";
import numeral from "numeral";
import { DateTime } from "luxon";
import parser from "fast-xml-parser";
import { decode } from "html-entities";
const baseUrl = "https://jarv.is/";
@ -96,14 +99,10 @@ const incrementPageHits = async (slug: string | string[], client: Client) => {
};
const getSiteStats = async (client: Client) => {
const parser = new rssParser({
timeout: 3000,
});
// get database and RSS results asynchronously
// eslint-disable-next-line @typescript-eslint/no-explicit-any
const [feed, result] = await Promise.all<{ [key: string]: any }, any>([
parser.parseURL(baseUrl + "feed.xml"),
parser.parse(await (await fetch(baseUrl + "feed.xml")).text()), // this is messy but it works :)
client.query(
q.Map(
q.Paginate(q.Documents(q.Collection("hits"))),
@ -120,11 +119,11 @@ const getSiteStats = async (client: Client) => {
pages.map((p: PageStats) => {
// match URLs from RSS feed with db to populate some metadata
const match = feed.items.find((x: { link: string }) => x.link === baseUrl + p.slug + "/");
const match = feed.rss.channel.item.find((x: { link: string }) => x.link === baseUrl + p.slug + "/");
if (match) {
p.title = match.title;
p.title = decode(match.title);
p.url = match.link;
p.date = match.isoDate;
p.date = DateTime.fromRFC2822(match.pubDate).toISO();
}
// it's easier to add comma-separated numbers and proper pluralization here on the backend

View File

@ -3,7 +3,7 @@
import * as Sentry from "@sentry/node";
import * as Tracing from "@sentry/tracing"; // eslint-disable-line @typescript-eslint/no-unused-vars
import { VercelRequest, VercelResponse } from "@vercel/node";
import { escape } from "html-escaper";
import { encode } from "html-entities";
import { DateTime } from "luxon";
import numeral from "numeral";
import { GraphQLClient } from "graphql-request";
@ -100,7 +100,7 @@ const fetchRepos = async (sort: string, limit: number): Promise<Repository[]> =>
const currentRepos: Repository[] = response.user.repositories.edges.map(
({ node: repo }: { [key: string]: Repository }) => ({
...repo,
description: escape(repo.description),
description: encode(repo.description),
stargazerCount_pretty: numeral(repo.stargazerCount).format("0,0"),
forkCount_pretty: numeral(repo.forkCount).format("0,0"),
pushedAt_relative: DateTime.fromISO(repo.pushedAt).toRelative({ locale: "en" }),

View File

@ -7,7 +7,7 @@ import * as Sentry from "@sentry/node";
import * as Tracing from "@sentry/tracing"; // eslint-disable-line @typescript-eslint/no-unused-vars
import { VercelRequest, VercelResponse } from "@vercel/node";
import fetch from "node-fetch";
import querystring from "querystring";
import * as queryString from "query-string";
const { SPOTIFY_CLIENT_ID, SPOTIFY_CLIENT_SECRET, SPOTIFY_REFRESH_TOKEN } = process.env;
@ -74,7 +74,7 @@ const getAccessToken = async () => {
Authorization: `Basic ${basic}`,
"Content-Type": "application/x-www-form-urlencoded",
},
body: querystring.stringify({
body: queryString.stringify({
grant_type: "refresh_token",
refresh_token: SPOTIFY_REFRESH_TOKEN,
}),