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
@@ -0,0 +1,66 @@
|
||||
/**
|
||||
* ตัวสร้าง sitemap.xml (ฟังก์ชันบริสุทธิ์ — ทดสอบได้โดยไม่ต้องมีเซิร์ฟเวอร์)
|
||||
*
|
||||
* หน้า static มาจาก `SITE.staticPages` · หน้าโรงหนังมาจากข้อมูลจริง
|
||||
* (ไม่รวมโรงที่ตั้ง `hidden: true` เพราะไม่ควรอยู่ในผลค้นหา)
|
||||
*/
|
||||
import type { Cinema } from "@/lib/cinemas";
|
||||
import { SITE } from "@/lib/site";
|
||||
|
||||
function escapeXml(value: string): string {
|
||||
return value
|
||||
.replace(/&/g, "&")
|
||||
.replace(/</g, "<")
|
||||
.replace(/>/g, ">")
|
||||
.replace(/"/g, """)
|
||||
.replace(/'/g, "'");
|
||||
}
|
||||
|
||||
/** ต่อพาธกับโดเมน — หน้าแรกต้องมี `/` ปิดท้าย */
|
||||
export function sitemapLocation(origin: string, path: string): string {
|
||||
const base = origin.replace(/\/+$/, "");
|
||||
if (path === "/" || path === "") return `${base}/`;
|
||||
return `${base}${path.startsWith("/") ? path : `/${path}`}`;
|
||||
}
|
||||
|
||||
function urlEntry(
|
||||
origin: string,
|
||||
path: string,
|
||||
options: { priority: string; changeFrequency: string },
|
||||
): string {
|
||||
return [
|
||||
" <url>",
|
||||
` <loc>${escapeXml(sitemapLocation(origin, path))}</loc>`,
|
||||
` <changefreq>${options.changeFrequency}</changefreq>`,
|
||||
` <priority>${options.priority}</priority>`,
|
||||
" </url>",
|
||||
].join("\n");
|
||||
}
|
||||
|
||||
/** จำนวน URL สูงสุดต่อไฟล์ (ข้อกำหนด sitemap = 50,000) */
|
||||
export function buildSitemapXml(origin: string, cinemas: Cinema[]): string {
|
||||
const entries = SITE.staticPages.map((page) =>
|
||||
urlEntry(origin, page.path, {
|
||||
priority: page.priority,
|
||||
changeFrequency: page.changeFrequency,
|
||||
}),
|
||||
);
|
||||
|
||||
for (const cinema of cinemas) {
|
||||
if (cinema.hidden) continue;
|
||||
entries.push(
|
||||
urlEntry(origin, `/cinema/${cinema.slug}`, {
|
||||
priority: "0.8",
|
||||
changeFrequency: "weekly",
|
||||
}),
|
||||
);
|
||||
}
|
||||
|
||||
return [
|
||||
'<?xml version="1.0" encoding="UTF-8"?>',
|
||||
'<urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9">',
|
||||
...entries,
|
||||
"</urlset>",
|
||||
"",
|
||||
].join("\n");
|
||||
}
|
||||
Reference in new issue
Block a user