Files
web-at-transit/frontend/src/app/check/[routeId]/page.tsx
T
Bkk1234 2fa73f43d9 Add SEO foundation: robots, sitemap, JSON-LD, OG/Twitter cards, per-page metadata
- src/lib/site.ts: single source for site name/url/description (rename via env only)
- src/app/robots.ts: allow all, disallow /api /files, explicit Googlebot/Bingbot/DuckDuckBot/Bravebot/Applebot
- src/app/sitemap.ts: static pages + routes/check/stops from backend, falls back to static when API is down
- src/components/JsonLd.tsx: WebSite + Organization + SearchAction, BreadcrumbList, BusStop, Service
- layout.tsx: metadataBase, canonical, keywords, robots, openGraph, twitter
- generateMetadata for /stops/[code], /routes/[routeId], /check/[routeId]
- canonical + description on /stops /routes /blog /about /credits
- public/og-image.png 1200x630
2026-10-23 23:15:06 +07:00

64 lines
2.1 KiB
TypeScript

import CheckView from "@/components/views/CheckView";
import PageRuntime from "@/components/PageRuntime";
import { BreadcrumbJsonLd, BusRouteJsonLd } from "@/components/JsonLd";
import { SITE_NAME } from "@/lib/site";
import { api } from "@/lib/api";
import type { Metadata } from "next";
type Params = { params: Promise<{ routeId: string }> };
async function loadRoute(id: string) {
try {
return await api.route(decodeURIComponent(id));
} catch {
return null;
}
}
export async function generateMetadata({ params }: Params): Promise<Metadata> {
const { routeId } = await params;
const r = await loadRoute(routeId);
if (!r) {
return { title: "เช็กเวลาเดินรถ", alternates: { canonical: `/check/${routeId}` } };
}
const title = `เวลาเดินรถ สาย ${r.route_id} ${r.name_th || ""}`.trim();
const description =
`ตารางเวลาเดินรถสาย ${r.route_id} ${r.name_th || ""} ทั้งวันทำการและวันหยุด ` +
`พร้อมเวลารถออกจากแต่ละจุดจอด — ${SITE_NAME}`;
return {
title,
description,
alternates: { canonical: `/check/${encodeURIComponent(r.route_id)}` },
openGraph: { type: "article", title, description, url: `/check/${encodeURIComponent(r.route_id)}` },
};
}
export default async function Page({ params }: Params) {
const { routeId } = await params;
const r = await loadRoute(routeId);
return (
<>
{r ? (
<>
<BreadcrumbJsonLd
items={[
{ name: "หน้าแรก", path: "/" },
{ name: `สาย ${r.route_id}`, path: `/routes/${r.route_id}` },
{ name: "เช็กเวลาเดินรถ", path: `/check/${r.route_id}` },
]}
/>
<BusRouteJsonLd
routeId={String(r.route_id)}
name={r.name_th || ""}
/>
</>
) : null}
<CheckView />
<PageRuntime page="check" params={{ routeId: decodeURIComponent(routeId) }} />
</>
);
}