fix(contacts): ช่องทางติดต่อกดใช้ได้จริง (tel:/mailto:/โซเชียล) + ซ่อมข้อมูลเดิม

ปัญหา: href ในข้อมูลดิบไม่สม่ำเสมอ (ว่าง / www. ไม่มี scheme / เบอร์ไม่มี tel: /
facebook ติด fbclid) ทำให้กดแล้วไม่เกิดอะไร และปุ่มโทรใช้ไม่ได้

- app/lib/contact-link.ts: resolveContact() จับคู่ลิงก์ตามชนิด
  · เบอร์ → tel:+66… (แปลง 0 นำหน้า, ตัดขีด/ช่องว่าง/วงเล็บ)
  · อีเมล → mailto: · LINE @id → line.me · เว็บ → https + ตัด fbclid/_rdc/utm_*
- ContactPanel: ไอคอนตามชนิด (phone/mail/fb/ig/line/ticket/globe),
  tel/mailto เปิดแท็บเดิม, เว็บเปิดแท็บใหม่; แถวที่ไม่มีลิงก์แสดงเป็นข้อความ (ไม่หลอกให้กด)
- sanitizeCinemas: คำนวณ href ใหม่ทุกครั้งที่บันทึก → ข้อมูลเก่าไม่กลับมาเพี้ยน
- ContactsEditor: auto-format ตอนออกจากช่อง + พรีวิว "✓ กดโทรได้ → tel:+66…"
- scripts/audit-contacts.mjs [--fix]: ตรวจ/ซ่อมทั้งไฟล์ (แก้ไป 13 จุด, สำรองข้อมูลแล้ว)
- contact-link.spec.ts 13 tests · docs: admin-guide/api/DESIGN
This commit is contained in:
Bkk1234 committed 2026-11-15 23:56:46 +07:00
1 parent 2c5918a614
commit 42572020d8
9 files changed
+656 -26

No files matched your search

+8 -3
View File
@@ -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<string, unknown>;
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 }),
};
})
: [],