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:
1 parent
2e794cd365
commit
1932098a1d
15 files changed
+362
-26
No files matched your search
+73
-2
@@ -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
@@ -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,
|
||||
|
||||
@@ -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),
|
||||
};
|
||||
|
||||
@@ -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
@@ -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;
|
||||
|
||||
|
||||
Reference in new issue
Block a user