- บทความจากหลังบ้าน: /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 ไฟล์)
92 lines
3.1 KiB
TypeScript
92 lines
3.1 KiB
TypeScript
/**
|
|
* /robots.txt — สร้างสด ๆ ที่ชั้น Nitro เพื่อให้บรรทัด `Sitemap:` ชี้โดเมนจริงของ request
|
|
* (ไฟล์ static ใน public/ ต้องฮาร์ดโค้ดโดเมน จึงย้ายมาเป็น route)
|
|
*/
|
|
import {
|
|
defineEventHandler,
|
|
getRequestHeaders,
|
|
getRequestProtocol,
|
|
setResponseHeader,
|
|
} from "h3";
|
|
|
|
import { originFromHeaders } from "../../app/lib/request-origin";
|
|
import { configuredOrigin } from "../../app/lib/site";
|
|
|
|
/** search engine ที่อนุญาตชัดเจน */
|
|
const ALLOWED_ENGINES = [
|
|
"Googlebot",
|
|
"Bingbot",
|
|
"DuckDuckBot",
|
|
"Bravebot",
|
|
"Applebot",
|
|
];
|
|
|
|
/** AI crawler ที่ไม่อนุญาต (ฝึกโมเดล/สรุปเนื้อหา) */
|
|
const AI_CRAWLERS = [
|
|
"GPTBot",
|
|
"OAI-SearchBot",
|
|
"ChatGPT-User",
|
|
"ClaudeBot",
|
|
"Claude-Web",
|
|
"anthropic-ai",
|
|
"Google-Extended",
|
|
"Applebot-Extended",
|
|
"PerplexityBot",
|
|
"Perplexity-User",
|
|
"CCBot",
|
|
"Bytespider",
|
|
"Amazonbot",
|
|
"meta-externalagent",
|
|
"cohere-ai",
|
|
"Diffbot",
|
|
"ImagesiftBot",
|
|
"Omgilibot",
|
|
"Timpibot",
|
|
"VelenPublicWebCrawler",
|
|
"YouBot",
|
|
];
|
|
|
|
/** ประกอบไฟล์ robots.txt จาก origin ของ request */
|
|
export function buildRobotsTxt(origin: string): string {
|
|
const lines: string[] = [
|
|
"# robots.txt — AlterFlixHub",
|
|
"# ค้นหาโรงหนังอิสระ/อาร์ตเฮาส์ในประเทศไทย",
|
|
"",
|
|
"# ── search engines (อนุญาตชัดเจน) ────────────────────────────────",
|
|
];
|
|
|
|
for (const engine of ALLOWED_ENGINES) {
|
|
lines.push(`User-agent: ${engine}`, "Allow: /", "");
|
|
}
|
|
|
|
lines.push(
|
|
"# ── ค่าเริ่มต้น: เปิดให้ index แต่ปิดส่วนที่ไม่ควรอยู่ในผลค้นหา ──",
|
|
"User-agent: *",
|
|
"Allow: /",
|
|
"Disallow: /api/",
|
|
"Disallow: /admin",
|
|
"Disallow: /admin/login",
|
|
"Disallow: /_agent-native/",
|
|
"Disallow: /c/ # ลิงก์ย่อสำหรับแชร์ (302 ไปหน้าโรงหนังจริง)",
|
|
"",
|
|
"# ── AI crawlers: ไม่อนุญาตให้นำเนื้อหาไปใช้ ─────────────────────",
|
|
"# (รวมถึงการฝึกโมเดล/สรุปเนื้อหาของผู้ให้บริการ AI)",
|
|
);
|
|
|
|
for (const crawler of AI_CRAWLERS) {
|
|
lines.push(`User-agent: ${crawler}`, "Disallow: /", "");
|
|
}
|
|
|
|
lines.push(`Sitemap: ${origin.replace(/\/+$/, "")}/sitemap.xml`, "");
|
|
return lines.join("\n");
|
|
}
|
|
|
|
export default defineEventHandler((event) => {
|
|
const origin =
|
|
configuredOrigin() ||
|
|
originFromHeaders(getRequestHeaders(event), getRequestProtocol(event));
|
|
setResponseHeader(event, "Content-Type", "text/plain; charset=utf-8");
|
|
setResponseHeader(event, "Cache-Control", "public, max-age=3600");
|
|
return buildRobotsTxt(origin);
|
|
});
|