Files
erika/app/page.tsx
T

105 lines
3.4 KiB
TypeScript

import { config } from "@/lib/config";
import { Card, CardHeader } from "@/components/ui/card";
import Image from "next/image";
import { getFollowerCounts } from "@/lib/followers";
import { LinkCard } from "@/components/LinkCard";
import { getRedisClient } from "@/lib/redis";
import { headers } from "next/headers";
import { connection } from "next/server";
import { Users } from "lucide-react";
import { Kbd } from "@/components/ui/kbd";
import Background from "@/public/background/space.webp";
export default async function Home() {
await connection();
const { counts } = await getFollowerCounts();
const headersList = await headers();
const ip = headersList.get("x-forwarded-for") || headersList.get("x-real-ip") || "unknown";
let visitorCount = 0;
try {
const redis = await getRedisClient();
if (ip !== "unknown") {
const added = await redis.sadd("erika:unique_visitors", ip);
if (added > 0) {
// New visitor — refresh the count
visitorCount = await redis.scard("erika:unique_visitors");
} else {
// Existing visitor — use cached count or fetch
visitorCount = await redis.scard("erika:unique_visitors");
}
} else {
visitorCount = await redis.scard("erika:unique_visitors");
}
} catch (e) {
console.error("Failed to track visitor:", e);
}
// Use configured profile data.
const profileName = config.profile.name;
const profileAvatar = config.profile.avatar;
const links1 = [...config.links];
const jsonLd = {
"@context": "https://schema.org",
"@type": "ProfilePage",
name: profileName,
description: config.profile.desc,
url: "https://erika.sudloh.com",
mainEntity: {
"@type": "Person",
name: profileName,
image: profileAvatar.startsWith("/") ? `https://erika.sudloh.com${profileAvatar}` : profileAvatar,
sameAs: links1.map((l) => l.link),
},
};
return (
<main className="dark relative flex min-h-screen flex-col items-center justify-center bg-background text-foreground">
<script
type="application/ld+json"
dangerouslySetInnerHTML={{ __html: JSON.stringify(jsonLd) }}
/>
<Image
src={Background}
alt="Background"
fill
priority
className="fixed top-0 left-0 z-0 h-full w-full object-cover opacity-60"
/>
<Card className="relative z-10 w-full max-w-sm overflow-hidden border-0 bg-black/20 md:max-w-lg md:border md:bg-card" role="article">
<CardHeader className="flex flex-col items-center gap-4 text-center">
<div className="relative w-24 h-24 overflow-hidden rounded-full">
<Image
src={profileAvatar}
alt={`${profileName} avatar`}
fill
sizes="96px"
priority
className="object-cover"
/>
</div>
<div>
<h1 className="text-2xl font-bold bg-linear-to-r from-pink-400 to-yellow-400 bg-clip-text text-transparent">
{profileName}
</h1>
{visitorCount > 0 && (
<div className="mt-3 flex justify-center">
<Kbd>
<Users className="size-3.5" />
<span>{visitorCount} Unique Visitors</span>
</Kbd>
</div>
)}
</div>
</CardHeader>
<LinkCard counts={counts} links1={links1} links2={config.secondaryLinks} />
</Card>
</main>
);
}