- บทความจากหลังบ้าน: /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 ไฟล์)
160 lines
4.6 KiB
TypeScript
160 lines
4.6 KiB
TypeScript
import { CINEMAS } from "@/lib/cinemas";
|
|
import type {
|
|
AboutContent,
|
|
ArticleContent,
|
|
ContentStore,
|
|
FooterItem,
|
|
LocaleEntry,
|
|
TermEntry,
|
|
} from "@/lib/content-types";
|
|
import type { Locale } from "@/lib/i18n/messages";
|
|
import { MESSAGES } from "@/lib/i18n/messages";
|
|
import type { Messages } from "@/lib/i18n/messages";
|
|
|
|
export const DEFAULT_LOCALES: LocaleEntry[] = [
|
|
{ code: "th", label: "ไทย" },
|
|
{ code: "en", label: "English" },
|
|
];
|
|
|
|
function flatten(
|
|
value: unknown,
|
|
prefix: string,
|
|
out: Record<string, string>,
|
|
): void {
|
|
if (typeof value === "string") {
|
|
out[prefix] = value;
|
|
return;
|
|
}
|
|
if (value && typeof value === "object") {
|
|
for (const [key, child] of Object.entries(
|
|
value as Record<string, unknown>,
|
|
)) {
|
|
flatten(child, prefix ? `${prefix}.${key}` : key, out);
|
|
}
|
|
}
|
|
}
|
|
|
|
/** รวมข้อความทุกภาษาเป็นรายการคำศัพท์ (ใช้เป็นค่าเริ่มต้นของหน้า admin) */
|
|
export function seedTerms(): TermEntry[] {
|
|
const perLocale: Record<string, Record<string, string>> = {};
|
|
for (const locale of Object.keys(MESSAGES) as Locale[]) {
|
|
const flat: Record<string, string> = {};
|
|
flatten(MESSAGES[locale], "", flat);
|
|
perLocale[locale] = flat;
|
|
}
|
|
const keys = Object.keys(perLocale.th ?? perLocale.en ?? {});
|
|
return keys.map((key) => ({
|
|
key,
|
|
values: Object.fromEntries(
|
|
Object.entries(perLocale).map(([locale, flat]) => [
|
|
locale,
|
|
flat[key] ?? "",
|
|
]),
|
|
),
|
|
}));
|
|
}
|
|
|
|
export const DEFAULT_FOOTER: FooterItem[] = [
|
|
{
|
|
id: "facebook",
|
|
icon_name: "IconBrandFacebook",
|
|
label: "Facebook",
|
|
href: "https://www.facebook.com/",
|
|
},
|
|
{
|
|
id: "instagram",
|
|
icon_name: "IconBrandInstagram",
|
|
label: "Instagram",
|
|
href: "https://www.instagram.com/",
|
|
},
|
|
{
|
|
id: "linkedin",
|
|
icon_name: "IconBrandLinkedin",
|
|
label: "LinkedIn",
|
|
href: "https://www.linkedin.com/",
|
|
},
|
|
{
|
|
id: "youtube",
|
|
icon_name: "IconBrandYoutube",
|
|
label: "YouTube",
|
|
href: "https://www.youtube.com/",
|
|
},
|
|
{
|
|
id: "telegram",
|
|
icon_name: "IconBrandTelegram",
|
|
label: "Telegram",
|
|
href: "https://t.me/",
|
|
},
|
|
];
|
|
|
|
/** เนื้อหาหน้า "เกี่ยวกับเรา" เริ่มต้น — ดึงจากข้อความ i18n เพื่อไม่ต้องดูแลสองที่ */
|
|
export function seedAbout(): Record<Locale, AboutContent> {
|
|
return {
|
|
th: toAboutContent(MESSAGES.th.about),
|
|
en: toAboutContent(MESSAGES.en.about),
|
|
};
|
|
}
|
|
|
|
function toAboutContent(source: Messages["about"]): AboutContent {
|
|
return {
|
|
title: source.title,
|
|
lead: source.lead,
|
|
sections: source.sections.map((section) => ({
|
|
heading: section.heading,
|
|
body: section.body,
|
|
})),
|
|
contactHeading: source.contactHeading,
|
|
contactNote: source.contactNote,
|
|
};
|
|
}
|
|
|
|
export function seedContent(): ContentStore {
|
|
return {
|
|
cinemas: CINEMAS,
|
|
site: {
|
|
locales: DEFAULT_LOCALES,
|
|
terms: seedTerms(),
|
|
footer: DEFAULT_FOOTER,
|
|
},
|
|
about: seedAbout(),
|
|
forCinemas: seedForCinemas(),
|
|
forFilmLovers: seedForFilmLovers(),
|
|
};
|
|
}
|
|
|
|
/** ค่าเริ่มต้นหน้า "สำหรับคนทำโรงหนัง" — ย่อหน้าตั้งต้นมาจาก messages (แก้ต่อได้ในหลังบ้าน) */
|
|
export function seedForCinemas(): Record<Locale, ArticleContent> {
|
|
return seedArticle(MESSAGES.th.forCinemas, MESSAGES.en.forCinemas);
|
|
}
|
|
|
|
/** ค่าเริ่มต้นหน้า "สำหรับคนรักหนัง" */
|
|
export function seedForFilmLovers(): Record<Locale, ArticleContent> {
|
|
return seedArticle(MESSAGES.th.forFilmLovers, MESSAGES.en.forFilmLovers);
|
|
}
|
|
|
|
type SeedArticle = {
|
|
title: string;
|
|
lead: string;
|
|
paragraphs: string[];
|
|
contactHeading: string;
|
|
contactNote: string;
|
|
};
|
|
|
|
/** แปลงข้อความ i18n ของหน้าบทความ → บล็อกเริ่มต้น (ใช้ทั้งหน้าโรงหนังและคนรักหนัง) */
|
|
function seedArticle(
|
|
th: SeedArticle,
|
|
en: SeedArticle,
|
|
): Record<Locale, ArticleContent> {
|
|
return { th: toArticleContent(th), en: toArticleContent(en) };
|
|
}
|
|
|
|
function toArticleContent(source: SeedArticle): ArticleContent {
|
|
return {
|
|
title: source.title,
|
|
lead: source.lead,
|
|
blocks: source.paragraphs.map((text) => ({ type: "paragraph", text })),
|
|
contactHeading: source.contactHeading,
|
|
contactNote: source.contactNote,
|
|
};
|
|
}
|