- {(cinema.contact_heading?.trim() || messages.detail.contactTitle)}
+ {cinema.contact_heading?.trim() || messages.detail.contactTitle}
{cinema.contacts.length === 0 ? (
-
{messages.detail.contactsFallback}
+
+ {messages.detail.contactsFallback}
+
) : (
cinema.contacts.map((channel) => (
diff --git a/app/lib/contact-link.spec.ts b/app/lib/contact-link.spec.ts
new file mode 100644
index 0000000..d5892c2
--- /dev/null
+++ b/app/lib/contact-link.spec.ts
@@ -0,0 +1,120 @@
+/**
+ * ทดสอบการจับคู่ลิงก์ของช่องทางติดต่อ — เคสที่พังจริงบนหน้าเว็บ
+ * (เบอร์กดไม่ได้, facebook ติด fbclid, `www.…` ไม่มี scheme, LINE ID)
+ */
+import { describe, expect, it } from "vitest";
+
+import {
+ contactHref,
+ looksLikePhone,
+ normalizePhone,
+ resolveContact,
+} from "@/lib/contact-link";
+
+describe("normalizePhone", () => {
+ it("แปลงเบอร์ไทย 0 นำหน้าเป็น +66 และตัดขีด/ช่องว่าง", () => {
+ expect(normalizePhone("098-869-0997")).toBe("+66988690997");
+ expect(normalizePhone("098 869 0997")).toBe("+66988690997");
+ expect(normalizePhone("(02) 123-4567")).toBe("+6621234567");
+ });
+
+ it("รองรับที่ขึ้นต้น 66 หรือ +66 อยู่แล้ว", () => {
+ expect(normalizePhone("66812345678")).toBe("+66812345678");
+ expect(normalizePhone("+66 81 234 5678")).toBe("+66812345678");
+ });
+
+ it("ไม่ใช่เบอร์ → null", () => {
+ expect(normalizePhone("12")).toBeNull();
+ expect(normalizePhone("housesamyan")).toBeNull();
+ });
+});
+
+describe("looksLikePhone", () => {
+ it("แยกเบอร์ออกจากข้อความ", () => {
+ expect(looksLikePhone("098-869-0997")).toBe(true);
+ expect(looksLikePhone("www.housesamyan.com")).toBe(false);
+ expect(looksLikePhone("House Samyan")).toBe(false);
+ });
+});
+
+describe("resolveContact", () => {
+ it("Call + เบอร์ → tel: (กดโทรได้จริง)", () => {
+ const resolved = resolveContact({
+ label: "Call",
+ value: "098-869-0997",
+ href: null,
+ });
+ expect(resolved.href).toBe("tel:+66988690997");
+ expect(resolved.kind).toBe("tel");
+ expect(resolved.external).toBe(false);
+ });
+
+ it("เบอร์ที่ href ผิดรูปแบบ → แก้ให้ถูก", () => {
+ expect(
+ contactHref({ label: "Call", value: "098-869-0997", href: "0988690997" }),
+ ).toBe("tel:+66988690997");
+ expect(
+ contactHref({
+ label: "Call",
+ value: "098-869-0997",
+ href: "tel:0988690997",
+ }),
+ ).toBe("tel:+66988690997");
+ });
+
+ it("Facebook → https + ตัด fbclid/_rdc + เปลี่ยน web. เป็น www.", () => {
+ const resolved = resolveContact({
+ label: "Facebook",
+ value: "Century Sukhumvit",
+ href: "https://web.facebook.com/CenturySukhumvit/?_rdc=1&_rdr",
+ });
+ expect(resolved.kind).toBe("web");
+ expect(resolved.external).toBe(true);
+ expect(resolved.href).toBe("https://www.facebook.com/CenturySukhumvit/");
+ });
+
+ it("เว็บที่ไม่มี scheme → เติม https", () => {
+ expect(
+ contactHref({
+ label: "Website",
+ value: "www.housesamyan.com",
+ href: null,
+ }),
+ ).toBe("https://www.housesamyan.com/");
+ });
+
+ it("Instagram ที่ติด fbclid → ตัดออก", () => {
+ const href = contactHref({
+ label: "Instagram",
+ value: "centurysukhumvit",
+ href: "https://www.instagram.com/centurysukhumvit?fbclid=abc123",
+ });
+ expect(href).toBe("https://www.instagram.com/centurysukhumvit");
+ });
+
+ it("อีเมล → mailto:", () => {
+ expect(
+ resolveContact({ label: "อีเมล", value: "hi@example.com" }).href,
+ ).toBe("mailto:hi@example.com");
+ });
+
+ it("LINE ID (@id) → line.me", () => {
+ expect(resolveContact({ label: "Line", value: "@alterflix" }).href).toBe(
+ "https://line.me/R/ti/p/~alterflix",
+ );
+ });
+
+ it("ค่าไม่มีข้อมูล/ว่าง → null (ไม่สร้างลิงก์หลอก)", () => {
+ expect(resolveContact({ label: "Call", value: "-" }).href).toBeNull();
+ expect(resolveContact({ label: "Call", value: "" }).href).toBeNull();
+ expect(
+ resolveContact({ label: "Website", value: "ไม่มีข้อมูล" }).href,
+ ).toBeNull();
+ });
+
+ it("ค่าแปลก ๆ ที่ไม่ใช่ทั้งเบอร์และโดเมน → null", () => {
+ expect(
+ resolveContact({ label: "Call", value: "โทรสอบถาม" }).href,
+ ).toBeNull();
+ });
+});
diff --git a/app/lib/contact-link.ts b/app/lib/contact-link.ts
new file mode 100644
index 0000000..a6b1a9f
--- /dev/null
+++ b/app/lib/contact-link.ts
@@ -0,0 +1,194 @@
+/**
+ * แปลง "ช่องทางติดต่อ" ของโรงหนังให้เป็นลิงก์ที่กดใช้ได้จริง
+ *
+ * ปัญหาเดิม: ข้อมูลเก็บ `href` ดิบจากหลังบ้าน (บางทีว่าง, บางทีเป็น `www.…` ไม่มี scheme,
+ * เบอร์โทรไม่ขึ้นต้นด้วย `tel:`) → หน้าเว็บได้ `
` ที่กดแล้วไม่เกิดอะไร
+ *
+ * กติกาที่นี่ (ใช้ทั้งตอนบันทึกในหลังบ้านและตอนแสดงผล):
+ * - เบอร์โทร → `tel:+66…` (แปลง 0 นำหน้าเป็น +66, ตัดขีด/วงเล็บ/ช่องว่าง)
+ * - อีเมล → `mailto:`
+ * - LINE ID (`@abc`) → `https://line.me/R/ti/p/~abc`
+ * - เว็บ/โซเชียล → บังคับ `https://`, แปลง `web.facebook.com` → `www.facebook.com`
+ * และตัดพารามิเตอร์ติดตาม (fbclid, _rdc, utm_*, igshid)
+ */
+
+export type ContactKind = "tel" | "mailto" | "web";
+
+export type ResolvedContact = {
+ /** href พร้อมใช้ — null = ไม่มีข้อมูลที่ใช้เป็นลิงก์ได้ */
+ href: string | null;
+ kind: ContactKind | null;
+ /** true = ลิงก์ออกเว็บนอก (เปิดแท็บใหม่) */
+ external: boolean;
+};
+
+const EMPTY_VALUES = new Set([
+ "-",
+ "–",
+ "—",
+ "n/a",
+ "na",
+ "null",
+ "undefined",
+ "ไม่มี",
+ "ไม่มีข้อมูล",
+]);
+
+const TRACKING_PARAMS = [
+ "fbclid",
+ "gclid",
+ "_rdc",
+ "_rdr",
+ "igshid",
+ "ref",
+ "ref_src",
+ "mibextid",
+];
+
+function isTrackingParam(name: string): boolean {
+ const key = name.toLowerCase();
+ return TRACKING_PARAMS.includes(key) || key.startsWith("utm_");
+}
+
+/** แปลงเบอร์เป็นรูปแบบที่กดโทรได้: `+66812345678` (คืน null ถ้าไม่ใช่เบอร์ที่ใช้ได้) */
+export function normalizePhone(raw: string): string | null {
+ const trimmed = raw.trim();
+ if (trimmed === "") return null;
+
+ const hasPlus = trimmed.startsWith("+");
+ const digits = trimmed.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}`;
+}
+
+/** ดูว่าข้อความนี้ "หน้าตาเป็นเบอร์โทร" ไหม (ใช้ตัดสินก่อนถือว่าเป็นเว็บ) */
+export function looksLikePhone(raw: string): boolean {
+ const trimmed = raw.trim();
+ if (trimmed === "") return false;
+ if (/[a-z@]/i.test(trimmed)) return false;
+ const digits = trimmed.replace(/\D/g, "");
+ return digits.length >= 8 && digits.length <= 15;
+}
+
+function stripTracking(url: URL): URL {
+ const keep = new URLSearchParams();
+ url.searchParams.forEach((value, key) => {
+ if (!isTrackingParam(key)) keep.append(key, value);
+ });
+ const query = keep.toString();
+ url.search = query === "" ? "" : `?${query}`;
+ return url;
+}
+
+function normalizeWebUrl(raw: string): string | null {
+ let candidate = raw.trim();
+ if (candidate === "") return null;
+
+ // LINE ID แบบ @id
+ if (/^@[\w.\-_]+$/.test(candidate)) {
+ return `https://line.me/R/ti/p/~${candidate.slice(1)}`;
+ }
+ if (/^line:/i.test(candidate)) {
+ candidate = candidate.replace(/^line:\/\//i, "https://line.me/R/ti/p/~");
+ }
+
+ if (!/^[a-z][a-z0-9+.-]*:\/\//i.test(candidate)) {
+ // `www.x.com` / `x.com/path` / `x.com` → https
+ if (!/^[\w-]+(\.[\w-]+)+/.test(candidate)) return null;
+ candidate = `https://${candidate}`;
+ }
+
+ try {
+ const url = new URL(candidate);
+ if (url.protocol === "http:") url.protocol = "https:";
+ if (url.hostname === "web.facebook.com") url.hostname = "www.facebook.com";
+ url.hostname = url.hostname.toLowerCase();
+ return stripTracking(url).toString();
+ } catch {
+ return null;
+ }
+}
+
+function looksLikeEmail(raw: string): boolean {
+ return /^[^\s@]+@[^\s@]+\.[^\s@]{2,}$/.test(raw.trim());
+}
+
+/**
+ * แปลงช่องทางติดต่อหนึ่งรายการ → ลิงก์ที่ใช้ได้
+ * ลำดับความเชื่อ: `href` ที่ผู้ใช้กรอก → ลักษณะของ `value` → label
+ */
+export function resolveContact(channel: {
+ label?: string;
+ value?: string;
+ href?: string | null;
+}): ResolvedContact {
+ const value = (channel.value ?? "").trim();
+ const href = (channel.href ?? "").trim();
+ const label = (channel.label ?? "").trim().toLowerCase();
+
+ const candidates = [href, value].filter(
+ (item) => item !== "" && !EMPTY_VALUES.has(item.toLowerCase()),
+ );
+ if (candidates.length === 0)
+ return { href: null, kind: null, external: false };
+
+ for (const candidate of candidates) {
+ const lower = candidate.toLowerCase();
+
+ // 1) เบอร์โทรที่ระบุชัด
+ if (lower.startsWith("tel:")) {
+ const phone = normalizePhone(candidate.slice(4));
+ if (phone) return { href: `tel:${phone}`, kind: "tel", external: false };
+ }
+
+ // 2) อีเมล
+ if (lower.startsWith("mailto:")) {
+ const address = candidate.slice(7).trim();
+ if (looksLikeEmail(address)) {
+ return { href: `mailto:${address}`, kind: "mailto", external: false };
+ }
+ }
+ if (looksLikeEmail(candidate)) {
+ return { href: `mailto:${candidate}`, kind: "mailto", external: false };
+ }
+
+ // 3) ลิงก์เว็บ/โซเชียล (ตัดสินจาก scheme หรือรูปทรงโดเมน)
+ if (
+ /^https?:\/\//i.test(candidate) ||
+ /^line:/i.test(candidate) ||
+ /^@[\w.\-_]+$/.test(candidate) ||
+ /^[\w-]+(\.[\w-]+)+(\/|$)/.test(candidate)
+ ) {
+ const url = normalizeWebUrl(candidate);
+ if (url) return { href: url, kind: "web", external: true };
+ }
+
+ // 4) เบอร์โทรที่ไม่ได้ใส่ tel:
+ if (
+ looksLikePhone(candidate) &&
+ /call|โทร|phone|tel|เบอร์|มือถือ/.test(label + " " + value)
+ ) {
+ const phone = normalizePhone(candidate);
+ if (phone) return { href: `tel:${phone}`, kind: "tel", external: false };
+ }
+ if (looksLikePhone(candidate)) {
+ const phone = normalizePhone(candidate);
+ if (phone) return { href: `tel:${phone}`, kind: "tel", external: false };
+ }
+ }
+
+ return { href: null, kind: null, external: false };
+}
+
+/** ค่าที่ควรบันทึกกลับลง `href` (ใช้ตอน sanitize/หลังบ้าน) */
+export function contactHref(channel: {
+ label?: string;
+ value?: string;
+ href?: string | null;
+}): string | null {
+ return resolveContact(channel).href;
+}
diff --git a/app/lib/content.server.ts b/app/lib/content.server.ts
index cf5c7a5..5765f8d 100644
--- a/app/lib/content.server.ts
+++ b/app/lib/content.server.ts
@@ -10,6 +10,7 @@ import path from "node:path";
import { sanitizeArticleBlocks } from "@/lib/article";
import type { Cinema } from "@/lib/cinemas";
+import { contactHref } from "@/lib/contact-link";
import {
seedAbout,
seedContent,
@@ -126,10 +127,14 @@ export function sanitizeCinemas(input: unknown): Cinema[] {
contacts: Array.isArray(raw.contacts)
? raw.contacts.map((contact) => {
const entry = (contact ?? {}) as Record;
+ const label = asString(entry.label);
+ const value = asString(entry.value);
+ const href = typeof entry.href === "string" ? entry.href : null;
+ // บังคับ href ให้เป็นลิงก์ที่กดใช้ได้จริง (tel:/mailto:/https:) ทุกครั้งที่บันทึก
return {
- label: asString(entry.label),
- value: asString(entry.value),
- href: typeof entry.href === "string" ? entry.href : null,
+ label,
+ value,
+ href: contactHref({ label, value, href }),
};
})
: [],
diff --git a/docs/admin-guide.md b/docs/admin-guide.md
index d2261d6..cf30977 100644
--- a/docs/admin-guide.md
+++ b/docs/admin-guide.md
@@ -97,7 +97,21 @@
| หัวข้อการ์ด | "หัวข้อ 'สอบถามข้อมูลและจองตั๋ว' (เฉพาะโรงนี้)" — ว่าง = ใช้ค่ากลาง |
| Website / Facebook / Call | แถว **ช่องทางติดต่อ** → ป้ายชื่อ / ข้อความที่แสดง / ลิงก์ |
| เพิ่มช่องทางใหม่ | **+ เพิ่มช่องทางติดต่อ** (ป้ายชื่อมีตัวเลือกแนะนำ) |
-| เบอร์โทรให้กดโทรได้ | ลิงก์ใส่ `tel:+668…` |
+| เบอร์โทรให้กดโทรได้ | ไม่ต้องพิมพ์ `tel:` เอง — ใส่เบอร์ในช่อง **ข้อความที่แสดง** ระบบเติมลิงก์ให้ |
+
+**ระบบสร้างลิงก์ให้อัตโนมัติ** (เห็นข้อความ `✓ กดโทรได้ → tel:+66…` ใต้แถวนั้น)
+
+| กรอก | ได้ลิงก์ |
+|---|---|
+| `098-869-0997` หรือ `0 9886 90997` | `tel:+66988690997` (แปลง 0 → +66 ให้) |
+| `hi@example.com` | `mailto:hi@example.com` |
+| `www.housesamyan.com` / `lidoconnect.com` | `https://…` (เปิดแท็บใหม่) |
+| `https://web.facebook.com/x/?_rdc=1&_rdr` | `https://www.facebook.com/x/` (ตัด `fbclid`, `_rdc`, `utm_*` ให้) |
+| `@lineid` | `https://line.me/R/ti/p/~lineid` |
+
+- ถ้าขึ้น **⚠ ค่านี้ยังใช้เป็นลิงก์ไม่ได้** = ข้อความนั้นไม่ใช่เบอร์/อีเมล/โดเมน → แก้ค่าให้เป็นอย่างใดอย่างหนึ่ง
+- แถวที่ไม่มีลิงก์จะแสดงเป็น **ข้อความธรรมดา** (ไม่หลอกให้กด)
+- ตรวจ/ซ่อมทั้งไฟล์พร้อมกัน: `node scripts/audit-contacts.mjs` (ดู) · `node scripts/audit-contacts.mjs --fix` (เขียนกลับ + สำรองไฟล์)
ค่ากลางของหัวข้อ (มีผลทุกโรงที่ไม่ได้กรอก) → แท็บ **คำศัพท์หลายภาษา** → `detail.contactTitle`
diff --git a/docs/api.md b/docs/api.md
index 7f05869..aa5817f 100644
--- a/docs/api.md
+++ b/docs/api.md
@@ -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 |
+| PUT | `/api/admin/content` | `{ cinemas?, site?, about?, forCinemas?, forFilmLovers? }` | บันทึกเฉพาะส่วนที่ส่งมา — ผ่าน `sanitizeCinemas` / `sanitizeSite` / `sanitizeAbout` / `sanitizeForCinemas` / `sanitizeForFilmLovers` แล้วเขียนไฟล์แบบ atomic · **`contacts[].href` ถูกคำนวณใหม่ให้กดใช้ได้จริง (tel:/mailto:/https:) ทุกครั้ง** |
| POST | `/api/admin/cinemas/import` | `{ cinemas: Cinema[] }` หรือรายการเดียว | นำเข้าโรงหนังโดยใช้ slug เป็นกุญแจ (มีอยู่ = ทับ) |
| GET | `/api/admin/analytics` | `?days=1\|7\|30\|90` | สรุปสถิติ (`summarize()`) — คำค้นยอดนิยม, คำค้นไม่พบผล, CTR, โรงที่ถูกเปิด/คลิก |
diff --git a/scripts/audit-contacts.mjs b/scripts/audit-contacts.mjs
new file mode 100644
index 0000000..9df3aad
--- /dev/null
+++ b/scripts/audit-contacts.mjs
@@ -0,0 +1,180 @@
+/**
+ * ตรวจ/ซ่อม `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 ที่ปรับแล้ว");
+}