feat(home): ชั้นกรองที่ 1 — ประเภทโรงหนัง (ท้องถิ่น / อินดี้ / กลุ่มคนฉายหนัง)

- แถบกรองสองชั้นในแถวเดียว: ทั้งหมด → 3 ประเภท │ ยอดนิยม → หมวดภาพยนตร์เดิม
- เก็บประเภทที่ฟิลด์เดี่ยว cinema.venue_type (ค่าเดียว) + hasVenue()/filterCinemas({ venue })
- ย้าย "กลุ่มคนฉายหนัง" จาก categories ขึ้นชั้น 1 (ไม่ให้ปุ่มซ้ำ) · tag ยังอยู่และยังค้นหาเจอ
- เลือกได้ทีละชั้น: กดประเภทล้างหมวด / กดหมวดล้างประเภท / ทั้งหมดล้างทั้งคู่
- ปิด popularity path เมื่อกรองด้วยประเภท (กันจัดอันดับข้ามประเภท)
- หลังบ้าน: ช่อง "ประเภทโรงหนัง" ในหมวดข้อมูลหลัก + sanitize เฉพาะค่าใน VENUE_TYPES
- i18n: messages.venues (TH/EN) · override ได้ผ่าน site.terms
- scripts/set-venue-types.mjs จัดประเภท 29 โรง (15 ท้องถิ่น / 11 อินดี้ / 3 กลุ่มคนฉายหนัง) พร้อมสำรอง content.json
- tests: hasVenue + filterCinemas (165 ผ่าน) · sw v2.0.5 · DESIGN/AGENTS/README/admin-guide/api อัปเดต
This commit is contained in:
Bkk1234 committed 2026-11-16 01:46:59 +07:00
1 parent 2e794cd365
commit 1932098a1d
15 files changed
+362 -26

No files matched your search

