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>
|
||||
|
||||
Reference in new issue
Block a user