Files
erika/app/page.tsx
T

102 lines
3.6 KiB
TypeScript

import { config, config_p2 } 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 { Users } from "lucide-react";
import { Kbd } from "@/components/ui/kbd";
export default async function Home() {
const { counts, tiktokProfile } = 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 TikTok profile data with config fallbacks
const profileName = tiktokProfile.displayName || 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="flex min-h-screen flex-col items-center justify-center p-4">
<script
type="application/ld+json"
dangerouslySetInnerHTML={{ __html: JSON.stringify(jsonLd) }}
/>
<video className="fixed top-0 left-0 w-full h-full -z-10 object-cover" autoPlay muted loop playsInline preload="none">
<source src="/background/erika.mp4" media="(min-width: 768px)"></source>
<source src="/background/erika-mb.mp4" media="(max-width: 767px)"></source>
</video>
<Card className="w-full max-w-sm overflow-hidden relative bg-transparent border-0 backdrop-blur-md md:backdrop-blur-none md:bg-card md:border md:max-w-lg" 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-500 to-yellow-200 bg-clip-text text-transparent">
{profileName}
</h1>
<p className="text-sm text-zinc-400 mt-1">
{config.profile.desc}
</p>
{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_p2.links} />
</Card>
</main>
);
}