+3
View File
@@ -46,5 +46,8 @@ Before building common workspace or agent UI, read `agent-native-toolkit`; for s
- SEO/AI: ข้อบังคับอยู่ใน `DESIGN.md` หัวข้อ "SEO และการป้องกัน AI" — **ห้ามฝังโดเมนในโค้ด**: canonical/OG/JSON-LD/sitemap/robots/ลิงก์แชร์มาจาก origin ของ request (`app/lib/request-origin.ts` + `resolvePageOrigin()`), ตัวสร้าง meta คือ `app/lib/seo.ts`, ไฟล์ crawler คือ `server/routes/sitemap.xml.ts` + `server/routes/robots.txt.ts` (Nitro route — ไม่ใช่ `public/`) + `public/ai.txt` · งาน cross-engine (Chromium/Firefox/Safari) ดูหัวข้อ "Cross-engine parity" ใน `DESIGN.md`
- คู่มือใช้งานหลังบ้าน (ภาษาไทย ทีละงาน): `docs/admin-guide.md` · API reference: `docs/api.md`
- Cross-engine parity: ทุกครั้งที่เพิ่ม CSS แบบ vendor-specific (`::-webkit-*`, `-webkit-mask-*`, `::-moz-*`) หรือสไตล์ของ native control ต้องใส่คู่ของอีกเอนจินในบล็อก "ความเท่ากันข้ามเอนจิน" (`app/global.css`, อยู่ใน `@layer base`) — **ตัวอนิเมชันห้ามผูกกับคลาส `fx-motion` อย่างเดียว** (เคยทำให้อนิเมชันหายทั้งเว็บ) · ข้อยกเว้นที่ตั้งใจปล่อยไว้ดูตารางใน `DESIGN.md`
- แถบกรองหน้าแรกมีสองชั้นในแถวเดียว: `totals → VENUE_TYPES (โรงภาพยนตร์ท้องถิ่น/อินดี้/กลุ่มคนฉายหนัง) → หมวด`
· ประเภทโรงหนังเก็บที่ `cinema.venue_type` (ค่าเดียว) ไม่ใช่ `tags` · ห้ามมีค่าซ้ำระหว่าง `VENUE_TYPES` กับ `CINEMA_CATEGORIES`
· เลือกได้ทีละชั้น (กดประเภท → ล้างหมวด, กดหมวด → ล้างประเภท) · ป้ายมาจาก `messages.venues` ห้าม hardcode
- เมื่อเพิ่ม/เปลี่ยนฟิลด์ใน `Cinema`, หมวดหมู่, หรือ flow ของหลังบ้าน → อัปเดต `DESIGN.md` + `docs/architecture.html` + `docs/admin-guide.md` พร้อมกัน (ห้ามปล่อยเอกสารตกรุ่น)
- ห้ามเขียนทับ `data/content/content.json` ด้วย seed: `readContent()` โยน error เมื่อไฟล์เสีย และสำรอง `.output/content.json.bakN` ก่อนแก้ด้วยสคริปต์
+12
View File
@@ -228,6 +228,18 @@ Single source of truth per concern — do not duplicate these:
- หมวดที่เพิ่มล่าสุด: `กลุ่มคนฉายหนัง` (Film collectives) · `หนังไทย` (Thai films)
- `ทั้งหมด` ใช้เป็น "ไม่กรอง" และไม่ถูกเสนอในชิปของหลังบ้าน (`ASSIGNABLE_CATEGORIES` ตัดออกให้)
## ชั้นกรองที่ 1 — ประเภทโรงหนัง (venue type) — บังคับ
แถบกรองหน้าแรกมี **สองชั้นในแถวเดียว** เรียงเป็น `ทั้งหมด → [3 ประเภท] │ หมวดภาพยนตร์…`
- ชั้นที่ 1 = `VENUE_TYPES` (`app/lib/cinemas.ts`): `โรงภาพยนตร์ท้องถิ่น` · `โรงภาพยนตร์อินดี้` · `กลุ่มคนฉายหนัง` — เก็บที่ฟิลด์เดี่ยว **`cinema.venue_type`** (โรงหนึ่งเป็นได้ประเภทเดียว จึงไม่ใช้ `tags` ที่เป็นหลายค่า)
- ชั้นที่ 2 = `CINEMA_CATEGORIES` เดิม (genre/ที่มา) — **ห้ามมีค่าซ้ำกับ `VENUE_TYPES`** (ตอนนี้ `กลุ่มคนฉายหนัง` ถูกย้ายขึ้นชั้น 1 แล้ว จึงไม่ปรากฏใน `categories`/`messages.categories` อีก แต่ tag ยังคงอยู่ในข้อมูลและยังค้นหาเจอ)
- **เลือกได้ทีละชั้น**: กดประเภท → ล้างหมวดเป็น `ทั้งหมด`; กดหมวด → ล้างประเภทเป็น `null`; `ทั้งหมด` ล้างทั้งสอง (กันการกรองซ้อนที่คนใช้คาดไม่ถึง)
- ตัวกรองจริงอยู่ใน `filterCinemas(..., { venue })` ทำงานแบบ AND กับหมวดและคำค้น (เผื่ออนาคตจะเปิดให้ซ้อน) — `venue = null` คือไม่กรอง
- โรงที่ยังไม่ตั้ง `venue_type` จะไม่โผล่เมื่อกรองด้วยประเภทใด ๆ · ตั้งค่าได้ที่หลังบ้าน → แท็บโรงหนัง → ข้อมูลหลัก → **ประเภทโรงหนัง** (sanitize ใน `content.server.ts` เท่านั้น)
- `venue_type` เป็นข้อมูล ไม่ใช่ข้อความ: ห้าม hardcode ป้ายใน component ต้องอ่าน `messages.venues` (คีย์ไทย) และ override ได้ผ่าน `site.terms` (`venues.<คีย์>`)
- Popularity path (`category === "ยอดนิยม"`) ถูกปิดเมื่อมี `venue` — กันการจัดอันดับข้ามประเภท
## คอมโพเนนต์หลังบ้าน (`app/components/admin/`)
| ไฟล์ | ใช้ทำอะไร |
+1
View File
@@ -36,6 +36,7 @@ pnpm dev # http://localhost:8080
## คุณสมบัติหลัก
- **กรองสองชั้น** — ประเภทโรงหนัง (ท้องถิ่น / อินดี้ / กลุ่มคนฉายหนัง) แล้วต่อด้วยหมวดภาพยนตร์
- **ค้นหา** — AND หลายคำ เรียงสลับได้ · ค้นทุกอย่างที่เห็นบนการ์ด (`name`, `name_th`, สถานที่, ที่อยู่, การเดินทาง, หมวด/แท็ก, คำอธิบาย) · ตัดวรรณยุกต์/สระบน-ล่าง และ normalize ตัวคั่น → พิมพ์ไม่ครบหรือไม่มีวรรณยุกต์ก็เจอ · เรียงผลตามความตรงของชื่อ
- **หาโรงใกล้ฉัน** — `navigator.geolocation` + ระยะเส้นตรง และระยะตามถนน (OSRM)
- **แชร์** — `navigator.share` → clipboard → fallback `<textarea>` · ลิงก์ย่อ `/c/<slug>` บนโดเมนจริงของ request · บอกผลด้วย `aria-live`
+68 -10
View File
@@ -1,5 +1,5 @@
import { CinemaCard } from "@/components/site/CinemaCard";
import type { Cinema, CinemaCategory } from "@/lib/cinemas";
import type { Cinema, CinemaCategory, VenueType } from "@/lib/cinemas";
import { useI18n } from "@/lib/i18n";
/** กริดการ์ดโรงหนัง — ใช้ทั้งหน้าแรกและส่วน "โรงหนังอิสระอื่นๆ" */
@@ -32,30 +32,88 @@ type CategoryFilterProps = {
active: CinemaCategory;
categories: readonly CinemaCategory[];
onChange: (category: CinemaCategory) => void;
/** ชั้นกรองที่ 1 — ประเภทโรงหนัง (แสดงต่อจาก "ทั้งหมด") */
venues?: readonly VenueType[];
activeVenue?: VenueType | null;
onVenueChange?: (venue: VenueType | null) => void;
};
const chipClass = (isActive: boolean) =>
`relative rounded-[18px] border px-4 py-2 text-sm after:absolute after:-inset-y-1.5 after:inset-x-0 after:content-[''] ${
isActive
? "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"
}`;
/**
* แถบกรองสองชั้นในแถวเดียว
* 1) ประเภทโรงหนัง (ท้องถิ่น / อินดี้ / กลุ่มคนฉายหนัง) — แทรกหลัง "ทั้งหมด"
* 2) หมวดภาพยนตร์แบบเดิม (อาร์ตเฮาส์ / สารคดี / …)
* เลือกได้ทีละชั้น: กดประเภท → ล้างหมวด, กดหมวด → ล้างประเภท (กันการกรองซ้อนที่ผู้ใช้คาดไม่ถึง)
*/
export function CategoryFilter({
active,
categories,
onChange,
venues = [],
activeVenue = null,
onVenueChange,
}: CategoryFilterProps) {
const { messages } = useI18n();
const [allCategory, ...restCategories] = categories;
const hasVenues = venues.length > 0 && typeof onVenueChange === "function";
const allActive = active === allCategory && activeVenue === null;
return (
<div className="flex flex-wrap gap-2">
{categories.map((category) => {
const isActive = category === active;
<div className="flex flex-wrap items-center gap-2">
<button
type="button"
onClick={() => {
onChange(allCategory);
onVenueChange?.(null);
}}
aria-pressed={allActive}
className={chipClass(allActive)}
>
{messages.categories[allCategory]}
</button>
{hasVenues
? venues.map((venue) => {
const isActive = activeVenue === venue;
return (
<button
key={venue}
type="button"
onClick={() => {
onChange(allCategory);
onVenueChange?.(isActive ? null : venue);
}}
aria-pressed={isActive}
className={chipClass(isActive)}
>
{messages.venues[venue]}
</button>
);
})
: null}
{hasVenues ? (
<span aria-hidden="true" className="mx-1 h-6 w-px bg-[#303030]" />
) : null}
{restCategories.map((category) => {
const isActive = category === active && activeVenue === null;
return (
<button
key={category}
type="button"
onClick={() => onChange(category)}
onClick={() => {
onChange(category);
onVenueChange?.(null);
}}
aria-pressed={isActive}
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
? "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"
}`}
className={chipClass(isActive)}
>
{messages.categories[category]}
</button>
+73 -2
View File
@@ -1,10 +1,13 @@
import { describe, expect, it } from "vitest";
import {
findCinemaBySlug,
listOtherCinemas,
CINEMAS,
findCinemaBySlug,
hasVenue,
listOtherCinemas,
type Cinema,
} from "./cinemas";
import { filterCinemas } from "./search";
describe("findCinemaBySlug", () => {
it("คืน undefined เมื่อไม่ได้ส่ง slug", () => {
@@ -27,3 +30,71 @@ describe("listOtherCinemas", () => {
);
});
});
describe("hasVenue / filterCinemas (ชั้นกรองประเภทโรงหนัง)", () => {
const base = {
slug: "x",
name: "X",
tags: ["อาร์ตเฮาส์"],
location_label: "",
coordinates: null,
description: "",
map_url: null,
address_lines: [],
transport: [],
contacts: [],
payments: [],
photos: [],
} as Cinema;
const local: Cinema = {
...base,
slug: "local",
venue_type: "โรงภาพยนตร์ท้องถิ่น",
};
const indie: Cinema = { ...base, slug: "indie", venue_type: "โรงภาพยนตร์อินดี้" };
const group: Cinema = { ...base, slug: "group", venue_type: "กลุ่มคนฉายหนัง" };
const unset: Cinema = { ...base, slug: "unset" };
it("hasVenue: null = ไม่กรอง", () => {
expect(hasVenue(local, null)).toBe(true);
expect(hasVenue(unset, null)).toBe(true);
});
it("hasVenue: ตรงประเภทเท่านั้น", () => {
expect(hasVenue(local, "โรงภาพยนตร์ท้องถิ่น")).toBe(true);
expect(hasVenue(local, "โรงภาพยนตร์อินดี้")).toBe(false);
expect(hasVenue(unset, "โรงภาพยนตร์อินดี้")).toBe(false);
});
it("filterCinemas กรองตามประเภทได้", () => {
const all = [local, indie, group, unset];
expect(
filterCinemas(all, {
category: "ทั้งหมด",
query: "",
venue: "โรงภาพยนตร์อินดี้",
}),
).toEqual([indie]);
expect(
filterCinemas(all, {
category: "ทั้งหมด",
query: "",
venue: "กลุ่มคนฉายหนัง",
}),
).toEqual([group]);
expect(filterCinemas(all, { category: "ทั้งหมด", query: "" })).toHaveLength(
4,
);
});
it("กรองประเภท + หมวดซ้อนกันได้ (AND)", () => {
expect(
filterCinemas([local, indie], {
category: "อาร์ตเฮาส์",
query: "",
venue: "โรงภาพยนตร์ท้องถิ่น",
}),
).toEqual([local]);
});
});
+22 -1
View File
@@ -51,6 +51,11 @@ export type Cinema = {
>;
/** ซ่อนจากหน้าเว็บ (ยังเปิดดูได้ด้วย URL ตรง) — ไม่แสดงในรายการ/ค้นหา/โรงอื่นๆ */
hidden?: boolean;
/**
* ชั้นกรองที่ 1 — ประเภทโรงหนัง (ค่าเดียว): โรงภาพยนตร์ท้องถิ่น / โรงภาพยนตร์อินดี้ / กลุ่มคนฉายหนัง
* ไม่กรอก = ยังไม่จัดประเภท (จะไม่ปรากฏเมื่อกรองด้วยประเภทใด ๆ)
*/
venue_type?: VenueType | null;
/** หัวข้อการ์ดติดต่อ/จองตั๋ว เฉพาะโรงนี้ (ว่าง = ใช้ค่าเริ่มต้นจาก messages) */
contact_heading?: string;
/** รูปโรงหนัง เรียงตามลำดับที่ใช้ในแกลเลอรี — ว่างได้ถ้ายังไม่มีรูป */
@@ -68,12 +73,23 @@ export const CINEMA_CATEGORIES = [
"หนังนอกกระแส",
"หนังในกระแส",
"หนังฝรั่งเศส",
"กลุ่มคนฉายหนัง",
"หนังไทย",
] as const;
export type CinemaCategory = (typeof CINEMA_CATEGORIES)[number];
/**
* ชั้นกรองที่ 1 — "ประเภทโรงหนัง" (เลือกได้ทีละอย่าง)
* ข้อมูลเก็บที่ `cinema.venue_type` (คนละฟิลด์กับ tags เพราะโรงหนึ่งเป็นได้ประเภทเดียว)
*/
export const VENUE_TYPES = [
"โรงภาพยนตร์ท้องถิ่น",
"โรงภาพยนตร์อินดี้",
"กลุ่มคนฉายหนัง",
] as const;
export type VenueType = (typeof VENUE_TYPES)[number];
export const DEFAULT_CATEGORY: CinemaCategory = "ทั้งหมด";
/** ลำดับ gradient ของการ์ด ใช้ร่วมกันทุกหน้าเพื่อให้สีคงที่ */
@@ -352,6 +368,11 @@ export function hasCategory(cinema: Cinema, category: CinemaCategory): boolean {
return category === DEFAULT_CATEGORY || cinema.tags.includes(category);
}
/** ชั้นกรองที่ 1: ประเภทโรงหนัง — null = ไม่กรอง */
export function hasVenue(cinema: Cinema, venue: VenueType | null): boolean {
return venue === null || cinema.venue_type === venue;
}
export function findCinemaBySlug(
cinemas: Cinema[],
slug: string | undefined,
+4 -1
View File
@@ -9,7 +9,7 @@ import { mkdir, readFile, rename, writeFile } from "node:fs/promises";
import path from "node:path";
import { sanitizeArticleBlocks } from "@/lib/article";
import type { Cinema } from "@/lib/cinemas";
import { VENUE_TYPES, type Cinema, type VenueType } from "@/lib/cinemas";
import { contactHref } from "@/lib/contact-link";
import {
seedAbout,
@@ -142,6 +142,9 @@ export function sanitizeCinemas(input: unknown): Cinema[] {
facilities: sanitizeFacilities(raw.facilities),
facility_details: sanitizeFacilityDetails(raw.facility_details),
hidden: raw.hidden === true,
venue_type: VENUE_TYPES.includes(raw.venue_type as VenueType)
? (raw.venue_type as VenueType)
: null,
contact_heading: asString(raw.contact_heading),
photos: asStringList(raw.photos),
};
+13 -3
View File
@@ -1,4 +1,4 @@
import type { CinemaCategory } from "@/lib/cinemas";
import type { CinemaCategory, VenueType } from "@/lib/cinemas";
export type Locale = "th" | "en";
@@ -138,6 +138,8 @@ export type Messages = {
};
/** ป้ายของหมวดหมู่ — คีย์ยังเป็นไทยเพื่อใช้กรองข้อมูล */
categories: Record<CinemaCategory, string>;
/** ชั้นกรองที่ 1 — ประเภทโรงหนัง (คีย์ไทย ใช้กรองข้อมูล) */
venues: Record<VenueType, string>;
/** ป้ายของ tag ในข้อมูลโรงหนัง */
tags: Record<string, string>;
facilities: Record<FacilityKey, { title: string; sub: string }>;
@@ -281,9 +283,13 @@ const TH: Messages = {
หนังนอกกระแส: "หนังนอกกระแส",
หนังในกระแส: "หนังในกระแส",
หนังฝรั่งเศส: "หนังฝรั่งเศส",
กลุ่มคนฉายหนัง: "กลุ่มคนฉายหนัง",
หนังไทย: "หนังไทย",
},
venues: {
โรงภาพยนตร์ท้องถิ่น: "โรงภาพยนตร์ท้องถิ่น",
โรงภาพยนตร์อินดี้: "โรงภาพยนตร์อินดี้",
กลุ่มคนฉายหนัง: "กลุ่มคนฉายหนัง",
},
tags: {
ยอดนิยม: "ยอดนิยม",
อาร์ตเฮาส์: "อาร์ตเฮาส์",
@@ -451,9 +457,13 @@ const EN: Messages = {
หนังนอกกระแส: "Independent",
หนังในกระแส: "Mainstream",
หนังฝรั่งเศส: "French films",
กลุ่มคนฉายหนัง: "Film collectives",
หนังไทย: "Thai films",
},
venues: {
โรงภาพยนตร์ท้องถิ่น: "Local cinemas",
โรงภาพยนตร์อินดี้: "Indie cinemas",
กลุ่มคนฉายหนัง: "Film collectives",
},
tags: {
ยอดนิยม: "Popular",
อาร์ตเฮาส์: "Arthouse",
+13 -2
View File
@@ -11,7 +11,13 @@
* 4) matchLevel + FIELD_WEIGHTS — ให้คะแนนความตรง
* 5) scoreCinema / filterCinemas — รวมผลและเรียงจากตรงที่สุด
*/
import { hasCategory, type Cinema, type CinemaCategory } from "@/lib/cinemas";
import {
hasCategory,
hasVenue,
type Cinema,
type CinemaCategory,
type VenueType,
} from "@/lib/cinemas";
/** อักขระล่องหนที่ติดมากับการคัดลอกข้อความ (zero-width, BOM) */
const ZERO_WIDTH = /[\u200B-\u200D\u2060\uFEFF]/g;
@@ -187,15 +193,20 @@ export function filterCinemas(
{
category,
query,
venue = null,
tagLabels = {},
}: {
category: CinemaCategory;
query: string;
/** ชั้นกรองที่ 1 — ประเภทโรงหนัง (null = ทุกประเภท) */
venue?: VenueType | null;
/** ป้ายหมวดตามภาษาที่แสดงบนการ์ด (messages.tags) */
tagLabels?: Record<string, string>;
},
): Cinema[] {
const inCategory = cinemas.filter((cinema) => hasCategory(cinema, category));
const inCategory = cinemas
.filter((cinema) => hasVenue(cinema, venue))
.filter((cinema) => hasCategory(cinema, category));
const tokens = searchTokens(query);
if (tokens.length === 0) return inCategory;
+18 -3
View File
@@ -11,9 +11,11 @@ import { APP_TITLE } from "@/lib/app-config";
import {
CINEMA_CATEGORIES,
DEFAULT_CATEGORY,
VENUE_TYPES,
publiclyVisible,
type Cinema,
type CinemaCategory,
type VenueType,
} from "@/lib/cinemas";
import { useContent } from "@/lib/content-context";
import { dailyOrder, dayKey } from "@/lib/daily-order";
@@ -67,6 +69,8 @@ export default function HomeRoute() {
const { cinemas } = useContent();
const { status: nearMeStatus, distances, requestLocation } = useNearMe();
const [category, setCategory] = useState<CinemaCategory>(DEFAULT_CATEGORY);
/** ชั้นกรองที่ 1 — ประเภทโรงหนัง (null = ทุกประเภท) */
const [venue, setVenue] = useState<VenueType | null>(null);
// รองรับลิงก์ค้นหาตรง ๆ (/?q=...) — ให้ SearchAction ใน JSON-LD ทำงานจริง
const [searchParams] = useSearchParams();
const [query, setQuery] = useState(() => searchParams.get("q") ?? "");
@@ -82,16 +86,24 @@ export default function HomeRoute() {
orderKey,
);
const byStats =
category === "ยอดนิยม" && popularity.ready && query.trim() === "";
category === "ยอดนิยม" &&
venue === null &&
popularity.ready &&
query.trim() === "";
if (!byStats)
return filterCinemas(base, { category, query, tagLabels: messages.tags });
return filterCinemas(base, {
category,
query,
venue,
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, messages.tags]);
}, [cinemas, category, query, venue, popularity, orderKey, messages.tags]);
// เรียงจากใกล้สุดไปไกลสุดเมื่อทราบตำแหน่งแล้ว (ไม่กรองตามรัศมี — ไกลแค่ไหนก็ยังแสดง)
const ordered =
nearMeStatus === "ready" ? sortByDistance(matched, distances) : matched;
@@ -163,6 +175,9 @@ export default function HomeRoute() {
active={category}
categories={CINEMA_CATEGORIES}
onChange={setCategory}
venues={VENUE_TYPES}
activeVenue={venue}
onVenueChange={setVenue}
/>
</Reveal>
+29 -1
View File
@@ -14,7 +14,12 @@ import { SlugInput, suggestSlug } from "@/components/admin/SlugInput";
import { TransportEditor } from "@/components/admin/TransportEditor";
import { FOOTER_ICON_NAMES } from "@/components/site/footer-icons";
import type { AnalyticsSummary } from "@/lib/analytics-types";
import { ASSIGNABLE_CATEGORIES, type Cinema } from "@/lib/cinemas";
import {
ASSIGNABLE_CATEGORIES,
VENUE_TYPES,
type Cinema,
type VenueType,
} from "@/lib/cinemas";
import {
seedAbout,
seedForCinemas,
@@ -380,6 +385,29 @@ export default function AdminRoute() {
}
/>
</label>
<label className={labelClass}>
ประเภทโรงหนัง (ตัวกรองชั้นแรกบนหน้าแรก)
<select
className={inputClass}
value={cinema.venue_type ?? ""}
onChange={(event) =>
updateCinema({
...cinema,
venue_type:
event.target.value === ""
? null
: (event.target.value as VenueType),
})
}
>
<option value="">— ยังไม่จัดประเภท —</option>
{VENUE_TYPES.map((venue) => (
<option key={venue} value={venue}>
{venue}
</option>
))}
</select>
</label>
<label className={labelClass}>
slug (ใช้ใน URL)
<SlugInput
+4 -1
View File
@@ -15,7 +15,7 @@
| หมวด | มีอะไร |
|---|---|
| **ข้อมูลหลัก** | ชื่อ EN/TH · slug (URL) · ตัวเลือก "ซ่อนโรงนี้จากหน้าเว็บ" |
| **ข้อมูลหลัก** | ชื่อ EN/TH · slug (URL) · **ประเภทโรงหนัง** (`venue_type` — ตัวกรองชั้นแรกบนหน้าแรก: ท้องถิ่น / อินดี้ / กลุ่มคนฉายหนัง) · ตัวเลือก "ซ่อนโรงนี้จากหน้าเว็บ" |
| **หมวดหมู่ & สิ่งอำนวยความสะดวก** | ชิปหมวด (เลือกได้หลายอัน) + ชิปหัวข้อสิ่งอำนวยความสะดวก + ช่องชื่อหัวข้อเฉพาะโรง |
| **การเดินทาง & การติดต่อ** | วิธีเดินทาง (icon/TH/EN) · หัวข้อ "สอบถามข้อมูลและจองตั๋ว" · ช่องทางติดต่อ (Website/Facebook/Call) · รูปภาพ · การชำระเงิน |
| **ที่ตั้ง & แผนที่** | ที่ตั้ง TH/EN · ละติจูด/ลองจิจูด · Google map URL · ที่อยู่ (บรรทัดละรายการ) |
@@ -61,6 +61,9 @@
## 3. หมวดหมู่ (categories)
หน้าแรกมี **สองชั้นกรอง**: (1) ประเภทโรงหนัง `venue_type` — โรงภาพยนตร์ท้องถิ่น / โรงภาพยนตร์อินดี้ / กลุ่มคนฉายหนัง และ (2) หมวดภาพยนตร์แบบเดิม (อาร์ตเฮาส์ / สารคดี / …) · เลือกได้ทีละชั้น
ประเภทโรงหนังตั้งที่หมวด **ข้อมูลหลัก** → ช่อง **ประเภทโรงหนัง** (เว้นว่าง = ยังไม่จัดประเภท; โรงที่ยังไม่จัดจะหายไปเมื่อกรองด้วยประเภทใด ๆ)
หมวด **หมวดหมู่ & สิ่งอำนวยความสะดวก** → กดชิปที่ต้องการ (เลือกได้หลายอัน) หรือพิมพ์เองในช่องใต้ชิป (คั่นด้วย `,`)
หมวดที่ใช้ได้ตอนนี้: ยอดนิยม · อาร์ตเฮาส์ · สารคดี · หนังสั้น · หนังคลาสสิก · หนังนานาชาติ · หนังนอกกระแส · หนังในกระแส · หนังฝรั่งเศส · **กลุ่มคนฉายหนัง** · **หนังไทย**
+1 -1
View File
@@ -21,7 +21,7 @@
| GET | `/api/admin/session` | — | ตรวจว่ายังล็อกอินอยู่ |
| GET | `/api/admin/content` | — | อ่าน `ContentStore` ทั้งก้อน (`cinemas`, `site`, `about`, `forCinemas`, `forFilmLovers`) |
| POST | `/api/admin/uploads` | `multipart/form-data`: `file` (บังคับ, ≤ 8 MB), `slug` (ไม่บังคับ) | อัปโหลดรูปโรงหนัง — ตรวจชนิดจริงจาก magic bytes (JPEG/PNG/WebP/AVIF) เก็บที่ `data/uploads/cinemas/` คืน `{ url, bytes, type }` โดย `url` = `/uploads/cinemas/<ไฟล์>` |
| PUT | `/api/admin/content` | `{ cinemas?, site?, about?, forCinemas?, forFilmLovers? }` | บันทึกเฉพาะส่วนที่ส่งมา — ผ่าน `sanitizeCinemas` / `sanitizeSite` / `sanitizeAbout` / `sanitizeForCinemas` / `sanitizeForFilmLovers` แล้วเขียนไฟล์แบบ atomic · **`contacts[].href` ถูกคำนวณใหม่ให้กดใช้ได้จริง (tel:/mailto:/https:) ทุกครั้ง** |
| PUT | `/api/admin/content` | `{ cinemas?, site?, about?, forCinemas?, forFilmLovers? }` | บันทึกเฉพาะส่วนที่ส่งมา — ผ่าน `sanitizeCinemas` / `sanitizeSite` / `sanitizeAbout` / `sanitizeForCinemas` / `sanitizeForFilmLovers` แล้วเขียนไฟล์แบบ atomic · **`contacts[].href` ถูกคำนวณใหม่ให้กดใช้ได้จริง (tel:/mailto:/https:) ทุกครั้ง** · `venue_type` รับเฉพาะค่าใน `VENUE_TYPES` (ค่าอื่นถูกทำให้เป็น `null`) |
| POST | `/api/admin/cinemas/import` | `{ cinemas: Cinema[] }` หรือรายการเดียว | นำเข้าโรงหนังโดยใช้ slug เป็นกุญแจ (มีอยู่ = ทับ) |
| GET | `/api/admin/analytics` | `?days=1\|7\|30\|90` | สรุปสถิติ (`summarize()`) — คำค้นยอดนิยม, คำค้นไม่พบผล, CTR, โรงที่ถูกเปิด/คลิก |
+1 -1
View File
@@ -18,7 +18,7 @@
* | โดเมนอื่น (รูป hotlink) | ไม่จัดการ |
* | /app/* · /node_modules/* · /@* | ไม่จัดการ (โมดูลของ dev server) |
*/
const VERSION = "v2.0.4";
const VERSION = "v2.0.5";
const PAGES_CACHE = `alterflixhub-pages-${VERSION}`;
const ASSETS_CACHE = `alterflixhub-assets-${VERSION}`;
+100
View File
@@ -0,0 +1,100 @@
/**
* ตั้งค่า `venue_type` (ชั้นกรองที่ 1) ให้โรงหนังทุกโรง
*
* ใช้: node scripts/set-venue-types.mjs [--dry]
*
* กติกาที่ใช้จัด (ปรับได้ทีหลังในหลังบ้าน → แท็บโรงหนัง → ข้อมูลหลัก → ประเภทโรงหนัง):
* - กลุ่มคนฉายหนัง = กลุ่ม/คอลเลกทีฟที่ฉายตามที่ต่าง ๆ หรือมีห้องฉายเล็กของตัวเอง
* - โรงภาพยนตร์อินดี้ = โรง/พื้นที่ฉายอาร์ตเฮาส์-อินดี้ประจำเมือง (มีที่นั่งถาวร)
* - โรงภาพยนตร์ท้องถิ่น = โรงหนังท้องถิ่น/มัลติเพล็กซ์ของจังหวัดและเชนไทย
*/
import fs from "node:fs";
const CONTENT_PATH = "data/content/content.json";
const DRY = process.argv.includes("--dry");
const LOCAL = [
"thana-cineplex",
"century-the-movie-plaza",
"century-the-movie-plaza-sukhumvit",
"ck-multiplex",
"major-hollywood",
"coliseum-paradise",
"dech-udom-theatre",
"muangthong-rama",
"mvp-cinema",
"nevada-multiplex",
"suen-heng-multiplex-sisaket",
"chumphae-cineplex",
"srisakon-cineplex",
"phahol-theatre",
"nang-loeng-cinema-sala-chalerm-thani",
];
const INDIE = [
"house-cinema-samyan",
"lido-connect",
"doc-club-and-friends",
"sala-saneha",
"the-friese-greene-club",
"cinema-oasis",
"alliance-francaise-de-bangkok",
"thai-film-archive",
"kku-cinema",
"mecani",
"wednesday-shine",
];
const COLLECTIVE = ["phok-bookshop-cinema", "homeflick", "loprama"];
const MAP = new Map();
for (const slug of LOCAL) MAP.set(slug, "โรงภาพยนตร์ท้องถิ่น");
for (const slug of INDIE) MAP.set(slug, "โรงภาพยนตร์อินดี้");
for (const slug of COLLECTIVE) MAP.set(slug, "กลุ่มคนฉายหนัง");
const raw = fs.readFileSync(CONTENT_PATH, "utf8");
const content = JSON.parse(raw);
const unknown = [];
let changed = 0;
const counts = new Map();
for (const cinema of content.cinemas) {
const venue = MAP.get(cinema.slug);
if (!venue) {
unknown.push(cinema.slug);
continue;
}
if (cinema.venue_type !== venue) {
cinema.venue_type = venue;
changed++;
}
counts.set(venue, (counts.get(venue) ?? 0) + 1);
// muangthong-rama ถูกติด tag "กลุ่มคนฉายหนัง" ผิด (เป็นโรงหนังท้องถิ่น) — เอา tag ออก
if (cinema.slug === "muangthong-rama" && Array.isArray(cinema.tags)) {
cinema.tags = cinema.tags.filter((tag) => tag !== "กลุ่มคนฉายหนัง");
}
}
for (const cinema of content.cinemas) {
const venue = cinema.venue_type ?? "(ยังไม่จัด)";
console.log(`${venue.padEnd(24)} ${cinema.slug}`);
}
console.log("\nสรุปตามประเภท:");
for (const [venue, count] of counts) console.log(` ${venue}: ${count}`);
if (unknown.length > 0) {
console.log(`\nยังไม่จัดประเภท (${unknown.length}): ${unknown.join(", ")}`);
}
if (DRY) {
console.log("\n--dry: ไม่ได้เขียนไฟล์");
} else {
const stamp = new Date().toISOString().replace(/[:.]/g, "-");
fs.writeFileSync(`${CONTENT_PATH}.bak-venue-${stamp}`, raw);
fs.writeFileSync(CONTENT_PATH, `${JSON.stringify(content, null, 2)}\n`);
console.log(
`\nเขียนไฟล์แล้ว (เปลี่ยน ${changed} โรง) · สำรอง: ${CONTENT_PATH}.bak-venue-${stamp}`,
);
}