chore(publish): replace source tree with static export at repo root
Publish the prerendered static export (index.html, 404.html, cinema/,
c/, about/, for-cinemas/, for-film-lovers/, assets/, images/, og/,
sitemap.xml, robots.txt) as the site root and remove the React Router
+ Nitro source tree from this branch. Source remains available in
history at 0548772.
Note: public/sw.js here reports VERSION v2.0.5 while the removed source
tree (v2.1.0) was newer, and .gitignore was not carried over.
This commit is contained in:
1 parent
05487728a7
commit
e6c4ebff48
394 files changed
+3977
-37891
No files matched your search
@@ -1,229 +0,0 @@
|
||||
import { useEffect, useMemo, useRef, useState } from "react";
|
||||
import { useLoaderData, useSearchParams } from "react-router";
|
||||
|
||||
import { HeroSection } from "@/components/home/HeroSection";
|
||||
import { CategoryFilter, CinemaGrid } from "@/components/site/CinemaGrid";
|
||||
import { Reveal } from "@/components/site/Reveal";
|
||||
import { SiteShell } from "@/components/site/SiteShell";
|
||||
import { useNearMe } from "@/hooks/use-near-me";
|
||||
import { trackEvent } from "@/lib/analytics-client";
|
||||
import { APP_TITLE } from "@/lib/app-config";
|
||||
import {
|
||||
CINEMA_CATEGORIES,
|
||||
DEFAULT_CATEGORY,
|
||||
VENUE_TYPES,
|
||||
publiclyVisible,
|
||||
type Cinema,
|
||||
type CinemaCategory,
|
||||
type VenueType,
|
||||
} from "@/lib/cinemas";
|
||||
import { useContent } from "@/lib/content-context";
|
||||
import { dailyOrder, dayKey } from "@/lib/daily-order";
|
||||
import { sortByDistance } from "@/lib/geo";
|
||||
import { useI18n } from "@/lib/i18n";
|
||||
import { DEFAULT_LOCALE, MESSAGES } from "@/lib/i18n/messages";
|
||||
import { scrollIntoViewRespectMotion } from "@/lib/motion";
|
||||
import { resolvePageOrigin } from "@/lib/page-origin";
|
||||
import { computePopularity } from "@/lib/popularity.server";
|
||||
import { filterCinemas } from "@/lib/search";
|
||||
import { pageMeta, originFromMatches, websiteJsonLd } from "@/lib/seo";
|
||||
import { SITE } from "@/lib/site";
|
||||
|
||||
/** head (title/description) ไม่เปลี่ยนตามภาษา — meta() ไม่มี access ต่อ cookie */
|
||||
const HEAD_MESSAGES = MESSAGES[DEFAULT_LOCALE];
|
||||
|
||||
/** meta() ของ route ลูกอ่าน origin ที่ root loader หาไว้ (ไม่ฝังโดเมน) */
|
||||
type MetaArgs = { matches?: Array<{ id?: string; data?: unknown }> };
|
||||
|
||||
export function meta({
|
||||
loaderData,
|
||||
matches,
|
||||
}: MetaArgs & { loaderData?: { origin?: string } }) {
|
||||
const origin = loaderData?.origin ?? originFromMatches(matches);
|
||||
return [
|
||||
...pageMeta({
|
||||
origin,
|
||||
title: SITE.title,
|
||||
description: HEAD_MESSAGES.meta.homeDescription,
|
||||
path: "/",
|
||||
}),
|
||||
...websiteJsonLd(origin),
|
||||
];
|
||||
}
|
||||
|
||||
/** จำนวนการ์ดที่แสดงก่อนกด "แสดงเพิ่ม" */
|
||||
const INITIAL_VISIBLE = 4;
|
||||
|
||||
/** อันดับยอดนิยม + คีย์วันที่สำหรับสลับลำดับการ์ด (memo 5 นาที) — ส่งมากับ loader */
|
||||
export async function loader({ request }: { request: Request }) {
|
||||
return {
|
||||
popularity: await computePopularity(),
|
||||
orderKey: dayKey(),
|
||||
origin: resolvePageOrigin(request),
|
||||
};
|
||||
}
|
||||
|
||||
export default function HomeRoute() {
|
||||
const { messages, locale } = useI18n();
|
||||
const { popularity, orderKey } = useLoaderData<typeof loader>();
|
||||
const { cinemas } = useContent();
|
||||
const { status: nearMeStatus, distances, requestLocation } = useNearMe();
|
||||
const [category, setCategory] = useState<CinemaCategory>(DEFAULT_CATEGORY);
|
||||
/** ชั้นกรองที่ 1 — ประเภทโรงหนัง (null = ทุกประเภท) */
|
||||
const [venue, setVenue] = useState<VenueType | null>(null);
|
||||
// รองรับลิงก์ค้นหาตรง ๆ (/?q=...) — ให้ SearchAction ใน JSON-LD ทำงานจริง
|
||||
const [searchParams] = useSearchParams();
|
||||
const [query, setQuery] = useState(() => searchParams.get("q") ?? "");
|
||||
const [showAll, setShowAll] = useState(false);
|
||||
/** หัวข้อผลลัพธ์ — ใช้เป็นจุดเลื่อนเมื่อกดปุ่ม "ค้นหา" หรือ Enter */
|
||||
const resultsRef = useRef<HTMLElement | null>(null);
|
||||
|
||||
const matched = useMemo(() => {
|
||||
// ลำดับการ์ดสลับทุกวัน (ไม่ให้โรงใดอยู่ตำแหน่งเดิมสองวันติดกัน)
|
||||
const base = dailyOrder(
|
||||
publiclyVisible(cinemas),
|
||||
(cinema) => cinema.slug,
|
||||
orderKey,
|
||||
);
|
||||
const byStats =
|
||||
category === "ยอดนิยม" &&
|
||||
venue === null &&
|
||||
popularity.ready &&
|
||||
query.trim() === "";
|
||||
if (!byStats)
|
||||
return filterCinemas(base, {
|
||||
category,
|
||||
query,
|
||||
venue,
|
||||
tagLabels: messages.tags,
|
||||
});
|
||||
|
||||
// ใช้เฉพาะโรงที่ยังไม่ถูกซ่อน และเรียงตามอันดับสถิติ
|
||||
const bySlug = new Map(base.map((cinema) => [cinema.slug, cinema]));
|
||||
return popularity.slugs
|
||||
.map((slug) => bySlug.get(slug))
|
||||
.filter((cinema): cinema is Cinema => cinema !== undefined);
|
||||
}, [cinemas, category, query, venue, popularity, orderKey, messages.tags]);
|
||||
// เรียงจากใกล้สุดไปไกลสุดเมื่อทราบตำแหน่งแล้ว (ไม่กรองตามรัศมี — ไกลแค่ไหนก็ยังแสดง)
|
||||
const ordered =
|
||||
nearMeStatus === "ready" ? sortByDistance(matched, distances) : matched;
|
||||
const visibleCinemas = showAll ? ordered : ordered.slice(0, INITIAL_VISIBLE);
|
||||
const hasMore = ordered.length > visibleCinemas.length;
|
||||
|
||||
const keyword = query.trim();
|
||||
|
||||
// เก็บสถิติการค้นหา: ยิงครั้งเดียวหลังผู้ใช้หยุดพิมพ์ 900ms และมีคำค้นอย่างน้อย 2 ตัวอักษร
|
||||
useEffect(() => {
|
||||
if (keyword.length < 2) return;
|
||||
const timer = setTimeout(() => {
|
||||
trackEvent({
|
||||
type: "search",
|
||||
query: keyword,
|
||||
category,
|
||||
result_count: matched.length,
|
||||
locale,
|
||||
});
|
||||
}, 900);
|
||||
return () => clearTimeout(timer);
|
||||
}, [keyword, category, matched.length, locale]);
|
||||
|
||||
/**
|
||||
* ปุ่ม "ค้นหา" / Enter — ผลลัพธ์ถูกกรองสดอยู่แล้วขณะพิมพ์
|
||||
* จึงทำหน้าที่แค่พาผู้ใช้ไปดูผล (ปิดคีย์บอร์ดมือถือทำที่ HeroSection)
|
||||
*/
|
||||
function handleSubmitSearch() {
|
||||
scrollIntoViewRespectMotion(resultsRef.current);
|
||||
}
|
||||
|
||||
function handleRequestLocation() {
|
||||
requestLocation();
|
||||
trackEvent({
|
||||
type: "near_me",
|
||||
category,
|
||||
query: keyword || undefined,
|
||||
result_count: matched.length,
|
||||
locale,
|
||||
});
|
||||
}
|
||||
|
||||
return (
|
||||
<SiteShell variant="home">
|
||||
<main className="relative z-10 mx-auto max-w-[1440px] px-5 pb-12 md:px-[108px] md:pb-16">
|
||||
<HeroSection
|
||||
query={query}
|
||||
onQueryChange={setQuery}
|
||||
nearMeStatus={nearMeStatus}
|
||||
onRequestLocation={handleRequestLocation}
|
||||
onSubmitSearch={handleSubmitSearch}
|
||||
/>
|
||||
|
||||
<section
|
||||
ref={resultsRef}
|
||||
className="mt-16 flex scroll-mt-[88px] flex-col gap-6 md:mt-[65px]"
|
||||
>
|
||||
<Reveal
|
||||
delay={260}
|
||||
className="flex min-h-[72px] items-center border-b border-[#1F1F1F] py-2"
|
||||
>
|
||||
<h2 className="text-[28px] font-semibold leading-[1.3]">
|
||||
{messages.list.title}
|
||||
</h2>
|
||||
</Reveal>
|
||||
|
||||
<Reveal delay={340}>
|
||||
<CategoryFilter
|
||||
active={category}
|
||||
categories={CINEMA_CATEGORIES}
|
||||
onChange={setCategory}
|
||||
venues={VENUE_TYPES}
|
||||
activeVenue={venue}
|
||||
onVenueChange={setVenue}
|
||||
/>
|
||||
</Reveal>
|
||||
|
||||
{visibleCinemas.length === 0 ? (
|
||||
<p className="py-16 text-center text-sm text-[#B3B3B3]">
|
||||
{messages.list.empty}
|
||||
</p>
|
||||
) : (
|
||||
<div className="mt-2">
|
||||
<CinemaGrid
|
||||
cinemas={visibleCinemas}
|
||||
source={keyword ? "search" : "category"}
|
||||
searchQuery={keyword || undefined}
|
||||
/>
|
||||
</div>
|
||||
)}
|
||||
|
||||
{hasMore ? (
|
||||
<Reveal kind="fade" className="flex justify-center pt-2">
|
||||
<button
|
||||
type="button"
|
||||
onClick={() => setShowAll(true)}
|
||||
className="h-10 w-[220px] rounded-lg border border-[#8F0808] bg-[#8F0808] transition hover:bg-[#a30a0a]"
|
||||
>
|
||||
{messages.list.showMore}
|
||||
</button>
|
||||
</Reveal>
|
||||
) : null}
|
||||
|
||||
{showAll && ordered.length > INITIAL_VISIBLE ? (
|
||||
<Reveal kind="fade" className="flex justify-center pt-2">
|
||||
<button
|
||||
type="button"
|
||||
onClick={() => {
|
||||
setShowAll(false);
|
||||
// ย่อกลับแล้วพาผู้ใช้ขึ้นไปที่หัวข้อผลลัพธ์ ไม่ให้ค้างอยู่ท้ายหน้า
|
||||
scrollIntoViewRespectMotion(resultsRef.current);
|
||||
}}
|
||||
className="h-10 w-[220px] rounded-lg border border-[#303030] px-4 text-sm transition hover:border-[#A92626] hover:text-[#D47272]"
|
||||
>
|
||||
{messages.list.showLess}
|
||||
</button>
|
||||
</Reveal>
|
||||
) : null}
|
||||
</section>
|
||||
</main>
|
||||
</SiteShell>
|
||||
);
|
||||
}
|
||||
@@ -1,167 +0,0 @@
|
||||
import { IconArrowBackUp } from "@tabler/icons-react";
|
||||
import { Link } from "react-router";
|
||||
|
||||
import { footerIcon } from "@/components/site/footer-icons";
|
||||
import { Reveal } from "@/components/site/Reveal";
|
||||
import { SiteShell } from "@/components/site/SiteShell";
|
||||
import { useReveal } from "@/hooks/use-reveal";
|
||||
import { APP_TITLE } from "@/lib/app-config";
|
||||
import { useContent } from "@/lib/content-context";
|
||||
import { COLORS } from "@/lib/design-tokens";
|
||||
import { useI18n } from "@/lib/i18n";
|
||||
import { DEFAULT_LOCALE, MESSAGES } from "@/lib/i18n/messages";
|
||||
import { resolvePageOrigin } from "@/lib/page-origin";
|
||||
import { breadcrumbJsonLd, originFromMatches, pageMeta } from "@/lib/seo";
|
||||
|
||||
const HEAD_MESSAGES = MESSAGES[DEFAULT_LOCALE];
|
||||
|
||||
/** meta() ของ route ลูกอ่าน origin ที่ root loader หาไว้ (ไม่ฝังโดเมน) */
|
||||
type MetaArgs = { matches?: Array<{ id?: string; data?: unknown }> };
|
||||
|
||||
export async function loader({ request }: { request: Request }) {
|
||||
return { origin: resolvePageOrigin(request) };
|
||||
}
|
||||
|
||||
export function meta({ loaderData }: { loaderData?: { origin?: string } }) {
|
||||
const origin = loaderData?.origin ?? "";
|
||||
const title = `${HEAD_MESSAGES.about.title} — AlterFlixHub`;
|
||||
const description = HEAD_MESSAGES.about.lead;
|
||||
return [
|
||||
...pageMeta({ origin, title, description, path: "/about" }),
|
||||
...breadcrumbJsonLd(origin, [
|
||||
{ name: "หน้าแรก", path: "/" },
|
||||
{ name: HEAD_MESSAGES.about.title, path: "/about" },
|
||||
]),
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* หนึ่งบล็อกของเนื้อหา — ค่อย ๆ โผล่เมื่อเลื่อนมาถึง
|
||||
* ใช้ hook บน <article> ตรง ๆ (ไม่ห่อ div) เพื่อให้ break-inside-avoid ของ
|
||||
* คอลัมน์ (lg:columns-2) ยังทำงานถูกต้อง
|
||||
*/
|
||||
function AboutBlock({
|
||||
section,
|
||||
index,
|
||||
}: {
|
||||
section: { heading: string; body: string };
|
||||
index: number;
|
||||
}) {
|
||||
const { ref, revealed, style } = useReveal<HTMLElement>((index % 2) * 80);
|
||||
|
||||
return (
|
||||
<article
|
||||
ref={ref}
|
||||
data-reveal="rise"
|
||||
data-revealed={revealed ? "" : undefined}
|
||||
style={{ ...style, border: `1px solid ${COLORS.border}` }}
|
||||
className="mb-8 flex break-inside-avoid flex-col gap-5 rounded-xl bg-[#1B1B1B]/70 p-7 backdrop-blur-sm transition-colors duration-300 hover:bg-[#1B1B1B] md:p-8"
|
||||
>
|
||||
<div className="flex items-center gap-3">
|
||||
<span
|
||||
className="flex size-12 shrink-0 items-center justify-center rounded-full text-sm font-semibold text-[#D47272]"
|
||||
style={{
|
||||
background: "rgba(143,8,8,0.16)",
|
||||
border: "1px solid rgba(169,38,38,0.45)",
|
||||
}}
|
||||
aria-hidden="true"
|
||||
>
|
||||
{String(index + 1).padStart(2, "0")}
|
||||
</span>
|
||||
<h2 className="text-2xl font-semibold leading-[1.3]">
|
||||
{section.heading}
|
||||
</h2>
|
||||
</div>
|
||||
<p className="font-content text-[17px] leading-[1.95] text-[#C7C7C7] md:text-[18px]">
|
||||
{section.body}
|
||||
</p>
|
||||
</article>
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* หน้า "เกี่ยวกับเรา" — เนื้อหามาจากหลังบ้าน (data/content) แยกตามภาษา
|
||||
* ภาษาภาพเดียวกับหน้าแรก/หน้ารายละเอียด: กรอบ 1440 + px-[108px], การ์ดขอบโทน #332B2B,
|
||||
* chip แดง, ตัวเลขในวงกลมไล่แสง (glowSoft) และไอคอนโซเชียลชุดเดียวกับ footer
|
||||
*/
|
||||
export default function AboutRoute() {
|
||||
const { messages, locale } = useI18n();
|
||||
const { site, about } = useContent();
|
||||
const content = about[locale];
|
||||
|
||||
return (
|
||||
<SiteShell variant="detail">
|
||||
<main className="relative z-10 mx-auto flex w-full max-w-[1440px] flex-col gap-10 px-5 pb-16 pt-4 md:px-[108px] md:pt-6">
|
||||
<Reveal kind="fade">
|
||||
<Link
|
||||
to="/"
|
||||
className="inline-flex w-fit items-center gap-2 text-xl font-medium transition hover:text-[#D47272]"
|
||||
>
|
||||
<IconArrowBackUp size={24} />
|
||||
{messages.nav.home}
|
||||
</Link>
|
||||
</Reveal>
|
||||
|
||||
<Reveal delay={40} className="flex flex-col gap-4">
|
||||
<h1 className="text-[32px] font-bold leading-[1.3] md:text-[40px]">
|
||||
{content.title}
|
||||
</h1>
|
||||
<p className="font-content max-w-[860px] text-[19px] leading-[1.8] text-[#C4C4C4] md:text-[21px]">
|
||||
{content.lead}
|
||||
</p>
|
||||
</Reveal>
|
||||
|
||||
<section className="gap-6 lg:columns-2">
|
||||
{content.sections.map((section, index) => (
|
||||
<AboutBlock
|
||||
key={`${section.heading}-${index}`}
|
||||
section={section}
|
||||
index={index}
|
||||
/>
|
||||
))}
|
||||
</section>
|
||||
|
||||
<Reveal kind="fade">
|
||||
<section
|
||||
className="flex flex-col gap-6 rounded-xl p-6 backdrop-blur-sm lg:flex-row lg:items-center lg:justify-between"
|
||||
style={{
|
||||
border: "1px solid rgba(169,38,38,0.45)",
|
||||
background:
|
||||
"linear-gradient(180deg, rgba(143,8,8,0.18) 0%, rgba(27,27,27,0.85) 65%, rgba(13,13,13,0.7) 100%)",
|
||||
}}
|
||||
>
|
||||
<div className="flex flex-col gap-3">
|
||||
<h2 className="text-2xl font-semibold leading-[1.3]">
|
||||
{content.contactHeading}
|
||||
</h2>
|
||||
<p className="font-content max-w-[720px] text-[16px] leading-[1.9] text-[#C4C4C4] md:text-[17px]">
|
||||
{content.contactNote}
|
||||
</p>
|
||||
</div>
|
||||
|
||||
{site.footer.length > 0 ? (
|
||||
<div className="flex flex-wrap items-center gap-2">
|
||||
{site.footer.map((item) => {
|
||||
const Icon = footerIcon(item.icon_name);
|
||||
return (
|
||||
<a
|
||||
key={item.id}
|
||||
href={item.href}
|
||||
aria-label={item.label}
|
||||
title={item.label}
|
||||
target="_blank"
|
||||
rel="noreferrer"
|
||||
className="flex size-11 items-center justify-center rounded-full bg-white/90 text-[#0D0D0D] transition hover:bg-white"
|
||||
>
|
||||
<Icon size={20} />
|
||||
</a>
|
||||
);
|
||||
})}
|
||||
</div>
|
||||
) : null}
|
||||
</section>
|
||||
</Reveal>
|
||||
</main>
|
||||
</SiteShell>
|
||||
);
|
||||
}
|
||||
File diff suppressed because it is too large.
Load diff
@@ -1,107 +0,0 @@
|
||||
import { useState } from "react";
|
||||
import { useNavigate } from "react-router";
|
||||
|
||||
import { resolvePageOrigin } from "@/lib/page-origin";
|
||||
import { originFromMatches, pageMeta } from "@/lib/seo";
|
||||
|
||||
const inputClass =
|
||||
"w-full rounded-lg border border-[#303030] bg-[#141414] px-3 py-2 text-sm text-white outline-none focus:border-[#A92626]";
|
||||
|
||||
/** meta() ของ route ลูกอ่าน origin ที่ root loader หาไว้ (ไม่ฝังโดเมน) */
|
||||
type MetaArgs = { matches?: Array<{ id?: string; data?: unknown }> };
|
||||
|
||||
/** หน้าล็อกอินหลังบ้าน — ไม่ให้ search engine เก็บ */
|
||||
export async function loader({ request }: { request: Request }) {
|
||||
return { origin: resolvePageOrigin(request) };
|
||||
}
|
||||
|
||||
export function meta({ loaderData }: { loaderData?: { origin?: string } }) {
|
||||
return pageMeta({
|
||||
origin: loaderData?.origin ?? "",
|
||||
title: "เข้าสู่ระบบหลังบ้าน — AlterFlixHub",
|
||||
description: "หน้าสำหรับผู้ดูแลเว็บไซต์เท่านั้น",
|
||||
path: "/admin/login",
|
||||
noIndex: true,
|
||||
});
|
||||
}
|
||||
|
||||
export default function AdminLoginRoute() {
|
||||
const navigate = useNavigate();
|
||||
const [username, setUsername] = useState("");
|
||||
const [password, setPassword] = useState("");
|
||||
const [error, setError] = useState<string | null>(null);
|
||||
const [busy, setBusy] = useState(false);
|
||||
|
||||
async function submit(event: React.FormEvent) {
|
||||
event.preventDefault();
|
||||
setBusy(true);
|
||||
setError(null);
|
||||
try {
|
||||
const response = await fetch("/api/admin/login", {
|
||||
method: "POST",
|
||||
headers: { "Content-Type": "application/json" },
|
||||
body: JSON.stringify({ username, password }),
|
||||
});
|
||||
if (!response.ok) {
|
||||
const payload = (await response.json().catch(() => ({}))) as {
|
||||
statusMessage?: string;
|
||||
message?: string;
|
||||
};
|
||||
setError(payload.statusMessage ?? payload.message ?? "เข้าสู่ระบบไม่สำเร็จ");
|
||||
return;
|
||||
}
|
||||
navigate("/admin");
|
||||
} catch {
|
||||
setError("เชื่อมต่อเซิร์ฟเวอร์ไม่ได้");
|
||||
} finally {
|
||||
setBusy(false);
|
||||
}
|
||||
}
|
||||
|
||||
return (
|
||||
<div className="flex min-h-dvh items-center justify-center bg-[#0D0D0D] px-5 text-white">
|
||||
<form
|
||||
onSubmit={submit}
|
||||
className="w-full max-w-sm rounded-2xl border border-[#303030] bg-[#141414] p-6"
|
||||
>
|
||||
<h1 className="text-2xl font-semibold">เข้าสู่ระบบหลังบ้าน</h1>
|
||||
<p className="mt-1 text-sm text-[#999]">AlterFlixHub · เฉพาะผู้ดูแล</p>
|
||||
|
||||
<label className="mt-6 block text-sm text-[#B3B3B3]">
|
||||
ชื่อผู้ใช้
|
||||
<input
|
||||
value={username}
|
||||
onChange={(event) => setUsername(event.target.value)}
|
||||
autoComplete="username"
|
||||
className={`mt-1 ${inputClass}`}
|
||||
/>
|
||||
</label>
|
||||
|
||||
<label className="mt-4 block text-sm text-[#B3B3B3]">
|
||||
รหัสผ่าน
|
||||
<input
|
||||
type="password"
|
||||
value={password}
|
||||
onChange={(event) => setPassword(event.target.value)}
|
||||
autoComplete="current-password"
|
||||
className={`mt-1 ${inputClass}`}
|
||||
/>
|
||||
</label>
|
||||
|
||||
{error ? (
|
||||
<p role="alert" className="mt-4 text-sm text-[#D47272]">
|
||||
{error}
|
||||
</p>
|
||||
) : null}
|
||||
|
||||
<button
|
||||
type="submit"
|
||||
disabled={busy}
|
||||
className="mt-6 h-10 w-full rounded-lg bg-[#8F0808] text-sm font-medium transition hover:bg-[#a30a0a] disabled:opacity-60"
|
||||
>
|
||||
{busy ? "กำลังเข้าสู่ระบบ…" : "เข้าสู่ระบบ"}
|
||||
</button>
|
||||
</form>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
@@ -1,18 +0,0 @@
|
||||
import { redirect } from "react-router";
|
||||
|
||||
/**
|
||||
* ลิงก์ย่อสำหรับแชร์: `/c/<slug>`
|
||||
*
|
||||
* ตั้งใจให้ redirect (302) ไปหน้าโรงหนังเต็ม `/cinema/<slug>` แทนการเรนเดอร์ซ้ำ
|
||||
* เพื่อไม่ให้มีเนื้อหาสอง URL ในสายตา search engine และไม่ต้องดูแลโค้ดหน้าซ้ำ
|
||||
* (อ่านสั้น ๆ ในแชท/LINE ได้ แต่ปลายทางคือหน้าเต็มปกติ)
|
||||
*/
|
||||
export function loader({ params }: { params: { slug?: string } }) {
|
||||
if (!params.slug) throw redirect("/");
|
||||
throw redirect(`/cinema/${params.slug}`);
|
||||
}
|
||||
|
||||
/** ไม่มีอะไรต้องเรนเดอร์ — loader เปลี่ยนเส้นทางก่อนถึงขั้นนี้เสมอ */
|
||||
export default function ShortCinemaLinkRoute() {
|
||||
return null;
|
||||
}
|
||||
@@ -1,214 +0,0 @@
|
||||
import { IconArrowBackUp } from "@tabler/icons-react";
|
||||
import { useEffect } from "react";
|
||||
import { Link, useParams } from "react-router";
|
||||
|
||||
import { CinemaNotFound } from "@/components/cinema/CinemaNotFound";
|
||||
import { CinemaSummary } from "@/components/cinema/CinemaSummary";
|
||||
import { ContactPanel } from "@/components/cinema/ContactPanel";
|
||||
import { FacilitiesSection } from "@/components/cinema/FacilitiesSection";
|
||||
import { Gallery } from "@/components/cinema/Gallery";
|
||||
import { TransportList } from "@/components/cinema/TransportList";
|
||||
import { CinemaGrid } from "@/components/site/CinemaGrid";
|
||||
import { Reveal } from "@/components/site/Reveal";
|
||||
import { ShareButton } from "@/components/site/ShareButton";
|
||||
import { SiteShell } from "@/components/site/SiteShell";
|
||||
import { useNearMe } from "@/hooks/use-near-me";
|
||||
import { trackEvent } from "@/lib/analytics-client";
|
||||
import { APP_TITLE } from "@/lib/app-config";
|
||||
import { findCinemaBySlug, cinemaName, listOtherCinemas } from "@/lib/cinemas";
|
||||
import { useContent } from "@/lib/content-context";
|
||||
import { readContent } from "@/lib/content.server";
|
||||
import { sortByDistance } from "@/lib/geo";
|
||||
import { useI18n } from "@/lib/i18n";
|
||||
import { DEFAULT_LOCALE, MESSAGES } from "@/lib/i18n/messages";
|
||||
import { resolvePageOrigin } from "@/lib/page-origin";
|
||||
import {
|
||||
breadcrumbJsonLd,
|
||||
cinemaJsonLd,
|
||||
originFromMatches,
|
||||
pageMeta,
|
||||
} from "@/lib/seo";
|
||||
|
||||
/** head (title) ไม่เปลี่ยนตามภาษา — meta() ไม่มี access ต่อ cookie */
|
||||
const HEAD_MESSAGES = MESSAGES[DEFAULT_LOCALE];
|
||||
|
||||
/** ฟิลด์ที่ต้องใช้ทำ SEO ของหน้าโรงหนัง (ส่งจาก loader เพื่อให้ crawler เห็นครบใน HTML แรก) */
|
||||
type CinemaSeo = {
|
||||
/** origin ของคำขอ (ไม่ฝังโดเมน) */
|
||||
origin: string;
|
||||
name: string | null;
|
||||
description: string | null;
|
||||
locationLabel: string | null;
|
||||
coordinates: { latitude: number; longitude: number } | null;
|
||||
mapUrl: string | null;
|
||||
photo: string | null;
|
||||
};
|
||||
|
||||
export async function loader({
|
||||
params,
|
||||
request,
|
||||
}: {
|
||||
params: { slug?: string };
|
||||
request: Request;
|
||||
}): Promise<CinemaSeo> {
|
||||
const content = await readContent();
|
||||
const cinema = findCinemaBySlug(content.cinemas, params.slug);
|
||||
if (!cinema) {
|
||||
return {
|
||||
origin: resolvePageOrigin(request),
|
||||
name: null,
|
||||
description: null,
|
||||
locationLabel: null,
|
||||
coordinates: null,
|
||||
mapUrl: null,
|
||||
photo: null,
|
||||
};
|
||||
}
|
||||
return {
|
||||
origin: resolvePageOrigin(request),
|
||||
name: cinema.name,
|
||||
description: cinema.description.trim() === "" ? null : cinema.description,
|
||||
locationLabel: cinema.location_label || null,
|
||||
coordinates: cinema.coordinates,
|
||||
mapUrl: cinema.map_url,
|
||||
photo: cinema.photos.find((photo) => photo.trim() !== "") ?? null,
|
||||
};
|
||||
}
|
||||
|
||||
export function meta({
|
||||
loaderData,
|
||||
params,
|
||||
matches,
|
||||
}: {
|
||||
loaderData?: CinemaSeo;
|
||||
params?: { slug?: string };
|
||||
matches?: Array<{ id?: string; data?: unknown }>;
|
||||
}) {
|
||||
const origin = loaderData?.origin ?? originFromMatches(matches);
|
||||
const name = loaderData?.name ?? null;
|
||||
|
||||
if (!name) {
|
||||
return pageMeta({
|
||||
origin,
|
||||
title: `${HEAD_MESSAGES.meta.cinemaNotFoundTitle} — ${APP_TITLE}`,
|
||||
description: HEAD_MESSAGES.meta.cinemaNotFoundTitle,
|
||||
path: "/",
|
||||
noIndex: true,
|
||||
});
|
||||
}
|
||||
|
||||
const path = `/cinema/${params?.slug ?? ""}`;
|
||||
const location = loaderData?.locationLabel ?? "";
|
||||
const description =
|
||||
loaderData?.description ??
|
||||
`${name}${location ? ` — ${location}` : ""} · ที่ตั้ง วิธีเดินทาง สิ่งอำนวยความสะดวก และช่องทางจองตั๋ว`;
|
||||
const title = location
|
||||
? `${name} — ${location} | AlterFlixHub`
|
||||
: `${name} — AlterFlixHub`;
|
||||
|
||||
return [
|
||||
...pageMeta({ origin, title, description, path }),
|
||||
...breadcrumbJsonLd(origin, [
|
||||
{ name: "หน้าแรก", path: "/" },
|
||||
{ name, path },
|
||||
]),
|
||||
...cinemaJsonLd({
|
||||
origin,
|
||||
name,
|
||||
description,
|
||||
path,
|
||||
image: loaderData?.photo ?? null,
|
||||
coordinates: loaderData?.coordinates ?? null,
|
||||
locationLabel: location,
|
||||
mapUrl: loaderData?.mapUrl ?? null,
|
||||
}),
|
||||
];
|
||||
}
|
||||
|
||||
export default function CinemaDetailRoute() {
|
||||
const { messages, locale } = useI18n();
|
||||
const { cinemas } = useContent();
|
||||
const { status: nearMeStatus, distances } = useNearMe();
|
||||
const { slug } = useParams();
|
||||
const cinema = findCinemaBySlug(cinemas, slug);
|
||||
|
||||
// เก็บสถิติการเปิดดูหน้ารายละเอียด (ต้องอยู่ก่อน early return เพื่อให้ hook เรียกทุกครั้ง)
|
||||
useEffect(() => {
|
||||
if (!cinema) return;
|
||||
trackEvent({ type: "cinema_view", slug: cinema.slug, locale });
|
||||
}, [cinema, locale]);
|
||||
|
||||
if (!cinema) return <CinemaNotFound />;
|
||||
|
||||
const otherCinemas = listOtherCinemas(cinemas, cinema.slug);
|
||||
const orderedOthers =
|
||||
nearMeStatus === "ready"
|
||||
? sortByDistance(otherCinemas, distances)
|
||||
: otherCinemas;
|
||||
|
||||
return (
|
||||
<SiteShell variant="detail">
|
||||
<main className="relative z-10 mx-auto flex w-full max-w-[1440px] flex-col gap-10 px-5 pb-16 pt-4 md:px-[108px] md:pt-6">
|
||||
<Reveal kind="fade">
|
||||
<Link
|
||||
to="/"
|
||||
className="inline-flex w-fit items-center gap-2 text-xl font-medium transition hover:text-[#D47272]"
|
||||
>
|
||||
<IconArrowBackUp size={24} />
|
||||
{messages.detail.back}
|
||||
</Link>
|
||||
</Reveal>
|
||||
|
||||
<Reveal kind="zoom">
|
||||
<Gallery photos={cinema.photos} cinemaName={cinema.name} />
|
||||
</Reveal>
|
||||
|
||||
<section className="grid gap-10 lg:grid-cols-[minmax(0,749px)_minmax(0,384px)] lg:justify-between">
|
||||
<div className="flex flex-col gap-12">
|
||||
<Reveal delay={60}>
|
||||
<CinemaSummary cinema={cinema} />
|
||||
</Reveal>
|
||||
<Reveal delay={120}>
|
||||
<TransportList transport={cinema.transport} />
|
||||
</Reveal>
|
||||
</div>
|
||||
<Reveal delay={160}>
|
||||
<ContactPanel cinema={cinema} />
|
||||
</Reveal>
|
||||
</section>
|
||||
|
||||
<Reveal>
|
||||
<FacilitiesSection cinema={cinema} />
|
||||
</Reveal>
|
||||
|
||||
<section className="flex flex-col gap-8">
|
||||
<Reveal className="w-full">
|
||||
<h2 className="text-2xl font-semibold leading-[1.3]">
|
||||
{messages.detail.otherCinemas}
|
||||
</h2>
|
||||
</Reveal>
|
||||
<CinemaGrid cinemas={orderedOthers} source="other_cinemas" />
|
||||
</section>
|
||||
|
||||
{/* แชร์หน้ารายละเอียดโรงนี้ (ท้ายหน้า) */}
|
||||
<Reveal kind="fade">
|
||||
<section className="flex flex-wrap items-center justify-between gap-4 rounded-xl border border-[#332B2B] bg-[#1B1B1B]/70 p-5 backdrop-blur-sm">
|
||||
<div className="flex flex-col gap-1">
|
||||
<h2 className="text-lg font-semibold leading-[1.3]">
|
||||
{messages.share.pageLabel}
|
||||
</h2>
|
||||
<p className="text-sm text-[#B3B3B3]">
|
||||
{cinemaName(cinema, locale)}
|
||||
</p>
|
||||
</div>
|
||||
<ShareButton
|
||||
variant="wide"
|
||||
slug={cinema.slug}
|
||||
title={cinemaName(cinema, locale)}
|
||||
/>
|
||||
</section>
|
||||
</Reveal>
|
||||
</main>
|
||||
</SiteShell>
|
||||
);
|
||||
}
|
||||
@@ -1,56 +0,0 @@
|
||||
import { ArticlePage } from "@/components/site/ArticlePage";
|
||||
import { APP_TITLE } from "@/lib/app-config";
|
||||
import { useContent } from "@/lib/content-context";
|
||||
import { useI18n } from "@/lib/i18n";
|
||||
import { DEFAULT_LOCALE, MESSAGES } from "@/lib/i18n/messages";
|
||||
import { resolvePageOrigin } from "@/lib/page-origin";
|
||||
import {
|
||||
articleJsonLd,
|
||||
breadcrumbJsonLd,
|
||||
originFromMatches,
|
||||
pageMeta,
|
||||
} from "@/lib/seo";
|
||||
|
||||
const HEAD_MESSAGES = MESSAGES[DEFAULT_LOCALE];
|
||||
|
||||
/** meta() ของ route ลูกอ่าน origin ที่ root loader หาไว้ (ไม่ฝังโดเมน) */
|
||||
type MetaArgs = { matches?: Array<{ id?: string; data?: unknown }> };
|
||||
|
||||
export async function loader({ request }: { request: Request }) {
|
||||
return { origin: resolvePageOrigin(request) };
|
||||
}
|
||||
|
||||
export function meta({ loaderData }: { loaderData?: { origin?: string } }) {
|
||||
const origin = loaderData?.origin ?? "";
|
||||
const title = `${HEAD_MESSAGES.forCinemas.title} — AlterFlixHub`;
|
||||
const description = HEAD_MESSAGES.forCinemas.lead;
|
||||
return [
|
||||
...pageMeta({
|
||||
origin,
|
||||
title,
|
||||
description,
|
||||
path: "/for-cinemas",
|
||||
type: "article",
|
||||
}),
|
||||
...breadcrumbJsonLd(origin, [
|
||||
{ name: "หน้าแรก", path: "/" },
|
||||
{ name: HEAD_MESSAGES.forCinemas.title, path: "/for-cinemas" },
|
||||
]),
|
||||
...articleJsonLd({
|
||||
origin,
|
||||
headline: HEAD_MESSAGES.forCinemas.title,
|
||||
description,
|
||||
path: "/for-cinemas",
|
||||
}),
|
||||
];
|
||||
}
|
||||
|
||||
/** หน้า "สำหรับคนทำโรงหนัง" — บทความแบบบล็อกที่แก้ได้จากหลังบ้าน (`forCinemas`) */
|
||||
export default function ForCinemasRoute() {
|
||||
const { messages, locale } = useI18n();
|
||||
const { forCinemas } = useContent();
|
||||
|
||||
return (
|
||||
<ArticlePage content={forCinemas[locale]} backLabel={messages.nav.home} />
|
||||
);
|
||||
}
|
||||
@@ -1,59 +0,0 @@
|
||||
import { ArticlePage } from "@/components/site/ArticlePage";
|
||||
import { APP_TITLE } from "@/lib/app-config";
|
||||
import { useContent } from "@/lib/content-context";
|
||||
import { useI18n } from "@/lib/i18n";
|
||||
import { DEFAULT_LOCALE, MESSAGES } from "@/lib/i18n/messages";
|
||||
import { resolvePageOrigin } from "@/lib/page-origin";
|
||||
import {
|
||||
articleJsonLd,
|
||||
breadcrumbJsonLd,
|
||||
originFromMatches,
|
||||
pageMeta,
|
||||
} from "@/lib/seo";
|
||||
|
||||
const HEAD_MESSAGES = MESSAGES[DEFAULT_LOCALE];
|
||||
|
||||
/** meta() ของ route ลูกอ่าน origin ที่ root loader หาไว้ (ไม่ฝังโดเมน) */
|
||||
type MetaArgs = { matches?: Array<{ id?: string; data?: unknown }> };
|
||||
|
||||
export async function loader({ request }: { request: Request }) {
|
||||
return { origin: resolvePageOrigin(request) };
|
||||
}
|
||||
|
||||
export function meta({ loaderData }: { loaderData?: { origin?: string } }) {
|
||||
const origin = loaderData?.origin ?? "";
|
||||
const title = `${HEAD_MESSAGES.forFilmLovers.title} — AlterFlixHub`;
|
||||
const description = HEAD_MESSAGES.forFilmLovers.lead;
|
||||
return [
|
||||
...pageMeta({
|
||||
origin,
|
||||
title,
|
||||
description,
|
||||
path: "/for-film-lovers",
|
||||
type: "article",
|
||||
}),
|
||||
...breadcrumbJsonLd(origin, [
|
||||
{ name: "หน้าแรก", path: "/" },
|
||||
{ name: HEAD_MESSAGES.forFilmLovers.title, path: "/for-film-lovers" },
|
||||
]),
|
||||
...articleJsonLd({
|
||||
origin,
|
||||
headline: HEAD_MESSAGES.forFilmLovers.title,
|
||||
description,
|
||||
path: "/for-film-lovers",
|
||||
}),
|
||||
];
|
||||
}
|
||||
|
||||
/** หน้า "สำหรับคนรักหนัง" — บทความแบบบล็อกที่แก้ได้จากหลังบ้าน (`forFilmLovers`) */
|
||||
export default function ForFilmLoversRoute() {
|
||||
const { messages, locale } = useI18n();
|
||||
const { forFilmLovers } = useContent();
|
||||
|
||||
return (
|
||||
<ArticlePage
|
||||
content={forFilmLovers[locale]}
|
||||
backLabel={messages.nav.home}
|
||||
/>
|
||||
);
|
||||
}
|
||||
Reference in new issue
Block a user