Files
web-alterflixhub/app/lib/gallery.ts
T
Bkk1234 319c271d23 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 ไฟล์)
2026-11-10 02:31:10 +07:00

36 lines
1.6 KiB
TypeScript

/** จำนวนช่องภาพที่แกลเลอรีแสดงจริง: 1 ภาพหลัก + 2 ภาพย่อย */
export const GALLERY_SLOTS = 3;
const THUMB_SLOTS = GALLERY_SLOTS - 1;
export type GalleryView = {
main: string | null;
thumbs: string[];
/** จำนวนรูปที่ยังไม่ถูกแสดง ใช้ทำป้าย "+N" — 0 คือไม่ต้องมีป้าย */
remaining: number;
};
/**
* หมุนรายการรูปให้เริ่มที่ index (ค่าติดลบ/เกินจำนวนได้ — วนกลับอัตโนมัติ)
* ใช้กับปุ่มก่อนหน้า/ถัดไปของแกลเลอรี: ภาพหลักเลื่อน และภาพย่อยเลื่อนตาม
*/
export function rotateGallery(photos: string[], index: number): string[] {
const total = photos.length;
if (total === 0) return [];
const start = ((index % total) + total) % total;
return [...photos.slice(start), ...photos.slice(0, start)];
}
/**
* แบ่งรูปทั้งหมดเป็นภาพหลัก + ภาพย่อย และนับรูปที่เหลือ
* ป้าย "+N" จึงมาจากจำนวนรูปจริง ไม่ใช่ค่าคงที่ในโค้ด
*/
export function splitGallery(photos: string[]): GalleryView {
const [main = null, ...rest] = photos;
return {
main,
thumbs: rest.slice(0, THUMB_SLOTS),
remaining: Math.max(rest.length - THUMB_SLOTS, 0),
};
}