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
This commit is contained in:
1 parent
7ac7bf5878
commit
2fa73f43d9
27 files changed
+850
-68
No files matched your search
@@ -1,12 +1,61 @@
|
||||
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";
|
||||
|
||||
export const metadata = { title: "เช็กเวลาเดินรถ" };
|
||||
type Params = { params: Promise<{ routeId: string }> };
|
||||
|
||||
export default async function Page({ 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) }} />
|
||||
</>
|
||||
|
||||
Reference in new issue
Block a user