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:
Bkk1234 committed 2026-11-10 02:31:10 +07:00
1 parent 1e84023a44
commit 319c271d23
72 files changed
+4731 -765

No files matched your search

+131 -32
View File
@@ -1,6 +1,14 @@
import { useI18n } from "@/lib/i18n";
import { LOCALE_OPTIONS } from "@/lib/i18n/messages";
import { IconCheck, IconChevronDown } from "@tabler/icons-react";
import {
useEffect,
useRef,
useState,
type KeyboardEvent as ReactKeyboardEvent,
} from "react";
import { COLORS } from "@/lib/design-tokens";
import { useI18n } from "@/lib/i18n";
import { LOCALE_OPTIONS, type Locale } from "@/lib/i18n/messages";
/** ธงชาติไทยย่อส่วน */
function FlagTh() {
@@ -47,40 +55,131 @@ function FlagEn() {
const FLAGS = { th: FlagTh, en: FlagEn } as const;
/**
* สลับภาษาเป็นปุ่มสองปุ่ม (TH / EN) — ไม่มีเมนูให้เปิด/ปิด
* จึงไม่มีปัญหาคลิกพลาดหรือเมนูถูกบัง และกดครั้งเดียวเปลี่ยนทันที
* สลับภาษาเป็น "ปุ่มเดียว + dropdown"
*
* - ปุ่มแสดงภาษาปัจจุบัน (ธง + รหัส) พร้อมลูกศรบอกว่ามีกั้นลงมา
* - เลือกแล้วเปลี่ยนภาษาทันทีและปิดเมนู คืนโฟกัสกลับไปที่ปุ่ม
* - ปิดได้ด้วยคลิกนอกเมนู หรือกด Escape
* (เดิมเป็นปุ่ม TH/EN สองปุ่ม — ยุบเหลือปุ่มเดียวเพื่อประหยัดที่ใน header มือถือ)
*/
export function LocaleSwitcher() {
const { locale, setLocale } = useI18n();
const { locale, setLocale, messages } = useI18n();
const [open, setOpen] = useState(false);
const wrapperRef = useRef<HTMLDivElement>(null);
const triggerRef = useRef<HTMLButtonElement>(null);
// ปิดเมนูเมื่อคลิกที่อื่น หรือกด Escape
useEffect(() => {
if (!open) return;
// ให้คีย์บอร์ดเริ่มที่ตัวเลือกปัจจุบัน (มาตรฐานของ role="menu")
wrapperRef.current
?.querySelector<HTMLButtonElement>(
'[role="menuitemradio"][aria-checked="true"]',
)
?.focus();
function handlePointerDown(event: MouseEvent) {
if (!wrapperRef.current?.contains(event.target as Node)) setOpen(false);
}
function handleKeyDown(event: KeyboardEvent) {
if (event.key !== "Escape") return;
setOpen(false);
triggerRef.current?.focus();
}
document.addEventListener("mousedown", handlePointerDown);
document.addEventListener("keydown", handleKeyDown);
return () => {
document.removeEventListener("mousedown", handlePointerDown);
document.removeEventListener("keydown", handleKeyDown);
};
}, [open]);
const current =
LOCALE_OPTIONS.find((option) => option.locale === locale) ??
LOCALE_OPTIONS[0];
const CurrentFlag = FLAGS[current.locale];
/** เลื่อนโฟกัสด้วยลูกศรขึ้น/ลงในเมนู (role="menu" ต้องรองรับคีย์บอร์ด) */
function handleMenuKeyDown(event: ReactKeyboardEvent<HTMLDivElement>) {
if (event.key !== "ArrowDown" && event.key !== "ArrowUp") return;
event.preventDefault();
const items = Array.from(
wrapperRef.current?.querySelectorAll<HTMLButtonElement>(
'[role="menuitemradio"]',
) ?? [],
);
if (items.length === 0) return;
const currentIndex = items.indexOf(
document.activeElement as HTMLButtonElement,
);
const step = event.key === "ArrowDown" ? 1 : -1;
const nextIndex = (currentIndex + step + items.length) % items.length;
items[nextIndex]?.focus();
}
function choose(next: Locale) {
setLocale(next);
setOpen(false);
triggerRef.current?.focus();
}
return (
<div role="group" aria-label="ภาษา" className="flex items-center gap-1">
{LOCALE_OPTIONS.map((option) => {
const Flag = FLAGS[option.locale];
const isActive = option.locale === locale;
return (
<button
key={option.locale}
type="button"
lang={option.locale}
onClick={() => setLocale(option.locale)}
aria-pressed={isActive}
title={option.name}
className={`flex items-center gap-1.5 rounded-lg px-1.5 py-1 text-sm transition sm:gap-2 sm:px-2 ${
isActive
? "bg-[#242424] font-semibold text-[#D47272]"
: "text-[#B3B3B3] hover:text-white"
}`}
>
<span className="hidden sm:block">
<Flag />
</span>
<span className="text-base font-medium leading-none sm:text-lg">
{option.code}
</span>
</button>
);
})}
<div ref={wrapperRef} className="relative">
<button
ref={triggerRef}
type="button"
aria-haspopup="menu"
aria-expanded={open}
aria-label={`${messages.nav.language}: ${current.name}`}
title={current.name}
onClick={() => setOpen((value) => !value)}
className="flex min-h-10 items-center gap-1.5 rounded-lg px-2 text-sm text-[#B3B3B3] transition hover:text-white focus-visible:outline focus-visible:outline-2 focus-visible:outline-[#A92626] after:absolute after:-inset-y-1 after:-inset-x-0.5 after:content-[''] sm:gap-2"
>
<CurrentFlag />
<span className="font-medium leading-none">{current.code}</span>
<IconChevronDown
size={14}
aria-hidden="true"
className={`transition-transform duration-200 ${open ? "rotate-180" : ""}`}
/>
</button>
{open ? (
<div
role="menu"
aria-label={messages.nav.language}
onKeyDown={handleMenuKeyDown}
className="absolute right-0 top-[calc(100%+8px)] z-30 flex w-[190px] flex-col gap-1 rounded-xl border border-[#303030] bg-[#141414] p-2 shadow-lg"
>
{LOCALE_OPTIONS.map((option) => {
const Flag = FLAGS[option.locale];
const isActive = option.locale === locale;
return (
<button
key={option.locale}
type="button"
role="menuitemradio"
aria-checked={isActive}
lang={option.locale}
onClick={() => choose(option.locale)}
className={`flex min-h-11 items-center gap-2 rounded-lg px-2.5 text-sm transition ${
isActive
? "bg-[#242424] font-semibold text-[#D47272]"
: "text-[#B3B3B3] hover:bg-[#1B1B1B] hover:text-white"
}`}
>
<Flag />
<span className="flex-1 text-left">{option.name}</span>
{isActive ? <IconCheck size={16} aria-hidden="true" /> : null}
</button>
);
})}
</div>
) : null}
</div>
);
}