feat: บทความ 2 หน้า + แชร์/ลิงก์ย่อ + PWA + แอนิเมชัน + SEO/AI + เอกสาร
- บทความจากหลังบ้าน: /for-film-lovers, /for-cinemas (ArticlePage + ArticleEditor แบบบล็อกย่อหน้า/รูป) - แชร์: ปุ่มบนการ์ดและท้ายหน้ารายละเอียด · ลิงก์ย่อ /c/<slug> (302) · ธีมแก้วตาม DESIGN.md - PWA: manifest/sw/offline + ถอดการล็อกซูม (WCAG 1.4.4) + touch target ≥44px - แอนิเมชัน reveal: IntersectionObserver + gate ด้วย html.fx-motion · เคารพ prefers-reduced-motion - ค้นหา: normalize/ตัดวรรณยุกต์ + AND หลายคำ + จัดอันดับ · รองรับ /?q= จาก SearchAction - SEO: pageMeta (canonical/OG/Twitter) + JSON-LD (WebSite/Organization/BreadcrumbList/MovieTheater/Article) - ไม่ฝังโดเมนในโค้ด: origin มาจาก request (x-forwarded-host/proto) ทั้ง canonical, sitemap, robots, ลิงก์แชร์ - กัน AI: robots.txt (Nitro route, บล็อก AI 21 ตัว) + ai.txt + OG image 1200x630 - เอกสาร: README สรุปโปรเจกต์, DESIGN.md (motion/PWA/SEO/ข้อมูล), architecture.html, admin-guide - tests: 135 ผ่าน (16 ไฟล์)
This commit is contained in:
1 parent
1e84023a44
commit
319c271d23
72 files changed
+4731
-765
No files matched your search
@@ -1,9 +1,24 @@
|
||||
/**
|
||||
* อ่าน/เขียนเนื้อหาที่แก้ได้จากหลังบ้าน (`data/content/content.json`)
|
||||
*
|
||||
* หมายเหตุเรื่องแคช: `cache` ด้านล่างเก็บผล sanitize ไว้ต่อ process (คีย์ = ความยาวไฟล์)
|
||||
* ดังนั้นถ้าแก้ "ข้อความตั้งต้น" ใน `messages.ts` ต้องรีสตาร์ต/ให้ dev server โหลดโมดูลใหม่
|
||||
* ไฟล์นี้จึงจะคำนวณ seed ใหม่ — การแก้ผ่านหน้า admin ไม่ต้องรีสตาร์ต (ไฟล์เปลี่ยนเอง)
|
||||
*/
|
||||
import { mkdir, readFile, rename, writeFile } from "node:fs/promises";
|
||||
import path from "node:path";
|
||||
|
||||
import { seedAbout, seedContent } from "@/lib/content-seed";
|
||||
import { sanitizeArticleBlocks } from "@/lib/article";
|
||||
import type { Cinema } from "@/lib/cinemas";
|
||||
import {
|
||||
seedAbout,
|
||||
seedContent,
|
||||
seedForCinemas,
|
||||
seedForFilmLovers,
|
||||
} from "@/lib/content-seed";
|
||||
import type {
|
||||
AboutContent,
|
||||
ArticleContent,
|
||||
ContentStore,
|
||||
FooterItem,
|
||||
LocaleEntry,
|
||||
@@ -12,7 +27,6 @@ import type {
|
||||
} from "@/lib/content-types";
|
||||
import type { Locale } from "@/lib/i18n/messages";
|
||||
import { FACILITY_KEYS } from "@/lib/i18n/messages";
|
||||
import type { Cinema } from "@/lib/cinemas";
|
||||
|
||||
const CONTENT_DIR = path.join(process.cwd(), "data", "content");
|
||||
const CONTENT_FILE = path.join(CONTENT_DIR, "content.json");
|
||||
@@ -48,9 +62,7 @@ function sanitizeFacilities(value: unknown): Cinema["facilities"] {
|
||||
}
|
||||
|
||||
/** ตรวจข้อความเฉพาะโรงของแต่ละหัวข้อ — เก็บเฉพาะคีย์/ฟิลด์ที่รู้จัก */
|
||||
function sanitizeFacilityDetails(
|
||||
value: unknown,
|
||||
): Cinema["facility_details"] {
|
||||
function sanitizeFacilityDetails(value: unknown): Cinema["facility_details"] {
|
||||
if (!value || typeof value !== "object") return {};
|
||||
const raw = value as Record<string, unknown>;
|
||||
const result: NonNullable<Cinema["facility_details"]> = {};
|
||||
@@ -201,7 +213,10 @@ export function sanitizeAbout(input: unknown): Record<Locale, AboutContent> {
|
||||
const body = asString(item.body).trim();
|
||||
return heading || body ? { heading, body } : null;
|
||||
})
|
||||
.filter((section): section is { heading: string; body: string } => section !== null)
|
||||
.filter(
|
||||
(section): section is { heading: string; body: string } =>
|
||||
section !== null,
|
||||
)
|
||||
: fallback.sections;
|
||||
|
||||
return {
|
||||
@@ -220,6 +235,55 @@ export function sanitizeAbout(input: unknown): Record<Locale, AboutContent> {
|
||||
};
|
||||
}
|
||||
|
||||
/**
|
||||
* ตรวจเนื้อหาหน้าบทความ (ใช้ทั้ง "สำหรับคนทำโรงหนัง" และ "สำหรับคนรักหนัง")
|
||||
*
|
||||
* ทำไมต้องมี seed: ถ้า editor ส่งค่าที่ใช้ไม่ได้มา (บล็อกว่างทั้งหมด, ไม่ได้ส่งภาษาใดภาษา
|
||||
* มาบ้าง) หน้าเว็บจะกลายเป็นหน้าว่าง — จึงต้องเติมข้อความตั้งต้นของภาษานั้นให้เสมอ
|
||||
* บล็อกที่ผิดรูปแบบ/ว่างจะถูกตัดทิ้งด้วย sanitizeArticleBlocks
|
||||
*/
|
||||
function sanitizeArticlePage(
|
||||
input: unknown,
|
||||
seed: Record<Locale, ArticleContent>,
|
||||
): Record<Locale, ArticleContent> {
|
||||
if (!input || typeof input !== "object") return seed;
|
||||
const raw = input as Record<string, unknown>;
|
||||
|
||||
function one(value: unknown, fallback: ArticleContent): ArticleContent {
|
||||
if (!value || typeof value !== "object") return fallback;
|
||||
const entry = value as Record<string, unknown>;
|
||||
const blocks = sanitizeArticleBlocks(entry.blocks);
|
||||
|
||||
return {
|
||||
title: asString(entry.title, "").trim() || fallback.title,
|
||||
lead: asString(entry.lead).trim() || fallback.lead,
|
||||
blocks: blocks.length > 0 ? blocks : fallback.blocks,
|
||||
contactHeading:
|
||||
asString(entry.contactHeading).trim() || fallback.contactHeading,
|
||||
contactNote: asString(entry.contactNote).trim() || fallback.contactNote,
|
||||
};
|
||||
}
|
||||
|
||||
return {
|
||||
th: one(raw.th, seed.th),
|
||||
en: one(raw.en, seed.en),
|
||||
};
|
||||
}
|
||||
|
||||
/** เนื้อหาหน้า "สำหรับคนทำโรงหนัง" */
|
||||
export function sanitizeForCinemas(
|
||||
input: unknown,
|
||||
): Record<Locale, ArticleContent> {
|
||||
return sanitizeArticlePage(input, seedForCinemas());
|
||||
}
|
||||
|
||||
/** เนื้อหาหน้า "สำหรับคนรักหนัง" */
|
||||
export function sanitizeForFilmLovers(
|
||||
input: unknown,
|
||||
): Record<Locale, ArticleContent> {
|
||||
return sanitizeArticlePage(input, seedForFilmLovers());
|
||||
}
|
||||
|
||||
/** อ่านเนื้อหาทั้งหมด — สร้างไฟล์เริ่มต้นให้อัตโนมัติเมื่อยังไม่มี */
|
||||
export async function readContent(): Promise<ContentStore> {
|
||||
let raw: string;
|
||||
@@ -251,6 +315,8 @@ function sanitizeStore(input: unknown): ContentStore {
|
||||
cinemas: sanitizeCinemas(raw.cinemas ?? []),
|
||||
site: sanitizeSite(raw.site ?? {}),
|
||||
about: sanitizeAbout(raw.about ?? {}),
|
||||
forCinemas: sanitizeForCinemas(raw.forCinemas ?? {}),
|
||||
forFilmLovers: sanitizeForFilmLovers(raw.forFilmLovers ?? {}),
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
Reference in new issue
Block a user