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
@@ -6,3 +6,10 @@ PING_MESSAGE=pong
|
||||
# need a stable BETTER_AUTH_SECRET; BETTER_AUTH_URL is inferred automatically.
|
||||
# BETTER_AUTH_SECRET=
|
||||
# AUTH_DISABLED=true
|
||||
|
||||
# โดเมนที่ใช้สร้างลิงก์แชร์ (ปุ่มแชร์บนการ์ด/ท้ายหน้ารายละเอียด)
|
||||
# เว้นว่าง = ใช้ origin ของหน้าเว็บที่เปิดอยู่ (สะดวกตอน dev)
|
||||
# SHARE_ORIGIN= # ไม่ต้องตั้ง — ใช้ origin ของ request (โดเมนจริงตอน deploy)
|
||||
|
||||
# โดเมนหลักของเว็บ (canonical / OG / sitemap) — เว้นว่างได้ ระบบจะใช้ SHARE_ORIGIN ต่อ
|
||||
# SITE_URL= # ไม่ต้องตั้ง — ระบบ derive จาก request (ตั้งเมื่อต้องบังคับโดเมนเท่านั้น)
|
||||
@@ -21,6 +21,7 @@ read the `multi-app-workspace` skill before touching the repo layout.
|
||||
- Normal app data must flow through actions. Keep actions deterministic and focused; use agent chat/AgentSidebar for AI work and follow-ups in the same thread. Keep structured state in SQL and large files in configured storage; persist references only.
|
||||
- For external integrations, inspect the workspace/provider connection catalog first; reuse its scoped resolver. Never hardcode credentials, webhook URLs, or private/customer data.
|
||||
- Never fabricate. Report failures and recover; verify writes by reading the row or screen. Navigation is in `<current-screen>`; use `view-screen` for fresh visible-record details.
|
||||
- PWA: ห้ามลบ `<link rel="manifest">` ใน `app/root.tsx` · ทุกครั้งที่ปล่อยเวอร์ชันให้ bump `VERSION` ใน `public/sw.js` (ขั้น activate จะลบแคชเก่าให้เอง) · ไอคอนแอปเป็น PNG (`public/icon-192|512|maskable-512|180.png`) ไม่ใช่ SVG
|
||||
|
||||
For custom branding, keep `server/plugins/agent-native-email-branding.ts` aligned: `app.name` appears in transactional email and optional `app.logoUrl` must be an absolute HTTPS URL.
|
||||
|
||||
@@ -42,6 +43,7 @@ Before building common workspace or agent UI, read `agent-native-toolkit`; for s
|
||||
- Guarded verification: run `pnpm agent-native:doctor`; fix findings before done.
|
||||
|
||||
- แผนผังการทำงาน (Frontend / Backend / Data): `docs/architecture.html` — เอกสารประกอบ เปิดด้วยเบราว์เซอร์ ไม่ถูก build เข้าแอป; อัปเดตเมื่อโครง route/API/data เปลี่ยน
|
||||
- SEO/AI: ข้อบังคับอยู่ใน `DESIGN.md` หัวข้อ "SEO และการป้องกัน AI" — `SITE_URL` คือแหล่งโดเมนเดียว, `app/lib/seo.ts` คือตัวสร้าง meta ทั้งหมด, `server/routes/sitemap.xml.ts` + `public/robots.txt` + `public/ai.txt` คือไฟล์สำหรับ crawler
|
||||
- คู่มือใช้งานหลังบ้าน (ภาษาไทย ทีละงาน): `docs/admin-guide.md` · API reference: `docs/api.md`
|
||||
- เมื่อเพิ่ม/เปลี่ยนฟิลด์ใน `Cinema`, หมวดหมู่, หรือ flow ของหลังบ้าน → อัปเดต `DESIGN.md` + `docs/architecture.html` + `docs/admin-guide.md` พร้อมกัน (ห้ามปล่อยเอกสารตกรุ่น)
|
||||
- ห้ามเขียนทับ `data/content/content.json` ด้วย seed: `readContent()` โยน error เมื่อไฟล์เสีย และสำรอง `.output/content.json.bakN` ก่อนแก้ด้วยสคริปต์
|
||||
@@ -72,6 +72,23 @@ part of that build, not leave them as an empty template.
|
||||
- ของตกแต่งพื้นหลัง (รูปฮีโร่, gradient, glow) ต้องอยู่ใน `BackdropFrame` = `absolute inset-0 overflow-hidden` เสมอ — ถ้าปล่อยเป็น absolute ลอย ๆ ที่ใช้ `top-[…px]`/`bottom` ค่าเยอะ ๆ จะยืด `scrollHeight` ให้ยาวเกินเนื้อหา ทำให้มีพื้นที่ว่างเลื่อนได้ใต้ footer
|
||||
- แสงที่ต้องอยู่ช่วงล่างของหน้าให้ยึด `bottom-*` ไม่ใช่ `top-[px]` ตายตัว เพราะความสูงหน้าเปลี่ยนตามจำนวนการ์ดที่แสดง
|
||||
|
||||
## Motion contract (บังคับ)
|
||||
|
||||
- อนิเมชันทั้งหมดอยู่ใน `app/global.css` ใต้ `html.fx-motion` — คลาสนี้ถูกใส่โดยสคริปต์ใน `<head>` (`MOTION_INIT_SCRIPT`, `app/lib/motion.ts`) **เฉพาะเมื่อผู้ใช้ไม่ได้ขอ `prefers-reduced-motion: reduce`** → ปิด JS หรือ reduced motion = ไม่มีอะไรถูกซ่อน (ห้ามเขียน `opacity:0` นอกขอบเขตนี้)
|
||||
- ใช้ `transform`/`opacity` เท่านั้น ห้าม animate `width/height/top/left` · ระยะเวลา: เร็ว 160ms · ปกติ 280ms · **เปลี่ยนหน้า 460ms (`--fx-page`)** · reveal 640ms · หน่วงต่อชิ้นไม่เกิน ~240ms
|
||||
- "ค่อย ๆ โผล่เมื่อเลื่อนถึง" ใช้ `useReveal` (`app/hooks/use-reveal.ts`) หรือ `<Reveal>` (`app/components/site/Reveal.tsx`) — มีกฎกันค้างซ่อน: บล็อกที่เลื่อนผ่านไปแล้ว (หรือถูกข้ามด้วยการกระโดด scroll) ต้องโผล่ทันที
|
||||
- hover ของการ์ดใช้ `translate` (Tailwind `hover:-translate-y-1`) ไม่ใช้ `transform` เพราะชนกับ keyframe ของ reveal · ทุกอนิเมชันต้องมีคู่มือปิดใน `@media (prefers-reduced-motion: reduce)`
|
||||
|
||||
## PWA & accessibility contract (บังคับ)
|
||||
|
||||
- **ติดตั้งได้**: `<link rel="manifest">` อยู่ใน `app/root.tsx` (ห้ามลบ) · `public/manifest.json` ต้องมี `display: standalone`, `id`, `scope`, `start_url: "/"`, `lang` และไอคอน **PNG** 192/512 + maskable 512 (Chrome ไม่รับ SVG, iOS ไม่รับ SVG) · `apple-touch-icon` ต้องชี้ `icon-180.png`
|
||||
- **ไอคอน**: ไฟล์จริงคือ `public/icon-192.png` / `icon-512.png` / `icon-maskable-512.png` / `icon-180.png` (สร้างจาก PNG 1024 ที่ฝังอยู่ใน `icon-512.svg`) — SVG เดิมเหลือไว้เป็น favicon เท่านั้น
|
||||
- **service worker**: `public/sw.js` — หน้าเว็บ network-first (ออฟไลน์ → แคชหน้า → `offline.html`), static cache-first + revalidate เบื้องหลัง, ไม่แคช `/api/*` และไม่แตะ `/app/*` `/node_modules/*` `/@*` (โมดูล dev) · ลงทะเบียนผ่าน `app/lib/pwa.ts` + `<ServiceWorkerSetup/>` ใน `root.tsx`
|
||||
- **ทุกครั้งที่ปล่อยเวอร์ชัน ให้ bump `VERSION` ใน `public/sw.js`** — `activate` จะลบแคชที่ไม่ตรงเวอร์ชัน (เคสจริง: แคช `alterflixhub-v1.2.0` ค้างหลังลบไฟล์ sw ออก ทำให้หน้าเว็บเสิร์ฟของเก่า)
|
||||
- **ห้ามปิดการซูม**: viewport ต้องเป็น `width=device-width, initial-scale=1` เท่านั้น (WCAG 1.4.4)
|
||||
- **contrast ที่วัดจริง** (พื้น `#0D0D0D`): `#B3B3B3` 9.27 · `#D47272` 5.97 · **`#A92626` = 2.77 → ห้ามใช้กับตัวอักษร** (ใช้ได้เฉพาะเส้นขอบ/พื้น) · placeholder ช่องค้นหาใช้ `#8A8A8A` (4.77 บน `#1F1F1F`) ไม่ใช่ `#454545` (1.72)
|
||||
- **hit area ≥ 44px**: ปุ่มที่หน้าตาเล็กกว่า (ใกล้ฉัน 20px, TH/EN 26px, chip 38px, ลูกศรแกลเลอรี 40px) ขยายด้วย `after:absolute after:-inset-*` — ห้ามเปลี่ยนความสูงที่มองเห็นเพื่อเพิ่ม hit area
|
||||
|
||||
## Agent-Native is structural, not visual
|
||||
|
||||
This shell already meets the Agent-Native contract: data in SQL, actions as the
|
||||
@@ -95,22 +112,33 @@ Surface And Page Boundaries so the surfaces are wired correctly.
|
||||
|
||||
Single source of truth per concern — do not duplicate these:
|
||||
|
||||
- `app/lib/cinemas.ts` — ข้อมูลโรงหนัง + ฟังก์ชันกรอง/ค้นหา (`filterCinemas`, `findCinemaBySlug`, `formatDistance`)
|
||||
- `app/lib/cinemas.ts` — ข้อมูลโรงหนัง + ฟังก์ชันกรอง/ค้นหา (`filterCinemas`, `matchesQuery`, `findCinemaBySlug`, `formatDistance`)
|
||||
- การค้นหา (`filterCinemas`) เป็นแบบ **ทุกคำต้องเจอ (AND) เรียงสลับได้** และค้นทุกอย่างที่ผู้ใช้เห็นบนการ์ด: `name` / `name_th` / slug / `location_label(+_en)` / `address_lines(+_en)` / ทางเดินทาง / tag + ป้ายหมวดตามภาษา / คำอธิบาย — ต้องส่ง `tagLabels: messages.tags` เข้ามาด้วย ไม่งั้นค้นคำหมวดภาษาอังกฤษไม่เจอ
|
||||
- ข้อความผ่าน `normalizeSearchText` (NFKC, ตัดอักขระล่องหน, ตัวพิมพ์เล็ก, แปลงตัวคั่นเป็นช่องว่าง) และ `foldSearchText` (ตัดวรรณยุกต์/สระบน-ล่าง) → "Française" = "francaise", "เฮ้าส์" = "เฮาส", พิมพ์ไม่ครบก็เจอ
|
||||
- ผลลัพธ์เรียงตามความตรง: ชื่อเท่ากัน 3 · ชื่อขึ้นต้นด้วยคำ 2 · ชื่อมีคำอยู่ข้างใน 1.2 · หมวด/สถานที่/รายละเอียดน้ำหนักต่ำกว่า (คะแนนเท่ากันคงลำดับเดิม)
|
||||
- **ปุ่ม "ค้นหา"/Enter ไม่ได้ทำหน้าที่กรอง** (กรองสดทุกคีย์อยู่แล้วใน `onChange`) — อยู่ใน `<form role="search">` เพื่อ `preventDefault` (กันหน้าโหลดใหม่) + `blur()` ปิดคีย์บอร์ดมือถือ + `scrollIntoView()` ไปที่หัวข้อผลลัพธ์ (`scroll-mt-[88px]`, เคารพ `prefers-reduced-motion`) · ห้ามเปลี่ยนปุ่มนี้เป็น `type="button"` เฉย ๆ (จะกลับไปเป็นปุ่มหลอก)
|
||||
- `app/lib/design-tokens.ts` — ค่าสีจาก Figma สำหรับ inline style (Tailwind class ยังเป็น literal เสมอ)
|
||||
- `app/lib/i18n/` — `messages.ts` (ข้อความ TH/EN ทั้งหมด คีย์หมวดหมู่/tag/ชำระเงิน/สิ่งอำนวยความสะดวก), `index.tsx` (`LocaleProvider`, `useI18n`, cookie `locale`)
|
||||
- ข้อความทุกคำใน UI ต้องมาจาก `messages` ไม่ hardcode ใน component · หมวดหมู่และ tag เก็บคีย์เป็นภาษาไทยเสมอ (ใช้กรองข้อมูล) แล้วแปลด้วย `messages.categories` / `messages.tags`
|
||||
- ข้อความอังกฤษของเนื้อหาโรงหนังเป็นฟิลด์เสริม `location_label_en` / `description_en` / `address_lines_en` / `value_en` — ไม่กรอกก็ fallback ไทย · ชื่อไทยใช้ `name_th` (+ helper `cinemaName(cinema, locale)`), ไม่กรอกก็แสดงชื่ออังกฤษ
|
||||
- `<title>` ของหน้ารายละเอียดสร้างจาก loader ของ route เอง (`meta({ loaderData })` — เวอร์ชันนี้ส่ง `loaderData` ไม่ใช่ `data`)
|
||||
- `<head>` (title/description) ไม่เปลี่ยนตามภาษา; ภาษาเริ่มต้นเลือกตามลำดับ **?lang= → localStorage → cookie → ไทย** (`resolveInitialLocale`) — ตั้งใจไม่ใช้ `navigator.language` เพราะเว็บไทย-first
|
||||
- สลับภาษาได้ 2 ทาง: ปุ่ม **TH / EN** ที่ header (ไม่มีเมนู ไม่มีจุดคลิกพลาด) หรือลิงก์ `?lang=en` ที่บังคับภาษาและ SSR ใส่ `<html lang>` ถูกต้อง
|
||||
- สลับภาษาได้ 2 ทาง: ปุ่มภาษาที่ header (ปุ่มเดียว + dropdown TH/EN — ดูหัวข้อตัวสลับภาษาด้านล่าง) หรือลิงก์ `?lang=en` ที่บังคับภาษาและ SSR ใส่ `<html lang>` ถูกต้อง
|
||||
- การเลือกถูกเก็บทั้ง cookie และ localStorage (รองรับเบราว์เซอร์ที่บล็อกคุกกี้) และซิงก์ข้ามแท็บผ่าน `storage` event
|
||||
- `app/components/site/` — โครงร่วม: `SiteShell` (flex column + `min-h-screen`, เนื้อหา `flex-1` เพื่อดัน footer ไปท้ายจอ), `SiteHeader`, `SiteFooter` (ความกว้างเนื้อหา cap ที่ 1016px เท่าคอลัมน์ฮีโร่ ไม่ยืดตามกริดการ์ด), `Logo`, `CinemaCard`, `CinemaGrid` + `CategoryFilter`
|
||||
- ปุ่มแชร์ (`app/components/site/ShareButton.tsx` + `app/lib/share.ts`)
|
||||
- ลิงก์สร้างจาก **origin ของ request** (root loader คืน `siteUrl` → `ShareOriginProvider`) + พาธย่อ `/c/<slug>` — ไม่ฝังโดเมนในโค้ด และไม่ต้องตั้ง env
|
||||
- `/c/<slug>` (`app/routes/c.$slug.tsx`) เป็น **302 redirect** ไป `/cinema/<slug>` — ลิงก์สั้นพอแปะในแชท แต่ไม่มีเนื้อหาสอง URL ให้ SEO ปวดหัว
|
||||
- ลำดับการแชร์: `navigator.share` (ถ้ามี) → `navigator.clipboard.writeText` → `<textarea>` + `execCommand` (origin ที่ไม่ใช่ HTTPS) → `failed` · คัดลอกสำรองเสมอเพื่อให้เดสก์ท็อปได้อะไรกลับไป
|
||||
- แสดงผลด้วย `role="status" aria-live="polite"` (การ์ด = `sr-only`, ท้ายหน้า = ข้อความข้างปุ่ม) และรีเซ็ตใน 2.5 วิ
|
||||
- ตำแหน่ง: การ์ดหน้าแรก = ปุ่มกลมมุมขวาบน (`variant="icon"`, `size-9`) · ท้ายหน้ารายละเอียด = แถบ "แชร์หน้านี้" (`variant="wide"`, `min-h-11`) หลังส่วน "โรงหนังอิสระอื่นๆ"
|
||||
- **หน้าตาตามธีม (ห้ามเปลี่ยนเป็นสีอื่น)**: การ์ด = ชิปแก้ว `rounded-xl` + `bg-[#1B1B1B]/80` + `backdrop-blur-xl` + `border-white/10` (สูตรเดียวกับแผงข้อมูลบนการ์ด) ไอคอนขาว → hover `#D47272` + ขอบ `#A92626/60` · แถบท้ายหน้า = `rounded-lg` + `bg-[#1B1B1B]/80` + `border-[#332B2B]` · สถานะสำเร็จ (คัดลอก/แชร์แล้ว) = ไอคอน `IconCheck` สี `#D47272` + ขอบ `#D47272/50` · hit area 44–48px ด้วย `after:-inset-*` (ไม่ขยายขนาดที่มองเห็น)
|
||||
- `app/components/home/` — ส่วนของหน้าแรก (`HeroSection`)
|
||||
- `app/components/cinema/` — ส่วนของหน้ารายละเอียด (`Gallery`, `CinemaSummary`, `TransportList`, `ContactPanel`, `FacilitiesSection`, `LocationPanel`, `CinemaNotFound`)
|
||||
- `app/routes/about.tsx` — หน้า "เกี่ยวกับเรา" (route `/about`, เมนูอยู่ทั้ง header และ footer, ใช้ `<Link>` ของ react-router จึงสลับหน้าแบบ SPA ไม่โหลดเอกสารใหม่) · เนื้อความเป็น `font-content` (มีหัว) ขนาด 17-18px `leading-[1.95]`, นำ 19-21px, หัวข้อยังเป็น Inter ตามเดิม
|
||||
- `docs/architecture.html` — แผนผังการทำงาน Frontend / Backend / Data (เอกสารประกอบ ไม่ถูก build เข้าแอป) เปิดด้วยเบราว์เซอร์ได้ตรง ๆ
|
||||
- `app/routes/_index.tsx` (หน้าแรก) และ `app/routes/cinema.$slug.tsx` (รายละเอียด) — ประกอบ component + จัดการ state ของ route เท่านั้น ข้อมูลมาจาก `useContent()`
|
||||
- `app/routes/admin_.login.tsx` (หน้า login) และ `app/routes/admin.tsx` (แดชบอร์ด **5 แท็บ**: โรงหนัง / หน้าเกี่ยวกับเรา / คำศัพท์หลายภาษา / Footer-ไอคอน / สถิติการค้นหา) — ใช้ `admin_.login` เพื่อให้เป็น route พี่น้องของ `/admin` (ถ้าตั้งชื่อ `admin.login` จะกลายเป็น route ลูกที่ไม่มี `<Outlet/>` แล้วหน้าว่าง)
|
||||
- `app/routes/admin_.login.tsx` (หน้า login) และ `app/routes/admin.tsx` (แดชบอร์ด **7 แท็บ**: โรงหนัง / หน้าเกี่ยวกับเรา / สำหรับคนรักหนัง / สำหรับคนทำโรงหนัง / คำศัพท์หลายภาษา / Footer-ไอคอน / สถิติการค้นหา) — ใช้ `admin_.login` เพื่อให้เป็น route พี่น้องของ `/admin` (ถ้าตั้งชื่อ `admin.login` จะกลายเป็น route ลูกที่ไม่มี `<Outlet/>` แล้วหน้าว่าง)
|
||||
- ฟอร์มโรงหนังแบ่งเป็น **หมวดพับได้** (`app/components/admin/AdminSection.tsx` ใช้ `<details>/<summary>` เนทีฟ) เปิดไว้เฉพาะ "ข้อมูลหลัก" — เพิ่มหมวดใหม่ให้ใช้คอมโพเนนต์นี้เสมอ อย่าเรียงช่องยาวรวดเดียว
|
||||
- ช่อง slug (`SlugInput.tsx`): ดึงจากชื่ออังกฤษอัตโนมัติ (`suggestSlug`) จนกว่าจะแก้เอง · กันค่าว่าง/ซ้ำ · เตือนว่าลิงก์เดิมจะใช้ไม่ได้
|
||||
|
||||
@@ -125,6 +153,13 @@ Single source of truth per concern — do not duplicate these:
|
||||
- ฟิลด์ที่เว้นว่างจะถูกเติมด้วยค่าเริ่มต้นจาก `MESSAGES[locale].about` ตอน sanitize (`sanitizeAbout`) — ไฟล์เก่าที่ไม่มีคีย์ `about` จึงยังใช้งานได้
|
||||
- `app/routes/about.tsx` อ่านจาก `useContent().about[locale]` เท่านั้น ไม่ผูกกับข้อความใน `messages.ts` อีก
|
||||
- ตัวแก้ไขมีแท็บภาษา + ตัวอย่างหน้าเว็บสด และปุ่ม "คืนค่าตั้งต้น" ต่อภาษา
|
||||
- หน้า **"สำหรับคนทำโรงหนัง"** (`/for-cinemas`) และ **"สำหรับคนรักหนัง"** (`/for-film-lovers`) — บทความแบบ **บล็อก** ที่แก้ได้จากหลังบ้าน (`ArticleEditor` คนละแท็บ) และเรนเดอร์ผ่าน component ร่วม `app/components/site/ArticlePage.tsx`
|
||||
- ข้อมูล: `forCinemas: { th, en }` และ `forFilmLovers: { th, en }` ใน `content.json` แต่ละภาษา = `{ title, lead, blocks[], contactHeading, contactNote }`
|
||||
- `blocks[]` มี 2 ชนิด: `{ type: "paragraph", text }` และ `{ type: "image", src, alt, caption }` — เรียงตามลำดับในอาร์เรย์เท่านั้น (มีปุ่ม ↑ ↓ / ลบ ในหลังบ้าน)
|
||||
- ตัวช่วยบริสุทธิ์อยู่ที่ `app/lib/article.ts` (`sanitizeArticleBlocks`, `moveBlock`, `removeBlock`, `createParagraphBlock`, `createImageBlock`) — ตัวตรวจฝั่งเซิร์ฟเวอร์คือ `sanitizeForCinemas` / `sanitizeForFilmLovers` ซึ่งใช้ตัวกลาง `sanitizeArticlePage` (ทิ้งบล็อกว่าง/ผิดชนิด, เติมค่าเริ่มต้นจาก `seedForCinemas()` / `seedForFilmLovers()`)
|
||||
- ภาษาภาพเดียวกับ `/about`: กรอบ 1440 + `px-[108px]`, `font-content` (IBM Plex Sans Thai Looped), การ์ดติดต่อไล่แดงขอบ `rgba(169,38,38,0.45)` + ไอคอนโซเชียลชุดเดียวกับ footer · มีลิงก์ใน header และ footer
|
||||
- header: มือถือ (< `sm`) ยุบเมนูทั้งสามหน้าไว้ใน `<details>` (native, คีย์บอร์ด/Esc ใช้ได้) เพราะป้ายภาษาไทยยาวและโลโก้มีขนาดตายตัวตามสเปก — อย่าเพิ่มลิงก์ตรงบนมือถืออีก
|
||||
- ตัวสลับภาษา (`LocaleSwitcher`) เป็น **ปุ่มเดียว + dropdown** (ไม่ใช่ปุ่ม TH/EN สองปุ่ม) — ต้องมี `aria-haspopup="menu"` / `aria-expanded`, ตัวเลือกเป็น `role="menuitemradio"` + `aria-checked`, เลื่อนด้วยลูกศรขึ้น/ลงได้ และปิดด้วย Esc/คลิกนอกเมนู
|
||||
- ลำดับโรงหนังในหลังบ้าน (`app/components/admin/CinemaList.tsx`) — ลำดับในอาร์เรย์ `cinemas` = ลำดับที่หน้าเว็บแสดง
|
||||
- โหมด **ลำดับที่จัดไว้** (ค่าเริ่มต้น): ลากวางสลับที่ได้ หรือกด ↑ ↓ ทีละขั้น (คีย์บอร์ดใช้ได้) · เมื่อลำดับต่างจากที่บันทึกจะมีปุ่ม **บันทึกลำดับใหม่** (`PUT /api/admin/content` ส่งเฉพาะ `cinemas`) หรือจะกด **บันทึกทั้งหมด** ในฟอร์มก็ได้
|
||||
- โหมด **ก-ฮ**: เรียงชื่อไทยด้วย `Intl.Collator("th")` — เป็นเพียงมุมมอง ลากสลับไม่ได้จนกว่าจะกด **ใช้ลำดับ ก-ฮ นี้**
|
||||
@@ -197,6 +232,20 @@ Single source of truth per concern — do not duplicate these:
|
||||
- ดูได้ที่หลังบ้าน แท็บ **สถิติการค้นหา** (`GET /api/admin/analytics?days=1|7|30|90`, ต้องล็อกอิน)
|
||||
- ตั้ง `ANALYTICS_SALT` ใน env เพื่อไม่ให้ hash ผู้เข้าชมคาดเดาได้ข้าม deployment
|
||||
|
||||
## SEO และการป้องกัน AI (บังคับ)
|
||||
|
||||
- **ไม่ฝังโดเมนในโค้ด (บังคับ)**: ทุกที่ที่ต้องใช้ URL เต็ม (canonical, OG, JSON-LD, sitemap, robots, ลิงก์แชร์) ต้องมาจาก origin ของ **request จริง** ผ่าน `originFromRequest()` / `originFromHeaders()` (`app/lib/request-origin.ts`) — รองรับ `x-forwarded-host`/`x-forwarded-proto` ของ reverse proxy · ตั้ง env `SITE_URL` เฉพาะเวลาต้องบังคับโดเมน (ปกติไม่ต้อง)
|
||||
- `meta()` ไม่มี access ต่อ request → route ที่มี meta ต้องมี loader คืน `{ origin }` ด้วย (`resolvePageOrigin()` ใน `app/lib/page-origin.ts`) แล้วอ่าน `loaderData.origin` · root loader คืน `siteUrl` ให้ปุ่มแชร์ใช้ผ่าน `ShareOriginProvider`
|
||||
- ทุกหน้าใช้ `pageMeta()` (`app/lib/seo.ts`) — ได้ title, description, canonical, robots, OG, Twitter ครบชุด · route ห้ามเขียน `{ title }` / `<meta>` เอง
|
||||
- JSON-LD: `WebSite` + `Organization` (+ `SearchAction`) ที่หน้าแรก · `BreadcrumbList` ทุกหน้าย่อย · `MovieTheater` หน้าโรงหนัง · `Article` หน้าบทความ
|
||||
- `SearchAction` ชี้ไป `/?q=<คำค้น>` — หน้าแรกจึง**ต้อง**อ่าน `q` จาก URL มาเป็นค่าเริ่มต้นของช่องค้นหา (ถ้าเปลี่ยนกลไกค้นหา ต้องแก้ทั้งคู่)
|
||||
- **ห้ามใส่ hreflang**: เว็บเดียวสลับภาษาได้ด้วย toggle (ไม่แยก URL) — ใส่แล้วจะกลายเป็นสัญญาณเนื้อหาซ้ำ
|
||||
- หน้า `/admin`, `/admin/login` = `noindex, nofollow` (หน้าโรงที่ไม่พบก็ noindex)
|
||||
- `server/routes/robots.txt.ts` — เปิด search engine หลัก, ปิด `/api/`, `/admin`, `/_agent-native/`, `/c/` (ลิงก์ย่อ), และบล็อก AI crawler 21 ตัว · บรรทัด `Sitemap:` ต่อจาก origin ของ request (ห้ามเปลี่ยนกลับเป็นไฟล์ static)
|
||||
- `public/ai.txt` — ประกาศไม่ให้นำเนื้อหาไปฝึกโมเดล (ไฟล์ static, ไม่มีโดเมนอยู่ในเนื้อหา)
|
||||
- `/sitemap.xml` เป็น **Nitro route** (`server/routes/sitemap.xml.ts`) ไม่ใช่ React Router route — เพราะ SSR handler ของ framework ตอบ 404 ให้พาธที่ลงท้ายด้วยนามสกุลไฟล์ · ตัวสร้าง XML แยกอยู่ที่ `app/lib/sitemap.ts` (มี unit test) และ**ต้องข้ามโรงที่ `hidden`**
|
||||
- OG image: `public/og/alterflixhub-1200x630.png` (1200×630, โลโก้ Jersey 15 สี `#8F0808` ตามสเปกโลโก้) — **ห้ามพิมพ์โดเมนลงบนภาพ** (ภาพเป็น static แก้ตาม request ไม่ได้) · เปลี่ยนคำบนภาพแล้วต้องสร้างใหม่ ไม่ใช้ภาพ placeholder
|
||||
|
||||
## หมวด "ยอดนิยม" (จากสถิติ ไม่ใช่ป้ายมือ)
|
||||
|
||||
- `app/lib/popularity.server.ts` — `computePopularity()` อ่าน `events.jsonl` แล้วให้สถานะ + อันดับ (memo 5 นาที)
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
# AlterFlixHub
|
||||
|
||||
ไดเรกทอรีโรงหนังอิสระ/อาร์ตเฮาส์และกลุ่มคนฉายหนังในประเทศไทย — ค้นหาโรงตามชื่อ/จังหวัด/หมวดหมู่ ดูรายละเอียดการเดินทาง ที่ตั้ง และช่องทางติดต่อของแต่ละโรง พร้อมหลังบ้านสำหรับแก้ข้อมูลได้เองโดยไม่ต้องแตะโค้ด
|
||||
ไดเรกทอรีโรงหนังอิสระ/อาร์ตเฮาส์และกลุ่มคนฉายหนังในประเทศไทย — ค้นหาโรงตามชื่อ/สถานที่/หมวดหมู่ ดูรายละเอียดการเดินทาง ที่ตั้ง และช่องทางติดต่อของแต่ละโรง พร้อมหลังบ้านที่แก้เนื้อหาเองได้โดยไม่ต้องแตะโค้ด
|
||||
|
||||
Stack: **React Router 8 (SSR) + Vite 8 + Tailwind 4 + TypeScript** บน Agent-Native runtime (Node/h3) · ข้อมูลเก็บเป็นไฟล์ JSON ใน `data/` · สถิติแบบ privacy-first (ไม่มีคุกกี้ ไม่เก็บ IP)
|
||||
|
||||
@@ -23,18 +23,32 @@ pnpm dev # http://localhost:8080
|
||||
|
||||
| Route | หน้า |
|
||||
|---|---|
|
||||
| `/` | หน้าแรก — ฮีโร่ค้นหา, แถบหมวด, กริดการ์ดโรงหนัง (รูปปกจาก `photos[0]` · **ลำดับการ์ดสลับเองทุกวัน** ไม่ให้ซ้ำตำแหน่งเดิม 2 วันติดกัน) |
|
||||
| `/cinema/<slug>` | รายละเอียดโรง — แกลเลอรี, สรุป, การเดินทาง, สิ่งอำนวยความสะดวก, ที่ตั้ง (แผนที่), ติดต่อ/ชำระเงิน |
|
||||
| `/about` | เกี่ยวกับเรา (เนื้อหาจากหลังบ้าน) |
|
||||
| `/admin` | หลังบ้าน (5 แท็บ) — ดู [docs/admin-guide.md](docs/admin-guide.md) |
|
||||
| `/` | หน้าแรก — ฮีโร่ค้นหา, แถบหมวด, กริดการ์ดโรงหนัง (ลำดับการ์ด **สลับเองทุกวัน** ไม่ให้ซ้ำตำแหน่งเดิม 2 วันติดกัน) · รองรับลิงก์ค้นหาตรง `/?q=<คำค้น>` |
|
||||
| `/cinema/<slug>` | รายละเอียดโรง — แกลเลอรี (กดลูกศรเลื่อนได้), สรุป, การเดินทาง, สิ่งอำนวยความสะดวก, ที่ตั้ง (แผนที่), ติดต่อ/ชำระเงิน, ปุ่มแชร์ |
|
||||
| `/c/<slug>` | ลิงก์ย่อสำหรับแชร์ → **302** ไป `/cinema/<slug>` |
|
||||
| `/for-film-lovers` | บทความ "สำหรับคนรักหนัง" (แก้จากหลังบ้าน) |
|
||||
| `/for-cinemas` | บทความ "สำหรับคนทำโรงหนัง" (แก้จากหลังบ้าน) |
|
||||
| `/about` | เกี่ยวกับเรา (แก้จากหลังบ้าน) |
|
||||
| `/admin` · `/admin/login` | หลังบ้าน 7 แท็บ — ดู [docs/admin-guide.md](docs/admin-guide.md) · `noindex` |
|
||||
| `/sitemap.xml` · `/robots.txt` · `/ai.txt` | ไฟล์สำหรับ crawler (sitemap/robots สร้างสดตามโดเมนของ request) |
|
||||
|
||||
รองรับ **ไทย/อังกฤษ** สลับที่ header หรือ `?lang=en` (จำค่าไว้ใน cookie + localStorage)
|
||||
รองรับ **ไทย/อังกฤษ** สลับที่ header (ปุ่มเดียว + dropdown) หรือ `?lang=en` (จำค่าใน cookie + localStorage)
|
||||
|
||||
## คุณสมบัติหลัก
|
||||
|
||||
- **ค้นหา** — AND หลายคำ เรียงสลับได้ · ค้นทุกอย่างที่เห็นบนการ์ด (`name`, `name_th`, สถานที่, ที่อยู่, การเดินทาง, หมวด/แท็ก, คำอธิบาย) · ตัดวรรณยุกต์/สระบน-ล่าง และ normalize ตัวคั่น → พิมพ์ไม่ครบหรือไม่มีวรรณยุกต์ก็เจอ · เรียงผลตามความตรงของชื่อ
|
||||
- **หาโรงใกล้ฉัน** — `navigator.geolocation` + ระยะเส้นตรง และระยะตามถนน (OSRM)
|
||||
- **แชร์** — `navigator.share` → clipboard → fallback `<textarea>` · ลิงก์ย่อ `/c/<slug>` บนโดเมนจริงของ request · บอกผลด้วย `aria-live`
|
||||
- **PWA** — manifest + service worker (navigate network-first, asset cache-first) + `/offline.html` · ติดตั้งลงจอโฮมได้
|
||||
- **แอนิเมชันเบา** — reveal ตอนเลื่อน/โหลด ใช้เฉพาะ `transform`/`opacity` · ปิดอัตโนมัติเมื่อตั้ง `prefers-reduced-motion`
|
||||
- **SEO + กัน AI** — canonical/OG/Twitter/JSON-LD (`WebSite`, `Organization`, `BreadcrumbList`, `MovieTheater`, `Article`), `sitemap.xml` จากข้อมูลจริง, `robots.txt` บล็อก AI crawler 21 ตัว, `ai.txt`
|
||||
- **สถิติ** — event `search` / `cinema_select` / `cinema_view` / `near_me` · หมวด "ยอดนิยม" เริ่มจัดอันดับจริงเมื่อข้อมูลครบ 6 เดือน
|
||||
|
||||
## หลังบ้าน
|
||||
|
||||
`http://localhost:8080/admin` — ล็อกอินด้วย `ADMIN_USERNAME` / `ADMIN_PASSWORD` (ค่าเริ่มต้น `it is me` / `it is me&it is me`)
|
||||
|
||||
แก้ได้: โรงหนัง (ชื่อ/slug/หมวด/สิ่งอำนวยความสะดวก/การเดินทาง/ติดต่อ/รูปภาพ/ที่ตั้ง/คำอธิบาย) · หน้าเกี่ยวกับเรา · คำศัพท์ทุกคำในหน้าเว็บ · Footer · ดูสถิติการค้นหา
|
||||
7 แท็บ: **โรงหนัง** (ชื่อ/slug/หมวด/สิ่งอำนวยความสะดวก/การเดินทาง/ติดต่อ/รูปภาพ/ที่ตั้ง/คำอธิบาย) · **หน้าเกี่ยวกับเรา** · **สำหรับคนรักหนัง** · **สำหรับคนทำโรงหนัง** · **คำศัพท์หลายภาษา** · **Footer-ไอคอน** · **สถิติการค้นหา**
|
||||
|
||||
คู่มือทีละงาน: **[docs/admin-guide.md](docs/admin-guide.md)**
|
||||
|
||||
@@ -42,36 +56,46 @@ pnpm dev # http://localhost:8080
|
||||
|
||||
```
|
||||
app/
|
||||
routes/ _index (หน้าแรก) · cinema.$slug · about · admin / admin_.login
|
||||
routes/ _index · cinema.$slug · c.$slug · about · for-film-lovers · for-cinemas · admin · admin_.login
|
||||
components/
|
||||
site/ SiteShell · SiteHeader/Footer · Logo · CinemaCard · CinemaGrid
|
||||
site/ SiteShell · SiteHeader/Footer · NavLink · Logo · CinemaCard · CinemaGrid · Reveal · ShareButton · ArticlePage
|
||||
cinema/ Gallery · CinemaSummary · TransportList · FacilitiesSection · LocationPanel · ContactPanel
|
||||
admin/ AdminSection · CinemaList · ChipPicker · CommaListInput · SlugInput · PhotosEditor ·
|
||||
TransportEditor · ContactsEditor · CinemaFacilitiesEditor · AboutEditor
|
||||
lib/ cinemas · content.server · map-embed · popularity.server · analytics.* · i18n/ · geo
|
||||
admin/ AdminSection · CinemaList · ChipPicker · CommaListInput · SlugInput · PhotosEditor · TransportEditor ·
|
||||
ContactsEditor · CinemaFacilitiesEditor · AboutEditor · ArticleEditor · ArticleBlockCard · form-styles
|
||||
hooks/ use-reveal · use-near-me · use-navigation-state
|
||||
lib/ cinemas (ค้นหา/กรอง) · search · gallery · article · content.* · map-embed · geo · daily-order
|
||||
motion · pwa · share · share-origin · seo · site · sitemap · request-origin · page-origin
|
||||
analytics.* · popularity.server · i18n/ · design-tokens
|
||||
server/
|
||||
routes/api/ admin/* (login, content, import, analytics) · analytics/collect
|
||||
routes/ [...page].get.ts (SSR) · robots.txt.ts · sitemap.xml.ts
|
||||
routes/api/ admin/* (login, session, content, import, analytics) · analytics/collect
|
||||
public/ manifest.json · sw.js · offline.html · ai.txt · og/ · icon-*.png
|
||||
data/
|
||||
content/content.json แหล่งข้อมูลจริงของโรงหนัง/คำศัพท์/about (แก้ผ่านหลังบ้าน)
|
||||
content/content.json แหล่งข้อมูลจริงของโรงหนัง/คำศัพท์/บทความ (แก้ผ่านหลังบ้าน)
|
||||
analytics/events.jsonl สถิติแบบ append-only
|
||||
docs/
|
||||
admin-guide.md คู่มือใช้งานหลังบ้าน (ภาษาไทย)
|
||||
api.md API reference
|
||||
architecture.html แผนผังการทำงาน Frontend/Backend/Data (เปิดด้วยเบราว์เซอร์)
|
||||
DESIGN.md สัญญาการออกแบบ (บังคับ) — สี ฟอนต์ โลโก้ layout กติกาข้อมูล
|
||||
push-to-gitea.md วิธี push ขึ้น Gitea
|
||||
DESIGN.md สัญญาการออกแบบ (บังคับ) — สี ฟอนต์ โลโก้ layout motion SEO กติกาข้อมูล
|
||||
AGENTS.md กฎสำหรับ agent/AI ที่แก้โค้ดโปรเจกต์นี้
|
||||
```
|
||||
|
||||
## ข้อมูลและสถิติ
|
||||
## โดเมนและ env
|
||||
|
||||
- โรงหนัง/คำศัพท์/หน้าเกี่ยวกับเรา เก็บที่ `data/content/content.json` (หลังบ้านเขียนแบบ atomic)
|
||||
- สถิติเก็บที่ `data/analytics/events.jsonl` — event: `search`, `cinema_select`, `cinema_view`, `near_me`; ไม่ใช้คุกกี้ ไม่เก็บ IP/UA ดิบ
|
||||
- หมวด "ยอดนิยม" จะเริ่มจัดอันดับจากสถิติจริงเมื่อข้อมูลครบ **6 เดือน** ก่อนหน้านั้นใช้ป้ายที่ตั้งมือ
|
||||
- ตั้ง `ANALYTICS_SALT` ใน `.env` ก่อน deploy จริง
|
||||
ระบบ**ไม่ฝังโดเมนในโค้ด** — canonical/OG/JSON-LD/sitemap/robots/ลิงก์แชร์ มาจาก origin ของ request (`app/lib/request-origin.ts` รองรับ `x-forwarded-host` / `x-forwarded-proto` ของ reverse proxy)
|
||||
|
||||
| env | จำเป็น | ใช้ทำอะไร |
|
||||
|---|---|---|
|
||||
| `ADMIN_USERNAME` · `ADMIN_PASSWORD` · `ADMIN_SESSION_SECRET` | แนะนำ | บัญชีหลังบ้าน + กุญแจเซ็น cookie |
|
||||
| `ANALYTICS_SALT` | แนะนำ | เกลือ hash ผู้เข้าชม (กันคาดเดา) |
|
||||
| `SITE_URL` / `SHARE_ORIGIN` | ไม่ต้อง | บังคับโดเมนเฉพาะกรณี (ปกติปล่อยว่าง) |
|
||||
|
||||
## เอกสารอื่น
|
||||
|
||||
- [DESIGN.md](DESIGN.md) — สัญญาการออกแบบ: พาเลตต์ ฟอนต์ โลโก้ layout ฟิลด์ข้อมูล และกติกากันข้อมูลหาย
|
||||
- [DESIGN.md](DESIGN.md) — สัญญาการออกแบบ: พาเลตต์ ฟอนต์ โลโก้ layout motion PWA SEO และกติกากันข้อมูลหาย
|
||||
- [docs/api.md](docs/api.md) — endpoint ทั้งหมด (method/path/auth/body)
|
||||
- [docs/architecture.html](docs/architecture.html) — แผนผังการทำงาน
|
||||
- [docs/push-to-gitea.md](docs/push-to-gitea.md) — วิธี push ขึ้น Gitea
|
||||
- [DEVELOPING.md](DEVELOPING.md) — คู่มือ framework ของ starter (ไม่ใช่ของเฉพาะโปรเจกต์นี้)
|
||||
@@ -1,16 +1,14 @@
|
||||
import { useState } from "react";
|
||||
|
||||
import {
|
||||
inputClass,
|
||||
labelClass,
|
||||
primaryButtonClass,
|
||||
secondaryButtonClass,
|
||||
} from "@/components/admin/form-styles";
|
||||
import type { AboutContent, AboutSection } from "@/lib/content-types";
|
||||
import type { Locale } from "@/lib/i18n/messages";
|
||||
|
||||
const inputClass =
|
||||
"w-full rounded-lg border border-[#303030] bg-[#141414] px-3 py-2 text-sm text-white outline-none transition focus:border-[#A92626] focus-visible:ring-2 focus-visible:ring-[#A92626]/40";
|
||||
const labelClass = "flex flex-col gap-1.5 text-xs text-[#999]";
|
||||
const buttonClass =
|
||||
"min-h-11 rounded-lg border border-[#303030] px-3 text-sm transition hover:border-[#A92626] hover:text-[#D47272] focus-visible:outline focus-visible:outline-2 focus-visible:outline-[#A92626]";
|
||||
const primaryButtonClass =
|
||||
"min-h-11 rounded-lg bg-[#8F0808] px-4 text-sm font-medium transition hover:bg-[#a30a0a] focus-visible:outline focus-visible:outline-2 focus-visible:outline-[#D47272]";
|
||||
|
||||
const LOCALE_TABS: Array<{ code: Locale; label: string }> = [
|
||||
{ code: "th", label: "ไทย" },
|
||||
{ code: "en", label: "English" },
|
||||
@@ -106,7 +104,11 @@ export function AboutEditor({
|
||||
</div>
|
||||
|
||||
<div className="flex flex-wrap items-center gap-2">
|
||||
<button type="button" className={buttonClass} onClick={restoreDefaults}>
|
||||
<button
|
||||
type="button"
|
||||
className={secondaryButtonClass}
|
||||
onClick={restoreDefaults}
|
||||
>
|
||||
คืนค่าตั้งต้น ({locale.toUpperCase()})
|
||||
</button>
|
||||
<button
|
||||
@@ -171,7 +173,9 @@ export function AboutEditor({
|
||||
className="rounded-xl border border-[#242424] bg-[#141414] p-4"
|
||||
>
|
||||
<div className="mb-2 flex items-center justify-between gap-2">
|
||||
<span className="text-xs text-[#8A8A8A]">ส่วนที่ {index + 1}</span>
|
||||
<span className="text-xs text-[#8A8A8A]">
|
||||
ส่วนที่ {index + 1}
|
||||
</span>
|
||||
<div className="flex items-center gap-1">
|
||||
<button
|
||||
type="button"
|
||||
@@ -226,7 +230,7 @@ export function AboutEditor({
|
||||
|
||||
<button
|
||||
type="button"
|
||||
className={`${buttonClass} self-start`}
|
||||
className={`${secondaryButtonClass} self-start`}
|
||||
onClick={addSection}
|
||||
>
|
||||
+ เพิ่มส่วน
|
||||
|
||||
@@ -0,0 +1,129 @@
|
||||
import {
|
||||
compactButtonClass,
|
||||
inputClass,
|
||||
labelClass,
|
||||
} from "@/components/admin/form-styles";
|
||||
import type { ArticleBlock } from "@/lib/content-types";
|
||||
|
||||
type ArticleBlockCardProps = {
|
||||
block: ArticleBlock;
|
||||
/** ตำแหน่งของบล็อก (0-based) — ใช้แสดงเลขและปิดปุ่มที่เกินขอบ */
|
||||
index: number;
|
||||
/** จำนวนบล็อกทั้งหมด — ใช้ปิดปุ่ม "เลื่อนลง" ที่บล็อกสุดท้าย */
|
||||
total: number;
|
||||
/** ส่งบล็อกที่แก้แล้วกลับไปทั้งก้อน (ชนิดถูกต้องตาม type ของบล็อก) */
|
||||
onChange: (next: ArticleBlock) => void;
|
||||
onMove: (direction: -1 | 1) => void;
|
||||
onRemove: () => void;
|
||||
};
|
||||
|
||||
/**
|
||||
* การ์ดแก้ไขบทความหนึ่งบล็อก — ย่อหน้าหรือรูป
|
||||
* แยกออกมาจาก ArticleEditor เพื่อให้แต่ละไฟล์มีขนาดอ่านไหว
|
||||
*/
|
||||
export function ArticleBlockCard({
|
||||
block,
|
||||
index,
|
||||
total,
|
||||
onChange,
|
||||
onMove,
|
||||
onRemove,
|
||||
}: ArticleBlockCardProps) {
|
||||
return (
|
||||
<div className="rounded-xl border border-[#242424] bg-[#141414] p-4">
|
||||
<div className="mb-3 flex flex-wrap items-center justify-between gap-2">
|
||||
<span className="text-xs uppercase tracking-wide text-[#999]">
|
||||
{block.type === "image" ? `รูปที่ ${index + 1}` : `ย่อหน้าที่ ${index + 1}`}
|
||||
</span>
|
||||
<div className="flex items-center gap-1.5">
|
||||
<button
|
||||
type="button"
|
||||
className={compactButtonClass}
|
||||
aria-label={`เลื่อนขึ้น (บล็อกที่ ${index + 1})`}
|
||||
onClick={() => onMove(-1)}
|
||||
disabled={index === 0}
|
||||
>
|
||||
↑
|
||||
</button>
|
||||
<button
|
||||
type="button"
|
||||
className={compactButtonClass}
|
||||
aria-label={`เลื่อนลง (บล็อกที่ ${index + 1})`}
|
||||
onClick={() => onMove(1)}
|
||||
disabled={index === total - 1}
|
||||
>
|
||||
↓
|
||||
</button>
|
||||
<button
|
||||
type="button"
|
||||
className={compactButtonClass}
|
||||
aria-label={`ลบบล็อกที่ ${index + 1}`}
|
||||
onClick={onRemove}
|
||||
>
|
||||
ลบ
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
{block.type === "paragraph" ? (
|
||||
<textarea
|
||||
value={block.text}
|
||||
onChange={(event) =>
|
||||
onChange({ type: "paragraph", text: event.target.value })
|
||||
}
|
||||
rows={4}
|
||||
placeholder="พิมพ์ย่อหน้าที่นี่ — เว้นบรรทัดใหม่ได้ ระบบจะแสดงตามที่พิมพ์"
|
||||
className={inputClass}
|
||||
/>
|
||||
) : (
|
||||
<div className="grid gap-3 md:grid-cols-[minmax(0,1fr)_180px]">
|
||||
<div className="flex flex-col gap-3">
|
||||
<label className={labelClass}>
|
||||
ลิงก์รูป (URL หรือ /images/…)
|
||||
<input
|
||||
value={block.src}
|
||||
onChange={(event) =>
|
||||
onChange({ ...block, src: event.target.value })
|
||||
}
|
||||
placeholder="/images/house-cinema.jpg"
|
||||
className={inputClass}
|
||||
/>
|
||||
</label>
|
||||
<label className={labelClass}>
|
||||
คำอธิบายรูป (alt) — จำเป็นต่อการเข้าถึง
|
||||
<input
|
||||
value={block.alt}
|
||||
onChange={(event) =>
|
||||
onChange({ ...block, alt: event.target.value })
|
||||
}
|
||||
placeholder="บรรยากาศภายในโรงหนัง"
|
||||
className={inputClass}
|
||||
/>
|
||||
</label>
|
||||
<label className={labelClass}>
|
||||
คำบรรยายใต้รูป (ไม่ใส่ก็ได้)
|
||||
<input
|
||||
value={block.caption}
|
||||
onChange={(event) =>
|
||||
onChange({ ...block, caption: event.target.value })
|
||||
}
|
||||
className={inputClass}
|
||||
/>
|
||||
</label>
|
||||
</div>
|
||||
<div className="flex items-start justify-center rounded-lg border border-[#242424] bg-[#0D0D0D] p-2">
|
||||
{block.src.trim() !== "" ? (
|
||||
<img
|
||||
src={block.src}
|
||||
alt=""
|
||||
className="max-h-[140px] w-full rounded-md object-cover"
|
||||
/>
|
||||
) : (
|
||||
<span className="py-8 text-xs text-[#666]">ยังไม่ได้ใส่ลิงก์รูป</span>
|
||||
)}
|
||||
</div>
|
||||
</div>
|
||||
)}
|
||||
</div>
|
||||
);
|
||||
}
|
||||
@@ -0,0 +1,215 @@
|
||||
import { useState } from "react";
|
||||
|
||||
import { ArticleBlockCard } from "@/components/admin/ArticleBlockCard";
|
||||
import {
|
||||
inputClass,
|
||||
labelClass,
|
||||
primaryButtonClass,
|
||||
secondaryButtonClass,
|
||||
} from "@/components/admin/form-styles";
|
||||
import {
|
||||
countImages,
|
||||
createImageBlock,
|
||||
createParagraphBlock,
|
||||
moveBlock,
|
||||
removeBlock,
|
||||
} from "@/lib/article";
|
||||
import type { ArticleBlock, ArticleContent } from "@/lib/content-types";
|
||||
import type { Locale } from "@/lib/i18n/messages";
|
||||
|
||||
const LOCALE_TABS: Array<{ code: Locale; label: string }> = [
|
||||
{ code: "th", label: "ไทย" },
|
||||
{ code: "en", label: "English" },
|
||||
];
|
||||
|
||||
type ArticleEditorProps = {
|
||||
value: Record<Locale, ArticleContent>;
|
||||
defaults: Record<Locale, ArticleContent>;
|
||||
onChange: (next: Record<Locale, ArticleContent>) => void;
|
||||
onSave: () => void;
|
||||
saving: boolean;
|
||||
/** ป้ายปุ่มบันทึก เช่น "บันทึกหน้าสำหรับคนทำโรงหนัง" */
|
||||
saveLabel: string;
|
||||
};
|
||||
|
||||
/**
|
||||
* ตัวแก้ไขหน้าบทความ (ใช้ทั้ง "สำหรับคนทำโรงหนัง" และ "สำหรับคนรักหนัง")
|
||||
*
|
||||
* ไฟล์นี้มีหน้าที่เดียว: ถือภาษาที่เลือก + ประกอบฟอร์ม
|
||||
* - รายละเอียดของแต่ละบล็อก → `ArticleBlockCard`
|
||||
* - สไตล์ฟอร์ม (input/label/ปุ่ม) → `form-styles`
|
||||
* ฟิลด์ที่เว้นว่างจะถูกเซิร์ฟเวอร์เติมค่าเริ่มต้น (sanitizeForCinemas / sanitizeForFilmLovers)
|
||||
*/
|
||||
export function ArticleEditor({
|
||||
value,
|
||||
defaults,
|
||||
onChange,
|
||||
onSave,
|
||||
saving,
|
||||
saveLabel,
|
||||
}: ArticleEditorProps) {
|
||||
const [locale, setLocale] = useState<Locale>("th");
|
||||
const current = value[locale];
|
||||
|
||||
/** อัปเดตฟิลด์ระดับหน้า (title/lead/contact… หรือทั้งรายการ blocks) */
|
||||
function patch(next: Partial<ArticleContent>) {
|
||||
onChange({ ...value, [locale]: { ...current, ...next } });
|
||||
}
|
||||
|
||||
/** แทนที่บล็อกตำแหน่งที่ index — ชนิดของบล็อกถูกต้องเสมอ เพราะผู้เรียกส่งมาทั้งก้อน */
|
||||
function replaceBlock(index: number, next: ArticleBlock) {
|
||||
patch({
|
||||
blocks: current.blocks.map((block, i) => (i === index ? next : block)),
|
||||
});
|
||||
}
|
||||
|
||||
function restoreDefaults() {
|
||||
onChange({ ...value, [locale]: defaults[locale] });
|
||||
}
|
||||
|
||||
const images = countImages(current.blocks);
|
||||
const paragraphs = current.blocks.length - images;
|
||||
|
||||
return (
|
||||
<div className="px-6 py-5">
|
||||
<div className="mb-4 flex flex-wrap items-center justify-between gap-3">
|
||||
<div
|
||||
role="tablist"
|
||||
aria-label="ภาษา"
|
||||
className="flex items-center gap-1 rounded-lg border border-[#242424] bg-[#141414] p-1"
|
||||
>
|
||||
{LOCALE_TABS.map((tab) => (
|
||||
<button
|
||||
key={tab.code}
|
||||
type="button"
|
||||
role="tab"
|
||||
aria-selected={locale === tab.code}
|
||||
onClick={() => setLocale(tab.code)}
|
||||
className={`min-h-9 rounded-md px-4 text-sm transition ${
|
||||
locale === tab.code
|
||||
? "bg-[#242424] font-semibold text-[#D47272]"
|
||||
: "text-[#999] hover:text-white"
|
||||
}`}
|
||||
>
|
||||
{tab.label}
|
||||
</button>
|
||||
))}
|
||||
</div>
|
||||
|
||||
<div className="flex flex-wrap items-center gap-2">
|
||||
<span className="text-xs text-[#999]">
|
||||
{paragraphs} ย่อหน้า · {images} รูป
|
||||
</span>
|
||||
<button
|
||||
type="button"
|
||||
className={secondaryButtonClass}
|
||||
onClick={restoreDefaults}
|
||||
>
|
||||
คืนค่าตั้งต้น ({locale.toUpperCase()})
|
||||
</button>
|
||||
<button
|
||||
type="button"
|
||||
className={primaryButtonClass}
|
||||
onClick={onSave}
|
||||
disabled={saving}
|
||||
>
|
||||
{saving ? "กำลังบันทึก…" : saveLabel}
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div className="grid gap-4 lg:grid-cols-2">
|
||||
<label className={labelClass}>
|
||||
หัวเรื่อง (H1)
|
||||
<input
|
||||
value={current.title}
|
||||
onChange={(event) => patch({ title: event.target.value })}
|
||||
placeholder="สำหรับคนทำโรงหนัง"
|
||||
className={inputClass}
|
||||
/>
|
||||
{current.title.trim() === "" ? (
|
||||
<span className="text-[#D47272]">เว้นว่างไม่ได้ — ระบบจะใช้ค่าเดิม</span>
|
||||
) : null}
|
||||
</label>
|
||||
|
||||
<label className={labelClass}>
|
||||
คำเกริ่นนำ (แสดงใต้หัวเรื่อง)
|
||||
<textarea
|
||||
value={current.lead}
|
||||
onChange={(event) => patch({ lead: event.target.value })}
|
||||
rows={3}
|
||||
className={inputClass}
|
||||
/>
|
||||
</label>
|
||||
</div>
|
||||
|
||||
<div className="mt-6 flex flex-col gap-3">
|
||||
<div className="flex flex-wrap items-center justify-between gap-2">
|
||||
<h3 className="text-sm font-semibold text-white">เนื้อหาบทความ</h3>
|
||||
<div className="flex flex-wrap gap-2">
|
||||
<button
|
||||
type="button"
|
||||
className={secondaryButtonClass}
|
||||
onClick={() =>
|
||||
patch({ blocks: [...current.blocks, createParagraphBlock()] })
|
||||
}
|
||||
>
|
||||
+ เพิ่มย่อหน้า
|
||||
</button>
|
||||
<button
|
||||
type="button"
|
||||
className={secondaryButtonClass}
|
||||
onClick={() =>
|
||||
patch({ blocks: [...current.blocks, createImageBlock()] })
|
||||
}
|
||||
>
|
||||
+ เพิ่มรูปภาพ
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
{current.blocks.length === 0 ? (
|
||||
<p className="rounded-lg border border-dashed border-[#303030] p-6 text-center text-sm text-[#999]">
|
||||
ยังไม่มีเนื้อหา — กด “เพิ่มย่อหน้า” หรือ “เพิ่มรูปภาพ” เพื่อเริ่มเขียน
|
||||
</p>
|
||||
) : null}
|
||||
|
||||
{current.blocks.map((block, index) => (
|
||||
<ArticleBlockCard
|
||||
key={`${block.type}-${index}`}
|
||||
block={block}
|
||||
index={index}
|
||||
total={current.blocks.length}
|
||||
onChange={(next) => replaceBlock(index, next)}
|
||||
onMove={(direction) =>
|
||||
patch({ blocks: moveBlock(current.blocks, index, direction) })
|
||||
}
|
||||
onRemove={() =>
|
||||
patch({ blocks: removeBlock(current.blocks, index) })
|
||||
}
|
||||
/>
|
||||
))}
|
||||
</div>
|
||||
|
||||
<div className="mt-6 grid gap-4 lg:grid-cols-2">
|
||||
<label className={labelClass}>
|
||||
หัวข้อการ์ดติดต่อ
|
||||
<input
|
||||
value={current.contactHeading}
|
||||
onChange={(event) => patch({ contactHeading: event.target.value })}
|
||||
className={inputClass}
|
||||
/>
|
||||
</label>
|
||||
<label className={labelClass}>
|
||||
ข้อความในการ์ดติดต่อ
|
||||
<textarea
|
||||
value={current.contactNote}
|
||||
onChange={(event) => patch({ contactNote: event.target.value })}
|
||||
rows={3}
|
||||
className={inputClass}
|
||||
/>
|
||||
</label>
|
||||
</div>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
@@ -0,0 +1,21 @@
|
||||
/**
|
||||
* คลาสฟอร์มที่ใช้ร่วมทุกแท็บของหลังบ้าน
|
||||
* อยู่ที่เดียวเพื่อให้หน้าตาเหมือนกันหมด และแก้สไตล์ครั้งเดียวมีผลทุกที่
|
||||
* (ห้ามประกาศ inputClass/labelClass ซ้ำใน component)
|
||||
*/
|
||||
export const inputClass =
|
||||
"w-full rounded-lg border border-[#303030] bg-[#141414] px-3 py-2 text-sm text-white outline-none transition focus:border-[#A92626] focus-visible:ring-2 focus-visible:ring-[#A92626]/40";
|
||||
|
||||
export const labelClass = "flex flex-col gap-1.5 text-xs text-[#999]";
|
||||
|
||||
/** ปุ่มหลัก — ใช้กับการกระทำที่ต้องการให้เด่น (เช่น บันทึก) */
|
||||
export const primaryButtonClass =
|
||||
"min-h-11 rounded-lg bg-[#8F0808] px-4 text-sm font-medium transition hover:bg-[#a30a0a] focus-visible:outline focus-visible:outline-2 focus-visible:outline-[#D47272]";
|
||||
|
||||
/** ปุ่มรอง — ใช้กับการกระทำทั่วไป (เช่น เพิ่มบล็อก/คืนค่าตั้งต้น) */
|
||||
export const secondaryButtonClass =
|
||||
"min-h-11 rounded-lg border border-[#303030] px-3 text-sm transition hover:border-[#A92626] hover:text-[#D47272] focus-visible:outline focus-visible:outline-2 focus-visible:outline-[#A92626]";
|
||||
|
||||
/** ปุ่มขนาดกะทัดรัด — ใช้กับเครื่องมือในแต่ละบล็อก (↑ ↓ ลบ) */
|
||||
export const compactButtonClass =
|
||||
"min-h-9 rounded-lg border border-[#303030] px-2.5 text-sm text-[#B3B3B3] transition hover:border-[#A92626] hover:text-[#D47272] focus-visible:outline focus-visible:outline-2 focus-visible:outline-[#A92626] disabled:opacity-40";
|
||||
@@ -1,8 +1,8 @@
|
||||
import { IconChevronLeft, IconChevronRight } from "@tabler/icons-react";
|
||||
import type { ReactNode } from "react";
|
||||
import { useState, type ReactNode } from "react";
|
||||
|
||||
import { Logo } from "@/components/site/Logo";
|
||||
import { splitGallery } from "@/lib/gallery";
|
||||
import { rotateGallery, splitGallery } from "@/lib/gallery";
|
||||
import { useI18n } from "@/lib/i18n";
|
||||
|
||||
type GalleryProps = {
|
||||
@@ -38,52 +38,71 @@ function GallerySlot({ photo, alt, placeholder, className }: GallerySlotProps) {
|
||||
);
|
||||
}
|
||||
|
||||
/** แกลเลอรีภาพโรงหนัง — ป้าย "+N" คำนวณจากจำนวนรูปจริงในข้อมูล */
|
||||
/** แกลเลอรีภาพโรงหนัง — ปุ่มลูกศรเลื่อนดูภาพทั้งหมดโดยภาพหลักและภาพย่อยเลื่อนตามกัน */
|
||||
export function Gallery({ photos, cinemaName }: GalleryProps) {
|
||||
const { messages } = useI18n();
|
||||
const { main, thumbs, remaining } = splitGallery(photos);
|
||||
const [startIndex, setStartIndex] = useState(0);
|
||||
const total = photos.length;
|
||||
// หมุนรายการตามตำแหน่งที่เลือก แล้วแบ่งเป็นภาพหลัก + ภาพย่อยตามเดิม
|
||||
const { main, thumbs, remaining } = splitGallery(
|
||||
rotateGallery(photos, startIndex),
|
||||
);
|
||||
const [firstThumb = null, secondThumb = null] = thumbs;
|
||||
const canNavigate = total > 1;
|
||||
|
||||
function step(direction: 1 | -1) {
|
||||
setStartIndex((current) => current + direction);
|
||||
}
|
||||
|
||||
return (
|
||||
<section className="grid gap-6 lg:grid-cols-[minmax(0,807px)_minmax(0,387px)]">
|
||||
<div className="relative overflow-hidden rounded-xl">
|
||||
<GallerySlot
|
||||
key={`main-${main ?? "empty"}`}
|
||||
photo={main}
|
||||
alt={`${messages.gallery.main} — ${cinemaName}`}
|
||||
placeholder={<Logo size="md" />}
|
||||
className="aspect-[269/202] w-full lg:aspect-auto lg:h-[606px]"
|
||||
className="fx-swap aspect-[269/202] w-full lg:aspect-auto lg:h-[606px]"
|
||||
/>
|
||||
<button
|
||||
type="button"
|
||||
aria-label={messages.gallery.previous}
|
||||
className="absolute left-6 top-1/2 flex size-10 -translate-y-1/2 items-center justify-center rounded-full bg-black/50"
|
||||
>
|
||||
<IconChevronLeft size={24} />
|
||||
</button>
|
||||
<button
|
||||
type="button"
|
||||
aria-label={messages.gallery.next}
|
||||
className="absolute right-6 top-1/2 flex size-10 -translate-y-1/2 items-center justify-center rounded-full bg-black/50"
|
||||
>
|
||||
<IconChevronRight size={24} />
|
||||
</button>
|
||||
{canNavigate ? (
|
||||
<>
|
||||
<button
|
||||
type="button"
|
||||
onClick={() => step(-1)}
|
||||
aria-label={messages.gallery.previous}
|
||||
className="absolute left-6 top-1/2 flex size-10 -translate-y-1/2 items-center justify-center rounded-full bg-black/50 text-white transition after:absolute after:-inset-1 after:content-[''] hover:bg-black/75 focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-[#A92626] active:scale-95"
|
||||
>
|
||||
<IconChevronLeft size={24} />
|
||||
</button>
|
||||
<button
|
||||
type="button"
|
||||
onClick={() => step(1)}
|
||||
aria-label={messages.gallery.next}
|
||||
className="absolute right-6 top-1/2 flex size-10 -translate-y-1/2 items-center justify-center rounded-full bg-black/50 text-white transition after:absolute after:-inset-1 after:content-[''] hover:bg-black/75 focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-[#A92626] active:scale-95"
|
||||
>
|
||||
<IconChevronRight size={24} />
|
||||
</button>
|
||||
</>
|
||||
) : null}
|
||||
</div>
|
||||
|
||||
<div className="grid grid-cols-2 gap-6 lg:grid-cols-1 lg:grid-rows-2">
|
||||
<div className="overflow-hidden rounded-xl">
|
||||
<GallerySlot
|
||||
key={`thumb-1-${firstThumb ?? "empty"}`}
|
||||
photo={firstThumb}
|
||||
alt={`${messages.gallery.second} — ${cinemaName}`}
|
||||
placeholder={<Logo size="sm" />}
|
||||
className="aspect-[387/290] w-full"
|
||||
className="fx-swap aspect-[387/290] w-full"
|
||||
/>
|
||||
</div>
|
||||
<div className="relative overflow-hidden rounded-xl">
|
||||
<GallerySlot
|
||||
key={`thumb-2-${secondThumb ?? "empty"}`}
|
||||
photo={secondThumb}
|
||||
alt={`${messages.gallery.third} — ${cinemaName}`}
|
||||
placeholder={<Logo size="sm" />}
|
||||
className="aspect-[387/290] w-full"
|
||||
className="fx-swap aspect-[387/290] w-full"
|
||||
/>
|
||||
{remaining > 0 ? (
|
||||
<div className="absolute bottom-2.5 right-2.5 flex size-[60px] items-center justify-center rounded-lg bg-black/80 text-lg font-medium">
|
||||
|
||||
@@ -1,5 +1,7 @@
|
||||
import { IconCircleCheck, IconMapPin, IconSearch } from "@tabler/icons-react";
|
||||
import { useRef, type FormEvent } from "react";
|
||||
|
||||
import { Reveal } from "@/components/site/Reveal";
|
||||
import type { NearMeStatus } from "@/hooks/use-near-me";
|
||||
import { useI18n } from "@/lib/i18n";
|
||||
|
||||
@@ -8,10 +10,15 @@ type HeroSectionProps = {
|
||||
onQueryChange: (query: string) => void;
|
||||
nearMeStatus: NearMeStatus;
|
||||
onRequestLocation: () => void;
|
||||
/** เรียกเมื่อผู้ใช้กดปุ่ม "ค้นหา" หรือกด Enter — ใช้เลื่อนไปที่ผลลัพธ์ (การกรองยังทำงานสดขณะพิมพ์) */
|
||||
onSubmitSearch: () => void;
|
||||
};
|
||||
|
||||
/** ข้อความสถานะของปุ่ม "ใกล้ฉัน" — แสดงเฉพาะตอนกำลังหา/ผิดพลาด/พร้อมใช้ */
|
||||
function statusMessage(status: NearMeStatus, messages: ReturnType<typeof useI18n>["messages"]) {
|
||||
function statusMessage(
|
||||
status: NearMeStatus,
|
||||
messages: ReturnType<typeof useI18n>["messages"],
|
||||
) {
|
||||
switch (status) {
|
||||
case "locating":
|
||||
return messages.search.locating;
|
||||
@@ -34,38 +41,63 @@ export function HeroSection({
|
||||
onQueryChange,
|
||||
nearMeStatus,
|
||||
onRequestLocation,
|
||||
onSubmitSearch,
|
||||
}: HeroSectionProps) {
|
||||
const { messages } = useI18n();
|
||||
const status = statusMessage(nearMeStatus, messages);
|
||||
const isReady = nearMeStatus === "ready";
|
||||
const inputRef = useRef<HTMLInputElement>(null);
|
||||
|
||||
/**
|
||||
* ปุ่ม "ค้นหา" / Enter — ไม่ได้ทำหน้าที่กรอง (กรองสดอยู่แล้วใน onChange)
|
||||
* หน้าที่คือ: กันหน้าโหลดใหม่, ปิดคีย์บอร์ดมือถือ, แล้วเลื่อนไปที่ผลลัพธ์
|
||||
*/
|
||||
function handleSubmit(event: FormEvent<HTMLFormElement>) {
|
||||
event.preventDefault();
|
||||
inputRef.current?.blur();
|
||||
onSubmitSearch();
|
||||
}
|
||||
|
||||
return (
|
||||
<section className="mx-auto flex max-w-[1016px] flex-col items-center gap-10 pt-24 md:pt-[167px]">
|
||||
<div className="flex max-w-[745px] flex-col items-center gap-4 text-center">
|
||||
<Reveal
|
||||
delay={60}
|
||||
className="flex max-w-[745px] flex-col items-center gap-4 text-center"
|
||||
>
|
||||
<h1 className="text-4xl font-bold leading-[1.3] md:text-[56px]">
|
||||
{messages.hero.titlePrefix}
|
||||
<span className="text-[#A92626]">{messages.hero.titleHighlight}</span>
|
||||
<span className="text-[#D47272]">{messages.hero.titleHighlight}</span>
|
||||
{messages.hero.titleSuffix}
|
||||
</h1>
|
||||
<p className="text-base md:text-xl">{messages.hero.subtitle}</p>
|
||||
</div>
|
||||
</Reveal>
|
||||
|
||||
<div className="w-full rounded-2xl border border-[#303030] bg-[#1B1B1B]/80 px-4 py-6 backdrop-blur-[32px] md:px-10">
|
||||
<div className="flex h-14 items-center gap-3 rounded-lg border border-[#1B1B1B] bg-[#1F1F1F] px-5">
|
||||
<Reveal
|
||||
delay={200}
|
||||
className="w-full rounded-2xl border border-[#303030] bg-[#1B1B1B]/80 px-4 py-6 backdrop-blur-[32px] md:px-10"
|
||||
>
|
||||
<form
|
||||
role="search"
|
||||
onSubmit={handleSubmit}
|
||||
className="flex h-14 items-center gap-3 rounded-lg border border-[#1B1B1B] bg-[#1F1F1F] px-5 transition-colors duration-300 focus-within:border-[#A92626]/70"
|
||||
>
|
||||
<IconSearch size={16} className="shrink-0 text-[#999]" />
|
||||
<input
|
||||
ref={inputRef}
|
||||
value={query}
|
||||
onChange={(event) => onQueryChange(event.target.value)}
|
||||
placeholder={messages.search.placeholder}
|
||||
aria-label={messages.search.placeholder}
|
||||
className="min-w-0 flex-1 bg-transparent text-sm text-white outline-none placeholder:text-[#454545]"
|
||||
type="search"
|
||||
enterKeyHint="search"
|
||||
className="min-w-0 flex-1 bg-transparent text-sm text-white outline-none placeholder:text-[#8A8A8A] [&::-webkit-search-cancel-button]:hidden"
|
||||
/>
|
||||
<button
|
||||
type="button"
|
||||
onClick={onRequestLocation}
|
||||
disabled={nearMeStatus === "locating"}
|
||||
aria-label={messages.search.nearMe}
|
||||
className={`hidden items-center gap-2 border-l border-[#999] px-4 text-sm transition disabled:opacity-60 sm:flex ${
|
||||
className={`relative hidden items-center gap-2 border-l border-[#999] px-4 text-sm transition after:absolute after:-inset-y-3 after:inset-x-0 after:content-[''] disabled:opacity-60 sm:flex ${
|
||||
isReady ? "text-[#D47272]" : "text-[#999] hover:text-white"
|
||||
}`}
|
||||
>
|
||||
@@ -73,12 +105,12 @@ export function HeroSection({
|
||||
{messages.search.nearMe}
|
||||
</button>
|
||||
<button
|
||||
type="button"
|
||||
className="h-8 rounded-lg border border-[#8F0808] bg-[#8F0808] px-6 text-sm font-medium transition hover:bg-[#a30a0a]"
|
||||
type="submit"
|
||||
className="relative h-8 rounded-lg border border-[#8F0808] bg-[#8F0808] px-6 text-sm font-medium transition after:absolute after:-inset-y-1.5 after:-inset-x-1 after:content-[''] hover:bg-[#a30a0a]"
|
||||
>
|
||||
{messages.search.submit}
|
||||
</button>
|
||||
</div>
|
||||
</form>
|
||||
|
||||
{status ? (
|
||||
<p
|
||||
@@ -91,7 +123,7 @@ export function HeroSection({
|
||||
{status}
|
||||
</p>
|
||||
) : null}
|
||||
</div>
|
||||
</Reveal>
|
||||
</section>
|
||||
);
|
||||
}
|
||||
@@ -0,0 +1,139 @@
|
||||
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 { useContent } from "@/lib/content-context";
|
||||
import type { ArticleBlock, ArticleContent } from "@/lib/content-types";
|
||||
|
||||
/** บล็อกบทความหนึ่งชิ้น — ย่อหน้าหรือรูป (รูปมีคำบรรยายได้) */
|
||||
function ArticleBlockView({
|
||||
block,
|
||||
index,
|
||||
}: {
|
||||
block: ArticleBlock;
|
||||
index: number;
|
||||
}) {
|
||||
// ไล่จังหวะแบบสั้น ๆ แต่ไม่เกิน 3 บล็อกแรก (บล็อกท้าย ๆ จะได้ไม่รอนาน)
|
||||
const delay = 100 + Math.min(index, 3) * 60;
|
||||
|
||||
if (block.type === "image") {
|
||||
return (
|
||||
<Reveal delay={delay}>
|
||||
<figure className="flex flex-col gap-2">
|
||||
<img
|
||||
src={block.src}
|
||||
alt={block.alt}
|
||||
loading="lazy"
|
||||
className="w-full rounded-xl bg-[#242424] object-cover"
|
||||
/>
|
||||
{block.caption ? (
|
||||
<figcaption className="font-content text-[14px] leading-[1.7] text-[#999]">
|
||||
{block.caption}
|
||||
</figcaption>
|
||||
) : null}
|
||||
</figure>
|
||||
</Reveal>
|
||||
);
|
||||
}
|
||||
|
||||
return (
|
||||
<Reveal delay={delay}>
|
||||
<p className="font-content max-w-[860px] text-[18px] leading-[1.95] text-[#C7C7C7] md:text-[20px]">
|
||||
{block.text}
|
||||
</p>
|
||||
</Reveal>
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* โครงหน้าบทความที่ใช้ร่วมกัน (สำหรับคนทำโรงหนัง / สำหรับคนรักหนัง)
|
||||
* ภาษาภาพเดียวกับหน้า "เกี่ยวกับเรา": กรอบ 1440 + px-[108px], ฟอนต์เนื้อหา IBM Plex Sans Thai Looped,
|
||||
* การ์ดติดต่อไล่แดงขอบ rgba(169,38,38,0.45) และไอคอนโซเชียลชุดเดียวกับ footer
|
||||
*/
|
||||
export function ArticlePage({
|
||||
content,
|
||||
backLabel,
|
||||
}: {
|
||||
content: ArticleContent;
|
||||
backLabel: string;
|
||||
}) {
|
||||
const { site } = useContent();
|
||||
|
||||
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} />
|
||||
{backLabel}
|
||||
</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>
|
||||
|
||||
<article className="flex flex-col gap-7">
|
||||
{content.blocks.map((block, index) => (
|
||||
<ArticleBlockView
|
||||
key={`${block.type}-${index}`}
|
||||
block={block}
|
||||
index={index}
|
||||
/>
|
||||
))}
|
||||
</article>
|
||||
|
||||
<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>
|
||||
);
|
||||
}
|
||||
@@ -5,6 +5,10 @@ import {
|
||||
} from "@tabler/icons-react";
|
||||
import { Link } from "react-router";
|
||||
|
||||
import { ShareButton } from "@/components/site/ShareButton";
|
||||
import { useNearMe } from "@/hooks/use-near-me";
|
||||
import { useReveal } from "@/hooks/use-reveal";
|
||||
import { trackEvent } from "@/lib/analytics-client";
|
||||
import {
|
||||
CARD_GRADIENTS,
|
||||
cinemaCategoryLabel,
|
||||
@@ -13,8 +17,6 @@ import {
|
||||
type Cinema,
|
||||
} from "@/lib/cinemas";
|
||||
import { formatDistance } from "@/lib/geo";
|
||||
import { trackEvent } from "@/lib/analytics-client";
|
||||
import { useNearMe } from "@/hooks/use-near-me";
|
||||
import { useI18n } from "@/lib/i18n";
|
||||
|
||||
type CinemaCardProps = {
|
||||
@@ -43,9 +45,18 @@ export function CinemaCard({
|
||||
messages.card.distanceFallback,
|
||||
);
|
||||
|
||||
// ไล่จังหวะโผล่ทีละใบตามคอลัมน์ (เริ่มหลังหัวข้อ/หมวด เพื่อให้ดูเป็นลำดับ)
|
||||
const { ref, revealed, style } = useReveal<HTMLElement>(
|
||||
140 + (index % 4) * 70,
|
||||
);
|
||||
|
||||
return (
|
||||
<article
|
||||
className={`relative flex aspect-[3/4] flex-col justify-end overflow-hidden rounded-[20px] bg-gradient-to-br p-2 lg:aspect-auto lg:h-[308px] ${gradient}`}
|
||||
ref={ref}
|
||||
data-reveal="zoom"
|
||||
data-revealed={revealed ? "" : undefined}
|
||||
style={style}
|
||||
className={`group relative flex aspect-[3/4] flex-col justify-end overflow-hidden rounded-[20px] bg-gradient-to-br p-2 transition-[translate,box-shadow] duration-300 ease-out hover:-translate-y-1 hover:shadow-[0_18px_38px_-24px_rgba(143,8,8,0.75)] lg:aspect-auto lg:h-[308px] ${gradient}`}
|
||||
>
|
||||
{cover ? (
|
||||
<>
|
||||
@@ -54,7 +65,7 @@ export function CinemaCard({
|
||||
alt=""
|
||||
aria-hidden="true"
|
||||
loading="lazy"
|
||||
className="absolute inset-0 size-full object-cover"
|
||||
className="absolute inset-0 size-full object-cover transition-transform duration-700 ease-out group-hover:scale-[1.06]"
|
||||
/>
|
||||
{/* ไล่เงาเพื่อให้ตัวอักษรบนการ์ดอ่านได้ */}
|
||||
<div
|
||||
@@ -64,12 +75,18 @@ export function CinemaCard({
|
||||
</>
|
||||
) : null}
|
||||
|
||||
<div className="relative flex flex-col gap-1.5 rounded-2xl border border-white/10 bg-[#1B1B1B]/80 p-3 backdrop-blur-xl">
|
||||
{/* ปุ่มแชร์ลอยมุมขวาบนของการ์ด */}
|
||||
<div className="absolute right-3 top-3 z-10">
|
||||
<ShareButton slug={cinema.slug} title={cinemaName(cinema, locale)} />
|
||||
</div>
|
||||
|
||||
<div className="relative flex flex-col gap-1.5 rounded-2xl border border-white/10 bg-[#1B1B1B]/80 p-3 backdrop-blur-xl transition-colors duration-300 group-hover:border-[#A92626]/40">
|
||||
<span className="text-[10px] text-[#B3B3B3]">{distanceLabel}</span>
|
||||
<h3 className="text-sm font-semibold">{cinemaName(cinema, locale)}</h3>
|
||||
<p className="flex items-center gap-1.5 text-xs text-[#B3B3B3]">
|
||||
<IconMapPin size={12} />
|
||||
{cinemaLocationLabel(cinema, locale) || messages.card.locationFallback}
|
||||
{cinemaLocationLabel(cinema, locale) ||
|
||||
messages.card.locationFallback}
|
||||
</p>
|
||||
<p className="flex items-center gap-1.5 text-xs text-[#B3B3B3]">
|
||||
<IconBuildingCommunity size={12} />
|
||||
|
||||
@@ -51,11 +51,11 @@ export function CategoryFilter({
|
||||
type="button"
|
||||
onClick={() => onChange(category)}
|
||||
aria-pressed={isActive}
|
||||
className={
|
||||
className={`relative rounded-[18px] border px-4 py-2 text-sm after:absolute after:-inset-y-1.5 after:inset-x-0 after:content-[''] ${
|
||||
isActive
|
||||
? "rounded-[18px] border border-[#A92626] bg-gradient-to-b from-[#8F0808]/30 to-[#1B1B1B]/0 px-4 py-2 text-sm text-[#D47272]"
|
||||
: "rounded-[18px] border border-[#303030] bg-[#242424] px-4 py-2 text-sm text-[#B3B3B3] transition hover:border-[#A92626]/60"
|
||||
}
|
||||
? "border-[#A92626] bg-gradient-to-b from-[#8F0808]/30 to-[#1B1B1B]/0 text-[#D47272]"
|
||||
: "border-[#303030] bg-[#242424] text-[#B3B3B3] transition hover:border-[#A92626]/60"
|
||||
}`}
|
||||
>
|
||||
{messages.categories[category]}
|
||||
</button>
|
||||
|
||||
@@ -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>
|
||||
);
|
||||
}
|
||||
@@ -0,0 +1,40 @@
|
||||
import { Link } from "react-router";
|
||||
|
||||
/**
|
||||
* ลิงก์เมนูใน header — ใช้ร่วมทั้งแถบเดสก์ท็อปและเมนูมือถือ
|
||||
* `variant` ต่างกันเพราะเดสก์ท็อปมีกรอบ/ไอคอนสถานะ active ส่วนเมนูมือถือเป็นรายการแนวตั้ง
|
||||
*/
|
||||
export function NavLink({
|
||||
to,
|
||||
label,
|
||||
isActive,
|
||||
variant,
|
||||
}: {
|
||||
to: string;
|
||||
label: string;
|
||||
isActive: boolean;
|
||||
variant: "bar" | "panel";
|
||||
}) {
|
||||
const className =
|
||||
variant === "bar"
|
||||
? `relative flex items-center rounded-lg border px-3 py-1.5 text-sm transition after:absolute after:-inset-y-2 after:-inset-x-0.5 after:content-[''] ${
|
||||
isActive
|
||||
? "border-[#A92626] bg-[#8F0808]/20 text-white"
|
||||
: "border-[#303030] text-[#B3B3B3] hover:border-[#A92626]/60 hover:text-white"
|
||||
}`
|
||||
: `flex min-h-11 items-center rounded-lg px-3 text-sm transition ${
|
||||
isActive
|
||||
? "bg-[#242424] text-white"
|
||||
: "text-[#B3B3B3] hover:bg-[#1B1B1B] hover:text-white"
|
||||
}`;
|
||||
|
||||
return (
|
||||
<Link
|
||||
to={to}
|
||||
aria-current={isActive ? "page" : undefined}
|
||||
className={className}
|
||||
>
|
||||
{label}
|
||||
</Link>
|
||||
);
|
||||
}
|
||||
@@ -0,0 +1,41 @@
|
||||
import type { ReactNode } from "react";
|
||||
|
||||
import { useReveal } from "@/hooks/use-reveal";
|
||||
import type { RevealKind } from "@/lib/motion";
|
||||
|
||||
type RevealProps = {
|
||||
children: ReactNode;
|
||||
/** rise = เลื่อนขึ้นเบา ๆ (ค่าตั้งต้น) · fade = จางเข้าอย่างเดียว · zoom = ขยายเล็กน้อย */
|
||||
kind?: RevealKind;
|
||||
/** หน่วงก่อนเริ่ม (ms) — ใช้ทำจังหวะไล่กันในกริด/คอลัมน์ */
|
||||
delay?: number;
|
||||
className?: string;
|
||||
};
|
||||
|
||||
/**
|
||||
* ห่อบล็อกให้ "ค่อย ๆ โผล่" เมื่อเลื่อนมาถึง
|
||||
*
|
||||
* ใช้ `data-revealed` เป็น attribute ว่าง (ไม่ใช่ boolean) เพราะ CSS เลือกด้วย
|
||||
* selector `[data-revealed]` ใน global.css
|
||||
* เป็น <div> ธรรมดา — ใช้ในบริบท block/flex/grid เท่านั้น (ไม่ใช้กับ inline)
|
||||
*/
|
||||
export function Reveal({
|
||||
children,
|
||||
kind = "rise",
|
||||
delay = 0,
|
||||
className,
|
||||
}: RevealProps) {
|
||||
const { ref, revealed, style } = useReveal<HTMLDivElement>(delay);
|
||||
|
||||
return (
|
||||
<div
|
||||
ref={ref}
|
||||
data-reveal={kind}
|
||||
data-revealed={revealed ? "" : undefined}
|
||||
style={style}
|
||||
className={className}
|
||||
>
|
||||
{children}
|
||||
</div>
|
||||
);
|
||||
}
|
||||
@@ -0,0 +1,129 @@
|
||||
import { IconCheck, IconShare } from "@tabler/icons-react";
|
||||
import {
|
||||
useEffect,
|
||||
useRef,
|
||||
useState,
|
||||
type MouseEvent as ReactMouseEvent,
|
||||
} from "react";
|
||||
|
||||
import { useI18n } from "@/lib/i18n";
|
||||
import {
|
||||
buildShareUrl,
|
||||
buildShortSharePath,
|
||||
resolveShareOrigin,
|
||||
shareOrCopy,
|
||||
type ShareResult,
|
||||
} from "@/lib/share";
|
||||
import { useShareOrigin } from "@/lib/share-origin";
|
||||
|
||||
type ShareButtonProps = {
|
||||
/** slug ของโรงหนัง — ใช้สร้างลิงก์ย่อ `/c/<slug>` */
|
||||
slug: string;
|
||||
/** ชื่อที่ส่งให้แผงแชร์ของระบบ */
|
||||
title: string;
|
||||
/** `icon` = ปุ่มกลมบนการ์ด · `wide` = ปุ่มมีข้อความ (ใช้ท้ายหน้ารายละเอียด) */
|
||||
variant?: "icon" | "wide";
|
||||
};
|
||||
|
||||
/**
|
||||
* ปุ่มแชร์โรงหนัง — ลิงก์ย่อ `/c/<slug>` บนโดเมนที่ตั้งใน env `SHARE_ORIGIN`
|
||||
* - มี Web Share (มือถือ) → เปิดแผงแชร์ของระบบ และคัดลอกลิงก์สำรองให้ด้วย
|
||||
* - ไม่มี → คัดลอกลิงก์ลงคลิปบอร์ด แล้วบอกผลผ่าน aria-live
|
||||
*/
|
||||
export function ShareButton({
|
||||
slug,
|
||||
title,
|
||||
variant = "icon",
|
||||
}: ShareButtonProps) {
|
||||
const { messages } = useI18n();
|
||||
const configuredOrigin = useShareOrigin();
|
||||
const [result, setResult] = useState<ShareResult | null>(null);
|
||||
const timerRef = useRef<ReturnType<typeof setTimeout> | null>(null);
|
||||
|
||||
// ล้างตัวจับเวลาเมื่อ unmount กัน state อัปเดตหลัง component ถูกถอด
|
||||
useEffect(() => {
|
||||
return () => {
|
||||
if (timerRef.current) clearTimeout(timerRef.current);
|
||||
};
|
||||
}, []);
|
||||
|
||||
async function handleClick(event: ReactMouseEvent<HTMLButtonElement>) {
|
||||
// กันการ์ดที่ห่ออยู่ถูกคลิกตาม (การ์ดมีลิงก์ "ดูรายละเอียด" ข้างใน)
|
||||
event.preventDefault();
|
||||
event.stopPropagation();
|
||||
|
||||
const url = buildShareUrl(
|
||||
resolveShareOrigin(configuredOrigin, window.location.origin),
|
||||
buildShortSharePath(slug),
|
||||
);
|
||||
const next = await shareOrCopy({ title, url });
|
||||
setResult(next);
|
||||
|
||||
if (timerRef.current) clearTimeout(timerRef.current);
|
||||
timerRef.current = setTimeout(() => setResult(null), 2500);
|
||||
}
|
||||
|
||||
const isCopy = result === "copied" || result === "shared";
|
||||
const label =
|
||||
result === "failed"
|
||||
? messages.share.failed
|
||||
: isCopy
|
||||
? messages.share.copied
|
||||
: variant === "wide"
|
||||
? messages.share.pageLabel
|
||||
: messages.share.label;
|
||||
|
||||
const icon = isCopy ? <IconCheck size={16} /> : <IconShare size={16} />;
|
||||
|
||||
if (variant === "wide") {
|
||||
return (
|
||||
<div className="flex flex-wrap items-center gap-3">
|
||||
<button
|
||||
type="button"
|
||||
onClick={handleClick}
|
||||
title={title}
|
||||
className={`flex min-h-11 items-center gap-2 rounded-lg border px-4 text-sm backdrop-blur transition focus-visible:outline focus-visible:outline-2 focus-visible:outline-[#A92626] ${
|
||||
result === "failed"
|
||||
? "border-[#A92626]/60 bg-[#1B1B1B]/80 text-[#D47272]"
|
||||
: isCopy
|
||||
? "border-[#D47272]/50 bg-[#1B1B1B]/80 text-[#D47272]"
|
||||
: "border-[#332B2B] bg-[#1B1B1B]/80 text-white hover:border-[#A92626]/60 hover:bg-[#242424]"
|
||||
}`}
|
||||
>
|
||||
{icon}
|
||||
{label}
|
||||
</button>
|
||||
<span
|
||||
role="status"
|
||||
aria-live="polite"
|
||||
className="text-xs text-[#B3B3B3]"
|
||||
>
|
||||
{result ? label : ""}
|
||||
</span>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
return (
|
||||
<div className="relative">
|
||||
<button
|
||||
type="button"
|
||||
onClick={handleClick}
|
||||
aria-label={`${messages.share.label}: ${title}`}
|
||||
title={messages.share.label}
|
||||
className={`relative flex size-9 items-center justify-center rounded-xl border backdrop-blur-xl transition after:absolute after:-inset-1.5 after:content-[''] focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-[#A92626] active:scale-95 ${
|
||||
result === "failed"
|
||||
? "border-[#A92626]/60 bg-[#1B1B1B]/80 text-[#D47272]"
|
||||
: isCopy
|
||||
? "border-[#D47272]/50 bg-[#1B1B1B]/80 text-[#D47272]"
|
||||
: "border-white/10 bg-[#1B1B1B]/80 text-white hover:border-[#A92626]/60 hover:bg-[#242424] hover:text-[#D47272]"
|
||||
}`}
|
||||
>
|
||||
{icon}
|
||||
</button>
|
||||
<span role="status" aria-live="polite" className="sr-only">
|
||||
{result ? label : ""}
|
||||
</span>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
@@ -1,7 +1,7 @@
|
||||
import { Link } from "react-router";
|
||||
|
||||
import { Logo } from "@/components/site/Logo";
|
||||
import { footerIcon } from "@/components/site/footer-icons";
|
||||
import { Logo } from "@/components/site/Logo";
|
||||
import { useContent } from "@/lib/content-context";
|
||||
import { useI18n } from "@/lib/i18n";
|
||||
|
||||
@@ -19,6 +19,18 @@ export function SiteFooter() {
|
||||
<div className="flex items-center gap-4">
|
||||
<Logo size="sm" />
|
||||
<nav aria-label="เมนูล่าง" className="flex items-center gap-3 text-xs">
|
||||
<Link
|
||||
to="/for-film-lovers"
|
||||
className="text-[#B3B3B3] transition hover:text-white"
|
||||
>
|
||||
{messages.nav.forFilmLovers}
|
||||
</Link>
|
||||
<Link
|
||||
to="/for-cinemas"
|
||||
className="text-[#B3B3B3] transition hover:text-white"
|
||||
>
|
||||
{messages.nav.forCinemas}
|
||||
</Link>
|
||||
<Link
|
||||
to="/about"
|
||||
className="text-[#B3B3B3] transition hover:text-white"
|
||||
|
||||
@@ -1,7 +1,8 @@
|
||||
import { Link, useLocation } from "react-router";
|
||||
|
||||
import { Logo } from "@/components/site/Logo";
|
||||
import { LocaleSwitcher } from "@/components/site/LocaleSwitcher";
|
||||
import { Logo } from "@/components/site/Logo";
|
||||
import { NavLink } from "@/components/site/NavLink";
|
||||
import { useI18n } from "@/lib/i18n";
|
||||
|
||||
/**
|
||||
@@ -11,26 +12,61 @@ import { useI18n } from "@/lib/i18n";
|
||||
export function SiteHeader() {
|
||||
const { messages } = useI18n();
|
||||
const { pathname } = useLocation();
|
||||
const isAbout = pathname.startsWith("/about");
|
||||
|
||||
// เมนูหลัก: หน้าเฉพาะกลุ่มมาก่อน แล้วปิดท้ายด้วย "เกี่ยวกับเรา"
|
||||
const links: Array<{ to: string; label: string }> = [
|
||||
{ to: "/for-film-lovers", label: messages.nav.forFilmLovers },
|
||||
{ to: "/for-cinemas", label: messages.nav.forCinemas },
|
||||
{ to: "/about", label: messages.nav.about },
|
||||
];
|
||||
|
||||
return (
|
||||
<header className="relative z-10 mx-auto flex h-[68px] w-full max-w-[1440px] items-center justify-between gap-4 px-5 md:px-[108px]">
|
||||
<Link to="/" aria-label={`AlterFlixHub — ${messages.nav.home}`} className="shrink-0">
|
||||
<header className="fx-drop relative z-10 mx-auto flex h-[68px] w-full max-w-[1440px] items-center justify-between gap-3 px-5 md:px-[108px]">
|
||||
<Link
|
||||
to="/"
|
||||
aria-label={`AlterFlixHub — ${messages.nav.home}`}
|
||||
className="shrink-0"
|
||||
>
|
||||
<Logo />
|
||||
</Link>
|
||||
|
||||
<div className="flex items-center gap-1.5 sm:gap-2">
|
||||
<Link
|
||||
to="/about"
|
||||
aria-current={isAbout ? "page" : undefined}
|
||||
className={`rounded-lg border px-2 py-1 text-xs transition sm:px-3 sm:py-1.5 sm:text-sm ${
|
||||
isAbout
|
||||
? "border-[#A92626] bg-[#8F0808]/20 text-white"
|
||||
: "border-[#303030] text-[#B3B3B3] hover:border-[#A92626]/60 hover:text-white"
|
||||
}`}
|
||||
{/* มือถือ: เมนูพับ (ใช้ <details> เนทีฟ — คีย์บอร์ด/ปิดด้วย Esc ได้เอง) */}
|
||||
<details className="group relative sm:hidden">
|
||||
<summary className="flex min-h-10 cursor-pointer list-none items-center rounded-lg border border-[#303030] px-3 text-sm text-[#B3B3B3] transition hover:border-[#A92626]/60 hover:text-white [&::-webkit-details-marker]:hidden">
|
||||
{messages.nav.menu}
|
||||
</summary>
|
||||
<nav
|
||||
aria-label={messages.nav.menu}
|
||||
className="absolute right-0 top-[calc(100%+8px)] z-20 flex w-[220px] flex-col gap-1 rounded-xl border border-[#303030] bg-[#141414] p-2 shadow-lg"
|
||||
>
|
||||
{links.map((link) => (
|
||||
<NavLink
|
||||
key={link.to}
|
||||
to={link.to}
|
||||
label={link.label}
|
||||
isActive={pathname.startsWith(link.to)}
|
||||
variant="panel"
|
||||
/>
|
||||
))}
|
||||
</nav>
|
||||
</details>
|
||||
|
||||
{/* เดสก์ท็อป: ลิงก์ตรงทั้งสามหน้า */}
|
||||
<nav
|
||||
aria-label={messages.nav.menu}
|
||||
className="hidden items-center gap-2 sm:flex"
|
||||
>
|
||||
{messages.nav.about}
|
||||
</Link>
|
||||
{links.map((link) => (
|
||||
<NavLink
|
||||
key={link.to}
|
||||
to={link.to}
|
||||
label={link.label}
|
||||
isActive={pathname.startsWith(link.to)}
|
||||
variant="bar"
|
||||
/>
|
||||
))}
|
||||
</nav>
|
||||
|
||||
<LocaleSwitcher />
|
||||
</div>
|
||||
|
||||
@@ -30,7 +30,7 @@ function HomeBackdrop() {
|
||||
<img
|
||||
src={HERO_IMAGE}
|
||||
alt=""
|
||||
className="pointer-events-none absolute inset-x-0 top-0 h-[553px] w-full object-cover"
|
||||
className="fx-hero-image pointer-events-none absolute inset-x-0 top-0 h-[553px] w-full object-cover"
|
||||
/>
|
||||
<div className="pointer-events-none absolute inset-x-0 top-0 h-[553px] bg-gradient-to-b from-transparent via-[#0D0D0D]/60 to-[#0D0D0D]" />
|
||||
<div className="pointer-events-none absolute left-1/2 top-0 size-[382px] -translate-x-1/2 -translate-y-1/2 rounded-full bg-[#8F0808] blur-[237px]" />
|
||||
@@ -66,7 +66,7 @@ export function SiteShell({
|
||||
<SiteHeader />
|
||||
{/* flex-1 ดัน footer ไปท้ายจอเมื่อเนื้อหาสั้น — เป็น block ธรรมดา
|
||||
(ไม่ใช้ flex-col เพื่อไม่ให้ main ที่มี mx-auto หดเหลือ max-content จนล้นจอมือถือ) */}
|
||||
<div className="flex-1">{children}</div>
|
||||
<div className="fx-page flex-1">{children}</div>
|
||||
<SiteFooter />
|
||||
</div>
|
||||
);
|
||||
|
||||
+139
@@ -261,3 +261,142 @@
|
||||
::-webkit-scrollbar-thumb:hover {
|
||||
background: hsl(var(--muted-foreground) / 0.34);
|
||||
}
|
||||
|
||||
/* ══ Motion — อนิเมชันเล็ก ๆ ตอนโหลด/เลื่อน ═══════════════════════════════
|
||||
เปิดใช้เฉพาะเมื่อผู้ใช้ไม่ได้ขอ reduced motion: สคริปต์ใน <head> (root.tsx)
|
||||
ใส่คลาส .fx-motion ให้ <html> ก่อน paint → ไม่กระพริบ และถ้าปิด JS ไว้
|
||||
เนื้อหาก็ยังแสดงครบเพราะไม่มีคลาสนี้ = ไม่มีอะไรถูกซ่อน
|
||||
กติกา: ใช้ transform/opacity เท่านั้น (ไม่กระตุก), หน่วงไม่เกิน ~360ms */
|
||||
:root {
|
||||
--fx-fast: 160ms;
|
||||
--fx-base: 280ms;
|
||||
--fx-page: 460ms;
|
||||
--fx-slow: 640ms;
|
||||
--fx-ease-out: cubic-bezier(0.16, 1, 0.3, 1);
|
||||
}
|
||||
|
||||
@keyframes fx-rise-in {
|
||||
from {
|
||||
opacity: 0;
|
||||
transform: translate3d(0, 28px, 0);
|
||||
}
|
||||
to {
|
||||
opacity: 1;
|
||||
transform: none;
|
||||
}
|
||||
}
|
||||
|
||||
@keyframes fx-fade-in {
|
||||
from {
|
||||
opacity: 0;
|
||||
}
|
||||
to {
|
||||
opacity: 1;
|
||||
}
|
||||
}
|
||||
|
||||
@keyframes fx-pop-in {
|
||||
from {
|
||||
opacity: 0;
|
||||
transform: scale(0.965);
|
||||
}
|
||||
to {
|
||||
opacity: 1;
|
||||
transform: none;
|
||||
}
|
||||
}
|
||||
|
||||
@keyframes fx-drop-in {
|
||||
from {
|
||||
opacity: 0;
|
||||
transform: translate3d(0, -14px, 0);
|
||||
}
|
||||
to {
|
||||
opacity: 1;
|
||||
transform: none;
|
||||
}
|
||||
}
|
||||
|
||||
@keyframes fx-hero-zoom {
|
||||
from {
|
||||
opacity: 0;
|
||||
transform: scale(1.06);
|
||||
}
|
||||
to {
|
||||
opacity: 1;
|
||||
transform: none;
|
||||
}
|
||||
}
|
||||
|
||||
@keyframes fx-page-in {
|
||||
from {
|
||||
opacity: 0;
|
||||
transform: translate3d(0, 26px, 0);
|
||||
}
|
||||
to {
|
||||
opacity: 1;
|
||||
transform: none;
|
||||
}
|
||||
}
|
||||
|
||||
/* สถานะตั้งต้น: ซ่อนเฉพาะเมื่อ motion เปิดอยู่ (JS ใส่คลาสแล้วเท่านั้น) */
|
||||
html.fx-motion [data-reveal] {
|
||||
opacity: 0;
|
||||
}
|
||||
|
||||
html.fx-motion [data-reveal="rise"][data-revealed] {
|
||||
animation: fx-rise-in var(--fx-slow) var(--fx-ease-out) var(--fx-delay, 0ms)
|
||||
both;
|
||||
}
|
||||
|
||||
html.fx-motion [data-reveal="fade"][data-revealed] {
|
||||
animation: fx-fade-in var(--fx-base) var(--fx-ease-out) var(--fx-delay, 0ms)
|
||||
both;
|
||||
}
|
||||
|
||||
html.fx-motion [data-reveal="zoom"][data-revealed] {
|
||||
animation: fx-pop-in var(--fx-slow) var(--fx-ease-out) var(--fx-delay, 0ms)
|
||||
both;
|
||||
}
|
||||
|
||||
/* อนิเมชันตอนโหลด (ไม่ผูกกับ scroll) */
|
||||
html.fx-motion .fx-page {
|
||||
animation: fx-page-in var(--fx-page) var(--fx-ease-out) both;
|
||||
}
|
||||
|
||||
/* สลับภาพในแกลเลอรี (ปุ่มลูกศร) — จางเข้าเบา ๆ ไม่กระตุก */
|
||||
@keyframes fx-swap-in {
|
||||
from {
|
||||
opacity: 0;
|
||||
transform: scale(1.015);
|
||||
}
|
||||
to {
|
||||
opacity: 1;
|
||||
transform: none;
|
||||
}
|
||||
}
|
||||
|
||||
html.fx-motion .fx-swap {
|
||||
animation: fx-swap-in 320ms var(--fx-ease-out) both;
|
||||
}
|
||||
|
||||
html.fx-motion .fx-drop {
|
||||
animation: fx-drop-in var(--fx-base) var(--fx-ease-out) both;
|
||||
}
|
||||
|
||||
html.fx-motion .fx-hero-image {
|
||||
animation: fx-hero-zoom 1400ms var(--fx-ease-out) both;
|
||||
}
|
||||
|
||||
/* ทางออกสุดท้าย: ถ้าผู้ใช้ขอ reduced motion ให้ทุกอย่างนิ่งและเห็นครบ */
|
||||
@media (prefers-reduced-motion: reduce) {
|
||||
html.fx-motion [data-reveal],
|
||||
html.fx-motion .fx-page,
|
||||
html.fx-motion .fx-drop,
|
||||
html.fx-motion .fx-swap,
|
||||
html.fx-motion .fx-hero-image {
|
||||
animation: none !important;
|
||||
opacity: 1 !important;
|
||||
transform: none !important;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,61 @@
|
||||
import { useEffect, useRef, useState, type CSSProperties } from "react";
|
||||
|
||||
/**
|
||||
* ระยะที่ถือว่า "ใกล้พอจะโผล่"
|
||||
* - `2000px` ด้านบน: ถ้าผู้ใช้เลื่อนข้ามไกล ๆ (หรือกลับเข้าหน้าที่ scroll ค้างอยู่)
|
||||
* บล็อกที่อยู่เหนือจอจะถูกนับว่าถึงแล้ว → ไม่ค้างซ่อน
|
||||
* - `-6%` ด้านล่าง: รอให้บล็อกโผล่เข้ามาในจอก่อนเริ่มอนิเมชันเล็กน้อย
|
||||
*/
|
||||
const REVEAL_ROOT_MARGIN = "2000px 0px -6% 0px";
|
||||
|
||||
/** ต้องเห็นบล็อกอย่างน้อย 6% ก่อนจึงเริ่มโผล่ */
|
||||
const REVEAL_THRESHOLD = 0.06;
|
||||
|
||||
/**
|
||||
* hook สำหรับ "ค่อย ๆ โผล่" เมื่อเลื่อนมาถึง (IntersectionObserver)
|
||||
*
|
||||
* คืน ref + style ที่ใส่วงหน่วง (stagger) ให้เอง — class/animation อยู่ใน global.css
|
||||
* ใต้ `html.fx-motion` ดังนั้นถ้าผู้ใช้ขอ reduced motion หรือ JS ไม่ทำงาน
|
||||
* เนื้อหาก็ยังแสดงปกติ (ไม่มีคลาส = ไม่มีอะไรถูกซ่อน)
|
||||
*/
|
||||
export function useReveal<T extends HTMLElement = HTMLDivElement>(delayMs = 0) {
|
||||
const ref = useRef<T | null>(null);
|
||||
const [revealed, setRevealed] = useState(false);
|
||||
|
||||
useEffect(() => {
|
||||
const node = ref.current;
|
||||
if (!node) return;
|
||||
|
||||
// เบราว์เซอร์เก่ามาก: ไม่มี observer → แสดงทันที ไม่ค้างซ่อน
|
||||
if (typeof IntersectionObserver === "undefined") {
|
||||
setRevealed(true);
|
||||
return;
|
||||
}
|
||||
|
||||
const observer = new IntersectionObserver(
|
||||
(entries) => {
|
||||
for (const entry of entries) {
|
||||
// กันกรณีเลื่อนเร็ว/กลับเข้าหน้าที่ scroll ค้างอยู่: บล็อกที่เลยจอขึ้นไปแล้ว
|
||||
// ต้องโผล่ทันที (ไม่งั้นจะค้างซ่อนตลอด เพราะไม่มีการตัดผ่านขอบเขตอีก)
|
||||
const rootTop = entry.rootBounds?.top ?? 0;
|
||||
const passed = entry.boundingClientRect.bottom <= rootTop;
|
||||
if (!entry.isIntersecting && !passed) continue;
|
||||
|
||||
setRevealed(true);
|
||||
observer.disconnect();
|
||||
break;
|
||||
}
|
||||
},
|
||||
{ threshold: REVEAL_THRESHOLD, rootMargin: REVEAL_ROOT_MARGIN },
|
||||
);
|
||||
|
||||
observer.observe(node);
|
||||
return () => observer.disconnect();
|
||||
}, []);
|
||||
|
||||
const style = {
|
||||
"--fx-delay": `${Math.max(0, delayMs)}ms`,
|
||||
} as CSSProperties;
|
||||
|
||||
return { ref, revealed, style };
|
||||
}
|
||||
@@ -0,0 +1,99 @@
|
||||
import { describe, expect, it } from "vitest";
|
||||
|
||||
import {
|
||||
countImages,
|
||||
createImageBlock,
|
||||
createParagraphBlock,
|
||||
moveBlock,
|
||||
removeBlock,
|
||||
sanitizeArticleBlocks,
|
||||
} from "./article";
|
||||
|
||||
describe("sanitizeArticleBlocks", () => {
|
||||
it("ไม่ใช่ array → คืนอาร์เรย์ว่าง", () => {
|
||||
expect(sanitizeArticleBlocks(undefined)).toEqual([]);
|
||||
expect(sanitizeArticleBlocks("ข้อความ")).toEqual([]);
|
||||
});
|
||||
|
||||
it("เก็บย่อหน้าที่มีข้อความ และตัดช่องว่างหัวท้าย", () => {
|
||||
expect(
|
||||
sanitizeArticleBlocks([{ type: "paragraph", text: " สวัสดี " }]),
|
||||
).toEqual([{ type: "paragraph", text: "สวัสดี" }]);
|
||||
});
|
||||
|
||||
it("ทิ้งย่อหน้าว่าง รูปที่ไม่มีลิงก์ และบล็อกชนิดที่ไม่รู้จัก", () => {
|
||||
expect(
|
||||
sanitizeArticleBlocks([
|
||||
{ type: "paragraph", text: " " },
|
||||
{ type: "image", src: " ", alt: "ไม่มีรูป" },
|
||||
{ type: "video", src: "x.mp4" },
|
||||
{ type: "paragraph", text: "เก็บอันนี้" },
|
||||
]),
|
||||
).toEqual([{ type: "paragraph", text: "เก็บอันนี้" }]);
|
||||
});
|
||||
|
||||
it("รูปเก็บ src/alt/caption และตัดฟิลด์เกินทิ้ง", () => {
|
||||
expect(
|
||||
sanitizeArticleBlocks([
|
||||
{
|
||||
type: "image",
|
||||
src: " /images/a.jpg ",
|
||||
alt: " บรรยากาศ ",
|
||||
caption: " โรงใหม่ ",
|
||||
evil: "x",
|
||||
},
|
||||
]),
|
||||
).toEqual([
|
||||
{
|
||||
type: "image",
|
||||
src: "/images/a.jpg",
|
||||
alt: "บรรยากาศ",
|
||||
caption: "โรงใหม่",
|
||||
},
|
||||
]);
|
||||
});
|
||||
|
||||
it("คงลำดับบล็อกตามที่รับมา", () => {
|
||||
const blocks = sanitizeArticleBlocks([
|
||||
{ type: "paragraph", text: "หนึ่ง" },
|
||||
{ type: "image", src: "/a.jpg" },
|
||||
{ type: "paragraph", text: "สอง" },
|
||||
]);
|
||||
expect(blocks.map((block) => block.type)).toEqual([
|
||||
"paragraph",
|
||||
"image",
|
||||
"paragraph",
|
||||
]);
|
||||
});
|
||||
});
|
||||
|
||||
describe("moveBlock / removeBlock", () => {
|
||||
const blocks = [
|
||||
createParagraphBlock("หนึ่ง"),
|
||||
createParagraphBlock("สอง"),
|
||||
createImageBlock(),
|
||||
];
|
||||
|
||||
it("เลื่อนขึ้น/ลงสลับตำแหน่งถูกต้อง", () => {
|
||||
expect(
|
||||
moveBlock(blocks, 1, -1).map((b) =>
|
||||
b.type === "paragraph" ? b.text : "img",
|
||||
),
|
||||
).toEqual(["สอง", "หนึ่ง", "img"]);
|
||||
expect(moveBlock(blocks, 0, 1)[1]).toEqual(blocks[0]);
|
||||
});
|
||||
|
||||
it("ไม่ทำอะไรเมื่อเกินขอบ", () => {
|
||||
expect(moveBlock(blocks, 0, -1)).toEqual(blocks);
|
||||
expect(moveBlock(blocks, blocks.length - 1, 1)).toEqual(blocks);
|
||||
});
|
||||
|
||||
it("ลบบล็อกตามตำแหน่ง และไม่แตะเมื่อ index ผิด", () => {
|
||||
expect(removeBlock(blocks, 1)).toHaveLength(2);
|
||||
expect(removeBlock(blocks, 99)).toHaveLength(3);
|
||||
});
|
||||
|
||||
it("นับจำนวนรูปได้", () => {
|
||||
expect(countImages(blocks)).toBe(1);
|
||||
});
|
||||
});
|
||||
@@ -0,0 +1,89 @@
|
||||
/**
|
||||
* ตัวช่วยจัดการบล็อกบทความของหน้า "สำหรับคนทำโรงหนัง"
|
||||
* แยกออกมาเป็นฟังก์ชันบริสุทธิ์เพื่อเทสต์ได้โดยไม่ต้องพึ่ง fs หรือ React
|
||||
*/
|
||||
import type {
|
||||
ArticleBlock,
|
||||
ArticleImage,
|
||||
ArticleParagraph,
|
||||
} from "@/lib/content-types";
|
||||
|
||||
function asString(value: unknown): string {
|
||||
return typeof value === "string" ? value : "";
|
||||
}
|
||||
|
||||
/**
|
||||
* ตรวจบล็อกที่รับมาจากหลังบ้าน/ไฟล์ JSON
|
||||
* - เก็บเฉพาะชนิดที่รู้จัก (paragraph / image)
|
||||
* - ย่อหน้าว่าง และรูปที่ไม่มี src → ทิ้ง
|
||||
* - ฟิลด์เกินถูกตัดทิ้ง (ไม่ให้ข้อมูลแปลกปลอมไหลเข้า store)
|
||||
*/
|
||||
export function sanitizeArticleBlocks(input: unknown): ArticleBlock[] {
|
||||
if (!Array.isArray(input)) return [];
|
||||
const blocks: ArticleBlock[] = [];
|
||||
|
||||
for (const item of input) {
|
||||
if (!item || typeof item !== "object") continue;
|
||||
const raw = item as Record<string, unknown>;
|
||||
const type = asString(raw.type);
|
||||
|
||||
if (type === "paragraph") {
|
||||
const text = asString(raw.text).trim();
|
||||
if (text) blocks.push({ type: "paragraph", text });
|
||||
continue;
|
||||
}
|
||||
|
||||
if (type === "image") {
|
||||
const src = asString(raw.src).trim();
|
||||
if (!src) continue;
|
||||
const block: ArticleImage = {
|
||||
type: "image",
|
||||
src,
|
||||
alt: asString(raw.alt).trim(),
|
||||
caption: asString(raw.caption).trim(),
|
||||
};
|
||||
blocks.push(block);
|
||||
}
|
||||
}
|
||||
|
||||
return blocks;
|
||||
}
|
||||
|
||||
/** ย่อหน้าใหม่ (ว่าง) สำหรับปุ่ม "เพิ่มย่อหน้า" */
|
||||
export function createParagraphBlock(text = ""): ArticleParagraph {
|
||||
return { type: "paragraph", text };
|
||||
}
|
||||
|
||||
/** รูปใหม่ (ว่าง) สำหรับปุ่ม "เพิ่มรูป" */
|
||||
export function createImageBlock(): ArticleImage {
|
||||
return { type: "image", src: "", alt: "", caption: "" };
|
||||
}
|
||||
|
||||
/** สลับตำแหน่งบล็อกขึ้น/ลง — คืนรายการใหม่ และไม่ทำอะไรถ้าเกินขอบ */
|
||||
export function moveBlock(
|
||||
blocks: ArticleBlock[],
|
||||
index: number,
|
||||
direction: -1 | 1,
|
||||
): ArticleBlock[] {
|
||||
const target = index + direction;
|
||||
if (index < 0 || index >= blocks.length) return blocks;
|
||||
if (target < 0 || target >= blocks.length) return blocks;
|
||||
const next = [...blocks];
|
||||
const [moved] = next.splice(index, 1);
|
||||
next.splice(target, 0, moved);
|
||||
return next;
|
||||
}
|
||||
|
||||
/** ลบบล็อกตามตำแหน่ง */
|
||||
export function removeBlock(
|
||||
blocks: ArticleBlock[],
|
||||
index: number,
|
||||
): ArticleBlock[] {
|
||||
if (index < 0 || index >= blocks.length) return blocks;
|
||||
return blocks.filter((_, i) => i !== index);
|
||||
}
|
||||
|
||||
/** จำนวนรูปในบทความ (ใช้แสดงสรุป/เตือนในหลังบ้าน) */
|
||||
export function countImages(blocks: ArticleBlock[]): number {
|
||||
return blocks.filter((block) => block.type === "image").length;
|
||||
}
|
||||
@@ -3,10 +3,10 @@ import { describe, expect, it } from "vitest";
|
||||
import type { Cinema } from "@/lib/cinemas";
|
||||
import {
|
||||
cinemaFacilities,
|
||||
filterCinemas,
|
||||
listOtherCinemas,
|
||||
publiclyVisible,
|
||||
} from "@/lib/cinemas";
|
||||
import { filterCinemas } from "@/lib/search";
|
||||
|
||||
/**
|
||||
* สเปกของกติกาที่เพิ่มเข้ามา: ซ่อนโรง (hidden) + สิ่งอำนวยความสะดวกต่อโรง
|
||||
|
||||
@@ -1,44 +1,11 @@
|
||||
import { describe, expect, it } from "vitest";
|
||||
|
||||
import {
|
||||
DEFAULT_CATEGORY,
|
||||
filterCinemas,
|
||||
findCinemaBySlug,
|
||||
listOtherCinemas,
|
||||
CINEMAS,
|
||||
} from "./cinemas";
|
||||
|
||||
describe("filterCinemas", () => {
|
||||
it("คืนทุกโรงหนังเมื่อเลือกหมวดทั้งหมดและไม่พิมพ์ค้นหา", () => {
|
||||
const result = filterCinemas(CINEMAS, { category: DEFAULT_CATEGORY, query: "" });
|
||||
expect(result.length).toBeGreaterThan(0);
|
||||
});
|
||||
|
||||
it("กรองตามหมวดหมู่จาก tags", () => {
|
||||
const result = filterCinemas(CINEMAS, { category: "อาร์ตเฮาส์", query: "" });
|
||||
expect(result.length).toBeGreaterThan(0);
|
||||
expect(result.every((cinema) => cinema.tags.includes("อาร์ตเฮาส์"))).toBe(
|
||||
true,
|
||||
);
|
||||
});
|
||||
|
||||
it("ค้นหาแบบไม่สนตัวพิมพ์และตัดช่องว่างหัวท้าย", () => {
|
||||
const result = filterCinemas(CINEMAS, {
|
||||
category: DEFAULT_CATEGORY,
|
||||
query: " house ",
|
||||
});
|
||||
expect(result.map((cinema) => cinema.slug)).toContain(
|
||||
"house-cinema-samyan",
|
||||
);
|
||||
});
|
||||
|
||||
it("คืนอาร์เรย์ว่างเมื่อไม่พบคำค้น", () => {
|
||||
expect(
|
||||
filterCinemas(CINEMAS, { category: DEFAULT_CATEGORY, query: "ไม่มีโรงนี้แน่นอน" }),
|
||||
).toEqual([]);
|
||||
});
|
||||
});
|
||||
|
||||
describe("findCinemaBySlug", () => {
|
||||
it("คืน undefined เมื่อไม่ได้ส่ง slug", () => {
|
||||
expect(findCinemaBySlug(CINEMAS, undefined)).toBeUndefined();
|
||||
|
||||
+4
-29
@@ -4,9 +4,9 @@
|
||||
* ข้อความอังกฤษเป็นฟิลด์เสริม (*_en) ถ้าไม่กรอกจะ fallback เป็นไทย
|
||||
*/
|
||||
|
||||
import type { Coordinates } from "@/lib/geo";
|
||||
import type { FacilityKey, Locale, Messages } from "@/lib/i18n/messages";
|
||||
import { FACILITY_KEYS } from "@/lib/i18n/messages";
|
||||
import type { Coordinates } from "@/lib/geo";
|
||||
|
||||
export type TransportMode = {
|
||||
/** ใช้เลือกไอคอนและชื่อวิธีเดินทางจากข้อความแปล */
|
||||
@@ -332,9 +332,9 @@ export function cinemaFacilities(cinema: Cinema): FacilityKey[] {
|
||||
}
|
||||
|
||||
/** หมวดที่เลือกได้ในหลังบ้าน — ตัด "ทั้งหมด" ออกเพราะใช้เป็นตัวกรอง "ไม่กรอง" */
|
||||
export const ASSIGNABLE_CATEGORIES: CinemaCategory[] =
|
||||
CINEMA_CATEGORIES.filter((category) => category !== DEFAULT_CATEGORY);
|
||||
|
||||
export const ASSIGNABLE_CATEGORIES: CinemaCategory[] = CINEMA_CATEGORIES.filter(
|
||||
(category) => category !== DEFAULT_CATEGORY,
|
||||
);
|
||||
|
||||
export function transportValue(route: TransportMode, locale: Locale): string {
|
||||
return pick(route.value, route.value_en, locale);
|
||||
@@ -352,31 +352,6 @@ export function hasCategory(cinema: Cinema, category: CinemaCategory): boolean {
|
||||
return category === DEFAULT_CATEGORY || cinema.tags.includes(category);
|
||||
}
|
||||
|
||||
export function matchesQuery(cinema: Cinema, query: string): boolean {
|
||||
const keyword = query.trim().toLowerCase();
|
||||
if (keyword === "") return true;
|
||||
return (
|
||||
cinema.name.toLowerCase().includes(keyword) ||
|
||||
cinema.location_label.toLowerCase().includes(keyword) ||
|
||||
(cinema.location_label_en ?? "").toLowerCase().includes(keyword)
|
||||
);
|
||||
}
|
||||
|
||||
export function filterCinemas(
|
||||
cinemas: Cinema[],
|
||||
{
|
||||
category,
|
||||
query,
|
||||
}: {
|
||||
category: CinemaCategory;
|
||||
query: string;
|
||||
},
|
||||
): Cinema[] {
|
||||
return cinemas.filter(
|
||||
(cinema) => hasCategory(cinema, category) && matchesQuery(cinema, query),
|
||||
);
|
||||
}
|
||||
|
||||
export function findCinemaBySlug(
|
||||
cinemas: Cinema[],
|
||||
slug: string | undefined,
|
||||
|
||||
@@ -0,0 +1,88 @@
|
||||
import { describe, expect, it } from "vitest";
|
||||
|
||||
import { seedForCinemas, seedForFilmLovers } from "./content-seed";
|
||||
import { sanitizeForCinemas, sanitizeForFilmLovers } from "./content.server";
|
||||
|
||||
/**
|
||||
* ทดสอบตัวตรวจข้อมูลของหน้าบทความทั้งสองหน้า
|
||||
* (สำหรับคนทำโรงหนัง / สำหรับคนรักหนัง)
|
||||
* ค่าที่เว้นว่าง/ผิดรูปแบบต้องถูกแทนด้วยค่าเริ่มต้น ไม่ใช่ปล่อยให้หน้าเว็บว่าง
|
||||
*/
|
||||
describe("sanitizeForCinemas", () => {
|
||||
const seed = seedForCinemas();
|
||||
|
||||
it("ไม่ส่งข้อมูลมา → คืนค่าเริ่มต้นทั้งสองภาษา", () => {
|
||||
expect(sanitizeForCinemas(undefined)).toEqual(seed);
|
||||
expect(sanitizeForCinemas("ผิดรูปแบบ")).toEqual(seed);
|
||||
});
|
||||
|
||||
it("เก็บบล็อกที่ถูกต้องตามลำดับ และตัดบล็อกที่ว่าง", () => {
|
||||
const result = sanitizeForCinemas({
|
||||
th: {
|
||||
title: "สำหรับคนทำโรงหนัง",
|
||||
lead: "เกริ่น",
|
||||
blocks: [
|
||||
{ type: "paragraph", text: "หนึ่ง" },
|
||||
{ type: "paragraph", text: " " },
|
||||
{ type: "image", src: "/images/a.jpg", alt: "a", caption: "" },
|
||||
{ type: "image", src: "" },
|
||||
],
|
||||
contactHeading: "ติดต่อ",
|
||||
contactNote: "โน้ต",
|
||||
},
|
||||
});
|
||||
|
||||
expect(result.th.blocks).toEqual([
|
||||
{ type: "paragraph", text: "หนึ่ง" },
|
||||
{ type: "image", src: "/images/a.jpg", alt: "a", caption: "" },
|
||||
]);
|
||||
expect(result.th.title).toBe("สำหรับคนทำโรงหนัง");
|
||||
});
|
||||
|
||||
it("ฟิลด์ที่เว้นว่างถูกแทนด้วยค่าเริ่มต้น", () => {
|
||||
const result = sanitizeForCinemas({
|
||||
th: {
|
||||
title: " ",
|
||||
lead: "",
|
||||
blocks: [],
|
||||
contactHeading: "",
|
||||
contactNote: "",
|
||||
},
|
||||
});
|
||||
expect(result.th.title).toBe(seed.th.title);
|
||||
expect(result.th.lead).toBe(seed.th.lead);
|
||||
expect(result.th.blocks).toEqual(seed.th.blocks);
|
||||
expect(result.th.contactHeading).toBe(seed.th.contactHeading);
|
||||
expect(result.th.contactNote).toBe(seed.th.contactNote);
|
||||
});
|
||||
|
||||
it("ภาษา en ที่ไม่ส่งมาจะได้ค่าเริ่มต้นของ en", () => {
|
||||
const result = sanitizeForCinemas({ th: { title: "ไทยเท่านั้น" } });
|
||||
expect(result.en).toEqual(seed.en);
|
||||
});
|
||||
});
|
||||
|
||||
describe("sanitizeForFilmLovers", () => {
|
||||
const seed = seedForFilmLovers();
|
||||
|
||||
it("ไม่ส่งข้อมูลมา → ค่าเริ่มต้นของหน้า 'สำหรับคนรักหนัง'", () => {
|
||||
expect(sanitizeForFilmLovers(undefined)).toEqual(seed);
|
||||
expect(seed.th.title).not.toBe(seedForCinemas().th.title);
|
||||
});
|
||||
|
||||
it("เก็บบล็อกและหัวเรื่องที่ส่งมา ตัดบล็อกว่าง", () => {
|
||||
const result = sanitizeForFilmLovers({
|
||||
th: {
|
||||
title: "สำหรับคนรักหนัง",
|
||||
blocks: [
|
||||
{ type: "paragraph", text: "ย่อหน้า" },
|
||||
{ type: "image", src: "/images/a.jpg", alt: "alt", caption: "" },
|
||||
{ type: "paragraph", text: "" },
|
||||
],
|
||||
},
|
||||
});
|
||||
expect(result.th.blocks).toHaveLength(2);
|
||||
expect(result.th.title).toBe("สำหรับคนรักหนัง");
|
||||
expect(result.th.lead).toBe(seed.th.lead);
|
||||
});
|
||||
});
|
||||
+48
-4
@@ -1,13 +1,14 @@
|
||||
import { CINEMAS } from "@/lib/cinemas";
|
||||
import type { Locale } from "@/lib/i18n/messages";
|
||||
import { MESSAGES } from "@/lib/i18n/messages";
|
||||
import type {
|
||||
AboutContent,
|
||||
ArticleContent,
|
||||
ContentStore,
|
||||
FooterItem,
|
||||
LocaleEntry,
|
||||
TermEntry,
|
||||
} from "@/lib/content-types";
|
||||
import type { Locale } from "@/lib/i18n/messages";
|
||||
import { MESSAGES } from "@/lib/i18n/messages";
|
||||
import type { Messages } from "@/lib/i18n/messages";
|
||||
|
||||
export const DEFAULT_LOCALES: LocaleEntry[] = [
|
||||
@@ -25,7 +26,9 @@ function flatten(
|
||||
return;
|
||||
}
|
||||
if (value && typeof value === "object") {
|
||||
for (const [key, child] of Object.entries(value as Record<string, unknown>)) {
|
||||
for (const [key, child] of Object.entries(
|
||||
value as Record<string, unknown>,
|
||||
)) {
|
||||
flatten(child, prefix ? `${prefix}.${key}` : key, out);
|
||||
}
|
||||
}
|
||||
@@ -43,7 +46,10 @@ export function seedTerms(): TermEntry[] {
|
||||
return keys.map((key) => ({
|
||||
key,
|
||||
values: Object.fromEntries(
|
||||
Object.entries(perLocale).map(([locale, flat]) => [locale, flat[key] ?? ""]),
|
||||
Object.entries(perLocale).map(([locale, flat]) => [
|
||||
locale,
|
||||
flat[key] ?? "",
|
||||
]),
|
||||
),
|
||||
}));
|
||||
}
|
||||
@@ -111,5 +117,43 @@ export function seedContent(): ContentStore {
|
||||
footer: DEFAULT_FOOTER,
|
||||
},
|
||||
about: seedAbout(),
|
||||
forCinemas: seedForCinemas(),
|
||||
forFilmLovers: seedForFilmLovers(),
|
||||
};
|
||||
}
|
||||
|
||||
/** ค่าเริ่มต้นหน้า "สำหรับคนทำโรงหนัง" — ย่อหน้าตั้งต้นมาจาก messages (แก้ต่อได้ในหลังบ้าน) */
|
||||
export function seedForCinemas(): Record<Locale, ArticleContent> {
|
||||
return seedArticle(MESSAGES.th.forCinemas, MESSAGES.en.forCinemas);
|
||||
}
|
||||
|
||||
/** ค่าเริ่มต้นหน้า "สำหรับคนรักหนัง" */
|
||||
export function seedForFilmLovers(): Record<Locale, ArticleContent> {
|
||||
return seedArticle(MESSAGES.th.forFilmLovers, MESSAGES.en.forFilmLovers);
|
||||
}
|
||||
|
||||
type SeedArticle = {
|
||||
title: string;
|
||||
lead: string;
|
||||
paragraphs: string[];
|
||||
contactHeading: string;
|
||||
contactNote: string;
|
||||
};
|
||||
|
||||
/** แปลงข้อความ i18n ของหน้าบทความ → บล็อกเริ่มต้น (ใช้ทั้งหน้าโรงหนังและคนรักหนัง) */
|
||||
function seedArticle(
|
||||
th: SeedArticle,
|
||||
en: SeedArticle,
|
||||
): Record<Locale, ArticleContent> {
|
||||
return { th: toArticleContent(th), en: toArticleContent(en) };
|
||||
}
|
||||
|
||||
function toArticleContent(source: SeedArticle): ArticleContent {
|
||||
return {
|
||||
title: source.title,
|
||||
lead: source.lead,
|
||||
blocks: source.paragraphs.map((text) => ({ type: "paragraph", text })),
|
||||
contactHeading: source.contactHeading,
|
||||
contactNote: source.contactNote,
|
||||
};
|
||||
}
|
||||
@@ -20,6 +20,31 @@ export type AboutContent = {
|
||||
contactNote: string;
|
||||
};
|
||||
|
||||
/** ย่อหน้าหนึ่งบล็อกของบทความ (หน้า "สำหรับคนทำโรงหนัง") */
|
||||
export type ArticleParagraph = {
|
||||
type: "paragraph";
|
||||
text: string;
|
||||
};
|
||||
|
||||
/** รูปหนึ่งบล็อกของบทความ — caption ไม่ใส่ได้ */
|
||||
export type ArticleImage = {
|
||||
type: "image";
|
||||
src: string;
|
||||
alt: string;
|
||||
caption: string;
|
||||
};
|
||||
|
||||
export type ArticleBlock = ArticleParagraph | ArticleImage;
|
||||
|
||||
/** เนื้อหาหน้า "สำหรับคนทำโรงหนัง" หนึ่งภาษา — บทความแบบบล็อก เพิ่มทีละย่อหน้า/รูปได้ */
|
||||
export type ArticleContent = {
|
||||
title: string;
|
||||
lead: string;
|
||||
blocks: ArticleBlock[];
|
||||
contactHeading: string;
|
||||
contactNote: string;
|
||||
};
|
||||
|
||||
export type FooterItem = {
|
||||
id: string;
|
||||
/** ชื่อไอคอน Tabler เช่น IconBrandFacebook */
|
||||
@@ -51,4 +76,8 @@ export type ContentStore = {
|
||||
site: SiteContent;
|
||||
/** เนื้อหาหน้า "เกี่ยวกับเรา" แยกตามภาษา — แก้ได้จากหลังบ้าน */
|
||||
about: Record<Locale, AboutContent>;
|
||||
/** เนื้อหาหน้า "สำหรับคนทำโรงหนัง" (บทความแบบบล็อก) แยกตามภาษา — แก้ได้จากหลังบ้าน */
|
||||
forCinemas: Record<Locale, ArticleContent>;
|
||||
/** เนื้อหาหน้า "สำหรับคนรักหนัง" (บทความแบบบล็อก) แยกตามภาษา — แก้ได้จากหลังบ้าน */
|
||||
forFilmLovers: Record<Locale, ArticleContent>;
|
||||
};
|
||||
@@ -1,9 +1,24 @@
|
||||
/**
|
||||
* อ่าน/เขียนเนื้อหาที่แก้ได้จากหลังบ้าน (`data/content/content.json`)
|
||||
*
|
||||
* หมายเหตุเรื่องแคช: `cache` ด้านล่างเก็บผล sanitize ไว้ต่อ process (คีย์ = ความยาวไฟล์)
|
||||
* ดังนั้นถ้าแก้ "ข้อความตั้งต้น" ใน `messages.ts` ต้องรีสตาร์ต/ให้ dev server โหลดโมดูลใหม่
|
||||
* ไฟล์นี้จึงจะคำนวณ seed ใหม่ — การแก้ผ่านหน้า admin ไม่ต้องรีสตาร์ต (ไฟล์เปลี่ยนเอง)
|
||||
*/
|
||||
import { mkdir, readFile, rename, writeFile } from "node:fs/promises";
|
||||
import path from "node:path";
|
||||
|
||||
import { seedAbout, seedContent } from "@/lib/content-seed";
|
||||
import { sanitizeArticleBlocks } from "@/lib/article";
|
||||
import type { Cinema } from "@/lib/cinemas";
|
||||
import {
|
||||
seedAbout,
|
||||
seedContent,
|
||||
seedForCinemas,
|
||||
seedForFilmLovers,
|
||||
} from "@/lib/content-seed";
|
||||
import type {
|
||||
AboutContent,
|
||||
ArticleContent,
|
||||
ContentStore,
|
||||
FooterItem,
|
||||
LocaleEntry,
|
||||
@@ -12,7 +27,6 @@ import type {
|
||||
} from "@/lib/content-types";
|
||||
import type { Locale } from "@/lib/i18n/messages";
|
||||
import { FACILITY_KEYS } from "@/lib/i18n/messages";
|
||||
import type { Cinema } from "@/lib/cinemas";
|
||||
|
||||
const CONTENT_DIR = path.join(process.cwd(), "data", "content");
|
||||
const CONTENT_FILE = path.join(CONTENT_DIR, "content.json");
|
||||
@@ -48,9 +62,7 @@ function sanitizeFacilities(value: unknown): Cinema["facilities"] {
|
||||
}
|
||||
|
||||
/** ตรวจข้อความเฉพาะโรงของแต่ละหัวข้อ — เก็บเฉพาะคีย์/ฟิลด์ที่รู้จัก */
|
||||
function sanitizeFacilityDetails(
|
||||
value: unknown,
|
||||
): Cinema["facility_details"] {
|
||||
function sanitizeFacilityDetails(value: unknown): Cinema["facility_details"] {
|
||||
if (!value || typeof value !== "object") return {};
|
||||
const raw = value as Record<string, unknown>;
|
||||
const result: NonNullable<Cinema["facility_details"]> = {};
|
||||
@@ -201,7 +213,10 @@ export function sanitizeAbout(input: unknown): Record<Locale, AboutContent> {
|
||||
const body = asString(item.body).trim();
|
||||
return heading || body ? { heading, body } : null;
|
||||
})
|
||||
.filter((section): section is { heading: string; body: string } => section !== null)
|
||||
.filter(
|
||||
(section): section is { heading: string; body: string } =>
|
||||
section !== null,
|
||||
)
|
||||
: fallback.sections;
|
||||
|
||||
return {
|
||||
@@ -220,6 +235,55 @@ export function sanitizeAbout(input: unknown): Record<Locale, AboutContent> {
|
||||
};
|
||||
}
|
||||
|
||||
/**
|
||||
* ตรวจเนื้อหาหน้าบทความ (ใช้ทั้ง "สำหรับคนทำโรงหนัง" และ "สำหรับคนรักหนัง")
|
||||
*
|
||||
* ทำไมต้องมี seed: ถ้า editor ส่งค่าที่ใช้ไม่ได้มา (บล็อกว่างทั้งหมด, ไม่ได้ส่งภาษาใดภาษา
|
||||
* มาบ้าง) หน้าเว็บจะกลายเป็นหน้าว่าง — จึงต้องเติมข้อความตั้งต้นของภาษานั้นให้เสมอ
|
||||
* บล็อกที่ผิดรูปแบบ/ว่างจะถูกตัดทิ้งด้วย sanitizeArticleBlocks
|
||||
*/
|
||||
function sanitizeArticlePage(
|
||||
input: unknown,
|
||||
seed: Record<Locale, ArticleContent>,
|
||||
): Record<Locale, ArticleContent> {
|
||||
if (!input || typeof input !== "object") return seed;
|
||||
const raw = input as Record<string, unknown>;
|
||||
|
||||
function one(value: unknown, fallback: ArticleContent): ArticleContent {
|
||||
if (!value || typeof value !== "object") return fallback;
|
||||
const entry = value as Record<string, unknown>;
|
||||
const blocks = sanitizeArticleBlocks(entry.blocks);
|
||||
|
||||
return {
|
||||
title: asString(entry.title, "").trim() || fallback.title,
|
||||
lead: asString(entry.lead).trim() || fallback.lead,
|
||||
blocks: blocks.length > 0 ? blocks : fallback.blocks,
|
||||
contactHeading:
|
||||
asString(entry.contactHeading).trim() || fallback.contactHeading,
|
||||
contactNote: asString(entry.contactNote).trim() || fallback.contactNote,
|
||||
};
|
||||
}
|
||||
|
||||
return {
|
||||
th: one(raw.th, seed.th),
|
||||
en: one(raw.en, seed.en),
|
||||
};
|
||||
}
|
||||
|
||||
/** เนื้อหาหน้า "สำหรับคนทำโรงหนัง" */
|
||||
export function sanitizeForCinemas(
|
||||
input: unknown,
|
||||
): Record<Locale, ArticleContent> {
|
||||
return sanitizeArticlePage(input, seedForCinemas());
|
||||
}
|
||||
|
||||
/** เนื้อหาหน้า "สำหรับคนรักหนัง" */
|
||||
export function sanitizeForFilmLovers(
|
||||
input: unknown,
|
||||
): Record<Locale, ArticleContent> {
|
||||
return sanitizeArticlePage(input, seedForFilmLovers());
|
||||
}
|
||||
|
||||
/** อ่านเนื้อหาทั้งหมด — สร้างไฟล์เริ่มต้นให้อัตโนมัติเมื่อยังไม่มี */
|
||||
export async function readContent(): Promise<ContentStore> {
|
||||
let raw: string;
|
||||
@@ -251,6 +315,8 @@ function sanitizeStore(input: unknown): ContentStore {
|
||||
cinemas: sanitizeCinemas(raw.cinemas ?? []),
|
||||
site: sanitizeSite(raw.site ?? {}),
|
||||
about: sanitizeAbout(raw.about ?? {}),
|
||||
forCinemas: sanitizeForCinemas(raw.forCinemas ?? {}),
|
||||
forFilmLovers: sanitizeForFilmLovers(raw.forFilmLovers ?? {}),
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
+25
-1
@@ -1,6 +1,6 @@
|
||||
import { describe, expect, it } from "vitest";
|
||||
|
||||
import { GALLERY_SLOTS, splitGallery } from "./gallery";
|
||||
import { GALLERY_SLOTS, rotateGallery, splitGallery } from "./gallery";
|
||||
|
||||
const photosOf = (count: number) =>
|
||||
Array.from({ length: count }, (_, index) => `/images/p${index + 1}.jpg`);
|
||||
@@ -36,3 +36,27 @@ describe("splitGallery", () => {
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
describe("rotateGallery", () => {
|
||||
it("ไม่มีรูป → อาร์เรย์ว่าง", () => {
|
||||
expect(rotateGallery([], 3)).toEqual([]);
|
||||
});
|
||||
|
||||
it("index 0 คงลำดับเดิม", () => {
|
||||
expect(rotateGallery(photosOf(3), 0)).toEqual(photosOf(3));
|
||||
});
|
||||
|
||||
it("index 1 เริ่มที่ภาพที่ 2 และวนภาพแรกไปท้าย", () => {
|
||||
expect(rotateGallery(photosOf(4), 1)).toEqual([
|
||||
"/images/p2.jpg",
|
||||
"/images/p3.jpg",
|
||||
"/images/p4.jpg",
|
||||
"/images/p1.jpg",
|
||||
]);
|
||||
});
|
||||
|
||||
it("index ติดลบและเกินจำนวนวนกลับถูกต้อง", () => {
|
||||
expect(rotateGallery(photosOf(3), -1)[0]).toBe("/images/p3.jpg");
|
||||
expect(rotateGallery(photosOf(3), 4)[0]).toBe("/images/p2.jpg");
|
||||
});
|
||||
});
|
||||
@@ -10,6 +10,17 @@ export type GalleryView = {
|
||||
remaining: number;
|
||||
};
|
||||
|
||||
/**
|
||||
* หมุนรายการรูปให้เริ่มที่ index (ค่าติดลบ/เกินจำนวนได้ — วนกลับอัตโนมัติ)
|
||||
* ใช้กับปุ่มก่อนหน้า/ถัดไปของแกลเลอรี: ภาพหลักเลื่อน และภาพย่อยเลื่อนตาม
|
||||
*/
|
||||
export function rotateGallery(photos: string[], index: number): string[] {
|
||||
const total = photos.length;
|
||||
if (total === 0) return [];
|
||||
const start = ((index % total) + total) % total;
|
||||
return [...photos.slice(start), ...photos.slice(0, start)];
|
||||
}
|
||||
|
||||
/**
|
||||
* แบ่งรูปทั้งหมดเป็นภาพหลัก + ภาพย่อย และนับรูปที่เหลือ
|
||||
* ป้าย "+N" จึงมาจากจำนวนรูปจริง ไม่ใช่ค่าคงที่ในโค้ด
|
||||
|
||||
@@ -39,6 +39,18 @@ export const FACILITY_KEYS: FacilityKey[] = [
|
||||
|
||||
export type TransportKey = "private_car" | "metro" | "bus";
|
||||
|
||||
/**
|
||||
* ข้อความของหน้า "บทความ" ที่ใช้ร่วมกันสองหน้า
|
||||
* (สำหรับคนทำโรงหนัง / สำหรับคนรักหนัง) — แก้โครงครั้งเดียวมีผลทั้งคู่
|
||||
*/
|
||||
export type ArticleMessages = {
|
||||
title: string;
|
||||
lead: string;
|
||||
paragraphs: string[];
|
||||
contactHeading: string;
|
||||
contactNote: string;
|
||||
};
|
||||
|
||||
export type Messages = {
|
||||
meta: {
|
||||
homeDescription: string;
|
||||
@@ -63,6 +75,10 @@ export type Messages = {
|
||||
nav: {
|
||||
home: string;
|
||||
about: string;
|
||||
forCinemas: string;
|
||||
forFilmLovers: string;
|
||||
menu: string;
|
||||
language: string;
|
||||
};
|
||||
about: {
|
||||
title: string;
|
||||
@@ -71,6 +87,15 @@ export type Messages = {
|
||||
contactHeading: string;
|
||||
contactNote: string;
|
||||
};
|
||||
forCinemas: ArticleMessages;
|
||||
forFilmLovers: ArticleMessages;
|
||||
/** ข้อความปุ่ม/สถานะการแชร์ */
|
||||
share: {
|
||||
label: string;
|
||||
pageLabel: string;
|
||||
copied: string;
|
||||
failed: string;
|
||||
};
|
||||
list: {
|
||||
title: string;
|
||||
showMore: string;
|
||||
@@ -145,6 +170,10 @@ const TH: Messages = {
|
||||
nav: {
|
||||
home: "หน้าแรก",
|
||||
about: "เกี่ยวกับเรา",
|
||||
forCinemas: "สำหรับคนทำโรงหนัง",
|
||||
forFilmLovers: "สำหรับคนรักหนัง",
|
||||
menu: "เมนู",
|
||||
language: "ภาษา",
|
||||
},
|
||||
about: {
|
||||
title: "เกี่ยวกับเรา",
|
||||
@@ -171,6 +200,36 @@ const TH: Messages = {
|
||||
contactNote:
|
||||
"พบข้อมูลโรงหนังผิด ต้องการเพิ่มโรงใหม่ หรืออยากให้เราช่วยประชาสัมพันธ์กิจกรรม ใช้ช่องทางโซเชียลในส่วนท้ายของหน้าเว็บได้เลย",
|
||||
},
|
||||
forCinemas: {
|
||||
title: "สำหรับคนทำโรงหนัง",
|
||||
lead: "AlterFlixHub เปิดพื้นที่ให้โรงหนังอิสระ กลุ่มคนฉายหนัง และโรงหนังท้องถิ่นได้เล่าเรื่องของตัวเอง พร้อมรายละเอียดที่คนดูอยากรู้ก่อนออกจากบ้าน",
|
||||
paragraphs: [
|
||||
"โรงหนังเล็ก ๆ ในประเทศไทยมีเรื่องเล่าที่น่าสนใจไม่แพ้โรงใหญ่ แต่หลายโรงยังไม่มีพื้นที่สื่อสารกับคนดูอย่างเป็นระบบ ข้อมูลกระจัดกระจาย และคนดูก็หาไม่เจอ",
|
||||
"เราจึงเปิดพื้นที่ให้ทุกโรงสร้างหน้ารายละเอียดของตัวเองบน AlterFlixHub ระบุที่ตั้ง วิธีเดินทาง สิ่งอำนวยความสะดวก พร้อมภาพบรรยากาศจริง เพื่อให้คนดูตัดสินใจได้ก่อนเดินทาง",
|
||||
"ถ้าคุณดูแลโรงหนัง กลุ่มคนฉายหนัง หรือพื้นที่ฉายหนังชุมชน แล้วอยากมีหน้ารายละเอียดบน AlterFlixHub ส่งข้อมูลมาให้ทีมงานได้เลย เราช่วยตรวจข้อมูลและจัดหน้าให้ในช่วงเริ่มต้น",
|
||||
],
|
||||
contactHeading: "สนใจลงโรงหนังกับเรา",
|
||||
contactNote:
|
||||
"ส่งชื่อโรง ที่ตั้ง และภาพบรรยากาศมาให้ทีมงานผ่านช่องทางโซเชียลในส่วนท้ายของหน้าเว็บ เราจะติดต่อกลับภายใน 2 วันทำการ",
|
||||
},
|
||||
forFilmLovers: {
|
||||
title: "สำหรับคนรักหนัง",
|
||||
lead: "รวมทางเลือกสำหรับคนที่อยากดูหนังมากกว่าหนังกระแสหลัก — โรงอาร์ตเฮาส์ กลุ่มคนฉายหนัง และรอบฉายพิเศษที่คัดมาแล้ว",
|
||||
paragraphs: [
|
||||
"ถ้าคุณตามหาหนังที่ไม่ได้อยู่ในโรงใหญ่ AlterFlixHub ช่วยให้เจอโรงที่ฉายหนังนอกกระแส สารคดี หนังคลาสสิก และรอบฉายพิเศษได้ในไม่กี่คลิก",
|
||||
"ทุกโรงในเว็บมีข้อมูลที่คนดูอยากรู้ก่อนตัดสินใจ — ประเภทหนังที่ฉาย สิ่งอำนวยความสะดวก วิธีเดินทาง และภาพบรรยากาศจริง พร้อมปุ่ม “ใกล้ฉัน” ที่เรียงโรงจากใกล้สุดไปไกลสุดตามระยะทางถนนจริง",
|
||||
"อยากแนะนำโรงใหม่ กลุ่มฉายหนัง หรือกิจกรรมที่ควรอยู่ในหน้านี้ ส่งมาให้ทีมงานได้เลย เราตรวจข้อมูลและเพิ่มให้ทุกสัปดาห์",
|
||||
],
|
||||
contactHeading: "มีโรงหรือรอบฉายที่อยากแนะนำ",
|
||||
contactNote:
|
||||
"ส่งชื่อโรงหรือกิจกรรมพร้อมลิงก์มาให้ทีมงานผ่านช่องทางโซเชียลในส่วนท้ายของหน้าเว็บ เราจะตรวจและเพิ่มให้ทุกสัปดาห์",
|
||||
},
|
||||
share: {
|
||||
label: "แชร์",
|
||||
pageLabel: "แชร์หน้านี้",
|
||||
copied: "คัดลอกลิงก์แล้ว",
|
||||
failed: "แชร์ไม่สำเร็จ",
|
||||
},
|
||||
list: {
|
||||
title: "รายชื่อโรงหนังทุกประเภทและกลุ่มคนฉายหนัง",
|
||||
showMore: "แสดงเพิ่ม",
|
||||
@@ -256,7 +315,8 @@ const TH: Messages = {
|
||||
|
||||
const EN: Messages = {
|
||||
meta: {
|
||||
homeDescription: "Find independent cinemas — an alternative way to watch films",
|
||||
homeDescription:
|
||||
"Find independent cinemas — an alternative way to watch films",
|
||||
cinemaNotFoundTitle: "Cinema not found",
|
||||
},
|
||||
hero: {
|
||||
@@ -279,6 +339,10 @@ const EN: Messages = {
|
||||
nav: {
|
||||
home: "Home",
|
||||
about: "About us",
|
||||
forCinemas: "For cinemas",
|
||||
forFilmLovers: "For film lovers",
|
||||
menu: "Menu",
|
||||
language: "Language",
|
||||
},
|
||||
about: {
|
||||
title: "About us",
|
||||
@@ -305,6 +369,36 @@ const EN: Messages = {
|
||||
contactNote:
|
||||
"Spotted wrong information, want to add a cinema, or need help promoting a screening? Use the social links in the footer of any page.",
|
||||
},
|
||||
forCinemas: {
|
||||
title: "For cinemas",
|
||||
lead: "AlterFlixHub gives independent cinemas, screening collectives and local theatres a place to tell their own story — with the details filmgoers need before leaving home.",
|
||||
paragraphs: [
|
||||
"Small cinemas in Thailand have stories as compelling as the big chains, yet many still have no structured way to reach their audience: information is scattered and viewers cannot find them.",
|
||||
"This page opens a dedicated detail page for any cinema on AlterFlixHub — location, how to get there, facilities and real photos — so people can decide before they travel.",
|
||||
"If you run a cinema, a screening collective or a community screening space and want to be listed, send your information to our team. We verify the details and set the page up for you during the launch period.",
|
||||
],
|
||||
contactHeading: "Want your cinema listed?",
|
||||
contactNote:
|
||||
"Send your cinema name, address and a few photos through the social links in the footer — we reply within two business days.",
|
||||
},
|
||||
forFilmLovers: {
|
||||
title: "For film lovers",
|
||||
lead: "A curated path for anyone who wants more than the mainstream — arthouse screens, screening collectives and special programmes, all in one place.",
|
||||
paragraphs: [
|
||||
"If you are looking for films that never reach the multiplex, AlterFlixHub helps you find the cinemas showing independent titles, documentaries, classics and special programmes in a few clicks.",
|
||||
"Every cinema listed comes with the details that matter before you leave home — genres, facilities, how to get there and real photos — plus a “Near me” button that sorts everything by real road distance.",
|
||||
"Know a cinema, a screening collective or an event that belongs here? Send it to our team and we will review it — new listings are added every week.",
|
||||
],
|
||||
contactHeading: "Know a cinema or a screening we should add?",
|
||||
contactNote:
|
||||
"Send the name and a link through the social channels in the footer — we review new listings every week.",
|
||||
},
|
||||
share: {
|
||||
label: "Share",
|
||||
pageLabel: "Share this page",
|
||||
copied: "Link copied",
|
||||
failed: "Couldn't share",
|
||||
},
|
||||
list: {
|
||||
title: "Local cinemas, indie screens and film collectives",
|
||||
showMore: "Show more",
|
||||
|
||||
@@ -0,0 +1,29 @@
|
||||
/**
|
||||
* ค่าคงที่ของ motion (ใช้ร่วมทุกหน้า)
|
||||
*
|
||||
* สคริปต์นี้ถูกฝังใน <head> (root.tsx) และรันก่อน paint เพื่อใส่คลาส `fx-motion`
|
||||
* ให้ <html> เฉพาะเมื่อผู้ใช้ไม่ได้ขอ reduced motion → เนื้อหาไม่กระพริบตอนโหลด
|
||||
* และถ้าปิด JS ไว้ก็ไม่มีคลาสนี้ = ไม่มีอะไรถูกซ่อน (progressive enhancement)
|
||||
*/
|
||||
export const MOTION_INIT_SCRIPT = `(function(){try{var m=window.matchMedia&&window.matchMedia("(prefers-reduced-motion: reduce)");if(m&&m.matches){return}document.documentElement.classList.add("fx-motion")}catch(e){}})();`;
|
||||
|
||||
/** รูปแบบการโผล่ของบล็อก — ตรงกับ selector `[data-reveal="…"]` ใน global.css */
|
||||
export type RevealKind = "rise" | "fade" | "zoom";
|
||||
|
||||
/**
|
||||
* เลื่อนหน้าไปที่ element โดยเคารพการตั้งค่า "ลดการเคลื่อนไหว" ของผู้ใช้
|
||||
* (ผู้ที่ปิดอนิเมชันจะกระโดดไปทันที ไม่มีการเลื่อนแบบ smooth)
|
||||
*/
|
||||
export function scrollIntoViewRespectMotion(
|
||||
element: HTMLElement | null,
|
||||
block: ScrollLogicalPosition = "start",
|
||||
): void {
|
||||
if (!element) return;
|
||||
const reduceMotion =
|
||||
typeof window !== "undefined" &&
|
||||
window.matchMedia("(prefers-reduced-motion: reduce)").matches;
|
||||
element.scrollIntoView({
|
||||
behavior: reduceMotion ? "auto" : "smooth",
|
||||
block,
|
||||
});
|
||||
}
|
||||
@@ -0,0 +1,14 @@
|
||||
/**
|
||||
* origin ของหน้าปัจจุบัน สำหรับใช้ใน `meta()` ของ route
|
||||
*
|
||||
* ทำไมต้องมาใน loader: `meta()` ไม่มี access ต่อ request และ (ใน framework นี้)
|
||||
* ไม่ได้รับ loader data ของ root ผ่าน `matches` — route ที่มี meta จึงต้อง
|
||||
* ส่ง origin ของคำขอตัวเองกลับมาใน loader แล้วอ่านจาก `loaderData.origin`
|
||||
*/
|
||||
import { originFromRequest } from "@/lib/request-origin";
|
||||
import { configuredOrigin } from "@/lib/site";
|
||||
|
||||
/** โดเมนของ request นี้ — ตั้ง env SITE_URL เฉพาะกรณีต้องบังคับ */
|
||||
export function resolvePageOrigin(request: Request): string {
|
||||
return configuredOrigin() || originFromRequest(request);
|
||||
}
|
||||
@@ -0,0 +1,44 @@
|
||||
/**
|
||||
* ลงทะเบียน service worker (PWA)
|
||||
*
|
||||
* - ลงทะเบียนทุกสภาพแวดล้อม: จำเป็นเพื่อ "ยึดอำนาจ" จาก SW เวอร์ชันเก่าที่อาจค้างอยู่
|
||||
* (SW ตัวใหม่จะลบแคชเก่าทิ้งในขั้น activate)
|
||||
* - ในโหมด dev ตัว SW จะไม่แตะโมดูลของ Vite (`/app/*`, `/node_modules/*`, `/@vite/*`)
|
||||
* เพราะกฎใน public/sw.js แคชเฉพาะ `/assets/*` กับไฟล์ static เท่านั้น → HMR ทำงานปกติ
|
||||
* - ถ้ามี SW ตัวใหม่รออยู่ ให้สั่ง skipWaiting ทันที (ไม่ต้องรอปิดแท็บทั้งหมด)
|
||||
* ไม่ reload หน้าอัตโนมัติเพื่อเลี่ยงลูปตอน dev
|
||||
*/
|
||||
export function registerServiceWorker(): void {
|
||||
if (typeof navigator === "undefined" || !("serviceWorker" in navigator)) return;
|
||||
|
||||
const start = () => {
|
||||
navigator.serviceWorker
|
||||
.register("/sw.js", { scope: "/", updateViaCache: "none" })
|
||||
.then((registration) => {
|
||||
// ตรวจไฟล์ sw.js ใหม่จากเครือข่ายทุกครั้ง (ไม่ใช้ HTTP cache)
|
||||
registration.update().catch(() => undefined);
|
||||
|
||||
const promote = (worker: ServiceWorker | null) => {
|
||||
if (!worker) return;
|
||||
worker.addEventListener("statechange", () => {
|
||||
if (worker.state === "installed" && navigator.serviceWorker.controller) {
|
||||
worker.postMessage("SKIP_WAITING");
|
||||
}
|
||||
});
|
||||
};
|
||||
|
||||
registration.addEventListener("updatefound", () => {
|
||||
promote(registration.installing);
|
||||
});
|
||||
|
||||
// มีตัวใหม่รออยู่แล้ว (เช่น เปิดแท็บค้างไว้ตอนปล่อยเวอร์ชัน)
|
||||
if (registration.waiting) registration.waiting.postMessage("SKIP_WAITING");
|
||||
})
|
||||
.catch(() => {
|
||||
// ลงทะเบียนไม่ได้ (เบราว์เซอร์เก่า/โหมดส่วนตัว) — เว็บยังใช้งานปกติ
|
||||
});
|
||||
};
|
||||
|
||||
if (document.readyState === "complete") start();
|
||||
else window.addEventListener("load", start, { once: true });
|
||||
}
|
||||
@@ -0,0 +1,102 @@
|
||||
/**
|
||||
* ทดสอบการหา origin จาก request — หัวใจของ "ไม่ฝังโดเมนในโค้ด"
|
||||
* (canonical/OG/sitemap/robots ใช้ค่านี้ทั้งหมด)
|
||||
*/
|
||||
import { describe, expect, it } from "vitest";
|
||||
|
||||
import {
|
||||
normalizeOrigin,
|
||||
originFromHeaders,
|
||||
originFromRequest,
|
||||
} from "@/lib/request-origin";
|
||||
|
||||
function headers(map: Record<string, string>): Headers {
|
||||
return new Headers(map);
|
||||
}
|
||||
|
||||
describe("normalizeOrigin", () => {
|
||||
it("ตัด / ท้ายและช่องว่าง", () => {
|
||||
expect(normalizeOrigin(" https://a.test/ ")).toBe("https://a.test");
|
||||
});
|
||||
|
||||
it("เติม https ให้ถ้าไม่มี scheme", () => {
|
||||
expect(normalizeOrigin("a.test")).toBe("https://a.test");
|
||||
});
|
||||
|
||||
it("ค่าว่าง → ค่าว่าง", () => {
|
||||
expect(normalizeOrigin(" ")).toBe("");
|
||||
});
|
||||
});
|
||||
|
||||
describe("originFromHeaders", () => {
|
||||
it("ใช้ host + https เป็นค่าเริ่มต้น", () => {
|
||||
expect(
|
||||
originFromHeaders(headers({ host: "alterflixhub.hobbypj.com" })),
|
||||
).toBe("https://alterflixhub.hobbypj.com");
|
||||
});
|
||||
|
||||
it("เชื่อ x-forwarded-host / x-forwarded-proto (อยู่หลัง proxy)", () => {
|
||||
expect(
|
||||
originFromHeaders(
|
||||
headers({
|
||||
host: "internal:3000",
|
||||
"x-forwarded-host": "alterflixhub.hobbypj.com",
|
||||
"x-forwarded-proto": "https",
|
||||
}),
|
||||
),
|
||||
).toBe("https://alterflixhub.hobbypj.com");
|
||||
});
|
||||
|
||||
it("รับค่าแรกเมื่อ header มีหลายชั้น", () => {
|
||||
expect(
|
||||
originFromHeaders(
|
||||
headers({
|
||||
"x-forwarded-host": "a.test, b.test",
|
||||
"x-forwarded-proto": "http, https",
|
||||
}),
|
||||
),
|
||||
).toBe("http://a.test");
|
||||
});
|
||||
|
||||
it("คง port ไว้ (localhost dev)", () => {
|
||||
expect(
|
||||
originFromHeaders(
|
||||
headers({ host: "localhost:8080", "x-forwarded-proto": "http" }),
|
||||
),
|
||||
).toBe("http://localhost:8080");
|
||||
});
|
||||
|
||||
it("ไม่มี host → ค่าว่าง", () => {
|
||||
expect(originFromHeaders(headers({}))).toBe("");
|
||||
});
|
||||
|
||||
it("รองรับ plain object ของ h3", () => {
|
||||
expect(
|
||||
originFromHeaders({ host: "h3.test", "x-forwarded-proto": "https" }),
|
||||
).toBe("https://h3.test");
|
||||
});
|
||||
});
|
||||
|
||||
describe("originFromRequest", () => {
|
||||
it("อ่าน host จาก header และใช้โปรโตคอลจริงของ request (dev = http)", () => {
|
||||
const request = new Request("http://internal/", {
|
||||
headers: { host: "alterflixhub.hobbypj.com" },
|
||||
});
|
||||
expect(originFromRequest(request)).toBe("http://alterflixhub.hobbypj.com");
|
||||
});
|
||||
|
||||
it("เชื่อ x-forwarded-proto เมื่ออยู่หลัง proxy ที่ปิด TLS", () => {
|
||||
const request = new Request("http://internal/", {
|
||||
headers: {
|
||||
host: "alterflixhub.hobbypj.com",
|
||||
"x-forwarded-proto": "https",
|
||||
},
|
||||
});
|
||||
expect(originFromRequest(request)).toBe("https://alterflixhub.hobbypj.com");
|
||||
});
|
||||
|
||||
it("ไม่มี header host → ใช้ URL ของ request", () => {
|
||||
const request = new Request("http://localhost:8080/cinema/x");
|
||||
expect(originFromRequest(request)).toBe("http://localhost:8080");
|
||||
});
|
||||
});
|
||||
@@ -0,0 +1,71 @@
|
||||
/**
|
||||
* หา "origin" ของคำขอนี้ (เช่น `https://alterflixhub.hobbypj.com`, `http://localhost:8080`)
|
||||
*
|
||||
* ใช้แทนการฮาร์ดโค้ดโดเมน: canonical / OG / sitemap / robots มาจาก request จริงทุกครั้ง
|
||||
* รองรับหลัง reverse proxy (Cloudflare, Nginx, Vercel) ที่ส่ง `x-forwarded-host` / `x-forwarded-proto`
|
||||
*/
|
||||
|
||||
/** header ที่อ่านได้ — รองรับทั้ง `Headers`, plain object ของ h3 และค่า undefined */
|
||||
export type HeaderSource =
|
||||
| { get(name: string): string | null }
|
||||
| Record<string, string | string[] | undefined>;
|
||||
|
||||
/** ตัด `/` ท้าย, เติม scheme ให้ถ้าไม่มี, คืน "" ถ้าว่าง */
|
||||
export function normalizeOrigin(value: string): string {
|
||||
const trimmed = value.trim().replace(/\/+$/, "");
|
||||
if (trimmed === "") return "";
|
||||
return /^[a-z][a-z0-9+.-]*:\/\//i.test(trimmed)
|
||||
? trimmed
|
||||
: `https://${trimmed}`;
|
||||
}
|
||||
|
||||
function readHeader(source: HeaderSource, name: string): string {
|
||||
if (typeof (source as { get?: unknown }).get === "function") {
|
||||
const value = (source as { get(n: string): string | null }).get(name);
|
||||
return typeof value === "string" ? value : "";
|
||||
}
|
||||
const record = source as Record<string, string | string[] | undefined>;
|
||||
const value = record[name.toLowerCase()] ?? record[name];
|
||||
if (Array.isArray(value)) return value[0] ?? "";
|
||||
return typeof value === "string" ? value : "";
|
||||
}
|
||||
|
||||
/** ค่าแรกก่อนจุลภาค (`a, b` → `a`) — proxy บางตัวต่อ host หลายชั้น */
|
||||
function firstValue(value: string): string {
|
||||
return value.split(",")[0]?.trim() ?? "";
|
||||
}
|
||||
|
||||
export function originFromHeaders(
|
||||
source: HeaderSource,
|
||||
fallbackProto = "https",
|
||||
): string {
|
||||
const forwardedHost = firstValue(readHeader(source, "x-forwarded-host"));
|
||||
const host =
|
||||
forwardedHost !== ""
|
||||
? forwardedHost
|
||||
: firstValue(readHeader(source, "host"));
|
||||
if (host === "") return "";
|
||||
|
||||
// proxy ที่ไม่ส่ง x-forwarded-proto → ใช้โปรโตคอลจริงของคำขอ (dev = http)
|
||||
const forwardedProto = firstValue(readHeader(source, "x-forwarded-proto"));
|
||||
const proto = forwardedProto !== "" ? forwardedProto : fallbackProto;
|
||||
return normalizeOrigin(`${proto}://${host}`);
|
||||
}
|
||||
|
||||
/** origin ของ Request (ใช้ใน loader / resource route) */
|
||||
export function originFromRequest(request: Request): string {
|
||||
let protocol = "https";
|
||||
try {
|
||||
protocol = new URL(request.url).protocol.replace(":", "");
|
||||
} catch {
|
||||
// URL เพี้ยน → ใช้ค่าเริ่มต้น
|
||||
}
|
||||
const fromHeaders = originFromHeaders(request.headers, protocol);
|
||||
if (fromHeaders !== "") return fromHeaders;
|
||||
// ไม่มี header host (เช่นเรียกภายใน) → ใช้ URL ที่ framework สร้างให้
|
||||
try {
|
||||
return normalizeOrigin(new URL(request.url).origin);
|
||||
} catch {
|
||||
return "";
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,183 @@
|
||||
import { describe, expect, it } from "vitest";
|
||||
|
||||
import { CINEMAS, DEFAULT_CATEGORY, type Cinema } from "./cinemas";
|
||||
import {
|
||||
buildSearchIndex,
|
||||
FIELD_WEIGHTS,
|
||||
filterCinemas,
|
||||
foldSearchText,
|
||||
normalizeSearchText,
|
||||
scoreCinema,
|
||||
searchTokens,
|
||||
} from "./search";
|
||||
|
||||
describe("normalizeSearchText", () => {
|
||||
it("ตัดช่องว่างหัวท้าย ลดตัวพิมพ์ และแปลงตัวคั่นเป็นช่องว่าง", () => {
|
||||
expect(normalizeSearchText(" HOUSE · สามย่าน ")).toBe("house สามย่าน");
|
||||
expect(normalizeSearchText("DOC CLUB & FRIENDS")).toBe("doc club friends");
|
||||
});
|
||||
|
||||
it("ตัดอักขระล่องหนที่ติดมากับการคัดลอก", () => {
|
||||
expect(normalizeSearchText("เฮ้า\u200Bส์")).toBe("เฮ้าส์");
|
||||
});
|
||||
});
|
||||
|
||||
describe("foldSearchText", () => {
|
||||
it("ตัดวรรณยุกต์ภาษาอังกฤษ (Française → francaise)", () => {
|
||||
expect(foldSearchText("Française")).toBe("francaise");
|
||||
});
|
||||
|
||||
it("ตัดวรรณยุกต์ไทย (เฮ้าส์ → เฮาส)", () => {
|
||||
expect(foldSearchText("เฮ้าส์")).toBe("เฮาส");
|
||||
});
|
||||
});
|
||||
|
||||
describe("searchTokens", () => {
|
||||
it("แยกหลายคำ และคืนอาร์เรย์ว่างเมื่อไม่มีคำค้น", () => {
|
||||
expect(searchTokens(" สามย่าน house ")).toEqual(["สามย่าน", "house"]);
|
||||
expect(searchTokens(" ")).toEqual([]);
|
||||
expect(searchTokens("·")).toEqual([]);
|
||||
});
|
||||
});
|
||||
|
||||
describe("filterCinemas", () => {
|
||||
it("คืนทุกโรงหนังเมื่อเลือกหมวดทั้งหมดและไม่พิมพ์ค้นหา", () => {
|
||||
const result = filterCinemas(CINEMAS, {
|
||||
category: DEFAULT_CATEGORY,
|
||||
query: "",
|
||||
});
|
||||
expect(result.length).toBeGreaterThan(0);
|
||||
});
|
||||
|
||||
it("กรองตามหมวดหมู่จาก tags", () => {
|
||||
const result = filterCinemas(CINEMAS, {
|
||||
category: "อาร์ตเฮาส์",
|
||||
query: "",
|
||||
});
|
||||
expect(result.length).toBeGreaterThan(0);
|
||||
expect(result.every((cinema) => cinema.tags.includes("อาร์ตเฮาส์"))).toBe(
|
||||
true,
|
||||
);
|
||||
});
|
||||
|
||||
it("ค้นหาแบบไม่สนตัวพิมพ์และตัดช่องว่างหัวท้าย", () => {
|
||||
const result = filterCinemas(CINEMAS, {
|
||||
category: DEFAULT_CATEGORY,
|
||||
query: " house ",
|
||||
});
|
||||
expect(result.map((cinema) => cinema.slug)).toContain(
|
||||
"house-cinema-samyan",
|
||||
);
|
||||
});
|
||||
|
||||
it("คืนอาร์เรย์ว่างเมื่อไม่พบคำค้น", () => {
|
||||
expect(
|
||||
filterCinemas(CINEMAS, {
|
||||
category: DEFAULT_CATEGORY,
|
||||
query: "ไม่มีโรงนี้แน่นอน",
|
||||
}),
|
||||
).toEqual([]);
|
||||
});
|
||||
|
||||
// ── ค้นด้วยข้อความที่แสดงบนการ์ดจริง ────────────────────────────────
|
||||
it("ค้นด้วยชื่อไทยที่แสดงบนการ์ด (name_th) ได้", () => {
|
||||
const result = filterCinemas(CINEMAS, {
|
||||
category: DEFAULT_CATEGORY,
|
||||
query: "เซ็นจูรี่มูฟวี่พลาซ่า",
|
||||
});
|
||||
expect(result.map((cinema) => cinema.slug)).toContain(
|
||||
"century-the-movie-plaza",
|
||||
);
|
||||
});
|
||||
|
||||
it("ค้นด้วยชื่อไทยที่พิมพ์ไม่ครบ (คำนำหน้า) ได้", () => {
|
||||
const result = filterCinemas(CINEMAS, {
|
||||
category: DEFAULT_CATEGORY,
|
||||
query: "เซ็นจูรี่",
|
||||
});
|
||||
expect(result.length).toBeGreaterThan(1);
|
||||
expect(
|
||||
result.every((cinema) => (cinema.name_th ?? "").includes("เซ็นจูรี่")),
|
||||
).toBe(true);
|
||||
});
|
||||
|
||||
it("ค้นชื่ออังกฤษแบบไม่ใส่วรรณยุกต์ก็เจอ", () => {
|
||||
expect(
|
||||
filterCinemas(CINEMAS, {
|
||||
category: DEFAULT_CATEGORY,
|
||||
query: "francaise",
|
||||
}).map((cinema) => cinema.slug),
|
||||
).toContain("alliance-francaise-de-bangkok");
|
||||
});
|
||||
|
||||
it("ค้นด้วยชื่อหมวดที่แสดงบนการ์ดได้ (ทั้งคีย์ไทยและป้ายภาษาอังกฤษ)", () => {
|
||||
const th = filterCinemas(CINEMAS, {
|
||||
category: DEFAULT_CATEGORY,
|
||||
query: "อาร์ตเฮาส์",
|
||||
});
|
||||
expect(th.map((cinema) => cinema.slug)).toContain("house-cinema-samyan");
|
||||
|
||||
const en = filterCinemas(CINEMAS, {
|
||||
category: DEFAULT_CATEGORY,
|
||||
query: "arthouse",
|
||||
tagLabels: { อาร์ตเฮาส์: "Arthouse" },
|
||||
});
|
||||
expect(en.map((cinema) => cinema.slug)).toContain("house-cinema-samyan");
|
||||
});
|
||||
|
||||
it("ค้นหลายคำสลับลำดับได้ (ทุกคำต้องเจอ)", () => {
|
||||
const result = filterCinemas(CINEMAS, {
|
||||
category: DEFAULT_CATEGORY,
|
||||
query: "samyan HOUSE",
|
||||
});
|
||||
expect(result.map((cinema) => cinema.slug)).toEqual([
|
||||
"house-cinema-samyan",
|
||||
]);
|
||||
});
|
||||
|
||||
it("ค้นข้อความที่คัดลอกมาจากการ์ดทั้งบรรทัด (มีตัวคั่น ·) ได้", () => {
|
||||
const result = filterCinemas(CINEMAS, {
|
||||
category: DEFAULT_CATEGORY,
|
||||
query: "HOUSE สามย่าน · อาร์ตเฮาส์",
|
||||
});
|
||||
expect(result.map((cinema) => cinema.slug)).toContain(
|
||||
"house-cinema-samyan",
|
||||
);
|
||||
});
|
||||
|
||||
it("เรียงผลลัพธ์ที่ตรงที่สุดก่อน", () => {
|
||||
const result = filterCinemas(CINEMAS, {
|
||||
category: DEFAULT_CATEGORY,
|
||||
query: "cineplex",
|
||||
});
|
||||
expect(result[0]?.slug).toBe("thana-cineplex");
|
||||
});
|
||||
});
|
||||
|
||||
describe("scoreCinema", () => {
|
||||
const house = CINEMAS.find(
|
||||
(cinema) => cinema.slug === "house-cinema-samyan",
|
||||
) as Cinema;
|
||||
|
||||
it("คืน 0 เมื่อไม่มีคำค้น หรือคำค้นไม่ตรงเลย", () => {
|
||||
expect(scoreCinema(house, [])).toBe(0);
|
||||
expect(scoreCinema(house, searchTokens("zzzz"))).toBe(0);
|
||||
});
|
||||
|
||||
it("ชื่อที่ตรงทั้งคำได้คะแนนสูงกว่าการเจอในรายละเอียด", () => {
|
||||
const byName = scoreCinema(house, searchTokens("house"));
|
||||
const byTag = scoreCinema(house, searchTokens("อาร์ตเฮาส์"));
|
||||
expect(byName).toBeGreaterThan(byTag);
|
||||
expect(byName).toBeGreaterThanOrEqual(FIELD_WEIGHTS.names);
|
||||
});
|
||||
});
|
||||
|
||||
describe("buildSearchIndex", () => {
|
||||
it("เตรียมฟิลด์ชื่อ/สถานที่/หมวดไว้เทียบ และไม่เก็บค่าว่าง", () => {
|
||||
const index = buildSearchIndex(CINEMAS[0], { อาร์ตเฮาส์: "Arthouse" });
|
||||
expect(index.length).toBeGreaterThan(0);
|
||||
expect(index.every((field) => field.exact !== "")).toBe(true);
|
||||
expect(index.some((field) => field.exact.includes("arthouse"))).toBe(true);
|
||||
expect(index.some((field) => field.group === "names")).toBe(true);
|
||||
});
|
||||
});
|
||||
@@ -0,0 +1,211 @@
|
||||
/**
|
||||
* เครื่องยนต์ค้นหาโรงหนัง
|
||||
*
|
||||
* แยกออกจาก `app/lib/cinemas.ts` (ซึ่งเป็น "ข้อมูล + ตัวกรองหมวด") เพื่อให้แต่ละไฟล์
|
||||
* ทำหน้าที่เดียว อ่านเข้าใจง่าย และเทสต์แยกได้โดยไม่ต้องโหลดข้อมูลทั้งชุด
|
||||
*
|
||||
* ลำดับการทำงาน
|
||||
* 1) normalizeSearchText / foldSearchText — ทำให้ข้อความเทียบกันได้
|
||||
* 2) searchTokens — แยกคำค้นเป็นหลายคำ (ทุกคำต้องเจอ = AND, เรียงสลับได้)
|
||||
* 3) buildSearchIndex — เตรียมข้อความทุกฟิลด์ของโรงหนึ่ง (ทำครั้งเดียวต่อโรง)
|
||||
* 4) matchLevel + FIELD_WEIGHTS — ให้คะแนนความตรง
|
||||
* 5) scoreCinema / filterCinemas — รวมผลและเรียงจากตรงที่สุด
|
||||
*/
|
||||
import { hasCategory, type Cinema, type CinemaCategory } from "@/lib/cinemas";
|
||||
|
||||
/** อักขระล่องหนที่ติดมากับการคัดลอกข้อความ (zero-width, BOM) */
|
||||
const ZERO_WIDTH = /[\u200B-\u200D\u2060\uFEFF]/g;
|
||||
/** วรรณยุกต์/สระบน-ล่าง (combining marks) — ใช้เทียบแบบหลวม */
|
||||
const COMBINING_MARKS = /\p{M}+/gu;
|
||||
|
||||
/**
|
||||
* ปรับข้อความให้เทียบกันได้: NFKC, ตัดอักขระล่องหน, ตัวพิมพ์เล็ก,
|
||||
* แปลงตัวคั่น (· • / & — …) เป็นช่องว่าง แล้วยุบช่องว่างซ้ำ
|
||||
*/
|
||||
export function normalizeSearchText(value: string): string {
|
||||
return value
|
||||
.normalize("NFKC")
|
||||
.replace(ZERO_WIDTH, "")
|
||||
.toLowerCase()
|
||||
.replace(/[·•・,،.\\/_|+&()\[\]{}<>"'’‘`“”«»—–~*:;!?$%^@#№-]+/g, " ")
|
||||
.replace(/\s+/g, " ")
|
||||
.trim();
|
||||
}
|
||||
|
||||
/**
|
||||
* รูปแบบ "หลวม" ของข้อความ: ตัดวรรณยุกต์/สระบน-ล่างออก
|
||||
* ทำให้ "Française" = "francaise", "เฮ้าส์" = "เฮาส" (พิมพ์ไม่ครบ/ไม่ใส่วรรณยุกต์ก็เจอ)
|
||||
*/
|
||||
export function foldSearchText(value: string): string {
|
||||
return normalizeSearchText(value)
|
||||
.normalize("NFD")
|
||||
.replace(COMBINING_MARKS, "")
|
||||
.replace(/[^\p{L}\p{N}\s]+/gu, " ")
|
||||
.replace(/\s+/g, " ")
|
||||
.trim();
|
||||
}
|
||||
|
||||
/** แยกคำค้นเป็น token — คืนอาร์เรย์ว่างเมื่อไม่มีอะไรให้ค้น */
|
||||
export function searchTokens(query: string): string[] {
|
||||
const normalized = normalizeSearchText(query);
|
||||
if (normalized === "") return [];
|
||||
return normalized.split(" ").filter((token) => token !== "");
|
||||
}
|
||||
|
||||
/**
|
||||
* กลุ่มฟิลด์ที่ค้น + น้ำหนัก
|
||||
* ชื่อโรงสำคัญที่สุด รองลงมาสถานที่/หมวด และรายละเอียดเป็นตัวสุดท้าย
|
||||
*/
|
||||
export const FIELD_WEIGHTS = {
|
||||
names: 400,
|
||||
place: 180,
|
||||
categories: 150,
|
||||
details: 60,
|
||||
} as const;
|
||||
|
||||
export type FieldGroup = keyof typeof FIELD_WEIGHTS;
|
||||
|
||||
/**
|
||||
* ระดับความตรง — คูณกับน้ำหนักของกลุ่มฟิลด์
|
||||
* | ระดับ | ค่า | ตัวอย่าง (ค้น "house") |
|
||||
* |------------------|-------|-----------------------------------|
|
||||
* | เท่ากันทั้งค่า | 3 | ฟิลด์ = "house" |
|
||||
* | ขึ้นต้นด้วยคำ | 2 | "house cinema samyan" |
|
||||
* | มีคำอยู่ข้างใน | 1.2 | "the house of films" |
|
||||
* | แบบหลวม (ตัดวรรณยุกต์) | 0.8 | "เฮ้าส์" จับคู่ "เฮาส" |
|
||||
* | ไม่ตรง | 0 | — |
|
||||
*/
|
||||
export const MATCH_LEVEL = {
|
||||
exact: 3,
|
||||
prefix: 2,
|
||||
contains: 1.2,
|
||||
loose: 0.8,
|
||||
} as const;
|
||||
|
||||
/** ฟิลด์หนึ่งฟิลด์ที่เตรียมไว้เทียบแล้ว (แปลงครั้งเดียว ใช้ได้ทุกคำค้น) */
|
||||
export type IndexedField = {
|
||||
group: FieldGroup;
|
||||
exact: string;
|
||||
loose: string;
|
||||
};
|
||||
|
||||
/**
|
||||
* รวมข้อความทุกจุดที่ผู้ใช้เห็น (ชื่อ/สถานที่/หมวด/รายละเอียด) แล้วแปลงล่วงหน้า
|
||||
* เรียกครั้งเดียวต่อโรง แล้วนำผลไปให้คะแนนได้หลาย token โดยไม่ต้องแปลงซ้ำ
|
||||
*/
|
||||
export function buildSearchIndex(
|
||||
cinema: Cinema,
|
||||
tagLabels: Record<string, string> = {},
|
||||
): IndexedField[] {
|
||||
const raw: Record<FieldGroup, string[]> = {
|
||||
names: [cinema.name, cinema.name_th ?? "", cinema.slug.replace(/-/g, " ")],
|
||||
place: [
|
||||
cinema.location_label,
|
||||
cinema.location_label_en ?? "",
|
||||
...(cinema.address_lines ?? []),
|
||||
...(cinema.address_lines_en ?? []),
|
||||
...cinema.transport.flatMap((mode) => [mode.value, mode.value_en ?? ""]),
|
||||
],
|
||||
categories: [
|
||||
...cinema.tags,
|
||||
...cinema.tags.map((tag) => tagLabels[tag] ?? ""),
|
||||
],
|
||||
details: [
|
||||
cinema.description,
|
||||
cinema.description_en ?? "",
|
||||
...cinema.contacts.flatMap((contact) => [contact.label, contact.value]),
|
||||
],
|
||||
};
|
||||
|
||||
const index: IndexedField[] = [];
|
||||
for (const group of Object.keys(raw) as FieldGroup[]) {
|
||||
for (const value of raw[group]) {
|
||||
if (value.trim() === "") continue;
|
||||
index.push({
|
||||
group,
|
||||
exact: normalizeSearchText(value),
|
||||
loose: foldSearchText(value),
|
||||
});
|
||||
}
|
||||
}
|
||||
return index;
|
||||
}
|
||||
|
||||
/** ความตรงของ "หนึ่งฟิลด์กับหนึ่งคำค้น" — คืน 0 เมื่อไม่ตรง */
|
||||
function matchLevel(
|
||||
field: IndexedField,
|
||||
token: string,
|
||||
looseToken: string,
|
||||
): number {
|
||||
if (field.exact === token) return MATCH_LEVEL.exact;
|
||||
if (field.exact.startsWith(token)) return MATCH_LEVEL.prefix;
|
||||
if (field.exact.includes(token)) return MATCH_LEVEL.contains;
|
||||
if (looseToken !== "" && field.loose.includes(looseToken)) {
|
||||
return MATCH_LEVEL.loose;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* ให้คะแนนโรงหนึ่งกับคำค้น (0 = ไม่ตรง)
|
||||
* ทุกคำต้องเจออย่างน้อยหนึ่งฟิลด์ (AND) แล้วนำคะแนนของแต่ละคำมารวมกัน
|
||||
*/
|
||||
export function scoreCinema(
|
||||
cinema: Cinema,
|
||||
tokens: string[],
|
||||
tagLabels: Record<string, string> = {},
|
||||
): number {
|
||||
if (tokens.length === 0) return 0;
|
||||
|
||||
const index = buildSearchIndex(cinema, tagLabels);
|
||||
let total = 0;
|
||||
|
||||
for (const token of tokens) {
|
||||
const looseToken = foldSearchText(token);
|
||||
let bestForToken = 0;
|
||||
|
||||
for (const field of index) {
|
||||
const level = matchLevel(field, token, looseToken);
|
||||
if (level === 0) continue;
|
||||
bestForToken = Math.max(bestForToken, FIELD_WEIGHTS[field.group] * level);
|
||||
}
|
||||
|
||||
if (bestForToken === 0) return 0;
|
||||
total += bestForToken;
|
||||
}
|
||||
|
||||
return total;
|
||||
}
|
||||
|
||||
/**
|
||||
* กรอง + เรียงผลลัพธ์
|
||||
* - ไม่มีคำค้น → คงลำดับเดิม (ลำดับรายวัน/ยอดนิยม) แล้วกรองแค่หมวด
|
||||
* - มีคำค้น → เรียงจากคะแนนมากไปน้อย (คะแนนเท่ากันคงลำดับเดิม)
|
||||
*/
|
||||
export function filterCinemas(
|
||||
cinemas: Cinema[],
|
||||
{
|
||||
category,
|
||||
query,
|
||||
tagLabels = {},
|
||||
}: {
|
||||
category: CinemaCategory;
|
||||
query: string;
|
||||
/** ป้ายหมวดตามภาษาที่แสดงบนการ์ด (messages.tags) */
|
||||
tagLabels?: Record<string, string>;
|
||||
},
|
||||
): Cinema[] {
|
||||
const inCategory = cinemas.filter((cinema) => hasCategory(cinema, category));
|
||||
const tokens = searchTokens(query);
|
||||
if (tokens.length === 0) return inCategory;
|
||||
|
||||
return inCategory
|
||||
.map((cinema, index) => ({
|
||||
cinema,
|
||||
index,
|
||||
score: scoreCinema(cinema, tokens, tagLabels),
|
||||
}))
|
||||
.filter((row) => row.score > 0)
|
||||
.sort((a, b) => b.score - a.score || a.index - b.index)
|
||||
.map((row) => row.cinema);
|
||||
}
|
||||
+211
@@ -0,0 +1,211 @@
|
||||
/**
|
||||
* ตัวช่วยสร้าง meta / JSON-LD ให้ทุก route (SEO พื้นฐาน)
|
||||
*
|
||||
* ทุกฟังก์ชันคืน "meta descriptor" ของ React Router — ใช้ได้ทั้ง SSR และตอนสลับหน้า
|
||||
* ค่าที่ crawler เห็นจึงเหมือนกันทุกครั้ง (ไม่พึ่ง JavaScript ฝั่ง client)
|
||||
*/
|
||||
import type { MetaDescriptor } from "react-router";
|
||||
|
||||
import { SITE } from "@/lib/site";
|
||||
|
||||
/** เติมโดเมนให้พาธ — canonical/OG ต้องเป็น URL เต็มเสมอ */
|
||||
export function absoluteUrl(origin: string, path: string): string {
|
||||
const suffix = path.startsWith("/") ? path : `/${path}`;
|
||||
return `${origin.replace(/\/+$/, "")}${suffix}`;
|
||||
}
|
||||
|
||||
type MetaMatch = { id?: string; data?: unknown };
|
||||
|
||||
/** อ่าน origin ที่ root loader คำนวณไว้ (ใช้ใน meta() ของ route ลูก) */
|
||||
export function originFromMatches(
|
||||
matches: Array<MetaMatch> | undefined,
|
||||
): string {
|
||||
if (!matches) return "";
|
||||
// ไม่ยึด id ของ root — เอา match แรกที่มี siteUrl (framework เปลี่ยน id ได้)
|
||||
for (const match of matches) {
|
||||
const data = match.data as { siteUrl?: unknown } | undefined;
|
||||
if (typeof data?.siteUrl === "string" && data.siteUrl !== "")
|
||||
return data.siteUrl;
|
||||
}
|
||||
return "";
|
||||
}
|
||||
|
||||
type PageMetaInput = {
|
||||
/** origin ของคำขอ เช่น `https://alterflixhub.hobbypj.com` (ห้ามฮาร์ดโค้ด) */
|
||||
origin: string;
|
||||
title: string;
|
||||
description: string;
|
||||
/** พาธของหน้านั้น ๆ เช่น `/about` หรือ `/cinema/lido-connect` */
|
||||
path: string;
|
||||
/** og:type — `article` สำหรับหน้าบทความ, `website` สำหรับหน้าทั่วไป */
|
||||
type?: "website" | "article";
|
||||
/** true = ไม่ให้ index (เช่นหน้าหลังบ้าน) */
|
||||
noIndex?: boolean;
|
||||
};
|
||||
|
||||
/** meta ชุดมาตรฐานของหนึ่งหน้า: title, description, canonical, OG, Twitter */
|
||||
export function pageMeta({
|
||||
origin,
|
||||
title,
|
||||
description,
|
||||
path,
|
||||
type = "website",
|
||||
noIndex = false,
|
||||
}: PageMetaInput): MetaDescriptor[] {
|
||||
const url = absoluteUrl(origin, path);
|
||||
const image = absoluteUrl(origin, SITE.ogImage);
|
||||
|
||||
return [
|
||||
{ title },
|
||||
{ name: "description", content: description },
|
||||
{
|
||||
name: "robots",
|
||||
content: noIndex
|
||||
? "noindex, nofollow"
|
||||
: "index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1",
|
||||
},
|
||||
{ tagName: "link", rel: "canonical", href: url },
|
||||
{ property: "og:type", content: type },
|
||||
{ property: "og:site_name", content: SITE.name },
|
||||
{ property: "og:locale", content: SITE.locale },
|
||||
{ property: "og:title", content: title },
|
||||
{ property: "og:description", content: description },
|
||||
{ property: "og:url", content: url },
|
||||
{ property: "og:image", content: image },
|
||||
{ property: "og:image:width", content: "1200" },
|
||||
{ property: "og:image:height", content: "630" },
|
||||
{ property: "og:image:alt", content: SITE.name },
|
||||
{ name: "twitter:card", content: "summary_large_image" },
|
||||
{ name: "twitter:title", content: title },
|
||||
{ name: "twitter:description", content: description },
|
||||
{ name: "twitter:image", content: image },
|
||||
];
|
||||
}
|
||||
|
||||
/** JSON-LD ของเว็บไซต์ + องค์กร (ใส่ที่หน้าแรกครั้งเดียว) */
|
||||
export function websiteJsonLd(origin: string): MetaDescriptor[] {
|
||||
return [
|
||||
{
|
||||
"script:ld+json": {
|
||||
"@context": "https://schema.org",
|
||||
"@graph": [
|
||||
{
|
||||
"@type": "WebSite",
|
||||
"@id": `${origin}/#website`,
|
||||
url: `${origin}/`,
|
||||
name: SITE.name,
|
||||
description: SITE.description,
|
||||
inLanguage: "th-TH",
|
||||
publisher: { "@id": `${origin}/#organization` },
|
||||
potentialAction: {
|
||||
"@type": "SearchAction",
|
||||
target: `${origin}/?q={search_term_string}`,
|
||||
"query-input": "required name=search_term_string",
|
||||
},
|
||||
},
|
||||
{
|
||||
"@type": "Organization",
|
||||
"@id": `${origin}/#organization`,
|
||||
name: SITE.name,
|
||||
url: `${origin}/`,
|
||||
logo: absoluteUrl(origin, "/icon-512.png"),
|
||||
},
|
||||
],
|
||||
},
|
||||
},
|
||||
];
|
||||
}
|
||||
|
||||
/** JSON-LD breadcrumb ของหน้า (ช่วยให้ Google แสดงเส้นทางในผลค้นหา) */
|
||||
export function breadcrumbJsonLd(
|
||||
origin: string,
|
||||
items: Array<{ name: string; path: string }>,
|
||||
): MetaDescriptor[] {
|
||||
return [
|
||||
{
|
||||
"script:ld+json": {
|
||||
"@context": "https://schema.org",
|
||||
"@type": "BreadcrumbList",
|
||||
itemListElement: items.map((item, index) => ({
|
||||
"@type": "ListItem",
|
||||
position: index + 1,
|
||||
name: item.name,
|
||||
item: absoluteUrl(origin, item.path),
|
||||
})),
|
||||
},
|
||||
},
|
||||
];
|
||||
}
|
||||
|
||||
/** JSON-LD ของหน้าโรงหนัง — MovieTheater + ที่ตั้ง + พิกัด */
|
||||
export function cinemaJsonLd(input: {
|
||||
origin: string;
|
||||
name: string;
|
||||
description: string;
|
||||
path: string;
|
||||
image?: string | null;
|
||||
coordinates?: { latitude: number; longitude: number } | null;
|
||||
locationLabel?: string;
|
||||
mapUrl?: string | null;
|
||||
}): MetaDescriptor[] {
|
||||
const image = input.image && input.image.trim() !== "" ? input.image : null;
|
||||
|
||||
return [
|
||||
{
|
||||
"script:ld+json": {
|
||||
"@context": "https://schema.org",
|
||||
"@type": "MovieTheater",
|
||||
name: input.name,
|
||||
description: input.description,
|
||||
url: absoluteUrl(input.origin, input.path),
|
||||
...(image
|
||||
? {
|
||||
image: image.startsWith("http")
|
||||
? image
|
||||
: absoluteUrl(input.origin, image),
|
||||
}
|
||||
: {}),
|
||||
...(input.coordinates
|
||||
? {
|
||||
geo: {
|
||||
"@type": "GeoCoordinates",
|
||||
latitude: input.coordinates.latitude,
|
||||
longitude: input.coordinates.longitude,
|
||||
},
|
||||
}
|
||||
: {}),
|
||||
address: {
|
||||
"@type": "PostalAddress",
|
||||
addressCountry: "TH",
|
||||
...(input.locationLabel
|
||||
? { streetAddress: input.locationLabel }
|
||||
: {}),
|
||||
},
|
||||
...(input.mapUrl ? { hasMap: input.mapUrl } : {}),
|
||||
},
|
||||
},
|
||||
];
|
||||
}
|
||||
|
||||
/** JSON-LD ของหน้าบทความ (สำหรับโรงหนัง / สำหรับคนรักหนัง) */
|
||||
export function articleJsonLd(input: {
|
||||
origin: string;
|
||||
headline: string;
|
||||
description: string;
|
||||
path: string;
|
||||
}): MetaDescriptor[] {
|
||||
return [
|
||||
{
|
||||
"script:ld+json": {
|
||||
"@context": "https://schema.org",
|
||||
"@type": "Article",
|
||||
headline: input.headline,
|
||||
description: input.description,
|
||||
inLanguage: "th-TH",
|
||||
mainEntityOfPage: absoluteUrl(input.origin, input.path),
|
||||
author: { "@type": "Organization", name: SITE.name },
|
||||
publisher: { "@type": "Organization", name: SITE.name },
|
||||
},
|
||||
},
|
||||
];
|
||||
}
|
||||
@@ -0,0 +1,27 @@
|
||||
import { createContext, useContext, type ReactNode } from "react";
|
||||
|
||||
/**
|
||||
* โดเมนที่ใช้ในลิงก์แชร์ (มาจาก env `SHARE_ORIGIN` ผ่าน loader ที่ root)
|
||||
*
|
||||
* ค่าเริ่มต้นเป็นสตริงว่าง = ให้ปุ่มแชร์ใช้ origin ของหน้าที่เปิดอยู่
|
||||
* แยกเป็น context เพื่อไม่ให้ component ต้องรู้จัก loader/route ของ root
|
||||
*/
|
||||
const ShareOriginContext = createContext<string>("");
|
||||
|
||||
export function ShareOriginProvider({
|
||||
origin,
|
||||
children,
|
||||
}: {
|
||||
origin: string;
|
||||
children: ReactNode;
|
||||
}) {
|
||||
return (
|
||||
<ShareOriginContext.Provider value={origin}>
|
||||
{children}
|
||||
</ShareOriginContext.Provider>
|
||||
);
|
||||
}
|
||||
|
||||
export function useShareOrigin(): string {
|
||||
return useContext(ShareOriginContext);
|
||||
}
|
||||
@@ -0,0 +1,90 @@
|
||||
import { describe, expect, it, vi } from "vitest";
|
||||
|
||||
import {
|
||||
buildShareUrl,
|
||||
buildShortSharePath,
|
||||
resolveShareOrigin,
|
||||
shareOrCopy,
|
||||
} from "./share";
|
||||
|
||||
describe("buildShareUrl", () => {
|
||||
it("ต่อ origin กับ path และตัด / ซ้ำท้าย origin", () => {
|
||||
expect(buildShareUrl("https://alterflixhub.com/", "/cinema/lido")).toBe(
|
||||
"https://alterflixhub.com/cinema/lido",
|
||||
);
|
||||
expect(buildShareUrl("http://localhost:8080", "cinema/lido")).toBe(
|
||||
"http://localhost:8080/cinema/lido",
|
||||
);
|
||||
});
|
||||
|
||||
it("คงพาธที่มีภาษาไทยไว้ตามเดิม", () => {
|
||||
expect(buildShareUrl("https://x.test", "/cinema/เมืองทองรามา")).toBe(
|
||||
"https://x.test/cinema/เมืองทองรามา",
|
||||
);
|
||||
});
|
||||
});
|
||||
|
||||
describe("resolveShareOrigin", () => {
|
||||
it("ใช้โดเมนที่ตั้งไว้ และตัด / ท้ายออก", () => {
|
||||
expect(
|
||||
resolveShareOrigin(
|
||||
"https://alterflixhub.hobbypj.com/",
|
||||
"http://localhost:8080",
|
||||
),
|
||||
).toBe("https://alterflixhub.hobbypj.com");
|
||||
});
|
||||
|
||||
it("ไม่ได้ตั้ง (ว่าง/undefined) → ใช้ origin ของหน้าเว็บ", () => {
|
||||
expect(resolveShareOrigin("", "http://localhost:8080")).toBe(
|
||||
"http://localhost:8080",
|
||||
);
|
||||
expect(resolveShareOrigin(undefined, "http://localhost:8080")).toBe(
|
||||
"http://localhost:8080",
|
||||
);
|
||||
expect(resolveShareOrigin(" ", "http://localhost:8080")).toBe(
|
||||
"http://localhost:8080",
|
||||
);
|
||||
});
|
||||
});
|
||||
|
||||
describe("buildShortSharePath", () => {
|
||||
it("สร้างลิงก์ย่อ /c/<slug>", () => {
|
||||
expect(buildShortSharePath("kku-cinema")).toBe("/c/kku-cinema");
|
||||
});
|
||||
});
|
||||
|
||||
describe("shareOrCopy", () => {
|
||||
const data = { title: "LIDO CONNECT", url: "https://x.test/cinema/lido" };
|
||||
|
||||
it("มี navigator.share → เรียกแผงแชร์ แล้วคัดลอกสำรองด้วย คืน shared", async () => {
|
||||
const share = vi.fn().mockResolvedValue(undefined);
|
||||
const writeText = vi.fn().mockResolvedValue(undefined);
|
||||
|
||||
expect(await shareOrCopy(data, { share, writeText })).toBe("shared");
|
||||
expect(share).toHaveBeenCalledWith({ title: data.title, url: data.url });
|
||||
expect(writeText).toHaveBeenCalledWith(data.url);
|
||||
});
|
||||
|
||||
it("ไม่มี navigator.share → คัดลอกแล้วคืน copied", async () => {
|
||||
const writeText = vi.fn().mockResolvedValue(undefined);
|
||||
expect(await shareOrCopy(data, { writeText })).toBe("copied");
|
||||
expect(writeText).toHaveBeenCalledWith(data.url);
|
||||
});
|
||||
|
||||
it("ผู้ใช้ยกเลิกแผงแชร์ แต่คัดลอกได้ → ยังคืน shared", async () => {
|
||||
const share = vi.fn().mockRejectedValue(new Error("AbortError"));
|
||||
const writeText = vi.fn().mockResolvedValue(undefined);
|
||||
expect(await shareOrCopy(data, { share, writeText })).toBe("shared");
|
||||
});
|
||||
|
||||
it("clipboard ใช้ไม่ได้ → ตกไปใช้ legacyCopy", async () => {
|
||||
const writeText = vi.fn().mockRejectedValue(new Error("denied"));
|
||||
const legacyCopy = vi.fn().mockReturnValue(true);
|
||||
expect(await shareOrCopy(data, { writeText, legacyCopy })).toBe("copied");
|
||||
expect(legacyCopy).toHaveBeenCalledWith(data.url);
|
||||
});
|
||||
|
||||
it("ทุกทางล้มเหลว → failed", async () => {
|
||||
expect(await shareOrCopy(data, {})).toBe("failed");
|
||||
});
|
||||
});
|
||||
@@ -0,0 +1,120 @@
|
||||
/**
|
||||
* ตัวช่วยแชร์ลิงก์โรงหนัง
|
||||
*
|
||||
* หลักการ: สร้างลิงก์จาก `origin + path` ตอนกดแชร์เท่านั้น (ไม่ฝังชื่อโดเมนไว้ในโค้ด)
|
||||
* → เปลี่ยนโดเมน/ย้ายโฮสต์ทีหลัง ลิงก์เก่ายังเปิดได้ และลิงก์ที่ได้สั้นที่สุด
|
||||
* (หน้า `/cinema/<slug>` ระบุโรงได้ครบอยู่แล้ว จึงไม่ต้องมี query เพิ่ม)
|
||||
*/
|
||||
|
||||
/** ผลลัพธ์ที่เอาไปแสดงให้ผู้ใช้ */
|
||||
export type ShareResult = "shared" | "copied" | "failed";
|
||||
|
||||
type ShareEnv = {
|
||||
/** navigator.share (มีบนมือถือ/เดสก์ท็อปที่รองรับ Web Share) */
|
||||
share?: (data: {
|
||||
title: string;
|
||||
text?: string;
|
||||
url: string;
|
||||
}) => Promise<void>;
|
||||
/** navigator.clipboard.writeText */
|
||||
writeText?: (text: string) => Promise<void>;
|
||||
/** ทางสำรองสำหรับorigin ที่ไม่ใช่ HTTPS — คืน true ถ้าคัดลอกสำเร็จ */
|
||||
legacyCopy?: (text: string) => boolean;
|
||||
};
|
||||
|
||||
/** รวม origin + path เป็นลิงก์เต็ม (ตัด `/` ซ้ำท้าย origin) */
|
||||
export function buildShareUrl(origin: string, path: string): string {
|
||||
const base = origin.replace(/\/+$/, "");
|
||||
const suffix = path.startsWith("/") ? path : `/${path}`;
|
||||
return `${base}${suffix}`;
|
||||
}
|
||||
|
||||
/**
|
||||
* โดเมนที่ใช้ในลิงก์แชร์
|
||||
* ตั้งได้ผ่าน env `SHARE_ORIGIN` (เช่น https://alterflixhub.hobbypj.com)
|
||||
* ถ้าไม่ได้ตั้ง ใช้ origin ของหน้าที่กำลังเปิดอยู่ (ใช้ตอน dev ได้ตามปกติ)
|
||||
*/
|
||||
export function resolveShareOrigin(
|
||||
configured: string | null | undefined,
|
||||
fallbackOrigin: string,
|
||||
): string {
|
||||
const value = (configured ?? "").trim();
|
||||
return (value === "" ? fallbackOrigin : value).replace(/\/+$/, "");
|
||||
}
|
||||
|
||||
/**
|
||||
* ลิงก์ย่อของโรงหนัง: `/c/<slug>` (route นี้ redirect ไปหน้าเต็ม `/cinema/<slug>`)
|
||||
* ไม่ encode slug เพราะ slug เป็น ASCII/ไทยที่ปลอดภัยอยู่แล้ว — encode จะทำให้ลิงก์ยาวและอ่านไม่ออก
|
||||
*/
|
||||
export function buildShortSharePath(slug: string): string {
|
||||
return `/c/${slug}`;
|
||||
}
|
||||
|
||||
/**
|
||||
* ทางสำรองสุดท้ายเมื่อ Clipboard API ใช้ไม่ได้ (เช่น http ธรรมดา)
|
||||
* ใช้ <textarea> ที่ซ่อนไว้ + execCommand("copy")
|
||||
*/
|
||||
function legacyCopy(text: string): boolean {
|
||||
if (typeof document === "undefined") return false;
|
||||
const area = document.createElement("textarea");
|
||||
area.value = text;
|
||||
area.setAttribute("readonly", "");
|
||||
area.style.position = "fixed";
|
||||
area.style.opacity = "0";
|
||||
document.body.appendChild(area);
|
||||
area.select();
|
||||
let copied = false;
|
||||
try {
|
||||
copied = document.execCommand("copy");
|
||||
} catch {
|
||||
copied = false;
|
||||
}
|
||||
document.body.removeChild(area);
|
||||
return copied;
|
||||
}
|
||||
|
||||
/** อ่านความสามารถของเบราว์เซอร์ปัจจุบัน (แยกออกมาเพื่อเทสต์ได้) */
|
||||
function defaultEnv(): ShareEnv {
|
||||
if (typeof navigator === "undefined") return {};
|
||||
const nav = navigator as Navigator & {
|
||||
share?: ShareEnv["share"];
|
||||
clipboard?: { writeText?: (text: string) => Promise<void> };
|
||||
};
|
||||
return {
|
||||
share: typeof nav.share === "function" ? nav.share.bind(nav) : undefined,
|
||||
writeText:
|
||||
typeof nav.clipboard?.writeText === "function"
|
||||
? nav.clipboard.writeText.bind(nav.clipboard)
|
||||
: undefined,
|
||||
legacyCopy,
|
||||
};
|
||||
}
|
||||
|
||||
/**
|
||||
* แชร์ลิงก์: ใช้แผงแชร์ของระบบถ้ามี แล้วคัดลอกลงคลิปบอร์ดเป็นทางเลือกให้เดสก์ท็อปเสมอ
|
||||
* ลำดับ: navigator.share → clipboard → textarea/execCommand → failed
|
||||
*/
|
||||
export async function shareOrCopy(
|
||||
data: { title: string; url: string },
|
||||
env: ShareEnv = defaultEnv(),
|
||||
): Promise<ShareResult> {
|
||||
if (env.share) {
|
||||
try {
|
||||
await env.share({ title: data.title, url: data.url });
|
||||
} catch {
|
||||
// ผู้ใช้กดยกเลิกแผงแชร์ หรือเบราว์เซอร์ปฏิเสธ → ไม่ถือว่าพัง ให้ลองคัดลอกต่อ
|
||||
}
|
||||
}
|
||||
|
||||
if (env.writeText) {
|
||||
try {
|
||||
await env.writeText(data.url);
|
||||
return env.share ? "shared" : "copied";
|
||||
} catch {
|
||||
// ตกไปใช้ทางสำรองด้านล่าง
|
||||
}
|
||||
}
|
||||
|
||||
if (env.legacyCopy?.(data.url)) return env.share ? "shared" : "copied";
|
||||
return "failed";
|
||||
}
|
||||
@@ -0,0 +1,42 @@
|
||||
/**
|
||||
* ข้อมูลระดับเว็บไซต์ (แหล่งเดียว) — ใช้โดย SEO, sitemap, robots และ JSON-LD
|
||||
*
|
||||
* **ไม่เก็บโดเมนไว้ในโค้ด**: origin มาจาก request จริง (`app/lib/request-origin.ts`)
|
||||
* ถ้าจำเป็นต้องบังคับโดเมน (เช่น dev หลัง proxy แปลก ๆ) ค่อยตั้ง env `SITE_URL`
|
||||
*/
|
||||
import { normalizeOrigin } from "@/lib/request-origin";
|
||||
|
||||
export const SITE = {
|
||||
name: "AlterFlixHub",
|
||||
/** ใช้เป็นค่าเริ่มต้นของ <title> (หน้าแรก) */
|
||||
title: "AlterFlixHub — โรงหนังอิสระ อาร์ตเฮาส์ และกลุ่มคนฉายหนังในไทย",
|
||||
description:
|
||||
"รวมโรงหนังอิสระและอาร์ตเฮาส์ในประเทศไทยไว้ที่เดียว พร้อมที่ตั้ง วิธีเดินทาง สิ่งอำนวยความสะดวก และปุ่มหาภาพยนตร์โรงใกล้ฉัน",
|
||||
locale: "th_TH",
|
||||
ogImage: "/og/alterflixhub-1200x630.png",
|
||||
/** หน้าแบบ static ที่ควรอยู่ใน sitemap (หน้าโรงหนังมาจากข้อมูลจริง) */
|
||||
staticPages: [
|
||||
{ path: "/", priority: "1.0", changeFrequency: "daily" as const },
|
||||
{
|
||||
path: "/for-film-lovers",
|
||||
priority: "0.7",
|
||||
changeFrequency: "monthly" as const,
|
||||
},
|
||||
{
|
||||
path: "/for-cinemas",
|
||||
priority: "0.7",
|
||||
changeFrequency: "monthly" as const,
|
||||
},
|
||||
{ path: "/about", priority: "0.5", changeFrequency: "yearly" as const },
|
||||
],
|
||||
} as const;
|
||||
|
||||
/**
|
||||
* โดเมนที่บังคับผ่าน env — คืน "" ถ้าไม่ได้ตั้ง (กรณีปกติ)
|
||||
* `SITE_URL` มาก่อน แล้วค่อย `SHARE_ORIGIN` (ใช้ร่วมกันเพื่อไม่ต้องตั้งซ้ำ)
|
||||
*/
|
||||
export function configuredOrigin(): string {
|
||||
// guard:allow-no-env-credentials — โดเมนสาธารณะ ไม่ใช่ข้อมูลลับ
|
||||
const raw = process.env.SITE_URL ?? process.env.SHARE_ORIGIN ?? "";
|
||||
return normalizeOrigin(raw);
|
||||
}
|
||||
@@ -0,0 +1,70 @@
|
||||
/**
|
||||
* ทดสอบ sitemap.xml — กันกรณี "crawler เปิดได้แต่ได้ไฟล์ผิด"
|
||||
* (ไม่มีโรงที่ hidden, URL เป็นโดเมน production, XML ถูกต้อง)
|
||||
*/
|
||||
import { describe, expect, it } from "vitest";
|
||||
|
||||
import type { Cinema } from "@/lib/cinemas";
|
||||
import { SITE } from "@/lib/site";
|
||||
|
||||
/** origin ปลอมสำหรับทดสอบ (โค้ดจริงหาจาก request) */
|
||||
const ORIGIN = "https://example.test";
|
||||
import { buildSitemapXml, sitemapLocation } from "@/lib/sitemap";
|
||||
|
||||
function cinema(slug: string, hidden = false): Cinema {
|
||||
return {
|
||||
slug,
|
||||
name: slug,
|
||||
tags: [],
|
||||
location_label: "",
|
||||
coordinates: null,
|
||||
description: "",
|
||||
map_url: null,
|
||||
address_lines: [],
|
||||
transport: [],
|
||||
contacts: [],
|
||||
payments: [],
|
||||
photos: [],
|
||||
...(hidden ? { hidden: true } : {}),
|
||||
} as Cinema;
|
||||
}
|
||||
|
||||
describe("sitemapLocation", () => {
|
||||
it("หน้าแรกต้องมี / ปิดท้าย", () => {
|
||||
expect(sitemapLocation(ORIGIN, "/")).toBe(`${ORIGIN}/`);
|
||||
});
|
||||
|
||||
it("พาธอื่นต่อท้ายโดเมนตรง ๆ", () => {
|
||||
expect(sitemapLocation(ORIGIN, "/about")).toBe(`${ORIGIN}/about`);
|
||||
expect(sitemapLocation(ORIGIN, "about")).toBe(`${ORIGIN}/about`);
|
||||
});
|
||||
});
|
||||
|
||||
describe("buildSitemapXml", () => {
|
||||
it("มีหน้า static ครบตาม SITE.staticPages", () => {
|
||||
const xml = buildSitemapXml(ORIGIN, []);
|
||||
for (const page of SITE.staticPages) {
|
||||
expect(xml).toContain(`<loc>${sitemapLocation(ORIGIN, page.path)}</loc>`);
|
||||
}
|
||||
expect(xml.startsWith('<?xml version="1.0" encoding="UTF-8"?>')).toBe(true);
|
||||
expect(xml).toContain("</urlset>");
|
||||
});
|
||||
|
||||
it("เพิ่มหน้าโรงหนัง และข้ามโรงที่ hidden", () => {
|
||||
const xml = buildSitemapXml(ORIGIN, [
|
||||
cinema("visible-cinema"),
|
||||
cinema("secret", true),
|
||||
]);
|
||||
expect(xml).toContain(`${ORIGIN}/cinema/visible-cinema`);
|
||||
expect(xml).not.toContain("secret");
|
||||
});
|
||||
|
||||
it("ไม่ปล่อย localhost ลงใน sitemap", () => {
|
||||
expect(buildSitemapXml(ORIGIN, [cinema("x")])).not.toContain("localhost");
|
||||
});
|
||||
|
||||
it("escape อักขระ XML ใน slug", () => {
|
||||
const xml = buildSitemapXml(ORIGIN, [cinema("a&b")]);
|
||||
expect(xml).toContain("a&b");
|
||||
});
|
||||
});
|
||||
@@ -0,0 +1,66 @@
|
||||
/**
|
||||
* ตัวสร้าง sitemap.xml (ฟังก์ชันบริสุทธิ์ — ทดสอบได้โดยไม่ต้องมีเซิร์ฟเวอร์)
|
||||
*
|
||||
* หน้า static มาจาก `SITE.staticPages` · หน้าโรงหนังมาจากข้อมูลจริง
|
||||
* (ไม่รวมโรงที่ตั้ง `hidden: true` เพราะไม่ควรอยู่ในผลค้นหา)
|
||||
*/
|
||||
import type { Cinema } from "@/lib/cinemas";
|
||||
import { SITE } from "@/lib/site";
|
||||
|
||||
function escapeXml(value: string): string {
|
||||
return value
|
||||
.replace(/&/g, "&")
|
||||
.replace(/</g, "<")
|
||||
.replace(/>/g, ">")
|
||||
.replace(/"/g, """)
|
||||
.replace(/'/g, "'");
|
||||
}
|
||||
|
||||
/** ต่อพาธกับโดเมน — หน้าแรกต้องมี `/` ปิดท้าย */
|
||||
export function sitemapLocation(origin: string, path: string): string {
|
||||
const base = origin.replace(/\/+$/, "");
|
||||
if (path === "/" || path === "") return `${base}/`;
|
||||
return `${base}${path.startsWith("/") ? path : `/${path}`}`;
|
||||
}
|
||||
|
||||
function urlEntry(
|
||||
origin: string,
|
||||
path: string,
|
||||
options: { priority: string; changeFrequency: string },
|
||||
): string {
|
||||
return [
|
||||
" <url>",
|
||||
` <loc>${escapeXml(sitemapLocation(origin, path))}</loc>`,
|
||||
` <changefreq>${options.changeFrequency}</changefreq>`,
|
||||
` <priority>${options.priority}</priority>`,
|
||||
" </url>",
|
||||
].join("\n");
|
||||
}
|
||||
|
||||
/** จำนวน URL สูงสุดต่อไฟล์ (ข้อกำหนด sitemap = 50,000) */
|
||||
export function buildSitemapXml(origin: string, cinemas: Cinema[]): string {
|
||||
const entries = SITE.staticPages.map((page) =>
|
||||
urlEntry(origin, page.path, {
|
||||
priority: page.priority,
|
||||
changeFrequency: page.changeFrequency,
|
||||
}),
|
||||
);
|
||||
|
||||
for (const cinema of cinemas) {
|
||||
if (cinema.hidden) continue;
|
||||
entries.push(
|
||||
urlEntry(origin, `/cinema/${cinema.slug}`, {
|
||||
priority: "0.8",
|
||||
changeFrequency: "weekly",
|
||||
}),
|
||||
);
|
||||
}
|
||||
|
||||
return [
|
||||
'<?xml version="1.0" encoding="UTF-8"?>',
|
||||
'<urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9">',
|
||||
...entries,
|
||||
"</urlset>",
|
||||
"",
|
||||
].join("\n");
|
||||
}
|
||||
+69
-28
@@ -5,8 +5,16 @@ import { createAgentNativeQueryClient } from "@agent-native/core/client/hooks";
|
||||
import { getThemeInitScript } from "@agent-native/core/client/ui";
|
||||
import { AppProviders } from "@agent-native/toolkit/app/providers";
|
||||
import { useQueryClient } from "@tanstack/react-query";
|
||||
import { useState } from "react";
|
||||
import { Links, Meta, Outlet, Scripts, ScrollRestoration, useLoaderData, useRouteLoaderData } from "react-router";
|
||||
import { useEffect, useState } from "react";
|
||||
import {
|
||||
Links,
|
||||
Meta,
|
||||
Outlet,
|
||||
Scripts,
|
||||
ScrollRestoration,
|
||||
useLoaderData,
|
||||
useRouteLoaderData,
|
||||
} from "react-router";
|
||||
import type { LinksFunction } from "react-router";
|
||||
|
||||
import { Layout as AppLayout } from "@/components/layout/Layout";
|
||||
@@ -17,6 +25,11 @@ import { APP_NAME, APP_TITLE } from "@/lib/app-config";
|
||||
import { ContentProvider } from "@/lib/content-context";
|
||||
import { readContent } from "@/lib/content.server";
|
||||
import { LocaleProvider, readLocaleFromRequestUrl } from "@/lib/i18n";
|
||||
import { MOTION_INIT_SCRIPT } from "@/lib/motion";
|
||||
import { registerServiceWorker } from "@/lib/pwa";
|
||||
import { originFromRequest } from "@/lib/request-origin";
|
||||
import { ShareOriginProvider } from "@/lib/share-origin";
|
||||
import { configuredOrigin } from "@/lib/site";
|
||||
import { TAB_ID } from "@/lib/tab-id";
|
||||
|
||||
import stylesheet from "./global.css?url";
|
||||
@@ -37,7 +50,14 @@ const THEME_INIT_SCRIPT = getThemeInitScript();
|
||||
/** เนื้อหาที่แก้ได้จากหลังบ้าน (โรงหนัง/คำศัพท์/footer) โหลดครั้งเดียวที่ root */
|
||||
export async function loader({ request }: { request: Request }) {
|
||||
const content = await readContent();
|
||||
return { content, localeFromUrl: readLocaleFromRequestUrl(request) };
|
||||
// origin ของคำขอนี้ (ไม่ฝังโดเมนในโค้ด) — ใช้ทั้ง canonical/OG และลิงก์แชร์
|
||||
const siteUrl = configuredOrigin() || originFromRequest(request);
|
||||
return {
|
||||
content,
|
||||
localeFromUrl: readLocaleFromRequestUrl(request),
|
||||
siteUrl,
|
||||
shareOrigin: siteUrl,
|
||||
};
|
||||
}
|
||||
|
||||
export function Layout({ children }: { children: React.ReactNode }) {
|
||||
@@ -47,16 +67,19 @@ export function Layout({ children }: { children: React.ReactNode }) {
|
||||
<html lang={lang} suppressHydrationWarning>
|
||||
<head>
|
||||
<meta charSet="utf-8" />
|
||||
<meta
|
||||
name="viewport"
|
||||
content="width=device-width, initial-scale=1, maximum-scale=1, user-scalable=no"
|
||||
/>
|
||||
{/* ไม่ล็อกการซูม — `maximum-scale`/`user-scalable=no` ปิด pinch-zoom และผิด WCAG 1.4.4 */}
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1" />
|
||||
<script
|
||||
suppressHydrationWarning
|
||||
dangerouslySetInnerHTML={{ __html: THEME_INIT_SCRIPT }}
|
||||
/>
|
||||
{/* ใส่คลาส fx-motion ก่อน paint — กันจังหวะกระพริบก่อนอนิเมชันเริ่ม */}
|
||||
<script
|
||||
suppressHydrationWarning
|
||||
dangerouslySetInnerHTML={{ __html: MOTION_INIT_SCRIPT }}
|
||||
/>
|
||||
{/* guard:allow-raw-color - theme-color metadata requires a concrete browser-chrome color. */}
|
||||
<meta name="theme-color" content="#18181B" />
|
||||
<meta name="theme-color" content="#0D0D0D" />
|
||||
<meta name="mobile-web-app-capable" content="yes" />
|
||||
<meta
|
||||
name="apple-mobile-web-app-status-bar-style"
|
||||
@@ -64,7 +87,13 @@ export function Layout({ children }: { children: React.ReactNode }) {
|
||||
/>
|
||||
<meta name="apple-mobile-web-app-title" content={APP_TITLE} />
|
||||
<link rel="icon" type="image/svg+xml" href={appPath("/favicon.svg")} />
|
||||
<link rel="apple-touch-icon" href={appPath("/icon-180.svg")} />
|
||||
<link rel="manifest" href={appPath("/manifest.json")} />
|
||||
{/* iOS รับเฉพาะ PNG — ไฟล์ .svg ถูกมองข้าม */}
|
||||
<link
|
||||
rel="apple-touch-icon"
|
||||
sizes="180x180"
|
||||
href={appPath("/icon-180.png")}
|
||||
/>
|
||||
<Meta />
|
||||
<Links />
|
||||
</head>
|
||||
@@ -87,28 +116,40 @@ function DbSyncSetup() {
|
||||
return null;
|
||||
}
|
||||
|
||||
/** ลงทะเบียน service worker ครั้งเดียวฝั่ง client — ทำให้ติดตั้งเป็นแอปได้และเปิดซ้ำตอนออฟไลน์ได้ */
|
||||
function ServiceWorkerSetup() {
|
||||
useEffect(() => {
|
||||
registerServiceWorker();
|
||||
}, []);
|
||||
return null;
|
||||
}
|
||||
|
||||
export default function Root() {
|
||||
const [queryClient] = useState(() => createAgentNativeQueryClient());
|
||||
const { content, localeFromUrl } = useLoaderData<typeof loader>();
|
||||
const { content, localeFromUrl, shareOrigin } =
|
||||
useLoaderData<typeof loader>();
|
||||
return (
|
||||
<ContentProvider content={content}>
|
||||
<LocaleProvider
|
||||
initialLocale={localeFromUrl === "en" ? "en" : "th"}
|
||||
localeFromUrl={localeFromUrl}
|
||||
terms={content.site.terms}
|
||||
>
|
||||
<NearMeProvider cinemas={content.cinemas}>
|
||||
<AppToolkitProvider>
|
||||
<AppProviders queryClient={queryClient}>
|
||||
<DbSyncSetup />
|
||||
<AppLayout>
|
||||
<Outlet />
|
||||
</AppLayout>
|
||||
</AppProviders>
|
||||
</AppToolkitProvider>
|
||||
</NearMeProvider>
|
||||
</LocaleProvider>
|
||||
</ContentProvider>
|
||||
<ShareOriginProvider origin={shareOrigin}>
|
||||
<ContentProvider content={content}>
|
||||
<LocaleProvider
|
||||
initialLocale={localeFromUrl === "en" ? "en" : "th"}
|
||||
localeFromUrl={localeFromUrl}
|
||||
terms={content.site.terms}
|
||||
>
|
||||
<NearMeProvider cinemas={content.cinemas}>
|
||||
<AppToolkitProvider>
|
||||
<AppProviders queryClient={queryClient}>
|
||||
<DbSyncSetup />
|
||||
<ServiceWorkerSetup />
|
||||
<AppLayout>
|
||||
<Outlet />
|
||||
</AppLayout>
|
||||
</AppProviders>
|
||||
</AppToolkitProvider>
|
||||
</NearMeProvider>
|
||||
</LocaleProvider>
|
||||
</ContentProvider>
|
||||
</ShareOriginProvider>
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
+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}
|
||||
/>
|
||||
);
|
||||
}
|
||||
+19
-4
@@ -3,7 +3,7 @@
|
||||
คู่มือนี้ตอบคำถาม "แก้ตรงไหน" ทีละงาน — ทุกอย่างอยู่ใน `http://localhost:8080/admin`
|
||||
(ล็อกอินด้วย `ADMIN_USERNAME` / `ADMIN_PASSWORD` ใน `.env`; ค่าเริ่มต้นคือ `it is me` / `it is me&it is me`)
|
||||
|
||||
หน้าหลังบ้านมี 5 แท็บ: **โรงหนัง · หน้าเกี่ยวกับเรา · คำศัพท์หลายภาษา · Footer / ไอคอน · สถิติการค้นหา**
|
||||
หน้าหลังบ้านมี 7 แท็บ: **โรงหนัง · หน้าเกี่ยวกับเรา · สำหรับคนทำโรงหนัง · สำหรับคนรักหนัง · คำศัพท์หลายภาษา · Footer / ไอคอน · สถิติการค้นหา**
|
||||
|
||||
---
|
||||
|
||||
@@ -125,14 +125,29 @@
|
||||
|
||||
---
|
||||
|
||||
## 10. คำศัพท์หลายภาษา / Footer
|
||||
## 10. หน้า "สำหรับคนทำโรงหนัง" และ "สำหรับคนรักหนัง" (บทความ)
|
||||
|
||||
สองหน้านี้ใช้ตัวแก้ไขแบบเดียวกัน ต่างกันแค่แท็บ — **สำหรับคนทำโรงหนัง** → `/for-cinemas` · **สำหรับคนรักหนัง** → `/for-film-lovers`
|
||||
|
||||
ในแท็บ เลือกภาษา (TH/EN) แล้วเขียนบทความแบบบล็อก:
|
||||
|
||||
- **+ เพิ่มย่อหน้า** — เพิ่มช่องข้อความทีละย่อหน้า (ขึ้นบรรทัดใหม่ได้ตามที่พิมพ์)
|
||||
- **+ เพิ่มรูปภาพ** — ใส่ลิงก์รูป (`/images/…` หรือ URL เต็ม) + คำอธิบายรูป (alt จำเป็นต่อการเข้าถึง) + คำบรรยายใต้รูป (ไม่ใส่ก็ได้) พร้อมพรีวิวรูปในฟอร์ม
|
||||
- ปุ่ม **↑ ↓** สลับลำดับบล็อก · **ลบ** เอาบล็อกออก
|
||||
- แก้ **หัวเรื่อง (H1)**, **คำเกริ่นนำ**, และ **การ์ดติดต่อ** (หัวข้อ + ข้อความ) ได้ในแท็บเดียวกัน
|
||||
- ตัวนับด้านบนบอกจำนวนย่อหน้า/รูป · ปุ่ม **คืนค่าตั้งต้น** คืนข้อความเริ่มต้นของภาษานั้น
|
||||
- กด **บันทึกหน้าสำหรับคนทำโรงหนัง** / **บันทึกหน้าสำหรับคนรักหนัง** → หน้าเว็บอัปเดตทันที (รูปแสดงตามลำดับที่วางไว้)
|
||||
|
||||
---
|
||||
|
||||
## 11. คำศัพท์หลายภาษา / Footer
|
||||
|
||||
- **คำศัพท์หลายภาษา**: แก้ข้อความทุกจุดในหน้าเว็บด้วย key (เช่น `hero.subtitle`, `detail.contactTitle`) — เว้นว่าง = ใช้ค่าเดิมจาก `messages.ts`
|
||||
- **Footer / ไอคอน**: เพิ่ม/แก้ไอคอนโซเชียล (ชื่อไอคอน Tabler เช่น `IconBrandFacebook`)
|
||||
|
||||
---
|
||||
|
||||
## 11. สถิติการค้นหา
|
||||
## 12. สถิติการค้นหา
|
||||
|
||||
แท็บ **สถิติการค้นหา** — เลือกช่วง 1 / 7 / 30 / 90 วัน: คำคันยอดนิยม, คำค้นที่ไม่พบผล, CTR, ผลลัพธ์เฉลี่ย, หมวดที่ถูกใช้, โรงที่ถูกเปิด/คลิก, การค้นหารายวัน
|
||||
|
||||
@@ -144,7 +159,7 @@
|
||||
|
||||
---
|
||||
|
||||
## 12. ข้อควรระวัง
|
||||
## 13. ข้อควรระวัง
|
||||
|
||||
- **กด "บันทึกทั้งหมด" ทุกครั้ง** — การแก้ในฟอร์มยังไม่ถูกบันทึกจนกว่าจะกดปุ่ม
|
||||
- ช่องที่กรอกคั่นด้วย `,` (หมวด/ชำระเงิน) จะถูกจัดรูปให้เป็น `, ` ตอนออกจากช่อง
|
||||
|
||||
+59
-8
@@ -457,9 +457,25 @@
|
||||
<span class="name"><code>/about</code></span>
|
||||
<span class="desc">เนื้อหาจาก data/content</span>
|
||||
</div>
|
||||
<div class="node f">
|
||||
<span class="name"><code>/for-cinemas</code></span>
|
||||
<span class="desc">บทความ 블록 (ย่อหน้า/รูป) จาก data/content · ธีมเดียวกับ /about</span>
|
||||
</div>
|
||||
<div class="node f">
|
||||
<span class="name"><code>/for-film-lovers</code></span>
|
||||
<span class="desc">บทความแบบบล็อก · ใช้ ArticlePage ร่วมกับ /for-cinemas</span>
|
||||
</div>
|
||||
<div class="node f">
|
||||
<span class="name"><code>/c/:slug</code></span>
|
||||
<span class="desc">ลิงก์ย่อสำหรับแชร์ → 302 redirect ไป /cinema/:slug</span>
|
||||
</div>
|
||||
<div class="node f">
|
||||
<span class="name"><code>/sitemap.xml</code> · <code>/robots.txt</code> · <code>/ai.txt</code></span>
|
||||
<span class="desc">ไฟล์สำหรับ crawler — sitemap สร้างจากข้อมูลจริง (Nitro route), robots/ai เป็น static ใน public/</span>
|
||||
</div>
|
||||
<div class="node f">
|
||||
<span class="name"><code>/admin</code></span>
|
||||
<span class="desc">login + แดชบอร์ด 4 แท็บ</span>
|
||||
<span class="desc">login + แดชบอร์ด 7 แท็บ</span>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
@@ -467,8 +483,8 @@
|
||||
<div class="node f">
|
||||
<span class="name">SiteShell + SiteHeader / SiteFooter</span>
|
||||
<span class="desc"
|
||||
>กรอบหน้า: BackdropFrame (glow) · Logo (Jersey 15) · nav หน้าแรก/เกี่ยวกับเรา
|
||||
· ปุ่มภาษา</span
|
||||
>กรอบหน้า: BackdropFrame (glow) · Logo (Jersey 15) · nav คนรักหนัง/โรงหนัง/เกี่ยวกับเรา
|
||||
· ปุ่มภาษา (dropdown) (มือถือ: ยุบในเมนู)</span
|
||||
>
|
||||
</div>
|
||||
|
||||
@@ -477,7 +493,7 @@
|
||||
<div class="row">
|
||||
<div class="node f">
|
||||
<span class="name">ContentProvider</span>
|
||||
<span class="desc">useContent() → cinemas / about / terms / footer</span>
|
||||
<span class="desc">useContent() → cinemas / about / forCinemas / forFilmLovers / terms / footer</span>
|
||||
</div>
|
||||
<div class="node f">
|
||||
<span class="name">LocaleProvider</span>
|
||||
@@ -517,12 +533,28 @@
|
||||
<span class="name">map-embed.ts</span>
|
||||
<span class="desc">URL แผนที่: map_url → พิกัด → null (แสดง "ไม่มีข้อมูล")</span>
|
||||
</div>
|
||||
<div class="node f">
|
||||
<span class="name">seo.ts · site.ts</span>
|
||||
<span class="desc">pageMeta (title/canonical/OG/Twitter) + JSON-LD · ข้อมูลระดับเว็บ (ชื่อ/คำอธิบาย/og image)</span>
|
||||
</div>
|
||||
<div class="node f">
|
||||
<span class="name">request-origin.ts · page-origin.ts</span>
|
||||
<span class="desc">หา origin จาก request (x-forwarded-host/proto) — ไม่ฝังโดเมนในโค้ด</span>
|
||||
</div>
|
||||
<div class="node f">
|
||||
<span class="name">sitemap.ts · article.ts · share.ts</span>
|
||||
<span class="desc">สร้าง sitemap XML · จัดการบล็อกบทความ (ย่อหน้า/รูป) · แชร์ + คัดลอกลิงก์ย่อ</span>
|
||||
</div>
|
||||
<div class="node f">
|
||||
<span class="name">motion.ts · pwa.ts</span>
|
||||
<span class="desc">เปิดใช้แอนิเมชันก่อน paint (เคารพ reduced-motion) · ลงทะเบียน service worker</span>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="node f">
|
||||
<span class="name">หลังบ้าน /admin</span>
|
||||
<span class="desc">AdminSection (หมวดพับ) · CinemaList (ก-ฮ + ลากสลับ) · SlugInput · ChipPicker · CommaListInput · PhotosEditor · TransportEditor · ContactsEditor · CinemaFacilitiesEditor</span>
|
||||
<span class="desc">AdminSection (หมวดพับ) · CinemaList (ก-ฮ + ลากสลับ) · SlugInput · ChipPicker · CommaListInput · PhotosEditor · TransportEditor · ContactsEditor · CinemaFacilitiesEditor · ArticleEditor (บทความแบบบล็อก)</span>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
@@ -553,7 +585,7 @@
|
||||
</div>
|
||||
<div class="node b">
|
||||
<span class="name"><code>admin/content</code> GET/PUT</span>
|
||||
<span class="desc">อ่าน/บันทึก cinemas · terms · footer · about</span>
|
||||
<span class="desc">อ่าน/บันทึก cinemas · terms · footer · about · forCinemas · forFilmLovers</span>
|
||||
</div>
|
||||
<div class="node b">
|
||||
<span class="name"><code>admin/cinemas/import</code></span>
|
||||
@@ -574,6 +606,24 @@
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="group">
|
||||
<span class="title">ไฟล์สำหรับ crawler — server/routes/</span>
|
||||
<div class="row">
|
||||
<div class="node b accent">
|
||||
<span class="name"><code>/robots.txt</code></span>
|
||||
<span class="desc">สร้างสด: เปิด search engine, ปิด /api/ /admin /_agent-native/ /c/, บล็อก AI crawler 21 ตัว · Sitemap: ตามโดเมนของ request</span>
|
||||
</div>
|
||||
<div class="node b accent">
|
||||
<span class="name"><code>/sitemap.xml</code></span>
|
||||
<span class="desc">สร้างจากข้อมูลจริง (หน้า static + โรงที่ไม่ hidden) · โดเมนจาก request · ไม่ throw ถ้าอ่าน content ไม่ได้</span>
|
||||
</div>
|
||||
<div class="node b">
|
||||
<span class="name"><code>public/ai.txt</code></span>
|
||||
<span class="desc">ประกาศไม่ให้นำเนื้อหาไปฝึกโมเดล AI (static, ไม่มีโดเมนในเนื้อหา)</span>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="group">
|
||||
<span class="title">Server libs</span>
|
||||
<div class="row">
|
||||
@@ -650,8 +700,9 @@
|
||||
<div class="node d">
|
||||
<span class="name">data/content/content.json</span>
|
||||
<span class="desc"
|
||||
>แหล่งเดียวของ cinemas · site.terms · footer · about{th,en} —
|
||||
หน้าเว็บอ่านผ่าน readContent() เท่านั้น</span
|
||||
>แหล่งเดียวของ cinemas · site.terms · footer · about{th,en} ·
|
||||
forCinemas{th,en} · forFilmLovers{th,en} (blocks) — หน้าเว็บอ่านผ่าน
|
||||
readContent() เท่านั้น</span
|
||||
>
|
||||
</div>
|
||||
<div class="node d">
|
||||
|
||||
@@ -0,0 +1,11 @@
|
||||
# ai.txt — AlterFlixHub
|
||||
#
|
||||
# ประกาศเจตนา: เนื้อหา ข้อความ รูปภาพ และข้อมูลโรงหนังบนเว็บไซต์นี้
|
||||
# ไม่อนุญาตให้นำไปใช้ฝึก (train) ทำ fine-tune หรือสร้างโมเดลปัญญาประดิษฐ์
|
||||
# รวมถึงการนำไปใช้เป็นคลังข้อมูลสำหรับคำตอบของระบบ AI โดยไม่ได้รับอนุญาตเป็นลายลักษณ์อักษร
|
||||
#
|
||||
# เว็บนี้ยังเปิดให้ search engine ปกติจัดทำดัชนีตามปกติ (ดู /robots.txt)
|
||||
# สอบถามเรื่องการใช้เนื้อหา: ช่องทางติดต่อในส่วนท้ายของเว็บไซต์
|
||||
|
||||
User-Agent: *
|
||||
Disallow: /
|
||||
Binary file not shown.
|
After Width: | Height: | Size: 3.7 KiB |
Binary file not shown.
|
After Width: | Height: | Size: 3.9 KiB |
Binary file not shown.
|
After Width: | Height: | Size: 18 KiB |
Binary file not shown.
|
After Width: | Height: | Size: 13 KiB |
+21
-5
@@ -2,19 +2,35 @@
|
||||
"name": "AlterFlixHub",
|
||||
"short_name": "AlterFlixHub",
|
||||
"description": "ค้นหาโรงภาพยนตร์อิสระ ทางเลือกในการดูหนัง",
|
||||
"start_url": "./",
|
||||
"id": "/",
|
||||
"lang": "th",
|
||||
"dir": "ltr",
|
||||
"start_url": "/",
|
||||
"scope": "/",
|
||||
"display": "standalone",
|
||||
"display_override": ["standalone", "minimal-ui"],
|
||||
"orientation": "any",
|
||||
"background_color": "#0D0D0D",
|
||||
"theme_color": "#0D0D0D",
|
||||
"categories": ["entertainment", "travel"],
|
||||
"icons": [
|
||||
{
|
||||
"src": "icon-192.svg",
|
||||
"src": "/icon-192.png",
|
||||
"sizes": "192x192",
|
||||
"type": "image/svg+xml"
|
||||
"type": "image/png",
|
||||
"purpose": "any"
|
||||
},
|
||||
{
|
||||
"src": "icon-512.svg",
|
||||
"src": "/icon-512.png",
|
||||
"sizes": "512x512",
|
||||
"type": "image/svg+xml"
|
||||
"type": "image/png",
|
||||
"purpose": "any"
|
||||
},
|
||||
{
|
||||
"src": "/icon-maskable-512.png",
|
||||
"sizes": "512x512",
|
||||
"type": "image/png",
|
||||
"purpose": "maskable"
|
||||
}
|
||||
]
|
||||
}
|
||||
@@ -0,0 +1,80 @@
|
||||
<!doctype html>
|
||||
<html lang="th">
|
||||
<head>
|
||||
<meta charset="utf-8" />
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1" />
|
||||
<title>ออฟไลน์อยู่ — AlterFlixHub</title>
|
||||
<meta name="theme-color" content="#0D0D0D" />
|
||||
<style>
|
||||
:root {
|
||||
color-scheme: dark;
|
||||
}
|
||||
* {
|
||||
box-sizing: border-box;
|
||||
}
|
||||
body {
|
||||
margin: 0;
|
||||
min-height: 100dvh;
|
||||
display: grid;
|
||||
place-items: center;
|
||||
padding: 24px;
|
||||
background:
|
||||
radial-gradient(
|
||||
380px 380px at 50% 0%,
|
||||
rgba(143, 8, 8, 0.55),
|
||||
transparent 70%
|
||||
),
|
||||
#0d0d0d;
|
||||
color: #fff;
|
||||
font-family:
|
||||
"Inter Variable", Inter, "Noto Sans Thai", system-ui, sans-serif;
|
||||
}
|
||||
main {
|
||||
max-width: 460px;
|
||||
text-align: center;
|
||||
}
|
||||
.logo {
|
||||
display: inline-block;
|
||||
color: #8f0808;
|
||||
font-size: 30px;
|
||||
letter-spacing: -0.01em;
|
||||
}
|
||||
h1 {
|
||||
margin: 20px 0 8px;
|
||||
font-size: 22px;
|
||||
line-height: 1.4;
|
||||
}
|
||||
p {
|
||||
margin: 0 0 24px;
|
||||
color: #b3b3b3;
|
||||
font-size: 15px;
|
||||
line-height: 1.7;
|
||||
}
|
||||
a {
|
||||
display: inline-block;
|
||||
padding: 12px 22px;
|
||||
border-radius: 10px;
|
||||
border: 1px solid #8f0808;
|
||||
background: #8f0808;
|
||||
color: #fff;
|
||||
font-size: 15px;
|
||||
text-decoration: none;
|
||||
touch-action: manipulation;
|
||||
}
|
||||
a:focus-visible {
|
||||
outline: 2px solid #d47272;
|
||||
outline-offset: 3px;
|
||||
}
|
||||
</style>
|
||||
</head>
|
||||
<body>
|
||||
<main>
|
||||
<span class="logo">AlterFlixHub</span>
|
||||
<h1>ตอนนี้ออฟไลน์อยู่</h1>
|
||||
<p>
|
||||
หน้าเว็บที่เคยเปิดไว้ยังดูได้ แต่ต้องต่ออินเทอร์เน็ตก่อนเพื่อโหลดข้อมูลโรงหนังชุดล่าสุด
|
||||
</p>
|
||||
<a href="/">ลองอีกครั้ง</a>
|
||||
</main>
|
||||
</body>
|
||||
</html>
|
||||
Binary file not shown.
|
After Width: | Height: | Size: 55 KiB |
+149
@@ -0,0 +1,149 @@
|
||||
/*
|
||||
* Service worker ของ AlterFlixHub
|
||||
*
|
||||
* กลยุทธ์
|
||||
* - หน้าเว็บ (navigate): network-first → ออฟไลน์ค่อยใช้แคชของหน้านั้น → สุดท้าย /offline.html
|
||||
* - ไฟล์ static (/assets/*.js|css, รูป, ฟอนต์): cache-first แล้วอัปเดตแคชเบื้องหลัง
|
||||
* - /api/* และของภายนอกโดเมน: ไม่แตะ (ข้อมูลต้องสด + เคารพความเป็นส่วนตัว)
|
||||
* - activate: ลบแคชเวอร์ชันเก่าทั้งหมด (กันเคสค้างเวอร์ชัน — เคยมีแคช `alterflixhub-v1.2.0` ค้าง)
|
||||
*
|
||||
* เวลาปล่อยเวอร์ชันใหม่: เปลี่ยน VERSION — พอ SW ตัวใหม่ activate จะเก็บกวาดแคชเก่าให้เอง
|
||||
*
|
||||
* ตารางกลยุทธ์ (อ่านประกอบ fetch handler ด้านล่าง)
|
||||
* | คำขอ | กลยุทธ์ |
|
||||
* |-------------------------------------|------------------------------------------|
|
||||
* | navigate (เปิดหน้า) | network-first → แคชของหน้านั้น → /offline.html |
|
||||
* | /assets/* · รูป · ฟอนต์ (.png/.svg…) | cache-first + อัปเดตเบื้องหลัง |
|
||||
* | /api/* · /__* · /sw.js | ไม่จัดการ (ปล่อยผ่านไปเครือข่าย) |
|
||||
* | โดเมนอื่น (รูป hotlink) | ไม่จัดการ |
|
||||
* | /app/* · /node_modules/* · /@* | ไม่จัดการ (โมดูลของ dev server) |
|
||||
*/
|
||||
const VERSION = "v2.0.1";
|
||||
const PAGES_CACHE = `alterflixhub-pages-${VERSION}`;
|
||||
const ASSETS_CACHE = `alterflixhub-assets-${VERSION}`;
|
||||
|
||||
/** ไฟล์ที่ต้องมีติดเครื่องไว้ตั้งแต่ก่อนออฟไลน์ครั้งแรก */
|
||||
const PRECACHE = [
|
||||
"/offline.html",
|
||||
"/manifest.json",
|
||||
"/icon-192.png",
|
||||
"/icon-512.png",
|
||||
"/favicon.svg",
|
||||
];
|
||||
|
||||
self.addEventListener("install", (event) => {
|
||||
event.waitUntil(
|
||||
(async () => {
|
||||
const cache = await caches.open(ASSETS_CACHE);
|
||||
// ไฟล์ใดโหลดไม่ได้ (เช่นตอน dev ที่ยังไม่ build) ไม่ทำให้ install ล้มทั้งชุด
|
||||
await Promise.all(
|
||||
PRECACHE.map((url) => cache.add(url).catch(() => undefined)),
|
||||
);
|
||||
})(),
|
||||
);
|
||||
});
|
||||
|
||||
self.addEventListener("activate", (event) => {
|
||||
event.waitUntil(
|
||||
(async () => {
|
||||
const keep = new Set([PAGES_CACHE, ASSETS_CACHE]);
|
||||
const names = await caches.keys();
|
||||
await Promise.all(
|
||||
names
|
||||
.filter((name) => !keep.has(name))
|
||||
.map((name) => caches.delete(name)),
|
||||
);
|
||||
// เข้าคุมแท็บที่เปิดอยู่ทันที เพื่อไม่ให้ค้าง SW เวอร์ชันเก่า
|
||||
await self.clients.claim();
|
||||
})(),
|
||||
);
|
||||
});
|
||||
|
||||
self.addEventListener("message", (event) => {
|
||||
if (event.data === "SKIP_WAITING") self.skipWaiting();
|
||||
});
|
||||
|
||||
function isSameOrigin(url) {
|
||||
return url.origin === self.location.origin;
|
||||
}
|
||||
|
||||
function isStaticAsset(url) {
|
||||
// ไม่แคชเส้นทางของ bundler/dev server (Vite เสิร์ฟโมดูลที่ /app, /node_modules, /@…)
|
||||
if (
|
||||
url.pathname.startsWith("/app/") ||
|
||||
url.pathname.startsWith("/node_modules/") ||
|
||||
url.pathname.startsWith("/@")
|
||||
) {
|
||||
return false;
|
||||
}
|
||||
if (url.pathname.startsWith("/assets/")) return true;
|
||||
return /\.(?:js|mjs|css|woff2?|ttf|png|jpe?g|webp|avif|gif|svg|ico)$/i.test(
|
||||
url.pathname,
|
||||
);
|
||||
}
|
||||
|
||||
self.addEventListener("fetch", (event) => {
|
||||
const request = event.request;
|
||||
if (request.method !== "GET") return;
|
||||
|
||||
let url;
|
||||
try {
|
||||
url = new URL(request.url);
|
||||
} catch {
|
||||
return;
|
||||
}
|
||||
if (!isSameOrigin(url)) return;
|
||||
// ข้อมูลสด/ข้อมูลหลังบ้าน — ห้ามแคช
|
||||
if (url.pathname.startsWith("/api/") || url.pathname.startsWith("/__"))
|
||||
return;
|
||||
if (url.pathname === "/sw.js") return;
|
||||
|
||||
if (request.mode === "navigate") {
|
||||
event.respondWith(
|
||||
(async () => {
|
||||
try {
|
||||
const fresh = await fetch(request);
|
||||
if (fresh && fresh.ok) {
|
||||
const cache = await caches.open(PAGES_CACHE);
|
||||
cache.put(request, fresh.clone()).catch(() => undefined);
|
||||
}
|
||||
return fresh;
|
||||
} catch {
|
||||
const cached = await caches.match(request);
|
||||
if (cached) return cached;
|
||||
const offline = await caches.match("/offline.html");
|
||||
return offline || Response.error();
|
||||
}
|
||||
})(),
|
||||
);
|
||||
return;
|
||||
}
|
||||
|
||||
if (isStaticAsset(url)) {
|
||||
event.respondWith(
|
||||
(async () => {
|
||||
const cache = await caches.open(ASSETS_CACHE);
|
||||
const cached = await cache.match(request);
|
||||
if (cached) {
|
||||
// อัปเดตเบื้องหลัง (stale-while-revalidate) — ไม่หน่วงการแสดงผล
|
||||
fetch(request)
|
||||
.then((fresh) => {
|
||||
if (fresh && fresh.ok)
|
||||
cache.put(request, fresh).catch(() => undefined);
|
||||
})
|
||||
.catch(() => undefined);
|
||||
return cached;
|
||||
}
|
||||
try {
|
||||
const fresh = await fetch(request);
|
||||
if (fresh && fresh.ok) {
|
||||
cache.put(request, fresh.clone()).catch(() => undefined);
|
||||
}
|
||||
return fresh;
|
||||
} catch {
|
||||
return Response.error();
|
||||
}
|
||||
})(),
|
||||
);
|
||||
}
|
||||
});
|
||||
@@ -35,6 +35,8 @@ export default defineEventHandler(async (event) => {
|
||||
cinemas: Array.from(bySlug.values()),
|
||||
site: current.site,
|
||||
about: current.about,
|
||||
forCinemas: current.forCinemas,
|
||||
forFilmLovers: current.forFilmLovers,
|
||||
};
|
||||
await writeContent(next);
|
||||
return { imported: incoming.length, store: next };
|
||||
|
||||
@@ -5,17 +5,21 @@ import {
|
||||
readContent,
|
||||
sanitizeAbout,
|
||||
sanitizeCinemas,
|
||||
sanitizeForCinemas,
|
||||
sanitizeForFilmLovers,
|
||||
sanitizeSite,
|
||||
writeContent,
|
||||
} from "@/lib/content.server";
|
||||
|
||||
/** บันทึกทั้งชุด: ส่งมาเฉพาะส่วนที่แก้ได้ (cinemas, site และ/หรือ about) */
|
||||
/** บันทึกทั้งชุด: ส่งมาเฉพาะส่วนที่แก้ได้ (cinemas, site, about และ/หรือ forCinemas) */
|
||||
export default defineEventHandler(async (event) => {
|
||||
requireAdmin(event);
|
||||
const body = (await readBody(event)) as {
|
||||
cinemas?: unknown;
|
||||
site?: unknown;
|
||||
about?: unknown;
|
||||
forCinemas?: unknown;
|
||||
forFilmLovers?: unknown;
|
||||
};
|
||||
const current = await readContent();
|
||||
|
||||
@@ -28,6 +32,14 @@ export default defineEventHandler(async (event) => {
|
||||
site: body?.site === undefined ? current.site : sanitizeSite(body.site),
|
||||
about:
|
||||
body?.about === undefined ? current.about : sanitizeAbout(body.about),
|
||||
forCinemas:
|
||||
body?.forCinemas === undefined
|
||||
? current.forCinemas
|
||||
: sanitizeForCinemas(body.forCinemas),
|
||||
forFilmLovers:
|
||||
body?.forFilmLovers === undefined
|
||||
? current.forFilmLovers
|
||||
: sanitizeForFilmLovers(body.forFilmLovers),
|
||||
};
|
||||
await writeContent(next);
|
||||
return next;
|
||||
|
||||
@@ -0,0 +1,91 @@
|
||||
/**
|
||||
* /robots.txt — สร้างสด ๆ ที่ชั้น Nitro เพื่อให้บรรทัด `Sitemap:` ชี้โดเมนจริงของ request
|
||||
* (ไฟล์ static ใน public/ ต้องฮาร์ดโค้ดโดเมน จึงย้ายมาเป็น route)
|
||||
*/
|
||||
import {
|
||||
defineEventHandler,
|
||||
getRequestHeaders,
|
||||
getRequestProtocol,
|
||||
setResponseHeader,
|
||||
} from "h3";
|
||||
|
||||
import { originFromHeaders } from "../../app/lib/request-origin";
|
||||
import { configuredOrigin } from "../../app/lib/site";
|
||||
|
||||
/** search engine ที่อนุญาตชัดเจน */
|
||||
const ALLOWED_ENGINES = [
|
||||
"Googlebot",
|
||||
"Bingbot",
|
||||
"DuckDuckBot",
|
||||
"Bravebot",
|
||||
"Applebot",
|
||||
];
|
||||
|
||||
/** AI crawler ที่ไม่อนุญาต (ฝึกโมเดล/สรุปเนื้อหา) */
|
||||
const AI_CRAWLERS = [
|
||||
"GPTBot",
|
||||
"OAI-SearchBot",
|
||||
"ChatGPT-User",
|
||||
"ClaudeBot",
|
||||
"Claude-Web",
|
||||
"anthropic-ai",
|
||||
"Google-Extended",
|
||||
"Applebot-Extended",
|
||||
"PerplexityBot",
|
||||
"Perplexity-User",
|
||||
"CCBot",
|
||||
"Bytespider",
|
||||
"Amazonbot",
|
||||
"meta-externalagent",
|
||||
"cohere-ai",
|
||||
"Diffbot",
|
||||
"ImagesiftBot",
|
||||
"Omgilibot",
|
||||
"Timpibot",
|
||||
"VelenPublicWebCrawler",
|
||||
"YouBot",
|
||||
];
|
||||
|
||||
/** ประกอบไฟล์ robots.txt จาก origin ของ request */
|
||||
export function buildRobotsTxt(origin: string): string {
|
||||
const lines: string[] = [
|
||||
"# robots.txt — AlterFlixHub",
|
||||
"# ค้นหาโรงหนังอิสระ/อาร์ตเฮาส์ในประเทศไทย",
|
||||
"",
|
||||
"# ── search engines (อนุญาตชัดเจน) ────────────────────────────────",
|
||||
];
|
||||
|
||||
for (const engine of ALLOWED_ENGINES) {
|
||||
lines.push(`User-agent: ${engine}`, "Allow: /", "");
|
||||
}
|
||||
|
||||
lines.push(
|
||||
"# ── ค่าเริ่มต้น: เปิดให้ index แต่ปิดส่วนที่ไม่ควรอยู่ในผลค้นหา ──",
|
||||
"User-agent: *",
|
||||
"Allow: /",
|
||||
"Disallow: /api/",
|
||||
"Disallow: /admin",
|
||||
"Disallow: /admin/login",
|
||||
"Disallow: /_agent-native/",
|
||||
"Disallow: /c/ # ลิงก์ย่อสำหรับแชร์ (302 ไปหน้าโรงหนังจริง)",
|
||||
"",
|
||||
"# ── AI crawlers: ไม่อนุญาตให้นำเนื้อหาไปใช้ ─────────────────────",
|
||||
"# (รวมถึงการฝึกโมเดล/สรุปเนื้อหาของผู้ให้บริการ AI)",
|
||||
);
|
||||
|
||||
for (const crawler of AI_CRAWLERS) {
|
||||
lines.push(`User-agent: ${crawler}`, "Disallow: /", "");
|
||||
}
|
||||
|
||||
lines.push(`Sitemap: ${origin.replace(/\/+$/, "")}/sitemap.xml`, "");
|
||||
return lines.join("\n");
|
||||
}
|
||||
|
||||
export default defineEventHandler((event) => {
|
||||
const origin =
|
||||
configuredOrigin() ||
|
||||
originFromHeaders(getRequestHeaders(event), getRequestProtocol(event));
|
||||
setResponseHeader(event, "Content-Type", "text/plain; charset=utf-8");
|
||||
setResponseHeader(event, "Cache-Control", "public, max-age=3600");
|
||||
return buildRobotsTxt(origin);
|
||||
});
|
||||
@@ -0,0 +1,39 @@
|
||||
/**
|
||||
* /sitemap.xml — จัดการที่ชั้น Nitro (ไม่ผ่านตัวเรนเดอร์ React)
|
||||
*
|
||||
* ทำไมไม่ใช้ React Router resource route: ตัว SSR handler ของ framework
|
||||
* ตอบ 404 ให้พาธที่ลงท้ายด้วยนามสกุลไฟล์ (.xml) แม้ route จะถูกประกาศไว้แล้ว
|
||||
* จึงประกาศที่ Nitro ตรง ๆ ให้ crawler ได้ XML เสมอโดยไม่ขึ้นกับ Accept header
|
||||
*/
|
||||
import {
|
||||
defineEventHandler,
|
||||
getRequestHeaders,
|
||||
getRequestProtocol,
|
||||
setResponseHeader,
|
||||
} from "h3";
|
||||
|
||||
import { readContent } from "../../app/lib/content.server";
|
||||
import { originFromHeaders } from "../../app/lib/request-origin";
|
||||
import { configuredOrigin } from "../../app/lib/site";
|
||||
import { buildSitemapXml } from "../../app/lib/sitemap";
|
||||
|
||||
export default defineEventHandler(async (event) => {
|
||||
// โดเมนมาจาก request จริง (ไม่ฝังในโค้ด) — ตั้ง SITE_URL เฉพาะกรณีต้องบังคับ
|
||||
const origin =
|
||||
configuredOrigin() ||
|
||||
originFromHeaders(getRequestHeaders(event), getRequestProtocol(event));
|
||||
|
||||
let xml: string;
|
||||
|
||||
try {
|
||||
const content = await readContent();
|
||||
xml = buildSitemapXml(origin, content.cinemas);
|
||||
} catch {
|
||||
// ข้อมูลอ่านไม่ได้ → ยังคืน sitemap ที่มีหน้า static (ดีกว่า 500)
|
||||
xml = buildSitemapXml(origin, []);
|
||||
}
|
||||
|
||||
setResponseHeader(event, "Content-Type", "application/xml; charset=utf-8");
|
||||
setResponseHeader(event, "Cache-Control", "public, max-age=3600");
|
||||
return xml;
|
||||
});
|
||||
Reference in new issue
Block a user