's'
This commit is contained in:
@@ -56,7 +56,7 @@ const FALLBACK_HOME_CONTENT: ContentItem[] = [
|
||||
subtitle: "个人访谈 / 现实纪录片",
|
||||
subtitleEn: "Interview documentary",
|
||||
coverImage: "https://images.unsplash.com/photo-1500530855697-b586d89ba3ee?w=1200",
|
||||
targetUrl: "/videos/lin-dali-documentary",
|
||||
targetUrl: "/videos",
|
||||
ctaLabel: "观看访谈",
|
||||
ctaLabelEn: "Watch",
|
||||
},
|
||||
@@ -86,7 +86,55 @@ const FALLBACK_HOME_CONTENT: ContentItem[] = [
|
||||
},
|
||||
];
|
||||
|
||||
const HIDDEN_HOME_RIGHT_CARD_TYPES = new Set<ContentItem["type"]>(["app", "guide"]);
|
||||
const COVER_FALLBACK: Record<"ebook" | "video", string> = {
|
||||
ebook: "https://images.unsplash.com/photo-1519389950473-47ba0277781c?w=1200",
|
||||
video: "https://images.unsplash.com/photo-1500530855697-b586d89ba3ee?w=1200",
|
||||
};
|
||||
|
||||
function normalizeHomeContentItem(item: Partial<ContentItem> & { slug: string }): ContentItem | null {
|
||||
const type = String(item.type || "").toLowerCase();
|
||||
if (type !== "ebook" && type !== "video" && type !== "app" && type !== "guide") return null;
|
||||
const fallback = FALLBACK_HOME_CONTENT.find((entry) => entry.slug === item.slug);
|
||||
const contentType = type as ContentItem["type"];
|
||||
const defaultTarget =
|
||||
contentType === "ebook"
|
||||
? `/ebooks/${item.slug}`
|
||||
: contentType === "video"
|
||||
? "/videos"
|
||||
: contentType === "app"
|
||||
? "/app"
|
||||
: "/digital";
|
||||
return {
|
||||
slug: item.slug,
|
||||
type: contentType,
|
||||
title: item.title || fallback?.title || item.slug,
|
||||
titleEn: item.titleEn || fallback?.titleEn,
|
||||
subtitle: item.subtitle || fallback?.subtitle || "",
|
||||
subtitleEn: item.subtitleEn || fallback?.subtitleEn,
|
||||
description: item.description || fallback?.description,
|
||||
coverImage:
|
||||
item.coverImage ||
|
||||
fallback?.coverImage ||
|
||||
(contentType === "ebook" || contentType === "video" ? COVER_FALLBACK[contentType] : "") ||
|
||||
"",
|
||||
targetUrl:
|
||||
contentType === "video"
|
||||
? "/videos"
|
||||
: item.targetUrl || fallback?.targetUrl || defaultTarget,
|
||||
ctaLabel: item.ctaLabel || fallback?.ctaLabel || "查看",
|
||||
ctaLabelEn: item.ctaLabelEn || fallback?.ctaLabelEn,
|
||||
durationMinutes: item.durationMinutes ?? fallback?.durationMinutes,
|
||||
};
|
||||
}
|
||||
|
||||
function pickHomepageFeatureContent(items: ContentItem[]): ContentItem[] {
|
||||
const normalized = items
|
||||
.map((item) => normalizeHomeContentItem(item))
|
||||
.filter((item): item is ContentItem => Boolean(item));
|
||||
const ebook = normalized.find((item) => item.type === "ebook");
|
||||
const video = normalized.find((item) => item.type === "video");
|
||||
return [ebook, video].filter((item): item is ContentItem => Boolean(item));
|
||||
}
|
||||
|
||||
interface ProfileItem {
|
||||
id: string;
|
||||
@@ -146,7 +194,12 @@ export default function Home() {
|
||||
})
|
||||
.catch(() => setLiveCities(cities));
|
||||
apiFetch<{ ok: boolean; items: ContentItem[] }>("/api/content/home")
|
||||
.then((data) => setHomeContent(data.items?.length ? data.items : FALLBACK_HOME_CONTENT))
|
||||
.then((data) => {
|
||||
const items = (data.items || [])
|
||||
.map((item) => normalizeHomeContentItem(item))
|
||||
.filter((item): item is ContentItem => Boolean(item));
|
||||
setHomeContent(items.length ? items : FALLBACK_HOME_CONTENT);
|
||||
})
|
||||
.catch(() => setHomeContent(FALLBACK_HOME_CONTENT));
|
||||
apiFetch<{ stats: { cities: number; nomads: number; meetups: number; minCost: number; profiles: number; discussions: number } }>("/api/stats/overview")
|
||||
.then((data) => {
|
||||
@@ -217,7 +270,7 @@ export default function Home() {
|
||||
}, [activeFilter, sortBy, liveCities]);
|
||||
|
||||
const homepageFeatureContent = useMemo(
|
||||
() => homeContent.filter((item) => !HIDDEN_HOME_RIGHT_CARD_TYPES.has(item.type)).slice(0, 4),
|
||||
() => pickHomepageFeatureContent(homeContent),
|
||||
[homeContent]
|
||||
);
|
||||
|
||||
@@ -264,58 +317,70 @@ export default function Home() {
|
||||
const title = locale === "zh" ? item.title : item.titleEn || item.title;
|
||||
const subtitle = locale === "zh" ? item.subtitle : item.subtitleEn || item.subtitle;
|
||||
const cta = locale === "zh" ? item.ctaLabel : item.ctaLabelEn || item.ctaLabel;
|
||||
const typeMeta: Record<string, { header: string; icon: string; href: string }> = {
|
||||
ebook: { header: "电子书", icon: "📘", href: `/ebooks/${item.slug}` },
|
||||
video: { header: "访谈视频", icon: "▶️", href: `/videos/${item.slug}` },
|
||||
app: { header: "App", icon: "📱", href: "/app" },
|
||||
guide: { header: "数字游民指南", icon: "🧭", href: "/digital" },
|
||||
const typeMeta: Record<ContentItem["type"], { headerKey: "rightCardEbook" | "rightCardVideo" | null; icon: string }> = {
|
||||
ebook: { headerKey: "rightCardEbook", icon: "📘" },
|
||||
video: { headerKey: "rightCardVideo", icon: "▶️" },
|
||||
app: { headerKey: null, icon: "📱" },
|
||||
guide: { headerKey: null, icon: "🧭" },
|
||||
};
|
||||
const meta = typeMeta[item.type] || typeMeta.guide;
|
||||
const isExternal = meta.href.startsWith("http");
|
||||
const meta = typeMeta[item.type];
|
||||
const href = item.targetUrl || "/";
|
||||
const coverSrc = mediaUrl(
|
||||
item.coverImage || COVER_FALLBACK[item.type as "ebook" | "video"] || ""
|
||||
);
|
||||
const isExternal = href.startsWith("http");
|
||||
const rowStyle = { "--right-row": index + 1 } as CSSProperties;
|
||||
const content = (
|
||||
<>
|
||||
<div className="right-item-header">{meta.header}</div>
|
||||
<div className="relative h-[calc(100%-38px)] sm:h-[calc(100%-42px)] overflow-hidden">
|
||||
<img src={mediaUrl(item.coverImage)} alt={title} className="absolute inset-0 h-full w-full object-cover" />
|
||||
<div className="absolute inset-0 bg-gradient-to-t from-black/75 via-black/35 to-transparent" />
|
||||
<div className="absolute inset-x-0 bottom-0 p-3 sm:p-4 text-white">
|
||||
<div className="mb-1 text-xl sm:text-2xl">{meta.icon}</div>
|
||||
<div className="right-item-header">
|
||||
{meta.headerKey ? t(meta.headerKey) : title}
|
||||
</div>
|
||||
<div className="right-item-body">
|
||||
{coverSrc ? (
|
||||
<img
|
||||
src={coverSrc}
|
||||
alt={title}
|
||||
className="absolute inset-0 h-full w-full object-cover"
|
||||
loading="lazy"
|
||||
/>
|
||||
) : (
|
||||
<div className="absolute inset-0 flex items-center justify-center bg-gradient-to-br from-gray-200 to-gray-300 text-4xl dark:from-gray-700 dark:to-gray-800">
|
||||
{meta.icon}
|
||||
</div>
|
||||
)}
|
||||
<div className="absolute inset-0 bg-gradient-to-t from-black/80 via-black/40 to-black/10" />
|
||||
<div className="absolute inset-x-0 bottom-0 z-10 p-3 sm:p-4 text-white">
|
||||
<div className="mb-1 text-lg sm:text-xl">{meta.icon}</div>
|
||||
<h3 className="line-clamp-2 text-xs sm:text-sm font-bold leading-snug">{title}</h3>
|
||||
<p className="mt-1 line-clamp-2 text-[10px] sm:text-xs text-white/80">{subtitle}</p>
|
||||
<span className="mt-2 inline-flex rounded-full bg-white/90 px-2.5 py-1 text-[10px] sm:text-xs font-semibold text-gray-900">
|
||||
<p className="mt-1 line-clamp-2 text-[10px] sm:text-xs text-white/85">{subtitle}</p>
|
||||
<span className="mt-2 inline-flex max-w-full truncate rounded-full bg-white/92 px-2.5 py-1 text-[10px] sm:text-xs font-semibold text-gray-900">
|
||||
{cta}
|
||||
</span>
|
||||
</div>
|
||||
</div>
|
||||
</>
|
||||
);
|
||||
const rowStyle = { "--right-row": index + 1 } as CSSProperties;
|
||||
return isExternal ? (
|
||||
<a
|
||||
key={item.slug}
|
||||
href={meta.href}
|
||||
href={href}
|
||||
target="_blank"
|
||||
rel="noopener noreferrer"
|
||||
className="right-item block"
|
||||
className="right-item"
|
||||
style={rowStyle}
|
||||
>
|
||||
{content}
|
||||
</a>
|
||||
) : (
|
||||
<Link
|
||||
key={item.slug}
|
||||
href={meta.href}
|
||||
className="right-item block"
|
||||
style={rowStyle}
|
||||
>
|
||||
<Link key={item.slug} href={href} className="right-item" style={rowStyle}>
|
||||
{content}
|
||||
</Link>
|
||||
);
|
||||
})}
|
||||
|
||||
<Link href="/join" className="right-item block" style={{ "--right-row": homepageFeatureContent.length + 1 } as React.CSSProperties}>
|
||||
<Link href="/join" className="right-item" style={{ "--right-row": homepageFeatureContent.length + 1 } as React.CSSProperties}>
|
||||
<div className="right-item-header">{t("joinCommunity")}</div>
|
||||
<div className="flex flex-col items-center justify-center text-center p-2 sm:p-5 h-[calc(100%-38px)] sm:h-[calc(100%-42px)]">
|
||||
<div className="right-item-body flex flex-col items-center justify-center text-center p-2 sm:p-5">
|
||||
<span className="text-2xl sm:text-5xl mb-1 sm:mb-3">💬</span>
|
||||
<p className="text-[10px] sm:text-sm text-gray-600 dark:text-gray-400 mb-0.5">
|
||||
{t("joinCommunityDesc")}
|
||||
@@ -329,9 +394,9 @@ export default function Home() {
|
||||
</div>
|
||||
</Link>
|
||||
|
||||
<Link href="/dating" className="right-item block" style={{ "--right-row": homepageFeatureContent.length + 2 } as React.CSSProperties}>
|
||||
<Link href="/dating" className="right-item" style={{ "--right-row": homepageFeatureContent.length + 2 } as React.CSSProperties}>
|
||||
<div className="right-item-header">{t("newMembers")}</div>
|
||||
<div className="p-2 sm:p-5 flex flex-wrap gap-1 sm:gap-2 content-start">
|
||||
<div className="right-item-body p-2 sm:p-5 flex flex-wrap gap-1 sm:gap-2 content-start">
|
||||
{memberPhotos.map((m, i) => (
|
||||
<img
|
||||
key={`${m.name}-${i}`}
|
||||
@@ -347,9 +412,9 @@ export default function Home() {
|
||||
</div>
|
||||
</Link>
|
||||
|
||||
<Link href="/meetups" className="right-item block" style={{ "--right-row": homepageFeatureContent.length + 3 } as React.CSSProperties}>
|
||||
<Link href="/meetups" className="right-item" style={{ "--right-row": homepageFeatureContent.length + 3 } as React.CSSProperties}>
|
||||
<div className="right-item-header">{t("latestEvents")}</div>
|
||||
<div className="p-1.5 sm:p-4 flex flex-col gap-0.5 sm:gap-2.5 text-[10px] sm:text-sm text-gray-700 dark:text-gray-300 h-[calc(100%-38px)] sm:h-[calc(100%-42px)]">
|
||||
<div className="right-item-body p-1.5 sm:p-4 flex flex-col gap-0.5 sm:gap-2.5 text-[10px] sm:text-sm text-gray-700 dark:text-gray-300">
|
||||
{homeMeetups.slice(0, 3).map((meetup) => (
|
||||
<div
|
||||
key={`${meetup.city}-${meetup.date}`}
|
||||
|
||||
Reference in New Issue
Block a user