Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,13 @@
"prepare": "husky"
},
"dependencies": {
"blurhash": "^2.0.5",
"clsx": "^2.1.1",
"focus-trap-react": "^11.0.4",
"next": "15.1.7",
"nodemailer": "^6.10.0",
"react": "^19.0.0",
"react-blurhash": "^0.3.0",
"react-dom": "^19.0.0",
"react-hot-toast": "^2.5.2",
"react-icons": "^5.5.0"
Expand Down
22 changes: 22 additions & 0 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

30 changes: 30 additions & 0 deletions src/components/sections/Hero.tsx
Original file line number Diff line number Diff line change
@@ -1,8 +1,36 @@
"use client";
import Image from "next/image";
import { useEffect, useState } from "react";
import { decode } from "blurhash";

import nav_items from "@/data/nav_items.json";

const HERO_BLURHASH = "LQFq2y}uGE5REMNawJn%RQaeso$*";

function blurhashToBase64(blurhash: string, width = 32, height = 32): string {
const pixels = decode(blurhash, width, height);

const canvas = document.createElement("canvas");
canvas.width = width;
canvas.height = height;

const ctx = canvas.getContext("2d");
if (!ctx) return "";

const imageData = ctx.createImageData(width, height);
imageData.data.set(pixels);
ctx.putImageData(imageData, 0, 0);

return canvas.toDataURL("image/jpeg", 0.5);
}

export default function Hero() {
const [blurDataURL, setBlurDataURL] = useState<string>("");

useEffect(() => {
setBlurDataURL(blurhashToBase64(HERO_BLURHASH, 32, 21));
}, []);

return (
<section id={nav_items[0]}>
<h2 className="hidden">{nav_items[0]}</h2>
Expand All @@ -16,6 +44,8 @@ export default function Hero() {
style={{ objectFit: "cover" }}
priority={true}
fetchPriority="high"
placeholder={blurDataURL ? "blur" : "empty"}
blurDataURL={blurDataURL || undefined}
/>
</div>
<div className="h-screen w-screen flex flex-col justify-center items-center">
Expand Down