Files
web-alterflixhub/app/lib/cinemas.ts
T
Bkk1234 319c271d23 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 ไฟล์)
2026-11-10 02:31:10 +07:00

377 lines
14 KiB
TypeScript

/**
* ข้อมูลโรงหนังอิสระ — แหล่งข้อมูลเดียวของทั้งหน้าแรกและหน้ารายละเอียด
* ค่าที่ไม่รู้จริงปล่อยเป็นค่าว่าง/null แล้ว UI แสดงข้อความสำรองตามภาษา (lib/i18n)
* ข้อความอังกฤษเป็นฟิลด์เสริม (*_en) ถ้าไม่กรอกจะ fallback เป็นไทย
*/
import type { Coordinates } from "@/lib/geo";
import type { FacilityKey, Locale, Messages } from "@/lib/i18n/messages";
import { FACILITY_KEYS } from "@/lib/i18n/messages";
export type TransportMode = {
/** ใช้เลือกไอคอนและชื่อวิธีเดินทางจากข้อความแปล */
icon_name: "private_car" | "metro" | "bus";
/** รายละเอียดเส้นทาง — ภาษาตามข้อมูล (ยังไม่มีฟิลด์ _en) */
value: string;
value_en?: string;
};
export type ContactChannel = {
label: string;
value: string;
href: string | null;
};
export type Cinema = {
slug: string;
name: string;
/** ชื่อภาษาไทย (ไม่กรอกก็ใช้ name อังกฤษ) */
name_th?: string;
tags: string[];
location_label: string;
location_label_en?: string;
/** พิกัดโรงหนังสำหรับคำนวณระยะทาง — null คือยังไม่ทราบตำแหน่งจริง */
coordinates: Coordinates | null;
description: string;
description_en?: string;
map_url: string | null;
address_lines: string[];
address_lines_en?: string[];
transport: TransportMode[];
contacts: ContactChannel[];
payments: string[];
/** สิ่งอำนวยความสะดวกที่มีจริง — คีย์ตาม FACILITY_KEYS (ไม่กรอก = ไม่ระบุ) */
facilities?: FacilityKey[];
/**
* ข้อความเฉพาะโรงนี้ต่อหัวข้อ (ทับค่าเริ่มต้นจาก messages.ts)
* label = ชื่อหัวข้อ (ไม่แยกภาษา) · sub_th/sub_en = คำอธิบาย
*/
facility_details?: Partial<
Record<FacilityKey, { label?: string; sub_th?: string; sub_en?: string }>
>;
/** ซ่อนจากหน้าเว็บ (ยังเปิดดูได้ด้วย URL ตรง) — ไม่แสดงในรายการ/ค้นหา/โรงอื่นๆ */
hidden?: boolean;
/** หัวข้อการ์ดติดต่อ/จองตั๋ว เฉพาะโรงนี้ (ว่าง = ใช้ค่าเริ่มต้นจาก messages) */
contact_heading?: string;
/** รูปโรงหนัง เรียงตามลำดับที่ใช้ในแกลเลอรี — ว่างได้ถ้ายังไม่มีรูป */
photos: string[];
};
export const CINEMA_CATEGORIES = [
"ทั้งหมด",
"ยอดนิยม",
"อาร์ตเฮาส์",
"สารคดี",
"หนังสั้น",
"หนังคลาสสิก",
"หนังนานาชาติ",
"หนังนอกกระแส",
"หนังในกระแส",
"หนังฝรั่งเศส",
"กลุ่มคนฉายหนัง",
"หนังไทย",
] as const;
export type CinemaCategory = (typeof CINEMA_CATEGORIES)[number];
export const DEFAULT_CATEGORY: CinemaCategory = "ทั้งหมด";
/** ลำดับ gradient ของการ์ด ใช้ร่วมกันทุกหน้าเพื่อให้สีคงที่ */
export const CARD_GRADIENTS = [
"from-[#3a2a22] via-[#2a2a3a] to-[#1b1b1b]",
"from-[#2a2a3a] via-[#1f2a3a] to-[#1b1b1b]",
"from-[#3a3a4a] via-[#2a2a2a] to-[#1b1b1b]",
"from-[#4a3320] via-[#2a2a2a] to-[#1b1b1b]",
] as const;
export const CINEMAS: Cinema[] = [
{
slug: "house-cinema-samyan",
name: "HOUSE CINEMA SAMYAN",
name_th: "HOUSE สามย่าน",
tags: ["หนังนอกกระแส", "อาร์ตเฮาส์"],
location_label: "ชั้น 5 สามย่านมิตรทาวน์ กรุงเทพฯ",
location_label_en: "5th floor, Samyan Mitrtown, Bangkok",
coordinates: { latitude: 13.7343452, longitude: 100.5282654 },
description:
"โรงภาพยนตร์สำหรับคนที่อยากค้นพบหนังหลากหลาย เน้นภาพยนตร์นอกกระแสและเรื่องที่ไม่ได้เข้าฉายในวงกว้าง พร้อมเรื่องราวและมุมมองที่แตกต่างสำหรับคนรักหนัง",
description_en:
"A cinema for people who want to discover a wide range of films — focused on independent titles and stories that never reach a wide release, with perspectives made for film lovers.",
map_url: "https://maps.google.com/?q=House+Samyan",
address_lines: [
"ชั้น 5 ศูนย์การค้าสามย่านมิตรทาวน์",
"944/1 ถนนพระราม 4 แขวงวังใหม่ เขตปทุมวัน กรุงเทพฯ 10330",
],
address_lines_en: [
"5th floor, Samyan Mitrtown",
"944/1 Rama IV Road, Wang Mai, Pathum Wan, Bangkok 10330",
],
transport: [
{
icon_name: "private_car",
value: "ที่จอดรถภายในศูนย์การค้าสามย่านมิตรทาวน์",
value_en: "Parking inside Samyan Mitrtown",
},
{
icon_name: "metro",
value: "MRT สถานีสามย่าน",
value_en: "MRT Sam Yan station",
},
{
icon_name: "bus",
value: "29, 34, 36, 40, 47, 50",
value_en: "29, 34, 36, 40, 47, 50",
},
],
contacts: [
{
label: "Website",
value: "www.housesamyan.com",
href: "https://www.housesamyan.com",
},
{
label: "Facebook",
value: "House Samyan",
href: "https://www.facebook.com/housesamyan",
},
{ label: "Call", value: "098-869-0997", href: "tel:0988690997" },
],
payments: ["เงินสด", "บัตรเครดิต", "สแกนจ่าย"],
// ใส่ path รูปจริง เช่น "/images/cinemas/house-samyan/1.jpg" — ป้าย "+N" คำนวณจากความยาวอาร์เรย์นี้
photos: [],
},
{
slug: "thana-cineplex",
name: "THANA CINEPLEX",
tags: ["หนังในกระแส", "ยอดนิยม"],
location_label: "เดอะมอลล์งามวงศ์วาน นนทบุรี",
location_label_en: "The Mall Ngamwongwan, Nonthaburi",
coordinates: { latitude: 13.8564363, longitude: 100.5419053 },
description: "",
map_url: null,
address_lines: [],
transport: [],
contacts: [],
payments: [],
photos: [],
},
{
slug: "century-the-movie-plaza",
name: "CENTURY",
name_th: "เซ็นจูรี่มูฟวี่พลาซ่า",
tags: ["หนังในกระแส"],
location_label: "เซ็นจูรี่ เดอะมูฟวี่ พลาซ่า อนุสาวรีย์ชัยฯ กรุงเทพฯ",
location_label_en: "Century The Movie Plaza, Victory Monument, Bangkok",
coordinates: { latitude: 13.7616674, longitude: 100.5371572 },
description: "",
map_url: null,
address_lines: [],
transport: [],
contacts: [],
payments: [],
photos: [],
},
{
slug: "ck-plaza",
name: "CK PLAZA",
tags: ["หนังในกระแส"],
location_label: "",
coordinates: null,
description: "",
map_url: null,
address_lines: [],
transport: [],
contacts: [],
payments: [],
photos: [],
},
{
slug: "major-hollywood",
name: "MAJOR HOLLYWOOD",
tags: ["หนังในกระแส", "ยอดนิยม"],
location_label: "",
coordinates: null,
description: "",
map_url: null,
address_lines: [],
transport: [],
contacts: [],
payments: [],
photos: [],
},
{
slug: "coliseum-paradise",
name: "COLISEUM PARADISE",
tags: ["หนังคลาสสิก", "อาร์ตเฮาส์"],
location_label: "",
coordinates: null,
description: "",
map_url: null,
address_lines: [],
transport: [],
contacts: [],
payments: [],
photos: [],
},
// รายการที่ผู้ใช้ให้มา — ใส่เฉพาะชื่อ TH/EN ฟิลด์อื่นรอเติม
{
slug: "alliance-francaise-de-bangkok",
name: "Alliance Française de Bangkok",
name_th: "สมาคมฝรั่งเศสกรุงเทพ",
tags: [],
location_label: "",
coordinates: null,
description: "",
map_url: null,
address_lines: [],
transport: [],
contacts: [],
payments: [],
photos: [],
},
{
slug: "cinema-oasis",
name: "Cinema Oasis",
name_th: "มูลนิธิซิเนม่าโอเอซิส",
tags: [],
location_label: "",
coordinates: null,
description: "",
map_url: null,
address_lines: [],
transport: [],
contacts: [],
payments: [],
photos: [],
},
{
slug: "the-friese-greene-club",
name: "The Friese-Greene Club",
name_th: "เดอะ ฟรีส-กรีน คลับ",
tags: [],
location_label: "",
coordinates: null,
description: "",
map_url: null,
address_lines: [],
transport: [],
contacts: [],
payments: [],
photos: [],
},
{
slug: "century-the-movie-plaza-sukhumvit",
name: "Century - The Movie Plaza Sukhumvit",
name_th: "เซ็นจูรี่มูวี่พลาซ่า สุขุมวิท",
tags: [],
location_label: "",
coordinates: null,
description: "",
map_url: null,
address_lines: [],
transport: [],
contacts: [],
payments: [],
photos: [],
},
{
slug: "thai-film-archive",
name: "Thai Film Archive",
name_th: "หอภาพยนตร์",
tags: [],
location_label: "",
coordinates: null,
description: "",
map_url: null,
address_lines: [],
transport: [],
contacts: [],
payments: [],
photos: [],
},
];
/** ฟิลด์ที่มี *_en จะใช้เมื่อภาษาเป็นอังกฤษ และ fallback เป็นไทยเมื่อยังไม่แปล */
function pick(primary: string, english: string | undefined, locale: Locale) {
return locale === "en" && english ? english : primary;
}
function pickList(
primary: string[],
english: string[] | undefined,
locale: Locale,
): string[] {
return locale === "en" && english && english.length > 0 ? english : primary;
}
export function cinemaLocationLabel(cinema: Cinema, locale: Locale): string {
return pick(cinema.location_label, cinema.location_label_en, locale);
}
/** ชื่อที่แสดงตามภาษา — ไทยใช้ name_th ถ้ามี ไม่งั้นใช้ชื่ออังกฤษ */
export function cinemaName(cinema: Cinema, locale: Locale): string {
if (locale === "th" && cinema.name_th) return cinema.name_th;
return cinema.name;
}
export function cinemaDescription(cinema: Cinema, locale: Locale): string {
return pick(cinema.description, cinema.description_en, locale);
}
export function cinemaAddressLines(cinema: Cinema, locale: Locale): string[] {
return pickList(cinema.address_lines, cinema.address_lines_en, locale);
}
/**
* สิ่งอำนวยความสะดวกของโรงนี้ เรียงตาม FACILITY_KEYS
* ข้อมูลเก่าที่ไม่มีฟิลด์นี้จะได้อาร์เรย์ว่าง (UI แสดง "ไม่มีข้อมูล")
*/
export function cinemaFacilities(cinema: Cinema): FacilityKey[] {
const selected = new Set(cinema.facilities ?? []);
return FACILITY_KEYS.filter((key) => selected.has(key));
}
/** หมวดที่เลือกได้ในหลังบ้าน — ตัด "ทั้งหมด" ออกเพราะใช้เป็นตัวกรอง "ไม่กรอง" */
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);
}
/** ประเภทภาพยนตร์ที่แสดงบนการ์ด สร้างจาก tags เพื่อไม่ต้องกรอกซ้ำ */
export function cinemaCategoryLabel(
cinema: Cinema,
messages: Messages,
): string {
return cinema.tags.map((tag) => messages.tags[tag] ?? tag).join(" · ");
}
export function hasCategory(cinema: Cinema, category: CinemaCategory): boolean {
return category === DEFAULT_CATEGORY || cinema.tags.includes(category);
}
export function findCinemaBySlug(
cinemas: Cinema[],
slug: string | undefined,
): Cinema | undefined {
if (!slug) return undefined;
return cinemas.find((cinema) => cinema.slug === slug);
}
export function listOtherCinemas(
cinemas: Cinema[],
slug: string,
limit = 4,
): Cinema[] {
return cinemas
.filter((cinema) => cinema.slug !== slug && !cinema.hidden)
.slice(0, limit);
}
/** โรงหนังที่แสดงบนหน้าเว็บ (ตัดตัวที่ถูกซ่อนในหลังบ้านออก) */
export function publiclyVisible(cinemas: Cinema[]): Cinema[] {
return cinemas.filter((cinema) => !cinema.hidden);
}