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