Skip to content

Commit 16f44c4

Browse files
committed
trim some unnecessary dependencies
1 parent 80793c7 commit 16f44c4

File tree

7 files changed

+218
-265
lines changed

7 files changed

+218
-265
lines changed

app/notes/[slug]/counter.tsx

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import { connection } from "next/server";
2-
import commaNumber from "comma-number";
32
import CountUp from "../../../components/CountUp";
43
import redis from "../../../lib/helpers/redis";
4+
import { siteLocale } from "../../../lib/config";
55

66
const HitCounter = async ({ slug }: { slug: string }) => {
77
await connection();
@@ -16,8 +16,8 @@ const HitCounter = async ({ slug }: { slug: string }) => {
1616

1717
// we have data!
1818
return (
19-
<span title={`${commaNumber(hits)} ${hits === 1 ? "view" : "views"}`}>
20-
<CountUp start={0} end={hits} delay={0} duration={2.5} />
19+
<span title={`${Intl.NumberFormat(siteLocale || "en-US").format(hits)} ${hits === 1 ? "view" : "views"}`}>
20+
<CountUp start={0} end={hits} delay={0} duration={1.5} />
2121
</span>
2222
);
2323
} catch (error) {

app/projects/page.tsx

Lines changed: 21 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,11 @@
11
import { graphql } from "@octokit/graphql";
2-
import commaNumber from "comma-number";
32
import { GitForkIcon, StarIcon } from "lucide-react";
43
import PageTitle from "../../components/PageTitle";
54
import Link from "../../components/Link";
65
import RelativeTime from "../../components/RelativeTime";
76
import { addMetadata } from "../../lib/helpers/metadata";
87
import * as config from "../../lib/config";
9-
import type { User, Repository } from "@octokit/graphql-schema";
8+
import type { User } from "@octokit/graphql-schema";
109

1110
import styles from "./page.module.css";
1211

@@ -18,25 +17,12 @@ export const metadata = addMetadata({
1817
},
1918
});
2019

21-
type Project = {
22-
name: string;
23-
url: string;
24-
description?: string;
25-
language?: {
26-
name: string;
27-
color?: string;
28-
};
29-
stars?: number;
30-
forks?: number;
31-
updatedAt: string;
32-
};
33-
34-
const getRepos = async (): Promise<Project[] | null> => {
20+
const getRepos = async () => {
3521
// don't fail the entire site build if the required API key for this page is missing
3622
if (!process.env.GITHUB_TOKEN) {
3723
console.warn(`ERROR: I can't fetch any GitHub projects without "GITHUB_TOKEN" set! Skipping for now...`);
3824

39-
return null;
25+
return undefined;
4026
}
4127

4228
// https://docs.github.com/en/graphql/reference/objects#repository
@@ -95,19 +81,7 @@ const getRepos = async (): Promise<Project[] | null> => {
9581
}
9682
);
9783

98-
const results = user.repositories.edges as Array<{ node: Repository }>;
99-
100-
const repos = results.map<Project>(({ node: repo }) => ({
101-
name: repo.name,
102-
url: repo.url,
103-
description: repo.description as string,
104-
updatedAt: repo.pushedAt,
105-
stars: repo.stargazerCount,
106-
forks: repo.forkCount,
107-
language: repo.primaryLanguage as Project["language"],
108-
}));
109-
110-
return repos;
84+
return user.repositories.edges?.map((edge) => edge!.node);
11185
};
11286

11387
const Page = async () => {
@@ -119,50 +93,50 @@ const Page = async () => {
11993

12094
<div className={styles.grid}>
12195
{repos?.map((repo) => (
122-
<div key={repo.name} className={styles.card}>
123-
<Link href={repo.url} className={styles.name}>
124-
{repo.name}
96+
<div key={repo!.name} className={styles.card}>
97+
<Link href={repo!.url} className={styles.name}>
98+
{repo!.name}
12599
</Link>
126100

127-
{repo.description && <p className={styles.description}>{repo.description}</p>}
101+
{repo!.description && <p className={styles.description}>{repo!.description}</p>}
128102

129103
<div className={styles.meta}>
130-
{repo.language && (
104+
{repo!.primaryLanguage && (
131105
<div className={styles.metaItem}>
132-
{repo.language.color && (
106+
{repo!.primaryLanguage.color && (
133107
<span
134108
className={styles.metaIcon}
135-
style={{ backgroundColor: repo.language.color, borderRadius: "50%" }}
109+
style={{ backgroundColor: repo!.primaryLanguage.color, borderRadius: "50%" }}
136110
/>
137111
)}
138-
<span>{repo.language.name}</span>
112+
<span>{repo!.primaryLanguage.name}</span>
139113
</div>
140114
)}
141115

142-
{repo.stars && repo.stars > 0 && (
116+
{repo!.stargazerCount > 0 && (
143117
<div className={styles.metaItem}>
144118
<Link
145-
href={`${repo.url}/stargazers`}
146-
title={`${commaNumber(repo.stars)} ${repo.stars === 1 ? "star" : "stars"}`}
119+
href={`${repo!.url}/stargazers`}
120+
title={`${Intl.NumberFormat(config.siteLocale || "en-US").format(repo!.stargazerCount)} ${repo!.stargazerCount === 1 ? "star" : "stars"}`}
147121
plain
148122
className={styles.metaLink}
149123
>
150124
<StarIcon size="1.25em" className={styles.metaIcon} />
151-
<span>{commaNumber(repo.stars)}</span>
125+
<span>{Intl.NumberFormat(config.siteLocale || "en-US").format(repo!.stargazerCount)}</span>
152126
</Link>
153127
</div>
154128
)}
155129

156-
{repo.forks && repo.forks > 0 && (
130+
{repo!.forkCount > 0 && (
157131
<div className={styles.metaItem}>
158132
<Link
159-
href={`${repo.url}/network/members`}
160-
title={`${commaNumber(repo.forks)} ${repo.forks === 1 ? "fork" : "forks"}`}
133+
href={`${repo!.url}/network/members`}
134+
title={`${Intl.NumberFormat(config.siteLocale || "en-US").format(repo!.forkCount)} ${repo!.forkCount === 1 ? "fork" : "forks"}`}
161135
plain
162136
className={styles.metaLink}
163137
>
164138
<GitForkIcon size="1.25em" className={styles.metaIcon} />
165-
<span>{commaNumber(repo.forks)}</span>
139+
<span>{Intl.NumberFormat(config.siteLocale || "en-US").format(repo!.forkCount)}</span>
166140
</Link>
167141
</div>
168142
)}
@@ -177,7 +151,7 @@ const Page = async () => {
177151
}}
178152
/>
179153
<span>
180-
Updated <RelativeTime date={repo.updatedAt} />
154+
Updated <RelativeTime date={repo!.pushedAt} />
181155
</span>
182156
</div>
183157
</div>

lib/helpers/build-feed.ts

Lines changed: 15 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import { Feed } from "feed";
33
import { getFrontMatter, getContent } from "./posts";
44
import * as config from "../config";
55
import { BASE_URL } from "../config/constants";
6+
import type { Item as FeedItem } from "feed";
67

78
import ogImage from "../../app/opengraph-image.jpg";
89

@@ -30,10 +31,10 @@ export const buildFeed = cache(async (): Promise<Feed> => {
3031
},
3132
});
3233

33-
// add posts separately using their frontmatter
34-
const posts = await getFrontMatter();
35-
for (const post of posts) {
36-
feed.addItem({
34+
// parse posts into feed items
35+
const frontmatter = await getFrontMatter();
36+
const posts: FeedItem[] = await Promise.all(
37+
frontmatter.map(async (post) => ({
3738
guid: post.permalink,
3839
link: post.permalink,
3940
title: post.title,
@@ -49,8 +50,16 @@ export const buildFeed = cache(async (): Promise<Feed> => {
4950
${await getContent(post.slug)}
5051
<p><a href="${post.permalink}"><strong>Continue reading...</strong></a></p>
5152
`.trim(),
52-
});
53-
}
53+
}))
54+
);
55+
56+
// sort posts reverse chronologically in case the promises resolved out of order
57+
posts.sort((post1, post2) => new Date(post2.date).getTime() - new Date(post1.date).getTime());
58+
59+
// officially add each post to the feed
60+
posts.forEach((post) => {
61+
feed.addItem(post);
62+
});
5463

5564
return feed;
5665
});

lib/helpers/posts.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
import { cache } from "react";
22
import path from "path";
3+
import fs from "fs/promises";
34
import glob from "fast-glob";
45
import { unified } from "unified";
5-
import { read } from "to-vfile";
66
import { remarkHtml, remarkParse, remarkSmartypants, remarkFrontmatter } from "./remark-rehype-plugins";
77
import { decode } from "html-entities";
88
import { BASE_URL, POSTS_DIR } from "../config/constants";
@@ -130,7 +130,7 @@ export const getContent = cache(async (slug: string): Promise<string | undefined
130130
],
131131
},
132132
})
133-
.process(await read(path.resolve(process.cwd(), `${POSTS_DIR}/${slug}/index.mdx`)));
133+
.process(await fs.readFile(path.resolve(process.cwd(), `${POSTS_DIR}/${slug}/index.mdx`)));
134134

135135
// convert the parsed content to a string with "safe" HTML
136136
return content.toString().replaceAll("<p></p>", "").trim();

next.config.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
/* eslint-disable @typescript-eslint/no-require-imports */
1+
/* eslint-disable @typescript-eslint/no-require-imports, import/no-anonymous-default-export */
22

33
import path from "path";
44
import { visit } from "unist-util-visit";
@@ -219,6 +219,5 @@ const nextPlugins: Array<
219219
}),
220220
];
221221

222-
// eslint-disable-next-line import/no-anonymous-default-export
223222
export default (): NextConfig =>
224223
nextPlugins.reduce((acc, plugin) => (Array.isArray(plugin) ? plugin[0](acc, plugin[1]) : plugin(acc)), nextConfig);

package.json

Lines changed: 7 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -23,13 +23,12 @@
2323
"@giscus/react": "^3.1.0",
2424
"@mdx-js/loader": "^3.1.0",
2525
"@mdx-js/react": "^3.1.0",
26-
"@next/bundle-analyzer": "15.3.0-canary.39",
27-
"@next/mdx": "15.3.0-canary.39",
26+
"@next/bundle-analyzer": "15.3.0-canary.40",
27+
"@next/mdx": "15.3.0-canary.40",
2828
"@octokit/graphql": "^8.2.1",
2929
"@octokit/graphql-schema": "^15.26.0",
30-
"@upstash/redis": "^1.34.6",
30+
"@upstash/redis": "^1.34.7",
3131
"clsx": "^2.1.1",
32-
"comma-number": "^2.1.0",
3332
"copy-to-clipboard": "^3.3.3",
3433
"date-fns": "^4.1.0",
3534
"fast-glob": "^3.3.3",
@@ -38,7 +37,7 @@
3837
"html-entities": "^2.6.0",
3938
"lucide-react": "0.487.0",
4039
"modern-normalize": "^3.0.1",
41-
"next": "15.3.0-canary.39",
40+
"next": "15.3.0-canary.40",
4241
"polished": "^4.3.1",
4342
"prop-types": "^15.8.1",
4443
"react": "19.1.0",
@@ -64,7 +63,6 @@
6463
"remark-smartypants": "^3.0.2",
6564
"resend": "^4.2.0",
6665
"shiki": "^3.2.1",
67-
"to-vfile": "^8.0.0",
6866
"unified": "^11.0.5",
6967
"unist-util-visit": "^5.0.0",
7068
"valibot": "^1.0.0"
@@ -73,25 +71,24 @@
7371
"@eslint/eslintrc": "^3.3.1",
7472
"@eslint/js": "^9.24.0",
7573
"@jakejarvis/eslint-config": "^4.0.7",
76-
"@types/comma-number": "^2.1.2",
7774
"@types/mdx": "^2.0.13",
7875
"@types/node": "^22.14.0",
7976
"@types/prop-types": "^15.7.14",
8077
"@types/react": "^19.1.0",
8178
"@types/react-dom": "^19.1.1",
8279
"@types/react-is": "^19.0.0",
83-
"babel-plugin-react-compiler": "19.0.0-beta-e993439-20250328",
80+
"babel-plugin-react-compiler": "19.0.0-beta-e993439-20250405",
8481
"cross-env": "^7.0.3",
8582
"eslint": "^9.24.0",
86-
"eslint-config-next": "15.3.0-canary.39",
83+
"eslint-config-next": "15.3.0-canary.40",
8784
"eslint-config-prettier": "^10.1.1",
8885
"eslint-plugin-css-modules": "^2.12.0",
8986
"eslint-plugin-import": "^2.31.0",
9087
"eslint-plugin-jsx-a11y": "^6.10.2",
9188
"eslint-plugin-mdx": "^3.4.0",
9289
"eslint-plugin-prettier": "^5.2.6",
9390
"eslint-plugin-react": "^7.37.5",
94-
"eslint-plugin-react-compiler": "19.0.0-beta-e993439-20250328",
91+
"eslint-plugin-react-compiler": "19.0.0-beta-e993439-20250405",
9592
"eslint-plugin-react-hooks": "^5.2.0",
9693
"husky": "^9.1.7",
9794
"lint-staged": "^15.5.0",

0 commit comments

Comments
 (0)