Files
web-alterflixhub/scripts/set-venue-types.mjs
T
Bkk1234 1932098a1d 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 อัปเดต
2026-11-16 01:46:59 +07:00

101 lines
3.9 KiB
JavaScript

/**
* ตั้งค่า `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}`,
);
}