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,16 +1,14 @@
|
||||
import { useState } from "react";
|
||||
|
||||
import {
|
||||
inputClass,
|
||||
labelClass,
|
||||
primaryButtonClass,
|
||||
secondaryButtonClass,
|
||||
} from "@/components/admin/form-styles";
|
||||
import type { AboutContent, AboutSection } from "@/lib/content-types";
|
||||
import type { Locale } from "@/lib/i18n/messages";
|
||||
|
||||
const inputClass =
|
||||
"w-full rounded-lg border border-[#303030] bg-[#141414] px-3 py-2 text-sm text-white outline-none transition focus:border-[#A92626] focus-visible:ring-2 focus-visible:ring-[#A92626]/40";
|
||||
const labelClass = "flex flex-col gap-1.5 text-xs text-[#999]";
|
||||
const buttonClass =
|
||||
"min-h-11 rounded-lg border border-[#303030] px-3 text-sm transition hover:border-[#A92626] hover:text-[#D47272] focus-visible:outline focus-visible:outline-2 focus-visible:outline-[#A92626]";
|
||||
const primaryButtonClass =
|
||||
"min-h-11 rounded-lg bg-[#8F0808] px-4 text-sm font-medium transition hover:bg-[#a30a0a] focus-visible:outline focus-visible:outline-2 focus-visible:outline-[#D47272]";
|
||||
|
||||
const LOCALE_TABS: Array<{ code: Locale; label: string }> = [
|
||||
{ code: "th", label: "ไทย" },
|
||||
{ code: "en", label: "English" },
|
||||
@@ -106,7 +104,11 @@ export function AboutEditor({
|
||||
</div>
|
||||
|
||||
<div className="flex flex-wrap items-center gap-2">
|
||||
<button type="button" className={buttonClass} onClick={restoreDefaults}>
|
||||
<button
|
||||
type="button"
|
||||
className={secondaryButtonClass}
|
||||
onClick={restoreDefaults}
|
||||
>
|
||||
คืนค่าตั้งต้น ({locale.toUpperCase()})
|
||||
</button>
|
||||
<button
|
||||
@@ -171,7 +173,9 @@ export function AboutEditor({
|
||||
className="rounded-xl border border-[#242424] bg-[#141414] p-4"
|
||||
>
|
||||
<div className="mb-2 flex items-center justify-between gap-2">
|
||||
<span className="text-xs text-[#8A8A8A]">ส่วนที่ {index + 1}</span>
|
||||
<span className="text-xs text-[#8A8A8A]">
|
||||
ส่วนที่ {index + 1}
|
||||
</span>
|
||||
<div className="flex items-center gap-1">
|
||||
<button
|
||||
type="button"
|
||||
@@ -226,7 +230,7 @@ export function AboutEditor({
|
||||
|
||||
<button
|
||||
type="button"
|
||||
className={`${buttonClass} self-start`}
|
||||
className={`${secondaryButtonClass} self-start`}
|
||||
onClick={addSection}
|
||||
>
|
||||
+ เพิ่มส่วน
|
||||
|
||||
@@ -0,0 +1,129 @@
|
||||
import {
|
||||
compactButtonClass,
|
||||
inputClass,
|
||||
labelClass,
|
||||
} from "@/components/admin/form-styles";
|
||||
import type { ArticleBlock } from "@/lib/content-types";
|
||||
|
||||
type ArticleBlockCardProps = {
|
||||
block: ArticleBlock;
|
||||
/** ตำแหน่งของบล็อก (0-based) — ใช้แสดงเลขและปิดปุ่มที่เกินขอบ */
|
||||
index: number;
|
||||
/** จำนวนบล็อกทั้งหมด — ใช้ปิดปุ่ม "เลื่อนลง" ที่บล็อกสุดท้าย */
|
||||
total: number;
|
||||
/** ส่งบล็อกที่แก้แล้วกลับไปทั้งก้อน (ชนิดถูกต้องตาม type ของบล็อก) */
|
||||
onChange: (next: ArticleBlock) => void;
|
||||
onMove: (direction: -1 | 1) => void;
|
||||
onRemove: () => void;
|
||||
};
|
||||
|
||||
/**
|
||||
* การ์ดแก้ไขบทความหนึ่งบล็อก — ย่อหน้าหรือรูป
|
||||
* แยกออกมาจาก ArticleEditor เพื่อให้แต่ละไฟล์มีขนาดอ่านไหว
|
||||
*/
|
||||
export function ArticleBlockCard({
|
||||
block,
|
||||
index,
|
||||
total,
|
||||
onChange,
|
||||
onMove,
|
||||
onRemove,
|
||||
}: ArticleBlockCardProps) {
|
||||
return (
|
||||
<div className="rounded-xl border border-[#242424] bg-[#141414] p-4">
|
||||
<div className="mb-3 flex flex-wrap items-center justify-between gap-2">
|
||||
<span className="text-xs uppercase tracking-wide text-[#999]">
|
||||
{block.type === "image" ? `รูปที่ ${index + 1}` : `ย่อหน้าที่ ${index + 1}`}
|
||||
</span>
|
||||
<div className="flex items-center gap-1.5">
|
||||
<button
|
||||
type="button"
|
||||
className={compactButtonClass}
|
||||
aria-label={`เลื่อนขึ้น (บล็อกที่ ${index + 1})`}
|
||||
onClick={() => onMove(-1)}
|
||||
disabled={index === 0}
|
||||
>
|
||||
↑
|
||||
</button>
|
||||
<button
|
||||
type="button"
|
||||
className={compactButtonClass}
|
||||
aria-label={`เลื่อนลง (บล็อกที่ ${index + 1})`}
|
||||
onClick={() => onMove(1)}
|
||||
disabled={index === total - 1}
|
||||
>
|
||||
↓
|
||||
</button>
|
||||
<button
|
||||
type="button"
|
||||
className={compactButtonClass}
|
||||
aria-label={`ลบบล็อกที่ ${index + 1}`}
|
||||
onClick={onRemove}
|
||||
>
|
||||
ลบ
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
{block.type === "paragraph" ? (
|
||||
<textarea
|
||||
value={block.text}
|
||||
onChange={(event) =>
|
||||
onChange({ type: "paragraph", text: event.target.value })
|
||||
}
|
||||
rows={4}
|
||||
placeholder="พิมพ์ย่อหน้าที่นี่ — เว้นบรรทัดใหม่ได้ ระบบจะแสดงตามที่พิมพ์"
|
||||
className={inputClass}
|
||||
/>
|
||||
) : (
|
||||
<div className="grid gap-3 md:grid-cols-[minmax(0,1fr)_180px]">
|
||||
<div className="flex flex-col gap-3">
|
||||
<label className={labelClass}>
|
||||
ลิงก์รูป (URL หรือ /images/…)
|
||||
<input
|
||||
value={block.src}
|
||||
onChange={(event) =>
|
||||
onChange({ ...block, src: event.target.value })
|
||||
}
|
||||
placeholder="/images/house-cinema.jpg"
|
||||
className={inputClass}
|
||||
/>
|
||||
</label>
|
||||
<label className={labelClass}>
|
||||
คำอธิบายรูป (alt) — จำเป็นต่อการเข้าถึง
|
||||
<input
|
||||
value={block.alt}
|
||||
onChange={(event) =>
|
||||
onChange({ ...block, alt: event.target.value })
|
||||
}
|
||||
placeholder="บรรยากาศภายในโรงหนัง"
|
||||
className={inputClass}
|
||||
/>
|
||||
</label>
|
||||
<label className={labelClass}>
|
||||
คำบรรยายใต้รูป (ไม่ใส่ก็ได้)
|
||||
<input
|
||||
value={block.caption}
|
||||
onChange={(event) =>
|
||||
onChange({ ...block, caption: event.target.value })
|
||||
}
|
||||
className={inputClass}
|
||||
/>
|
||||
</label>
|
||||
</div>
|
||||
<div className="flex items-start justify-center rounded-lg border border-[#242424] bg-[#0D0D0D] p-2">
|
||||
{block.src.trim() !== "" ? (
|
||||
<img
|
||||
src={block.src}
|
||||
alt=""
|
||||
className="max-h-[140px] w-full rounded-md object-cover"
|
||||
/>
|
||||
) : (
|
||||
<span className="py-8 text-xs text-[#666]">ยังไม่ได้ใส่ลิงก์รูป</span>
|
||||
)}
|
||||
</div>
|
||||
</div>
|
||||
)}
|
||||
</div>
|
||||
);
|
||||
}
|
||||
@@ -0,0 +1,215 @@
|
||||
import { useState } from "react";
|
||||
|
||||
import { ArticleBlockCard } from "@/components/admin/ArticleBlockCard";
|
||||
import {
|
||||
inputClass,
|
||||
labelClass,
|
||||
primaryButtonClass,
|
||||
secondaryButtonClass,
|
||||
} from "@/components/admin/form-styles";
|
||||
import {
|
||||
countImages,
|
||||
createImageBlock,
|
||||
createParagraphBlock,
|
||||
moveBlock,
|
||||
removeBlock,
|
||||
} from "@/lib/article";
|
||||
import type { ArticleBlock, ArticleContent } from "@/lib/content-types";
|
||||
import type { Locale } from "@/lib/i18n/messages";
|
||||
|
||||
const LOCALE_TABS: Array<{ code: Locale; label: string }> = [
|
||||
{ code: "th", label: "ไทย" },
|
||||
{ code: "en", label: "English" },
|
||||
];
|
||||
|
||||
type ArticleEditorProps = {
|
||||
value: Record<Locale, ArticleContent>;
|
||||
defaults: Record<Locale, ArticleContent>;
|
||||
onChange: (next: Record<Locale, ArticleContent>) => void;
|
||||
onSave: () => void;
|
||||
saving: boolean;
|
||||
/** ป้ายปุ่มบันทึก เช่น "บันทึกหน้าสำหรับคนทำโรงหนัง" */
|
||||
saveLabel: string;
|
||||
};
|
||||
|
||||
/**
|
||||
* ตัวแก้ไขหน้าบทความ (ใช้ทั้ง "สำหรับคนทำโรงหนัง" และ "สำหรับคนรักหนัง")
|
||||
*
|
||||
* ไฟล์นี้มีหน้าที่เดียว: ถือภาษาที่เลือก + ประกอบฟอร์ม
|
||||
* - รายละเอียดของแต่ละบล็อก → `ArticleBlockCard`
|
||||
* - สไตล์ฟอร์ม (input/label/ปุ่ม) → `form-styles`
|
||||
* ฟิลด์ที่เว้นว่างจะถูกเซิร์ฟเวอร์เติมค่าเริ่มต้น (sanitizeForCinemas / sanitizeForFilmLovers)
|
||||
*/
|
||||
export function ArticleEditor({
|
||||
value,
|
||||
defaults,
|
||||
onChange,
|
||||
onSave,
|
||||
saving,
|
||||
saveLabel,
|
||||
}: ArticleEditorProps) {
|
||||
const [locale, setLocale] = useState<Locale>("th");
|
||||
const current = value[locale];
|
||||
|
||||
/** อัปเดตฟิลด์ระดับหน้า (title/lead/contact… หรือทั้งรายการ blocks) */
|
||||
function patch(next: Partial<ArticleContent>) {
|
||||
onChange({ ...value, [locale]: { ...current, ...next } });
|
||||
}
|
||||
|
||||
/** แทนที่บล็อกตำแหน่งที่ index — ชนิดของบล็อกถูกต้องเสมอ เพราะผู้เรียกส่งมาทั้งก้อน */
|
||||
function replaceBlock(index: number, next: ArticleBlock) {
|
||||
patch({
|
||||
blocks: current.blocks.map((block, i) => (i === index ? next : block)),
|
||||
});
|
||||
}
|
||||
|
||||
function restoreDefaults() {
|
||||
onChange({ ...value, [locale]: defaults[locale] });
|
||||
}
|
||||
|
||||
const images = countImages(current.blocks);
|
||||
const paragraphs = current.blocks.length - images;
|
||||
|
||||
return (
|
||||
<div className="px-6 py-5">
|
||||
<div className="mb-4 flex flex-wrap items-center justify-between gap-3">
|
||||
<div
|
||||
role="tablist"
|
||||
aria-label="ภาษา"
|
||||
className="flex items-center gap-1 rounded-lg border border-[#242424] bg-[#141414] p-1"
|
||||
>
|
||||
{LOCALE_TABS.map((tab) => (
|
||||
<button
|
||||
key={tab.code}
|
||||
type="button"
|
||||
role="tab"
|
||||
aria-selected={locale === tab.code}
|
||||
onClick={() => setLocale(tab.code)}
|
||||
className={`min-h-9 rounded-md px-4 text-sm transition ${
|
||||
locale === tab.code
|
||||
? "bg-[#242424] font-semibold text-[#D47272]"
|
||||
: "text-[#999] hover:text-white"
|
||||
}`}
|
||||
>
|
||||
{tab.label}
|
||||
</button>
|
||||
))}
|
||||
</div>
|
||||
|
||||
<div className="flex flex-wrap items-center gap-2">
|
||||
<span className="text-xs text-[#999]">
|
||||
{paragraphs} ย่อหน้า · {images} รูป
|
||||
</span>
|
||||
<button
|
||||
type="button"
|
||||
className={secondaryButtonClass}
|
||||
onClick={restoreDefaults}
|
||||
>
|
||||
คืนค่าตั้งต้น ({locale.toUpperCase()})
|
||||
</button>
|
||||
<button
|
||||
type="button"
|
||||
className={primaryButtonClass}
|
||||
onClick={onSave}
|
||||
disabled={saving}
|
||||
>
|
||||
{saving ? "กำลังบันทึก…" : saveLabel}
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div className="grid gap-4 lg:grid-cols-2">
|
||||
<label className={labelClass}>
|
||||
หัวเรื่อง (H1)
|
||||
<input
|
||||
value={current.title}
|
||||
onChange={(event) => patch({ title: event.target.value })}
|
||||
placeholder="สำหรับคนทำโรงหนัง"
|
||||
className={inputClass}
|
||||
/>
|
||||
{current.title.trim() === "" ? (
|
||||
<span className="text-[#D47272]">เว้นว่างไม่ได้ — ระบบจะใช้ค่าเดิม</span>
|
||||
) : null}
|
||||
</label>
|
||||
|
||||
<label className={labelClass}>
|
||||
คำเกริ่นนำ (แสดงใต้หัวเรื่อง)
|
||||
<textarea
|
||||
value={current.lead}
|
||||
onChange={(event) => patch({ lead: event.target.value })}
|
||||
rows={3}
|
||||
className={inputClass}
|
||||
/>
|
||||
</label>
|
||||
</div>
|
||||
|
||||
<div className="mt-6 flex flex-col gap-3">
|
||||
<div className="flex flex-wrap items-center justify-between gap-2">
|
||||
<h3 className="text-sm font-semibold text-white">เนื้อหาบทความ</h3>
|
||||
<div className="flex flex-wrap gap-2">
|
||||
<button
|
||||
type="button"
|
||||
className={secondaryButtonClass}
|
||||
onClick={() =>
|
||||
patch({ blocks: [...current.blocks, createParagraphBlock()] })
|
||||
}
|
||||
>
|
||||
+ เพิ่มย่อหน้า
|
||||
</button>
|
||||
<button
|
||||
type="button"
|
||||
className={secondaryButtonClass}
|
||||
onClick={() =>
|
||||
patch({ blocks: [...current.blocks, createImageBlock()] })
|
||||
}
|
||||
>
|
||||
+ เพิ่มรูปภาพ
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
{current.blocks.length === 0 ? (
|
||||
<p className="rounded-lg border border-dashed border-[#303030] p-6 text-center text-sm text-[#999]">
|
||||
ยังไม่มีเนื้อหา — กด “เพิ่มย่อหน้า” หรือ “เพิ่มรูปภาพ” เพื่อเริ่มเขียน
|
||||
</p>
|
||||
) : null}
|
||||
|
||||
{current.blocks.map((block, index) => (
|
||||
<ArticleBlockCard
|
||||
key={`${block.type}-${index}`}
|
||||
block={block}
|
||||
index={index}
|
||||
total={current.blocks.length}
|
||||
onChange={(next) => replaceBlock(index, next)}
|
||||
onMove={(direction) =>
|
||||
patch({ blocks: moveBlock(current.blocks, index, direction) })
|
||||
}
|
||||
onRemove={() =>
|
||||
patch({ blocks: removeBlock(current.blocks, index) })
|
||||
}
|
||||
/>
|
||||
))}
|
||||
</div>
|
||||
|
||||
<div className="mt-6 grid gap-4 lg:grid-cols-2">
|
||||
<label className={labelClass}>
|
||||
หัวข้อการ์ดติดต่อ
|
||||
<input
|
||||
value={current.contactHeading}
|
||||
onChange={(event) => patch({ contactHeading: event.target.value })}
|
||||
className={inputClass}
|
||||
/>
|
||||
</label>
|
||||
<label className={labelClass}>
|
||||
ข้อความในการ์ดติดต่อ
|
||||
<textarea
|
||||
value={current.contactNote}
|
||||
onChange={(event) => patch({ contactNote: event.target.value })}
|
||||
rows={3}
|
||||
className={inputClass}
|
||||
/>
|
||||
</label>
|
||||
</div>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
@@ -0,0 +1,21 @@
|
||||
/**
|
||||
* คลาสฟอร์มที่ใช้ร่วมทุกแท็บของหลังบ้าน
|
||||
* อยู่ที่เดียวเพื่อให้หน้าตาเหมือนกันหมด และแก้สไตล์ครั้งเดียวมีผลทุกที่
|
||||
* (ห้ามประกาศ inputClass/labelClass ซ้ำใน component)
|
||||
*/
|
||||
export const inputClass =
|
||||
"w-full rounded-lg border border-[#303030] bg-[#141414] px-3 py-2 text-sm text-white outline-none transition focus:border-[#A92626] focus-visible:ring-2 focus-visible:ring-[#A92626]/40";
|
||||
|
||||
export const labelClass = "flex flex-col gap-1.5 text-xs text-[#999]";
|
||||
|
||||
/** ปุ่มหลัก — ใช้กับการกระทำที่ต้องการให้เด่น (เช่น บันทึก) */
|
||||
export const primaryButtonClass =
|
||||
"min-h-11 rounded-lg bg-[#8F0808] px-4 text-sm font-medium transition hover:bg-[#a30a0a] focus-visible:outline focus-visible:outline-2 focus-visible:outline-[#D47272]";
|
||||
|
||||
/** ปุ่มรอง — ใช้กับการกระทำทั่วไป (เช่น เพิ่มบล็อก/คืนค่าตั้งต้น) */
|
||||
export const secondaryButtonClass =
|
||||
"min-h-11 rounded-lg border border-[#303030] px-3 text-sm transition hover:border-[#A92626] hover:text-[#D47272] focus-visible:outline focus-visible:outline-2 focus-visible:outline-[#A92626]";
|
||||
|
||||
/** ปุ่มขนาดกะทัดรัด — ใช้กับเครื่องมือในแต่ละบล็อก (↑ ↓ ลบ) */
|
||||
export const compactButtonClass =
|
||||
"min-h-9 rounded-lg border border-[#303030] px-2.5 text-sm text-[#B3B3B3] transition hover:border-[#A92626] hover:text-[#D47272] focus-visible:outline focus-visible:outline-2 focus-visible:outline-[#A92626] disabled:opacity-40";
|
||||
Reference in new issue
Block a user