feat: บทความ 2 หน้า + แชร์/ลิงก์ย่อ + PWA + แอนิเมชัน + SEO/AI + เอกสาร
- บทความจากหลังบ้าน: /for-film-lovers, /for-cinemas (ArticlePage + ArticleEditor แบบบล็อกย่อหน้า/รูป) - แชร์: ปุ่มบนการ์ดและท้ายหน้ารายละเอียด · ลิงก์ย่อ /c/<slug> (302) · ธีมแก้วตาม DESIGN.md - PWA: manifest/sw/offline + ถอดการล็อกซูม (WCAG 1.4.4) + touch target ≥44px - แอนิเมชัน reveal: IntersectionObserver + gate ด้วย html.fx-motion · เคารพ prefers-reduced-motion - ค้นหา: normalize/ตัดวรรณยุกต์ + AND หลายคำ + จัดอันดับ · รองรับ /?q= จาก SearchAction - SEO: pageMeta (canonical/OG/Twitter) + JSON-LD (WebSite/Organization/BreadcrumbList/MovieTheater/Article) - ไม่ฝังโดเมนในโค้ด: origin มาจาก request (x-forwarded-host/proto) ทั้ง canonical, sitemap, robots, ลิงก์แชร์ - กัน AI: robots.txt (Nitro route, บล็อก AI 21 ตัว) + ai.txt + OG image 1200x630 - เอกสาร: README สรุปโปรเจกต์, DESIGN.md (motion/PWA/SEO/ข้อมูล), architecture.html, admin-guide - tests: 135 ผ่าน (16 ไฟล์)
This commit is contained in:
1 parent
1e84023a44
commit
319c271d23
72 files changed
+4731
-765
No files matched your search
+78
-24
@@ -1,27 +1,51 @@
|
||||
import { useEffect, useMemo, useState } from "react";
|
||||
import { useLoaderData } from "react-router";
|
||||
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 { filterCinemas, CINEMA_CATEGORIES, DEFAULT_CATEGORY, publiclyVisible, type Cinema, type CinemaCategory } from "@/lib/cinemas";
|
||||
import { dailyOrder, dayKey } from "@/lib/daily-order";
|
||||
import { computePopularity } from "@/lib/popularity.server";
|
||||
import {
|
||||
CINEMA_CATEGORIES,
|
||||
DEFAULT_CATEGORY,
|
||||
publiclyVisible,
|
||||
type Cinema,
|
||||
type CinemaCategory,
|
||||
} 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];
|
||||
|
||||
export function meta() {
|
||||
/** 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 [
|
||||
{ title: APP_TITLE },
|
||||
{ name: "description", content: HEAD_MESSAGES.meta.homeDescription },
|
||||
...pageMeta({
|
||||
origin,
|
||||
title: SITE.title,
|
||||
description: HEAD_MESSAGES.meta.homeDescription,
|
||||
path: "/",
|
||||
}),
|
||||
...websiteJsonLd(origin),
|
||||
];
|
||||
}
|
||||
|
||||
@@ -29,8 +53,12 @@ export function meta() {
|
||||
const INITIAL_VISIBLE = 4;
|
||||
|
||||
/** อันดับยอดนิยม + คีย์วันที่สำหรับสลับลำดับการ์ด (memo 5 นาที) — ส่งมากับ loader */
|
||||
export async function loader() {
|
||||
return { popularity: await computePopularity(), orderKey: dayKey() };
|
||||
export async function loader({ request }: { request: Request }) {
|
||||
return {
|
||||
popularity: await computePopularity(),
|
||||
orderKey: dayKey(),
|
||||
origin: resolvePageOrigin(request),
|
||||
};
|
||||
}
|
||||
|
||||
export default function HomeRoute() {
|
||||
@@ -39,22 +67,31 @@ export default function HomeRoute() {
|
||||
const { cinemas } = useContent();
|
||||
const { status: nearMeStatus, distances, requestLocation } = useNearMe();
|
||||
const [category, setCategory] = useState<CinemaCategory>(DEFAULT_CATEGORY);
|
||||
const [query, setQuery] = useState("");
|
||||
// รองรับลิงก์ค้นหาตรง ๆ (/?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 base = dailyOrder(
|
||||
publiclyVisible(cinemas),
|
||||
(cinema) => cinema.slug,
|
||||
orderKey,
|
||||
);
|
||||
const byStats =
|
||||
category === "ยอดนิยม" && popularity.ready && query.trim() === "";
|
||||
if (!byStats) return filterCinemas(base, { category, query });
|
||||
if (!byStats)
|
||||
return filterCinemas(base, { category, query, 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, popularity, orderKey]);
|
||||
}, [cinemas, category, query, popularity, orderKey, messages.tags]);
|
||||
// เรียงจากใกล้สุดไปไกลสุดเมื่อทราบตำแหน่งแล้ว (ไม่กรองตามรัศมี — ไกลแค่ไหนก็ยังแสดง)
|
||||
const ordered =
|
||||
nearMeStatus === "ready" ? sortByDistance(matched, distances) : matched;
|
||||
@@ -78,6 +115,14 @@ export default function HomeRoute() {
|
||||
return () => clearTimeout(timer);
|
||||
}, [keyword, category, matched.length, locale]);
|
||||
|
||||
/**
|
||||
* ปุ่ม "ค้นหา" / Enter — ผลลัพธ์ถูกกรองสดอยู่แล้วขณะพิมพ์
|
||||
* จึงทำหน้าที่แค่พาผู้ใช้ไปดูผล (ปิดคีย์บอร์ดมือถือทำที่ HeroSection)
|
||||
*/
|
||||
function handleSubmitSearch() {
|
||||
scrollIntoViewRespectMotion(resultsRef.current);
|
||||
}
|
||||
|
||||
function handleRequestLocation() {
|
||||
requestLocation();
|
||||
trackEvent({
|
||||
@@ -97,20 +142,29 @@ export default function HomeRoute() {
|
||||
onQueryChange={setQuery}
|
||||
nearMeStatus={nearMeStatus}
|
||||
onRequestLocation={handleRequestLocation}
|
||||
onSubmitSearch={handleSubmitSearch}
|
||||
/>
|
||||
|
||||
<section className="mt-16 flex flex-col gap-6 md:mt-[65px]">
|
||||
<div className="flex min-h-[72px] items-center border-b border-[#1F1F1F] py-2">
|
||||
<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>
|
||||
</div>
|
||||
</Reveal>
|
||||
|
||||
<CategoryFilter
|
||||
active={category}
|
||||
categories={CINEMA_CATEGORIES}
|
||||
onChange={setCategory}
|
||||
/>
|
||||
<Reveal delay={340}>
|
||||
<CategoryFilter
|
||||
active={category}
|
||||
categories={CINEMA_CATEGORIES}
|
||||
onChange={setCategory}
|
||||
/>
|
||||
</Reveal>
|
||||
|
||||
{visibleCinemas.length === 0 ? (
|
||||
<p className="py-16 text-center text-sm text-[#B3B3B3]">
|
||||
@@ -127,7 +181,7 @@ export default function HomeRoute() {
|
||||
)}
|
||||
|
||||
{hasMore ? (
|
||||
<div className="flex justify-center pt-2">
|
||||
<Reveal kind="fade" className="flex justify-center pt-2">
|
||||
<button
|
||||
type="button"
|
||||
onClick={() => setShowAll(true)}
|
||||
@@ -135,7 +189,7 @@ export default function HomeRoute() {
|
||||
>
|
||||
{messages.list.showMore}
|
||||
</button>
|
||||
</div>
|
||||
</Reveal>
|
||||
) : null}
|
||||
</section>
|
||||
</main>
|
||||
|
||||
+119
-73
@@ -1,23 +1,84 @@
|
||||
import { IconArrowBackUp } from "@tabler/icons-react";
|
||||
import { Link } from "react-router";
|
||||
|
||||
import { SiteShell } from "@/components/site/SiteShell";
|
||||
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];
|
||||
|
||||
export function meta() {
|
||||
/** 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 [
|
||||
{ title: `${HEAD_MESSAGES.about.title} — ${APP_TITLE}` },
|
||||
{ name: "description", content: HEAD_MESSAGES.about.lead },
|
||||
...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,
|
||||
@@ -31,90 +92,75 @@ export default function AboutRoute() {
|
||||
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">
|
||||
<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 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>
|
||||
|
||||
<header className="flex flex-col gap-4">
|
||||
<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>
|
||||
</header>
|
||||
</Reveal>
|
||||
|
||||
<section className="gap-6 lg:columns-2">
|
||||
{content.sections.map((section, index) => (
|
||||
<article
|
||||
<AboutBlock
|
||||
key={`${section.heading}-${index}`}
|
||||
className="mb-8 flex break-inside-avoid flex-col gap-5 rounded-xl bg-[#1B1B1B]/70 p-7 backdrop-blur-sm transition hover:bg-[#1B1B1B] md:p-8"
|
||||
style={{ border: `1px solid ${COLORS.border}` }}
|
||||
>
|
||||
<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>
|
||||
section={section}
|
||||
index={index}
|
||||
/>
|
||||
))}
|
||||
</section>
|
||||
|
||||
<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>
|
||||
);
|
||||
})}
|
||||
<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>
|
||||
) : null}
|
||||
</section>
|
||||
|
||||
{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>
|
||||
);
|
||||
|
||||
+498
-391
File diff suppressed because it is too large.
Load diff
@@ -1,9 +1,30 @@
|
||||
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("");
|
||||
|
||||
@@ -0,0 +1,18 @@
|
||||
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;
|
||||
}
|
||||
+146
-29
@@ -1,5 +1,5 @@
|
||||
import { useEffect } from "react";
|
||||
import { IconArrowBackUp } from "@tabler/icons-react";
|
||||
import { useEffect } from "react";
|
||||
import { Link, useParams } from "react-router";
|
||||
|
||||
import { CinemaNotFound } from "@/components/cinema/CinemaNotFound";
|
||||
@@ -9,35 +9,119 @@ 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 { APP_TITLE } from "@/lib/app-config";
|
||||
import { findCinemaBySlug, listOtherCinemas } from "@/lib/cinemas";
|
||||
import { readContent } from "@/lib/content.server";
|
||||
import { useContent } from "@/lib/content-context";
|
||||
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];
|
||||
|
||||
/** อ่านชื่อโรงหนังฝั่งเซิร์ฟเวอร์ เพื่อให้ <title> ถูกตั้งแต่ HTML แรก */
|
||||
export async function loader({ params }: { params: { slug?: string } }) {
|
||||
/** ฟิลด์ที่ต้องใช้ทำ 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);
|
||||
return { name: cinema ? cinema.name : null };
|
||||
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 }: { loaderData?: { name?: string | 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 [
|
||||
{
|
||||
title: name
|
||||
? `${name} — ${APP_TITLE}`
|
||||
: `${HEAD_MESSAGES.meta.cinemaNotFoundTitle} — ${APP_TITLE}`,
|
||||
},
|
||||
...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,
|
||||
}),
|
||||
];
|
||||
}
|
||||
|
||||
@@ -65,32 +149,65 @@ export default function CinemaDetailRoute() {
|
||||
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">
|
||||
<Link
|
||||
to="/"
|
||||
className="inline-flex w-fit items-center gap-2 text-xl font-medium"
|
||||
>
|
||||
<IconArrowBackUp size={24} />
|
||||
{messages.detail.back}
|
||||
</Link>
|
||||
<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>
|
||||
|
||||
<Gallery photos={cinema.photos} cinemaName={cinema.name} />
|
||||
<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">
|
||||
<CinemaSummary cinema={cinema} />
|
||||
<TransportList transport={cinema.transport} />
|
||||
<Reveal delay={60}>
|
||||
<CinemaSummary cinema={cinema} />
|
||||
</Reveal>
|
||||
<Reveal delay={120}>
|
||||
<TransportList transport={cinema.transport} />
|
||||
</Reveal>
|
||||
</div>
|
||||
<ContactPanel cinema={cinema} />
|
||||
<Reveal delay={160}>
|
||||
<ContactPanel cinema={cinema} />
|
||||
</Reveal>
|
||||
</section>
|
||||
|
||||
<FacilitiesSection cinema={cinema} />
|
||||
<Reveal>
|
||||
<FacilitiesSection cinema={cinema} />
|
||||
</Reveal>
|
||||
|
||||
<section className="flex flex-col gap-8">
|
||||
<h2 className="text-2xl font-semibold leading-[1.3]">
|
||||
{messages.detail.otherCinemas}
|
||||
</h2>
|
||||
<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>
|
||||
);
|
||||
|
||||
@@ -0,0 +1,56 @@
|
||||
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} />
|
||||
);
|
||||
}
|
||||
@@ -0,0 +1,59 @@
|
||||
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