chore(publish): replace source tree with static export at repo root
Publish the prerendered static export (index.html, 404.html, cinema/,
c/, about/, for-cinemas/, for-film-lovers/, assets/, images/, og/,
sitemap.xml, robots.txt) as the site root and remove the React Router
+ Nitro source tree from this branch. Source remains available in
history at 0548772.
Note: public/sw.js here reports VERSION v2.0.5 while the removed source
tree (v2.1.0) was newer, and .gitignore was not carried over.
This commit is contained in:
1 parent
05487728a7
commit
e6c4ebff48
394 files changed
+3977
-37891
No files matched your search
@@ -1,238 +0,0 @@
|
||||
#!/usr/bin/env python
|
||||
# -*- coding: utf-8 -*-
|
||||
"""เพิ่มโรงหนังชุดใหม่ (ข้อมูลพื้นฐาน) เข้า data/content/content.json"""
|
||||
import json
|
||||
|
||||
PATH = "data/content/content.json"
|
||||
|
||||
|
||||
def cinema(slug, name, name_th, tags, loc, loc_en, coords, desc, desc_en,
|
||||
map_url, addr, addr_en, transport, contacts):
|
||||
return {
|
||||
"slug": slug,
|
||||
"name": name,
|
||||
"name_th": name_th,
|
||||
"tags": tags,
|
||||
"location_label": loc,
|
||||
"location_label_en": loc_en,
|
||||
"coordinates": coords,
|
||||
"description": desc,
|
||||
"description_en": desc_en,
|
||||
"map_url": map_url,
|
||||
"address_lines": addr,
|
||||
"address_lines_en": addr_en,
|
||||
"transport": transport,
|
||||
"contacts": contacts,
|
||||
"payments": [],
|
||||
"photos": [],
|
||||
}
|
||||
|
||||
|
||||
NEW = [
|
||||
cinema(
|
||||
"doc-club-and-friends", "DOC CLUB & FRIENDS", "ด็อกคลับ แอนด์ เฟรนด์ส",
|
||||
["อาร์ตเฮาส์", "สารคดี", "หนังนอกกระแส"],
|
||||
"ชั้น 2 อาคาร Cloud 11 สุขุมวิท (BTS ปุณณวิถี) กรุงเทพฯ",
|
||||
"2nd floor, Cloud 11, Sukhumvit (BTS Punnawithi), Bangkok", None,
|
||||
"โรงหนังของ Doc Club & Friends ชั้น 2 อาคาร Cloud 11 ห้องขนาด 34 ที่นั่ง "
|
||||
"ฉายหนังสารคดีและหนังนอกกระแส มีบาร์และพื้นที่นั่งคุยกันหลังหนังจบ เปิดทุกวัน 11.00–24.00",
|
||||
"Doc Club & Friends' 34-seat screening room on the 2nd floor of Cloud 11 — "
|
||||
"documentaries and independent films, with a bar and a place to talk after the credits. Open daily 11.00–24.00.",
|
||||
"https://maps.google.com/?q=Doc+Club+%26+Friends+Cloud+11",
|
||||
["ชั้น 2 อาคาร Cloud 11", "888 ถนนสุขุมวิท แขวงพระโขนงใต้ เขตพระโขนง กรุงเทพฯ 10260"],
|
||||
["2nd floor, Cloud 11", "888 Sukhumvit Rd., Phra Khanong Tai, Phra Khanong, Bangkok 10260"],
|
||||
[{"icon_name": "metro", "value": "BTS สายสุขุมวิท ลงสถานีปุณณวิถี แล้วเดินเข้าห้าง Cloud 11",
|
||||
"value_en": "BTS Sukhumvit line, Punnawithi station — walk into Cloud 11"}],
|
||||
[{"label": "เว็บไซต์", "value": "docclubandfriends.com", "href": "https://docclubandfriends.com/"}],
|
||||
),
|
||||
cinema(
|
||||
"sala-saneha", "SALA SANEHA", "ศาลาเสน่หา",
|
||||
["อาร์ตเฮาส์", "หนังคลาสสิก"],
|
||||
"ซอยเดโช สีลม เขตบางรัก กรุงเทพฯ",
|
||||
"Soi Decho, Silom, Bang Rak, Bangkok", None,
|
||||
"โรงหนังอิสระและไวน์บาร์ในอาคารเก่าอายุกว่า 70 ปีกลางย่านสีลม ฉายหนังคัดสรรพร้อมพื้นที่นั่งเล่นและชั้นหนังสือ",
|
||||
"An independent cinema and wine bar inside a 70-year-old building in Silom — curated screenings with a lounge and a small library.",
|
||||
"https://maps.google.com/?q=Sala+Saneha+Silom+Bangkok",
|
||||
["ซอยเดโช (ถนนเดโช) แขวงสีลม เขตบางรัก กรุงเทพฯ"],
|
||||
["Soi Decho, Silom, Bang Rak, Bangkok"],
|
||||
[{"icon_name": "metro", "value": "BTS สถานีศาลาแดง หรือ MRT สถานีสีลม แล้วเดินเข้าซอยเดโช",
|
||||
"value_en": "BTS Sala Daeng or MRT Silom, then walk into Soi Decho"}],
|
||||
[],
|
||||
),
|
||||
cinema(
|
||||
"lido-connect", "LIDO CONNECT", "ลิโด้ คอนเน็กต์",
|
||||
["อาร์ตเฮาส์", "หนังนอกกระแส", "หนังคลาสสิก"],
|
||||
"สยามสแควร์ ถนนพระราม 1 ปทุมวัน กรุงเทพฯ",
|
||||
"Siam Square, Rama I Rd., Pathum Wan, Bangkok", None,
|
||||
"พื้นที่ฉายหนังและกิจกรรมกลางสยามสแควร์ ปรับปรุงจากโรงหนังลิโด้เดิม จัดฉายหนังนอกกระแส หนังคลาสสิก และอีเวนต์ตลอดปี",
|
||||
"A screening and event space in the middle of Siam Square, rebuilt from the original Lido cinema — indie and classic films plus events year round.",
|
||||
"https://maps.google.com/?q=Lido+Connect+Siam+Square",
|
||||
["258 ถนนพระราม 1 แขวงปทุมวัน เขตปทุมวัน กรุงเทพฯ 10330"],
|
||||
["258 Rama I Rd., Pathum Wan, Bangkok 10330"],
|
||||
[{"icon_name": "metro", "value": "BTS สถานีสยาม ทางออกสยามสแควร์",
|
||||
"value_en": "BTS Siam station, Siam Square exit"}],
|
||||
[{"label": "เว็บไซต์", "value": "lidoconnect.com", "href": "https://www.lidoconnect.com/"}],
|
||||
),
|
||||
cinema(
|
||||
"dech-udom-theatre", "เดชอุดมเธียเตอร์", "เดชอุดมเธียเตอร์",
|
||||
["หนังในกระแส"],
|
||||
"อำเภอเดชอุดม จังหวัดอุบลราชธานี",
|
||||
"Dech Udom, Ubon Ratchathani", None,
|
||||
"โรงภาพยนตร์เก่าในอำเภอเดชอุดม จังหวัดอุบลราชธานี — ยังต้องเติมรอบฉายและช่องทางติดต่อ",
|
||||
"An old cinema in Dech Udom district, Ubon Ratchathani — screen times and contacts still need to be added.",
|
||||
"https://maps.google.com/?q=Dech+Udom+Theatre+Ubon+Ratchathani",
|
||||
["อำเภอเดชอุดม จังหวัดอุบลราชธานี"],
|
||||
["Dech Udom district, Ubon Ratchathani"],
|
||||
[], [],
|
||||
),
|
||||
cinema(
|
||||
"muangthong-rama", "เมืองทองรามา", "เมืองทองรามา",
|
||||
["หนังในกระแส", "หนังคลาสสิก"],
|
||||
"อำเภอเมือง จังหวัดพะเยา",
|
||||
"Mueang district, Phayao", None,
|
||||
"โรงหนัง stand-alone ของจังหวัดพะเยา เปิดฉายตั้งแต่ปี 2518 เคยเป็นโรงหลักของเมือง "
|
||||
"ก่อนถูกมัลติเพล็กซ์แทนที่ และกลับมาฉายอีกครั้งโดยทายาทรุ่นลูก",
|
||||
"Phayao's stand-alone cinema, open since 1975. Once the town's main picture house, it lost ground to multiplexes and has been revived by the founder's children.",
|
||||
"https://maps.google.com/?q=Muangthong+Rama+Phayao",
|
||||
["อำเภอเมืองพะเยา จังหวัดพะเยา"],
|
||||
["Mueang district, Phayao"],
|
||||
[], [],
|
||||
),
|
||||
cinema(
|
||||
"phok-bookshop-cinema", "พก PHOK", "พก — ร้านหนังสือและโรงหนัง",
|
||||
["สารคดี", "หนังนอกกระแส"],
|
||||
"จังหวัดเชียงราย (เคลื่อนที่ ไม่มีหน้าร้าน)",
|
||||
"Chiang Rai (mobile, no fixed shop)", None,
|
||||
"ร้านหนังสือและโรงหนังสารคดีเคลื่อนที่ในรถตู้ เดินทางไปฉายหนังและขายหนังสือตามพื้นที่ต่าง ๆ ทั้งในและนอกจังหวัดเชียงราย",
|
||||
"A bookshop and documentary cinema in a van — travelling to screen films and sell books in and beyond Chiang Rai.",
|
||||
None,
|
||||
["จังหวัดเชียงราย (ไม่มีที่ตั้งถาวร — ดูประกาศรอบฉายจากเพจ)"],
|
||||
["Chiang Rai (no fixed address — check the page for upcoming screenings)"],
|
||||
[], [],
|
||||
),
|
||||
cinema(
|
||||
"wednesday-shine", "WEDNESDAY SHINE", "พุธฉาย",
|
||||
["อาร์ตเฮาส์", "หนังนอกกระแส"],
|
||||
"ถนนช้างเผือก ตำบลศรีภูมิ เมืองเชียงใหม่",
|
||||
"Chang Phueak Rd., Si Phum, Mueang Chiang Mai", None,
|
||||
"ไมโครซีนีมาในย่านช้างเผือก เชียงใหม่ จัดฉายหนังนอกกระแสและหนังสารคดีเป็นรอบ ๆ พร้อมกิจกรรมพูดคุยหลังหนังจบ",
|
||||
"A microcinema on Chang Phueak in Chiang Mai, screening independent and documentary films in rounds with post-screening talks.",
|
||||
"https://maps.google.com/?q=Wednesday+Shine+Chiang+Mai",
|
||||
["5/27 ถนนช้างเผือก ซอย 4 ง ตำบลศรีภูมิ อำเภอเมืองเชียงใหม่ จังหวัดเชียงใหม่"],
|
||||
["5/27 Chang Phueak Rd., Si Phum, Mueang Chiang Mai, Chiang Mai"],
|
||||
[],
|
||||
[{"label": "โทรศัพท์", "value": "081-854-6649", "href": "tel:+66818546649"}],
|
||||
),
|
||||
cinema(
|
||||
"mecani", "MECANI", "เมคานี",
|
||||
["อาร์ตเฮาส์", "หนังนอกกระแส", "หนังคลาสสิก"],
|
||||
"ตำบลดอนแก้ว อำเภอแม่ริม จังหวัดเชียงใหม่",
|
||||
"Don Kaeo, Mae Rim, Chiang Mai", None,
|
||||
"โรงหนังเล็ก 24 ที่นั่งในตำบลดอนแก้ว อำเภอแม่ริม ฉายหนังนอกกระแสและหนังเก่า ตั้งใจให้เป็นโรงหนังของคนในชุมชน",
|
||||
"A 24-seat house in Don Kaeo, Mae Rim, screening independent and older films — built to be the neighbourhood's own cinema.",
|
||||
"https://maps.google.com/?q=Mecani+Don+Kaeo+Mae+Rim+Chiang+Mai",
|
||||
["1380 ตำบลดอนแก้ว อำเภอแม่ริม จังหวัดเชียงใหม่"],
|
||||
["1380 Don Kaeo, Mae Rim, Chiang Mai"],
|
||||
[],
|
||||
[{"label": "โทรศัพท์", "value": "06 5989 8657", "href": "tel:+66659898657"}],
|
||||
),
|
||||
cinema(
|
||||
"kku-cinema", "โรงหนัง ม.ขอนแก่น", "โรงหนัง มหาวิทยาลัยขอนแก่น",
|
||||
["สารคดี", "หนังคลาสสิก", "หนังนอกกระแส"],
|
||||
"ศูนย์ศิลปวัฒนธรรม มหาวิทยาลัยขอนแก่น อำเภอเมือง จังหวัดขอนแก่น",
|
||||
"Cultural Center, Khon Kaen University, Mueang, Khon Kaen", None,
|
||||
"โรงภาพยนตร์ของหอภาพยนตร์อีสาน ศูนย์ศิลปวัฒนธรรม มหาวิทยาลัยขอนแก่น "
|
||||
"ฉายหนังคลาสสิก หนังสารคดี และหนังหาดูยาก และเปิดให้จองรอบฉาย",
|
||||
"The cinema of the Isan Film Archive at Khon Kaen University's Cultural Center — classic, documentary and rare films, with bookable screenings.",
|
||||
"https://maps.google.com/?q=Isan+Film+Archive+Khon+Kaen+University",
|
||||
["ศูนย์ศิลปวัฒนธรรม มหาวิทยาลัยขอนแก่น",
|
||||
"123 หมู่ 16 ตำบลศิลา อำเภอเมืองขอนแก่น จังหวัดขอนแก่น 40002"],
|
||||
["Cultural Center, Khon Kaen University", "123 Moo 16, Sila, Mueang Khon Kaen, Khon Kaen 40002"],
|
||||
[],
|
||||
[{"label": "โทรศัพท์", "value": "043-202-663", "href": "tel:+6643202663"}],
|
||||
),
|
||||
cinema(
|
||||
"mvp-cinema", "MVP CINEMA", "เอ็มวีพี",
|
||||
["หนังในกระแส"],
|
||||
"บุรีรัมย์ · กาฬสินธุ์ · เลย · ศรีสะเกษ",
|
||||
"Buriram · Kalasin · Loei · Sisaket", None,
|
||||
"เครือโรงภาพยนตร์ในภาคอีสาน 4 สาขา — บุรีรัมย์ กาฬสินธุ์ เลย และศรีสะเกษ เช็กรอบฉายรวมทุกสาขาได้ที่เว็บไซต์",
|
||||
"An Isan cinema chain with four branches — Buriram, Kalasin, Loei and Sisaket; showtimes for every branch are listed on its site.",
|
||||
"https://www.ilovemvp.com/",
|
||||
["สาขา บุรีรัมย์ / กาฬสินธุ์ / เลย / ศรีสะเกษ"],
|
||||
["Branches: Buriram / Kalasin / Loei / Sisaket"],
|
||||
[],
|
||||
[{"label": "เว็บไซต์", "value": "ilovemvp.com", "href": "https://www.ilovemvp.com/"}],
|
||||
),
|
||||
cinema(
|
||||
"nevada-multiplex", "NEVADA MULTIPLEX", "เนวาด้ามัลติเพล็กซ์",
|
||||
["หนังในกระแส"],
|
||||
"ถนนสุขเกษม อำเภอเมืองสกลนคร จังหวัดสกลนคร",
|
||||
"Suk Kasem Rd., Mueang Sakon Nakhon", None,
|
||||
"โรงภาพยนตร์มัลติเพล็กซ์ในอำเภอเมืองสกลนคร อยู่บนถนนสุขเกษมในย่านศูนย์การค้าของเมือง",
|
||||
"A multiplex in Mueang Sakon Nakhon on Suk Kasem Road, inside the town's shopping area.",
|
||||
"https://maps.google.com/?q=Nevada+Multiplex+Sakon+Nakhon",
|
||||
["ถนนสุขเกษม ตำบลดงมะไฟ อำเภอเมืองสกลนคร จังหวัดสกลนคร"],
|
||||
["Suk Kasem Rd., Dong Mafai, Mueang Sakon Nakhon, Sakon Nakhon"],
|
||||
[], [],
|
||||
),
|
||||
cinema(
|
||||
"suen-heng-multiplex-sisaket", "SUEN-HENG MULTIPLEX SISAKET", "ซุ่นเฮง มัลติเพล็กซ์ ศรีสะเกษ",
|
||||
["หนังในกระแส"],
|
||||
"ถนนวันลูกเสือ เทศบาลเมืองศรีสะเกษ จังหวัดศรีสะเกษ",
|
||||
"Wan Luksuea Rd., Mueang Sisaket", {"latitude": 15.1116618, "longitude": 104.3284349},
|
||||
"โรงภาพยนตร์มัลติเพล็กซ์ในศูนย์การค้าซุ่นเฮง ใจกลางเมืองศรีสะเกษ",
|
||||
"A multiplex inside the Suen Heng shopping centre in the middle of Sisaket town.",
|
||||
"https://maps.google.com/?q=Suen+Heng+Sisaket",
|
||||
["ศูนย์การค้าซุ่นเฮง ถนนวันลูกเสือ ตำบลน้ำคำ อำเภอเมืองศรีสะเกษ จังหวัดศรีสะเกษ 33000"],
|
||||
["Suen Heng Plaza, Wan Luksuea Rd., Nam Kham, Mueang Sisaket, Sisaket 33000"],
|
||||
[], [],
|
||||
),
|
||||
cinema(
|
||||
"homeflick", "HOMEFLICK", "โฮมฟลิก",
|
||||
["หนังนอกกระแส", "อาร์ตเฮาส์"],
|
||||
"อำเภอเมืองนครราชสีมา (โคราช)",
|
||||
"Mueang Nakhon Ratchasima (Korat)", None,
|
||||
"กลุ่มฉายหนังนอกกระแสในโคราช เริ่มฉายครั้งแรกปี 2556 และมีห้องฉายของตัวเอง จัดรอบฉายพร้อมเสวนาอย่างต่อเนื่อง",
|
||||
"A Korat screening collective that started in 2013, now running its own screening room with regular post-film talks.",
|
||||
None,
|
||||
["อำเภอเมืองนครราชสีมา จังหวัดนครราชสีมา"],
|
||||
["Mueang Nakhon Ratchasima, Nakhon Ratchasima"],
|
||||
[], [],
|
||||
),
|
||||
cinema(
|
||||
"loprama", "ลพรามา LOPRAMA", "ลพรามา",
|
||||
["หนังนอกกระแส", "สารคดี", "อาร์ตเฮาส์"],
|
||||
"อำเภอเมืองลพบุรี (ฉายตามสถานที่ในเมือง)",
|
||||
"Mueang Lopburi (pop-up venues in town)", None,
|
||||
"กลุ่มฉายหนังอิสระในลพบุรี ใช้ภาพยนตร์ขับเคลื่อนเมือง จัดฉายหนังนอกกระแส สารคดี และหนังหาดูยากตามสถานที่ต่าง ๆ เช่น คาเฟ่และแกลเลอรี",
|
||||
"A Lopburi independent screening collective using film to animate the town — indie, documentary and rare titles shown in cafes, galleries and other venues.",
|
||||
None,
|
||||
["อำเภอเมืองลพบุรี จังหวัดลพบุรี"],
|
||||
["Mueang Lopburi, Lopburi"],
|
||||
[], [],
|
||||
),
|
||||
]
|
||||
|
||||
|
||||
def main():
|
||||
raw = open(PATH, encoding="utf-8").read()
|
||||
crlf = "\r\n" in raw
|
||||
store = json.loads(raw)
|
||||
have = {c["slug"] for c in store["cinemas"]}
|
||||
added = [c for c in NEW if c["slug"] not in have]
|
||||
store["cinemas"].extend(added)
|
||||
|
||||
out = json.dumps(store, ensure_ascii=False, indent=2)
|
||||
if crlf:
|
||||
out = out.replace("\n", "\r\n")
|
||||
with open(PATH, "w", encoding="utf-8", newline="") as fh:
|
||||
fh.write(out + ("\r\n" if crlf else "\n"))
|
||||
|
||||
print("added:", len(added), "/ total:", len(store["cinemas"]), "/ crlf:", crlf)
|
||||
for c in added:
|
||||
print(" -", c["slug"], "|", c["name_th"], "|", c["location_label"])
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
main()
|
||||
@@ -1,180 +0,0 @@
|
||||
/**
|
||||
* ตรวจ/ซ่อม `href` ของช่องทางติดต่อใน content.json ให้กดใช้ได้จริง
|
||||
*
|
||||
* ปัญหาที่เจอ: href ว่าง, เป็น `www.…` ไม่มี scheme, เบอร์ไม่มี `tel:`,
|
||||
* facebook ติด `fbclid`, หรือ label "Call" แต่ค่าไม่ใช่เบอร์
|
||||
*
|
||||
* ใช้: node scripts/audit-contacts.mjs # ดูอย่างเดียว
|
||||
* node scripts/audit-contacts.mjs --fix # เขียน href ที่แก้ได้กลับลงไฟล์ (สำรองก่อน)
|
||||
*/
|
||||
import fs from "node:fs";
|
||||
import path from "node:path";
|
||||
|
||||
const CONTENT_PATH = path.join("data", "content", "content.json");
|
||||
const FIX = process.argv.includes("--fix");
|
||||
|
||||
const PHONE_LABEL = /call|โทร|phone|tel|เบอร์|มือถือ/i;
|
||||
|
||||
function emptyish(value) {
|
||||
const text = String(value ?? "")
|
||||
.trim()
|
||||
.toLowerCase();
|
||||
return (
|
||||
text === "" || ["-", "–", "n/a", "null", "ไม่มี", "ไม่มีข้อมูล"].includes(text)
|
||||
);
|
||||
}
|
||||
|
||||
function normalizePhone(raw) {
|
||||
const text = String(raw ?? "").trim();
|
||||
if (text === "") return null;
|
||||
const hasPlus = text.startsWith("+");
|
||||
const digits = text.replace(/[^\d]/g, "");
|
||||
if (digits.length < 8 || digits.length > 15) return null;
|
||||
if (hasPlus) return `+${digits}`;
|
||||
if (digits.startsWith("66")) return `+${digits}`;
|
||||
if (digits.startsWith("0")) return `+66${digits.slice(1)}`;
|
||||
return `+${digits}`;
|
||||
}
|
||||
|
||||
/** เหมือน app/lib/contact-link.ts (สคริปต์เป็น .mjs จึงต้องพอร์ตกฎมาใช้เอง) */
|
||||
function resolve(channel) {
|
||||
const value = String(channel.value ?? "").trim();
|
||||
const href = String(channel.href ?? "").trim();
|
||||
const label = String(channel.label ?? "").toLowerCase();
|
||||
const candidates = [href, value].filter((item) => !emptyish(item));
|
||||
if (candidates.length === 0) return { href: null, kind: null };
|
||||
|
||||
for (const candidate of candidates) {
|
||||
const lower = candidate.toLowerCase();
|
||||
if (lower.startsWith("tel:")) {
|
||||
const phone = normalizePhone(candidate.slice(4));
|
||||
if (phone) return { href: `tel:${phone}`, kind: "tel" };
|
||||
}
|
||||
if (lower.startsWith("mailto:")) {
|
||||
return { href: `mailto:${candidate.slice(7).trim()}`, kind: "mailto" };
|
||||
}
|
||||
if (/^[^\s@]+@[^\s@]+\.[^\s@]{2,}$/.test(candidate)) {
|
||||
return { href: `mailto:${candidate}`, kind: "mailto" };
|
||||
}
|
||||
if (
|
||||
/^https?:\/\//i.test(candidate) ||
|
||||
/^line:/i.test(candidate) ||
|
||||
/^@[\w.\-_]+$/.test(candidate) ||
|
||||
/^[\w-]+(\.[\w-]+)+(\/|$)/.test(candidate)
|
||||
) {
|
||||
let url = candidate;
|
||||
if (/^@[\w.\-_]+$/.test(url))
|
||||
url = `https://line.me/R/ti/p/~${url.slice(1)}`;
|
||||
if (!/^[a-z][a-z0-9+.-]*:\/\//i.test(url)) url = `https://${url}`;
|
||||
try {
|
||||
const parsed = new URL(url);
|
||||
if (parsed.protocol === "http:") parsed.protocol = "https:";
|
||||
if (parsed.hostname === "web.facebook.com")
|
||||
parsed.hostname = "www.facebook.com";
|
||||
for (const key of [...parsed.searchParams.keys()]) {
|
||||
if (
|
||||
[
|
||||
"fbclid",
|
||||
"gclid",
|
||||
"_rdc",
|
||||
"_rdr",
|
||||
"igshid",
|
||||
"mibextid",
|
||||
"ref",
|
||||
].includes(key.toLowerCase()) ||
|
||||
key.toLowerCase().startsWith("utm_")
|
||||
) {
|
||||
parsed.searchParams.delete(key);
|
||||
}
|
||||
}
|
||||
return { href: parsed.toString(), kind: "web" };
|
||||
} catch {
|
||||
return { href: null, kind: null };
|
||||
}
|
||||
}
|
||||
const digits = candidate.replace(/\D/g, "");
|
||||
if (
|
||||
digits.length >= 8 &&
|
||||
digits.length <= 15 &&
|
||||
!/[a-z@]/i.test(candidate)
|
||||
) {
|
||||
const phone = normalizePhone(candidate);
|
||||
if (phone) return { href: `tel:${phone}`, kind: "tel" };
|
||||
}
|
||||
}
|
||||
return { href: null, kind: null };
|
||||
}
|
||||
|
||||
const raw = fs.readFileSync(CONTENT_PATH, "utf8");
|
||||
const content = JSON.parse(raw);
|
||||
|
||||
const rows = [];
|
||||
const phoneOwners = new Map();
|
||||
let changed = 0;
|
||||
|
||||
for (const cinema of content.cinemas ?? []) {
|
||||
const contacts = cinema.contacts ?? [];
|
||||
if (contacts.length === 0) {
|
||||
rows.push({
|
||||
slug: cinema.slug,
|
||||
label: "—",
|
||||
value: "—",
|
||||
href: null,
|
||||
kind: null,
|
||||
note: "ไม่มีช่องทางติดต่อ",
|
||||
});
|
||||
continue;
|
||||
}
|
||||
for (const channel of contacts) {
|
||||
const resolved = resolve(channel);
|
||||
const notes = [];
|
||||
if (!resolved.href) notes.push("ลิงก์ใช้ไม่ได้");
|
||||
if (PHONE_LABEL.test(channel.label ?? "") && resolved.kind !== "tel") {
|
||||
notes.push("label โทร แต่ค่าไม่ใช่เบอร์");
|
||||
}
|
||||
if (resolved.kind === "tel") {
|
||||
const owner = phoneOwners.get(resolved.href);
|
||||
if (owner && owner !== cinema.slug) notes.push(`เบอร์ซ้ำกับ ${owner}`);
|
||||
else phoneOwners.set(resolved.href, cinema.slug);
|
||||
}
|
||||
if (channel.href && channel.href !== resolved.href)
|
||||
notes.push("href จะถูกปรับ");
|
||||
rows.push({
|
||||
slug: cinema.slug,
|
||||
label: channel.label,
|
||||
value: channel.value,
|
||||
href: resolved.href,
|
||||
kind: resolved.kind,
|
||||
note: notes.join(", "),
|
||||
});
|
||||
|
||||
if (FIX && resolved.href !== channel.href) {
|
||||
channel.href = resolved.href;
|
||||
changed++;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
for (const row of rows) {
|
||||
const state = row.href ? row.kind.padEnd(6) : "ไม่มี ";
|
||||
console.log(
|
||||
`${state} ${row.slug} · ${row.label} · ${String(row.value).slice(0, 42)}${row.note ? ` ⚠ ${row.note}` : ""}`,
|
||||
);
|
||||
if (row.href && row.href !== row.value) console.log(` → ${row.href}`);
|
||||
}
|
||||
|
||||
const withoutContacts = rows.filter((row) => row.label === "—").length;
|
||||
console.log(
|
||||
`\nสรุป: ${rows.length - withoutContacts} ช่องทางจาก ${(content.cinemas ?? []).length - withoutContacts} โรง · ไม่มีช่องทางติดต่อ ${withoutContacts} โรง`,
|
||||
);
|
||||
|
||||
if (FIX) {
|
||||
const stamp = new Date().toISOString().replace(/[:.]/g, "-");
|
||||
fs.writeFileSync(`${CONTENT_PATH}.bak-contacts-${stamp}`, raw);
|
||||
fs.writeFileSync(CONTENT_PATH, `${JSON.stringify(content, null, 2)}\n`);
|
||||
console.log(
|
||||
`ปรับ href ${changed} จุด · สำรองไว้ที่ ${CONTENT_PATH}.bak-contacts-${stamp}`,
|
||||
);
|
||||
} else {
|
||||
console.log("ยังไม่เขียนไฟล์ — ใส่ --fix เพื่อบันทึก href ที่ปรับแล้ว");
|
||||
}
|
||||
@@ -1,99 +0,0 @@
|
||||
/**
|
||||
* ตรวจว่ารูปที่อ้างจากภายนอก (http/https) ใน content.json ยังใช้งานได้จริงไหม
|
||||
*
|
||||
* ทำไมต้องมี: โฮสต์อย่าง Google Maps ตอบ **200 แต่ 0 ไบต์** เมื่อลิงก์หมดอายุ/ถูกบล็อก
|
||||
* → หน้าเว็บขึ้นรูปแตก (เบราว์เซอร์ไม่ถือว่า error จึงไม่มี event อะไรให้จับ)
|
||||
*
|
||||
* ใช้: node scripts/audit-photos.mjs
|
||||
* exit 1 = พบรูปเสีย (ใช้ใน CI ได้)
|
||||
*/
|
||||
import fs from "node:fs";
|
||||
import path from "node:path";
|
||||
|
||||
const CONTENT_PATH = path.join("data", "content", "content.json");
|
||||
const MIN_BYTES = 2000; // เล็กกว่านี้ถือว่าใช้ไม่ได้
|
||||
const CONCURRENCY = 5;
|
||||
|
||||
function readContent() {
|
||||
try {
|
||||
return JSON.parse(fs.readFileSync(CONTENT_PATH, "utf8"));
|
||||
} catch (error) {
|
||||
console.error(`อ่าน ${CONTENT_PATH} ไม่ได้: ${error.message}`);
|
||||
process.exit(2);
|
||||
}
|
||||
}
|
||||
|
||||
async function check(url) {
|
||||
try {
|
||||
const res = await fetch(url, {
|
||||
redirect: "follow",
|
||||
headers: {
|
||||
// ให้เหมือนเบราว์เซอร์ที่สุด (บางโฮสต์บังคับ UA)
|
||||
"user-agent":
|
||||
"Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/140.0 Safari/537.36",
|
||||
accept: "image/avif,image/webp,image/*,*/*;q=0.8",
|
||||
},
|
||||
signal: AbortSignal.timeout(20000),
|
||||
});
|
||||
const type = res.headers.get("content-type") ?? "";
|
||||
const bytes = (await res.arrayBuffer()).byteLength;
|
||||
const ok = res.ok && type.startsWith("image/") && bytes >= MIN_BYTES;
|
||||
return { ok, status: res.status, type, bytes };
|
||||
} catch (error) {
|
||||
return { ok: false, status: 0, type: "-", bytes: 0, error: error.message };
|
||||
}
|
||||
}
|
||||
|
||||
const content = readContent();
|
||||
const targets = [];
|
||||
for (const cinema of content.cinemas ?? []) {
|
||||
(cinema.photos ?? []).forEach((url, index) => {
|
||||
if (/^https?:\/\//i.test(url)) {
|
||||
targets.push({ slug: cinema.slug, index, url });
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
if (targets.length === 0) {
|
||||
console.log("✓ ไม่มีรูปภายนอกให้ตรวจ (ทุกรูปเป็นพาธในโปรเจกต์)");
|
||||
process.exit(0);
|
||||
}
|
||||
|
||||
console.log(`ตรวจ ${targets.length} รูปภายนอก...\n`);
|
||||
const results = [];
|
||||
for (let i = 0; i < targets.length; i += CONCURRENCY) {
|
||||
const batch = targets.slice(i, i + CONCURRENCY);
|
||||
const checked = await Promise.all(
|
||||
batch.map(async (t) => ({ ...t, ...(await check(t.url)) })),
|
||||
);
|
||||
results.push(...checked);
|
||||
}
|
||||
|
||||
const dead = results.filter((r) => !r.ok);
|
||||
const host = (url) => {
|
||||
try {
|
||||
return new URL(url).host;
|
||||
} catch {
|
||||
return "?";
|
||||
}
|
||||
};
|
||||
|
||||
for (const row of results) {
|
||||
const state = row.ok ? "OK " : "พัง ";
|
||||
console.log(
|
||||
`${state} ${row.slug} #${row.index} — ${row.status} ${row.type} ${row.bytes}B — ${host(row.url)}`,
|
||||
);
|
||||
}
|
||||
|
||||
console.log(`\nสรุป: ใช้ได้ ${results.length - dead.length} · พัง ${dead.length}`);
|
||||
|
||||
if (dead.length > 0) {
|
||||
console.log("\nรูปที่ต้องแก้ (slug → ตำแหน่งใน photos[]):");
|
||||
for (const row of dead) {
|
||||
console.log(` ${row.slug} #${row.index}`);
|
||||
}
|
||||
console.log(
|
||||
"\nแนะนำ: ดาวน์โหลดรูปจริงเก็บใน public/images/cinemas/<slug>.jpg แล้วเปลี่ยน photos[] เป็นพาธนั้น",
|
||||
);
|
||||
process.exit(1);
|
||||
}
|
||||
@@ -1,35 +0,0 @@
|
||||
import { spawnSync } from "node:child_process";
|
||||
|
||||
const branchKind = process.env.FUSION_BRANCH_KIND;
|
||||
|
||||
if (branchKind !== "feature") {
|
||||
if (branchKind !== "main") {
|
||||
console.warn(
|
||||
`Skipping database migrations because FUSION_BRANCH_KIND is ${branchKind ?? "unset"}`,
|
||||
);
|
||||
}
|
||||
|
||||
process.exit(0);
|
||||
}
|
||||
|
||||
if (!process.env.DATABASE_URL_UNPOOLED) {
|
||||
console.warn(
|
||||
"Skipping database migrations because DATABASE_URL_UNPOOLED is not set",
|
||||
);
|
||||
process.exit(0);
|
||||
}
|
||||
|
||||
const isWindows = process.platform === "win32";
|
||||
const pnpmCommand = isWindows ? "pnpm.cmd" : "pnpm";
|
||||
const result = spawnSync(pnpmCommand, ["run", "db:migrate"], {
|
||||
env: process.env,
|
||||
shell: isWindows,
|
||||
stdio: "inherit",
|
||||
});
|
||||
|
||||
if (result.error) {
|
||||
console.error(result.error.message);
|
||||
process.exit(1);
|
||||
}
|
||||
|
||||
process.exit(result.status ?? 1);
|
||||
@@ -1,53 +0,0 @@
|
||||
import { realpathSync } from "node:fs";
|
||||
import { fileURLToPath, pathToFileURL } from "node:url";
|
||||
|
||||
import { closeDbExec, withMigrationRuntime } from "@agent-native/core/db";
|
||||
import { loadEnv } from "@agent-native/core/scripts";
|
||||
import {
|
||||
runAppReleaseMigrations,
|
||||
runFrameworkReleaseMigrations,
|
||||
} from "@agent-native/core/server";
|
||||
|
||||
loadEnv();
|
||||
|
||||
async function main(): Promise<void> {
|
||||
await withMigrationRuntime(async () => {
|
||||
await runFrameworkReleaseMigrations(null);
|
||||
await runAppReleaseMigrations();
|
||||
});
|
||||
}
|
||||
|
||||
// Guard: closeDbExec() below tears down the shared database pool, so this
|
||||
// script must run only as its own process (`pnpm migrate:production`). The
|
||||
// framework's action auto-discovery would otherwise mount it as a live route
|
||||
// and running the teardown in-process breaks every other request with "Cannot
|
||||
// use a pool after calling end on the pool." Throw instead of tearing down a
|
||||
// pool this process does not own.
|
||||
function isProcessEntrypoint(): boolean {
|
||||
const entry = process.argv[1];
|
||||
if (!entry) return false;
|
||||
try {
|
||||
return (
|
||||
pathToFileURL(realpathSync(entry)).href ===
|
||||
pathToFileURL(realpathSync(fileURLToPath(import.meta.url))).href
|
||||
);
|
||||
} catch {
|
||||
// coercion-ok: an unresolvable entry path is not this script, so the guard below throws.
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
if (!isProcessEntrypoint()) {
|
||||
throw new Error(
|
||||
"scripts/migrate-production.ts must run as its own process " +
|
||||
"(pnpm migrate:production); it closes the shared database pool when it " +
|
||||
"finishes, so importing or invoking it in-process — e.g. via an " +
|
||||
"auto-discovered action route — would break every other request.",
|
||||
);
|
||||
}
|
||||
|
||||
try {
|
||||
await main();
|
||||
} finally {
|
||||
await closeDbExec();
|
||||
}
|
||||
@@ -1,123 +0,0 @@
|
||||
/**
|
||||
* ทำสำเนารูปที่อ้างจากภายนอก (http/https) ลงเครื่อง แล้วเปลี่ยน content.json ให้ชี้ไฟล์ในโปรเจกต์
|
||||
*
|
||||
* ทำไม: โฮสต์อย่าง Google Maps / googleusercontent / fbcdn / gstatic เป็น **hotlink-hostile**
|
||||
* (ลิงก์มีอายุ, จำกัด rate, ตอบ 200 แต่ 0 ไบต์) → หน้าเว็บขึ้นรูปแตกเป็นครั้งคราว
|
||||
* การเก็บสำเนาไว้ใน `public/images/cinemas/` ทำให้เว็บไม่พึ่งโฮสต์เหล่านั้นอีก
|
||||
*
|
||||
* ใช้: node scripts/mirror-photos.mjs [--dry]
|
||||
* --dry = ดาวน์โหลดและรายงานเฉย ๆ ไม่แก้ไฟล์
|
||||
*
|
||||
* ปลอดภัย: สำรอง content.json เป็น `content.json.bak-photos-<เวลา>` ก่อนเขียน
|
||||
*/
|
||||
import fs from "node:fs";
|
||||
import path from "node:path";
|
||||
|
||||
const CONTENT_PATH = path.join("data", "content", "content.json");
|
||||
const OUT_DIR = path.join("public", "images", "cinemas");
|
||||
const PUBLIC_PREFIX = "/images/cinemas";
|
||||
const MIN_BYTES = 2000;
|
||||
const DELAY_MS = 900;
|
||||
const RETRIES = 3;
|
||||
const DRY = process.argv.includes("--dry");
|
||||
|
||||
const UA =
|
||||
"Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/140.0 Safari/537.36";
|
||||
|
||||
const EXT_BY_TYPE = {
|
||||
"image/jpeg": "jpg",
|
||||
"image/jpg": "jpg",
|
||||
"image/png": "png",
|
||||
"image/webp": "webp",
|
||||
"image/gif": "gif",
|
||||
"image/avif": "avif",
|
||||
};
|
||||
|
||||
const sleep = (ms) => new Promise((resolve) => setTimeout(resolve, ms));
|
||||
|
||||
async function download(url) {
|
||||
for (let attempt = 1; attempt <= RETRIES; attempt++) {
|
||||
try {
|
||||
const res = await fetch(url, {
|
||||
redirect: "follow",
|
||||
headers: {
|
||||
"user-agent": UA,
|
||||
accept: "image/avif,image/webp,image/*,*/*;q=0.8",
|
||||
"accept-language": "th,en;q=0.9",
|
||||
},
|
||||
signal: AbortSignal.timeout(25000),
|
||||
});
|
||||
const type = (res.headers.get("content-type") ?? "").split(";")[0].trim();
|
||||
const buffer = Buffer.from(await res.arrayBuffer());
|
||||
if (res.ok && type.startsWith("image/") && buffer.byteLength >= MIN_BYTES) {
|
||||
return { ok: true, type, buffer, status: res.status };
|
||||
}
|
||||
if (attempt < RETRIES) await sleep(DELAY_MS * attempt);
|
||||
} catch (error) {
|
||||
if (attempt < RETRIES) await sleep(DELAY_MS * attempt);
|
||||
if (attempt === RETRIES) return { ok: false, reason: error.message };
|
||||
}
|
||||
}
|
||||
return { ok: false, reason: "ยังไม่ได้ไฟล์ที่ใช้ได้ (0 ไบต์ / 429 / ไม่ใช่รูป)" };
|
||||
}
|
||||
|
||||
function slugifyName(value, fallback) {
|
||||
const clean = String(value ?? "")
|
||||
.toLowerCase()
|
||||
.replace(/[^a-z0-9-]+/g, "-")
|
||||
.replace(/^-+|-+$/g, "");
|
||||
return clean === "" ? fallback : clean;
|
||||
}
|
||||
|
||||
const raw = fs.readFileSync(CONTENT_PATH, "utf8");
|
||||
const content = JSON.parse(raw);
|
||||
fs.mkdirSync(OUT_DIR, { recursive: true });
|
||||
|
||||
const report = { saved: [], failed: [], skipped: 0 };
|
||||
|
||||
for (const cinema of content.cinemas ?? []) {
|
||||
const photos = cinema.photos ?? [];
|
||||
for (let index = 0; index < photos.length; index++) {
|
||||
const url = photos[index];
|
||||
if (!/^https?:\/\//i.test(url)) {
|
||||
report.skipped++;
|
||||
continue;
|
||||
}
|
||||
|
||||
const result = await download(url);
|
||||
if (!result.ok) {
|
||||
report.failed.push({ slug: cinema.slug, index, reason: result.reason });
|
||||
console.log(`พัง ${cinema.slug} #${index} — ${result.reason}`);
|
||||
continue;
|
||||
}
|
||||
|
||||
const ext = EXT_BY_TYPE[result.type] ?? "jpg";
|
||||
const stem = slugifyName(cinema.slug, "cinema");
|
||||
const fileName = photos.length > 1 ? `${stem}-${index + 1}.${ext}` : `${stem}.${ext}`;
|
||||
const filePath = path.join(OUT_DIR, fileName);
|
||||
const publicPath = `${PUBLIC_PREFIX}/${fileName}`;
|
||||
|
||||
if (!DRY) {
|
||||
fs.writeFileSync(filePath, result.buffer);
|
||||
photos[index] = publicPath;
|
||||
}
|
||||
report.saved.push({ slug: cinema.slug, index, publicPath, bytes: result.buffer.byteLength });
|
||||
console.log(
|
||||
`OK ${cinema.slug} #${index} → ${publicPath} (${Math.round(result.buffer.byteLength / 1024)} KB)`,
|
||||
);
|
||||
await sleep(DELAY_MS);
|
||||
}
|
||||
}
|
||||
|
||||
if (!DRY) {
|
||||
const stamp = new Date().toISOString().replace(/[:.]/g, "-");
|
||||
fs.writeFileSync(`${CONTENT_PATH}.bak-photos-${stamp}`, raw);
|
||||
fs.writeFileSync(CONTENT_PATH, `${JSON.stringify(content, null, 2)}\n`);
|
||||
console.log(`\nสำรองข้อมูลเดิม: ${CONTENT_PATH}.bak-photos-${stamp}`);
|
||||
}
|
||||
|
||||
console.log(`\nสรุป: บันทึก ${report.saved.length} · พัง ${report.failed.length} · ข้าม ${report.skipped}`);
|
||||
if (report.failed.length > 0) {
|
||||
console.log("รูปที่ยังพัง (หน้าเว็บจะแสดงโลโก้แทน): ");
|
||||
for (const row of report.failed) console.log(` ${row.slug} #${row.index}`);
|
||||
}
|
||||
@@ -1,100 +0,0 @@
|
||||
/**
|
||||
* ตั้งค่า `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}`,
|
||||
);
|
||||
}
|
||||
@@ -1,146 +0,0 @@
|
||||
/**
|
||||
* static-export — ดึง HTML ทุกหน้าจาก production server มาเป็นไฟล์ static (มี index.html)
|
||||
*
|
||||
* ใช้: node scripts/static-export.mjs [baseUrl] [outDir]
|
||||
* baseUrl default http://127.0.0.1:8090
|
||||
* outDir default ./static-export
|
||||
*
|
||||
* หมายเหตุสำคัญ: ไฟล์ HTML ที่ได้ "hydrate ได้" (ฟิลเตอร์/ค้นหา/แสดงเพิ่ม ทำงาน)
|
||||
* แต่การคลิก link ไปหน้าอื่นจะเป็นการโหลดหน้าใหม่แบบเต็ม (ไม่มี `?_data=` บน static host)
|
||||
*/
|
||||
import fs from "node:fs";
|
||||
import path from "node:path";
|
||||
|
||||
const BASE = (process.argv[2] ?? "http://127.0.0.1:8090").replace(/\/$/, "");
|
||||
const OUT = process.argv[3] ?? "static-export";
|
||||
|
||||
const STATIC_ROUTES = [
|
||||
"/",
|
||||
"/about",
|
||||
"/for-cinemas",
|
||||
"/for-film-lovers",
|
||||
"/sitemap.xml",
|
||||
"/robots.txt",
|
||||
];
|
||||
|
||||
async function get(urlPath) {
|
||||
const res = await fetch(`${BASE}${urlPath}`, { redirect: "manual" });
|
||||
const body = await res.text();
|
||||
return {
|
||||
status: res.status,
|
||||
type: res.headers.get("content-type") ?? "",
|
||||
body,
|
||||
};
|
||||
}
|
||||
|
||||
function writeRoute(routePath, body) {
|
||||
const clean = routePath.split("?")[0].replace(/\/$/, "");
|
||||
const isFile = /\.[a-z0-9]+$/i.test(clean);
|
||||
const target = isFile
|
||||
? path.join(OUT, clean)
|
||||
: path.join(OUT, clean, "index.html");
|
||||
fs.mkdirSync(path.dirname(target), { recursive: true });
|
||||
fs.writeFileSync(target, body);
|
||||
return target;
|
||||
}
|
||||
|
||||
// 1) อ่าน slug จาก data/content/content.json (การ์ดในหน้าแรก render ฝั่ง client จึงหา link ใน HTML ไม่เจอ)
|
||||
const contentPath = path.join("data", "content", "content.json");
|
||||
const home = await get("/");
|
||||
if (home.status !== 200) {
|
||||
console.error(`หน้าแรกตอบ ${home.status} — server รันอยู่ไหม? (${BASE})`);
|
||||
process.exit(1);
|
||||
}
|
||||
fs.rmSync(OUT, { recursive: true, force: true });
|
||||
fs.mkdirSync(OUT, { recursive: true });
|
||||
|
||||
let slugs = [];
|
||||
if (fs.existsSync(contentPath)) {
|
||||
const content = JSON.parse(fs.readFileSync(contentPath, "utf8"));
|
||||
slugs = (content.cinemas ?? [])
|
||||
.filter((cinema) => cinema.hidden !== true && cinema.slug)
|
||||
.map((cinema) => cinema.slug);
|
||||
} else {
|
||||
slugs = [...home.body.matchAll(/\/cinema\/([a-z0-9-]+)/g)].map((m) => m[1]);
|
||||
}
|
||||
const uniqueSlugs = [...new Set(slugs)];
|
||||
|
||||
const routes = [
|
||||
...STATIC_ROUTES,
|
||||
...uniqueSlugs.map((slug) => `/cinema/${slug}`),
|
||||
];
|
||||
|
||||
let ok = 0;
|
||||
const failed = [];
|
||||
for (const route of routes) {
|
||||
const res = await get(route);
|
||||
if (res.status !== 200) {
|
||||
failed.push(`${route} (${res.status})`);
|
||||
continue;
|
||||
}
|
||||
writeRoute(route, res.body);
|
||||
ok++;
|
||||
}
|
||||
|
||||
// 2.5) static host ไม่มี endpoint `?_data=` ของ React Router
|
||||
// → ดักคลิก link ภายในให้เป็นการโหลดหน้าเต็ม (ทุกหน้ามี HTML ของตัวเองอยู่แล้ว)
|
||||
const STATIC_NAV_PATCH = `<script data-static-export-nav>(()=>{
|
||||
document.addEventListener("click",(event)=>{
|
||||
if(event.defaultPrevented||event.button!==0||event.metaKey||event.ctrlKey||event.shiftKey||event.altKey)return;
|
||||
const anchor=event.target instanceof Element?event.target.closest("a[href]"):null;
|
||||
if(!anchor||!anchor.getAttribute("href").startsWith("/")||anchor.target&&anchor.target!=="_self"||anchor.hasAttribute("download"))return;
|
||||
event.preventDefault();
|
||||
event.stopImmediatePropagation();
|
||||
location.assign(anchor.getAttribute("href"));
|
||||
},true);
|
||||
})();</script>`;
|
||||
|
||||
function injectNavPatch(file) {
|
||||
const html = fs.readFileSync(file, "utf8");
|
||||
if (html.includes("data-static-export-nav")) return;
|
||||
const patched = html.includes("</body>")
|
||||
? html.replace("</body>", `${STATIC_NAV_PATCH}</body>`)
|
||||
: html + STATIC_NAV_PATCH;
|
||||
fs.writeFileSync(file, patched);
|
||||
}
|
||||
|
||||
// 2) คัดลอก asset ที่ build ไว้แล้ว (ไม่ต้องโหลดซ้ำ)
|
||||
const publicDir = path.join(".output", "public");
|
||||
if (fs.existsSync(publicDir)) {
|
||||
fs.cpSync(publicDir, OUT, { recursive: true });
|
||||
}
|
||||
|
||||
// 3) ลิงก์ย่อ /c/<slug> ทำเป็นหน้า redirect แบบ static
|
||||
let redirects = 0;
|
||||
for (const slug of uniqueSlugs) {
|
||||
const dir = path.join(OUT, "c", slug);
|
||||
fs.mkdirSync(dir, { recursive: true });
|
||||
fs.writeFileSync(
|
||||
path.join(dir, "index.html"),
|
||||
`<!doctype html><meta charset="utf-8"><title>กำลังพาไป…</title>
|
||||
<link rel="canonical" href="/cinema/${slug}">
|
||||
<meta http-equiv="refresh" content="0; url=/cinema/${slug}">
|
||||
<script>location.replace("/cinema/${slug}")</script>
|
||||
<a href="/cinema/${slug}">ไปที่หน้าโรงหนัง</a>
|
||||
`,
|
||||
);
|
||||
redirects++;
|
||||
}
|
||||
|
||||
// 4) 404 fallback (static host ส่วนใหญ่ใช้ 404.html)
|
||||
fs.writeFileSync(
|
||||
path.join(OUT, "404.html"),
|
||||
fs.readFileSync(path.join(OUT, "index.html"), "utf8"),
|
||||
);
|
||||
|
||||
for (const file of fs.readdirSync(OUT, { recursive: true })) {
|
||||
const full = path.join(OUT, String(file));
|
||||
if (full.endsWith(".html")) injectNavPatch(full);
|
||||
}
|
||||
|
||||
const files = fs.readdirSync(OUT, { recursive: true }).length;
|
||||
console.log(
|
||||
`export เสร็จ: ${ok}/${routes.length} หน้า · ${redirects} redirect · ${files} entries`,
|
||||
);
|
||||
console.log(`outDir: ${path.resolve(OUT)}`);
|
||||
if (failed.length) console.log(`ล้มเหลว: ${failed.join(", ")}`);
|
||||
Reference in new issue
Block a user