Skip to content

Commit 3542917

Browse files
committed
refactor!: remove react dependency for UI interactions (#457)
Remove react as a dependency for UI interactions. Update jsx components such as Search and Datetime with astro components.
1 parent 846315a commit 3542917

20 files changed

Lines changed: 467 additions & 925 deletions

astro.config.ts

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
import { defineConfig } from "astro/config";
22
import tailwindcss from "@tailwindcss/vite";
3-
import react from "@astrojs/react";
43
import sitemap from "@astrojs/sitemap";
54
import remarkToc from "remark-toc";
65
import remarkCollapse from "remark-collapse";
@@ -10,7 +9,6 @@ import { SITE } from "./src/config";
109
export default defineConfig({
1110
site: SITE.website,
1211
integrations: [
13-
react(),
1412
sitemap({
1513
filter: page => SITE.showArchives || !page.endsWith("/archives"),
1614
}),

package.json

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -12,18 +12,13 @@
1212
"lint": "eslint ."
1313
},
1414
"dependencies": {
15-
"@astrojs/react": "^4.2.0",
1615
"@astrojs/rss": "^4.0.11",
1716
"@astrojs/sitemap": "^3.2.1",
1817
"@resvg/resvg-js": "^2.6.2",
1918
"@tailwindcss/vite": "^4.0.8",
20-
"@types/react": "^19.0.10",
21-
"@types/react-dom": "^19.0.4",
2219
"astro": "^5.3.1",
2320
"fuse.js": "^7.1.0",
2421
"lodash.kebabcase": "^4.1.1",
25-
"react": "^19.0.0",
26-
"react-dom": "^19.0.0",
2722
"remark-collapse": "^0.1.2",
2823
"remark-toc": "^9.0.0",
2924
"satori": "^0.12.1",

pnpm-lock.yaml

Lines changed: 0 additions & 436 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/components/Card.astro

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
---
2+
import { slugifyStr } from "@/utils/slugify";
3+
import type { CollectionEntry } from "astro:content";
4+
import Datetime from "./Datetime.astro";
5+
6+
export interface Props {
7+
href?: string;
8+
frontmatter: CollectionEntry<"blog">["data"];
9+
secHeading?: boolean;
10+
}
11+
12+
const { href, frontmatter, secHeading = true } = Astro.props;
13+
14+
const { title, pubDatetime, modDatetime, description } = frontmatter;
15+
16+
const headerProps = {
17+
style: { viewTransitionName: slugifyStr(title) },
18+
class: "text-lg font-medium decoration-dashed hover:underline",
19+
};
20+
---
21+
22+
<li class="my-6">
23+
<a
24+
href={href}
25+
class="inline-block text-lg font-medium text-accent decoration-dashed underline-offset-4 focus-visible:no-underline focus-visible:underline-offset-0"
26+
>
27+
{
28+
secHeading ? (
29+
<h2 {...headerProps}>{title}</h2>
30+
) : (
31+
<h3 {...headerProps}>{title}</h3>
32+
)
33+
}
34+
</a>
35+
<Datetime pubDatetime={pubDatetime} modDatetime={modDatetime} />
36+
<p>{description}</p>
37+
</li>

src/components/Card.tsx

Lines changed: 0 additions & 35 deletions
This file was deleted.

src/components/Datetime.astro

Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
---
2+
import { LOCALE } from "@/constants";
3+
4+
export interface Props {
5+
pubDatetime: string | Date;
6+
modDatetime: string | Date | undefined | null;
7+
size?: "sm" | "lg";
8+
class?: string;
9+
}
10+
11+
const {
12+
pubDatetime,
13+
modDatetime,
14+
size = "sm",
15+
class: className = "",
16+
} = Astro.props;
17+
18+
/* ========== Formatted Datetime ========== */
19+
const myDatetime = new Date(
20+
modDatetime && modDatetime > pubDatetime ? modDatetime : pubDatetime
21+
);
22+
const date = myDatetime.toLocaleDateString(LOCALE.langTag, {
23+
year: "numeric",
24+
month: "short",
25+
day: "numeric",
26+
});
27+
28+
const time = myDatetime.toLocaleTimeString(LOCALE.langTag, {
29+
hour: "2-digit",
30+
minute: "2-digit",
31+
});
32+
---
33+
34+
<div class={`flex items-end space-x-2 opacity-80 ${className}`.trim()}>
35+
<svg
36+
xmlns="http://www.w3.org/2000/svg"
37+
class={`${
38+
size === "sm" ? "scale-90" : "scale-100"
39+
} inline-block h-6 w-6 min-w-[1.375rem] fill-foreground`}
40+
aria-hidden="true"
41+
>
42+
<path
43+
d="M7 11h2v2H7zm0 4h2v2H7zm4-4h2v2h-2zm0 4h2v2h-2zm4-4h2v2h-2zm0 4h2v2h-2z"
44+
></path>
45+
<path
46+
d="M5 22h14c1.103 0 2-.897 2-2V6c0-1.103-.897-2-2-2h-2V2h-2v2H9V2H7v2H5c-1.103 0-2 .897-2 2v14c0 1.103.897 2 2 2zM19 8l.001 12H5V8h14z"
47+
></path>
48+
</svg>
49+
{
50+
modDatetime && modDatetime > pubDatetime ? (
51+
<span
52+
class={`italic ${size === "sm" ? "text-sm" : "text-sm sm:text-base"}`}
53+
>
54+
Updated:
55+
</span>
56+
) : (
57+
<span class="sr-only">Published:</span>
58+
)
59+
}
60+
<span class={`italic ${size === "sm" ? "text-sm" : "text-sm sm:text-base"}`}>
61+
<time datetime={myDatetime.toISOString()}>{date}</time>
62+
<span aria-hidden="true"> | </span>
63+
<span class="sr-only">&nbsp;at&nbsp;</span>
64+
<span class="text-nowrap">{time}</span>
65+
</span>
66+
</div>

src/components/Datetime.tsx

Lines changed: 0 additions & 76 deletions
This file was deleted.

src/components/SearchBar.tsx

Lines changed: 0 additions & 135 deletions
This file was deleted.

0 commit comments

Comments
 (0)