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
@@ -89,7 +89,7 @@
|
||||
"home.lead": "Browse routes, find stops, and preview a route right from this page",
|
||||
"home.chooseProvince": "Select Province",
|
||||
"home.chooseStation": "Select Terminal",
|
||||
"share.label": "Share short link",
|
||||
"share.label": "Share this page",
|
||||
"share.copied": "Link copied",
|
||||
"share.short": "Short link",
|
||||
"share.line": "Share on LINE",
|
||||
|
||||
@@ -89,7 +89,7 @@
|
||||
"home.lead": "ดูสายรถ, ค้นหาป้าย และเปิดตัวอย่างเส้นทางได้ทันทีจากหน้าแรก",
|
||||
"home.chooseProvince": "เลือกจังหวัด",
|
||||
"home.chooseStation": "เลือกสถานีขนส่งผู้โดยสาร",
|
||||
"share.label": "แชร์ลิงก์สั้น",
|
||||
"share.label": "แชร์หน้านี้",
|
||||
"share.copied": "คัดลอกลิงก์แล้ว",
|
||||
"share.short": "ลิงก์สั้น",
|
||||
"share.line": "แชร์ผ่าน LINE",
|
||||
|
||||
@@ -1,7 +1,11 @@
|
||||
import AboutView from "@/components/views/AboutView";
|
||||
import PageRuntime from "@/components/PageRuntime";
|
||||
|
||||
export const metadata = { title: "เกี่ยวกับเรา" };
|
||||
export const metadata = {
|
||||
title: "เกี่ยวกับเรา",
|
||||
description: "Atroute — แหล่งรวมข้อมูลรถโดยสารจังหวัดอ่างทอง",
|
||||
alternates: { canonical: "/about" },
|
||||
};
|
||||
|
||||
export default function Page() {
|
||||
return (
|
||||
|
||||
@@ -1,7 +1,11 @@
|
||||
import BlogView from "@/components/views/BlogView";
|
||||
import PageRuntime from "@/components/PageRuntime";
|
||||
|
||||
export const metadata = { title: "บ่นไปเรื่อย" };
|
||||
export const metadata = {
|
||||
title: "บ่นไปเรื่อย",
|
||||
description: "บทความและเรื่องเล่าเกี่ยวกับการเดินทางด้วยรถโดยสารในจังหวัดอ่างทอง",
|
||||
alternates: { canonical: "/blog" },
|
||||
};
|
||||
|
||||
export default function Page() {
|
||||
return (
|
||||
|
||||
@@ -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) }} />
|
||||
</>
|
||||
|
||||
@@ -1,6 +1,10 @@
|
||||
import CreditsView from "@/components/views/CreditsView";
|
||||
|
||||
export const metadata = { title: "เครดิต" };
|
||||
export const metadata = {
|
||||
title: "เครดิต",
|
||||
description: "แหล่งที่มาของข้อมูล รูปภาพ ฟอนต์ และซอฟต์แวร์ที่ใช้บนเว็บนี้",
|
||||
alternates: { canonical: "/credits" },
|
||||
};
|
||||
|
||||
export default function Page() {
|
||||
return <CreditsView />;}
|
||||
@@ -1,4 +1,6 @@
|
||||
import type { Metadata, Viewport } from "next";
|
||||
import { SITE_URL, SITE_NAME, SITE_TITLE, SITE_DESCRIPTION, SITE_LOCALE, SITE_OG_IMAGE } from "@/lib/site";
|
||||
import { SiteJsonLd } from "@/components/JsonLd";
|
||||
import IconSprite from "@/components/IconSprite";
|
||||
import PwaBoot from "@/components/PwaBoot";
|
||||
import SiteBoot from "@/components/SiteBoot";
|
||||
@@ -15,13 +17,64 @@ import "@/styles/responsive.css";
|
||||
// (router เดิม inject <style> ของ partial หลัง <link responsive.css>)
|
||||
|
||||
export const metadata: Metadata = {
|
||||
/* ฐาน URL — จำเป็นสำหรับ canonical / OG แบบ relative */
|
||||
metadataBase: new URL(SITE_URL),
|
||||
|
||||
title: {
|
||||
default: "Atroute — สถานีขนส่งผู้โดยสารจังหวัดอ่างทอง",
|
||||
template: "Atroute — %s",
|
||||
default: SITE_TITLE,
|
||||
template: `${SITE_NAME} — %s`,
|
||||
},
|
||||
description: SITE_DESCRIPTION,
|
||||
keywords: [
|
||||
"รถโดยสารอ่างทอง",
|
||||
"ตารางเดินรถ",
|
||||
"ป้ายหยุดรถ",
|
||||
"สายรถ",
|
||||
"สถานีขนส่งอ่างทอง",
|
||||
"เวลาเดินรถ",
|
||||
"bus schedule Ang Thong",
|
||||
],
|
||||
applicationName: SITE_NAME,
|
||||
|
||||
/* canonical — กัน duplicate content */
|
||||
alternates: { canonical: "/" },
|
||||
|
||||
/* ให้บอทเก็บหน้าและรูป */
|
||||
robots: {
|
||||
index: true,
|
||||
follow: true,
|
||||
googleBot: {
|
||||
index: true,
|
||||
follow: true,
|
||||
"max-image-preview": "large",
|
||||
"max-snippet": -1,
|
||||
"max-video-preview": -1,
|
||||
},
|
||||
},
|
||||
|
||||
/* การ์ดแชร์ (LINE / Facebook / X / Telegram) */
|
||||
openGraph: {
|
||||
type: "website",
|
||||
siteName: SITE_NAME,
|
||||
title: SITE_TITLE,
|
||||
description: SITE_DESCRIPTION,
|
||||
locale: SITE_LOCALE,
|
||||
url: "/",
|
||||
images: [
|
||||
{
|
||||
url: SITE_OG_IMAGE,
|
||||
width: 1200,
|
||||
height: 630,
|
||||
alt: SITE_TITLE,
|
||||
},
|
||||
],
|
||||
},
|
||||
twitter: {
|
||||
card: "summary_large_image",
|
||||
title: SITE_TITLE,
|
||||
description: SITE_DESCRIPTION,
|
||||
images: [SITE_OG_IMAGE],
|
||||
},
|
||||
description:
|
||||
"ศูนย์รวมข้อมูลตารางเดินรถ จุดจอด และเส้นทางในจังหวัดอ่างทองและจังหวัดใกล้เคียง",
|
||||
applicationName: "Atroute",
|
||||
manifest: "/ui-manifest.json",
|
||||
icons: {
|
||||
icon: [
|
||||
@@ -71,6 +124,7 @@ export default function RootLayout({ children }: { children: React.ReactNode })
|
||||
<script src="/vendor/leaflet/leaflet.js" defer />
|
||||
</head>
|
||||
<body className="main-theme-page">
|
||||
<SiteJsonLd />
|
||||
<IconSprite />
|
||||
<SiteHeader />
|
||||
<div id="view">{children}</div>
|
||||
|
||||
@@ -0,0 +1,24 @@
|
||||
import type { MetadataRoute } from "next";
|
||||
import { SITE_URL, DISALLOW_PATHS } from "@/lib/site";
|
||||
|
||||
/**
|
||||
* robots.txt — บอกบอท Google / Bing / Brave / DuckDuckGo ว่าอะไรเก็บได้
|
||||
*
|
||||
* หมายเหตุ: DuckDuckGo ใช้ index ของ Bing เป็นหลัก, Brave ใช้ index ของตัวเอง
|
||||
* ทั้งคู่เคารพ robots.txt มาตรฐานเดียวกัน
|
||||
*/
|
||||
export default function robots(): MetadataRoute.Robots {
|
||||
return {
|
||||
rules: [
|
||||
{
|
||||
userAgent: "*",
|
||||
allow: "/",
|
||||
disallow: DISALLOW_PATHS,
|
||||
},
|
||||
/* บอทสำคัญ — อนุญาตชัดเจน */
|
||||
{ userAgent: ["Googlebot", "Bingbot", "DuckDuckBot", "Bravebot", "Applebot"], allow: "/", disallow: DISALLOW_PATHS },
|
||||
],
|
||||
sitemap: `${SITE_URL}/sitemap.xml`,
|
||||
host: SITE_URL,
|
||||
};
|
||||
}
|
||||
@@ -1,12 +1,63 @@
|
||||
import RouteView from "@/components/views/RouteView";
|
||||
import PageRuntime from "@/components/PageRuntime";
|
||||
export const metadata = { title: "รายละเอียดสายรถ" };
|
||||
import { BusRouteJsonLd, BreadcrumbJsonLd } from "@/components/JsonLd";
|
||||
import { SITE_NAME } from "@/lib/site";
|
||||
import { api } from "@/lib/api";
|
||||
import type { Metadata } from "next";
|
||||
|
||||
export default async function Page({ params }: { params: Promise<{ routeId: string }> }) {
|
||||
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: `/routes/${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: `/routes/${encodeURIComponent(r.route_id)}` },
|
||||
openGraph: { type: "article", title, description, url: `/routes/${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: "สายรถ", path: "/routes" },
|
||||
{ name: `สาย ${r.route_id}`, path: `/routes/${r.route_id}` },
|
||||
]}
|
||||
/>
|
||||
<BusRouteJsonLd
|
||||
routeId={String(r.route_id)}
|
||||
name={r.name_th || ""}
|
||||
|
||||
provinces={r.province_ids?.length ?? undefined}
|
||||
/>
|
||||
</>
|
||||
) : null}
|
||||
<RouteView />
|
||||
<PageRuntime page="route" params={{ routeId: decodeURIComponent(routeId) }} />
|
||||
</> );
|
||||
</>
|
||||
);
|
||||
}
|
||||
@@ -1,6 +1,10 @@
|
||||
import RouteView from "@/components/views/RouteView";
|
||||
import PageRuntime from "@/components/PageRuntime";
|
||||
export const metadata = { title: "รายละเอียดสายรถ" };
|
||||
export const metadata = {
|
||||
title: "รายละเอียดสายรถ",
|
||||
description: "รวมสายรถโดยสารทุกเส้นทางในจังหวัดอ่างทอง พร้อมจุดจอดหลักและตารางเดินรถ",
|
||||
alternates: { canonical: "/routes" },
|
||||
};
|
||||
|
||||
export default function Page() {
|
||||
return (
|
||||
|
||||
@@ -0,0 +1,69 @@
|
||||
import type { MetadataRoute } from "next";
|
||||
import { SITE_URL, STATIC_PAGES } from "@/lib/site";
|
||||
import { api } from "@/lib/api";
|
||||
|
||||
/**
|
||||
* sitemap.xml — สร้างอัตโนมัติจากข้อมูลจริงใน backend
|
||||
*
|
||||
* ถ้า backend ล่ม อย่าให้ sitemap ล่ม → fallback เป็นหน้าคงที่
|
||||
* (บอทจะได้ไม่เจอ 500 แล้วเลิก crawl)
|
||||
*/
|
||||
export const revalidate = 3600; /* สร้างใหม่ทุกชั่วโมง */
|
||||
|
||||
type Entry = {
|
||||
url: string;
|
||||
lastModified?: Date | string;
|
||||
changeFrequency?: "always" | "hourly" | "daily" | "weekly" | "monthly" | "yearly" | "never";
|
||||
priority?: number;
|
||||
};
|
||||
|
||||
export default async function sitemap(): Promise<MetadataRoute.Sitemap> {
|
||||
const now = new Date();
|
||||
const entries: Entry[] = STATIC_PAGES.map((p) => ({
|
||||
url: SITE_URL + p.path,
|
||||
lastModified: now,
|
||||
changeFrequency: p.changeFrequency,
|
||||
priority: p.priority,
|
||||
}));
|
||||
|
||||
try {
|
||||
const { items: routes } = await api.routes();
|
||||
for (const r of routes) {
|
||||
const id = String((r as { route_id?: string | number }).route_id ?? "");
|
||||
if (!id) continue;
|
||||
entries.push({
|
||||
url: `${SITE_URL}/routes/${encodeURIComponent(id)}`,
|
||||
lastModified: now,
|
||||
changeFrequency: "weekly",
|
||||
priority: 0.8,
|
||||
});
|
||||
/* หน้าเช็กเวลาเดินรถของสายเดียวกัน */
|
||||
entries.push({
|
||||
url: `${SITE_URL}/check/${encodeURIComponent(id)}`,
|
||||
lastModified: now,
|
||||
changeFrequency: "daily",
|
||||
priority: 0.7,
|
||||
});
|
||||
}
|
||||
} catch {
|
||||
/* backend ไม่ตอบ — ปล่อยให้มีเฉพาะหน้าคงที่ */
|
||||
}
|
||||
|
||||
try {
|
||||
const { items: stops } = await api.stops();
|
||||
for (const s of stops) {
|
||||
const code = String((s as { station_code?: string }).station_code ?? "");
|
||||
if (!code) continue;
|
||||
entries.push({
|
||||
url: `${SITE_URL}/stops/${encodeURIComponent(code)}`,
|
||||
lastModified: now,
|
||||
changeFrequency: "weekly",
|
||||
priority: 0.6,
|
||||
});
|
||||
}
|
||||
} catch {
|
||||
/* backend ไม่ตอบ */
|
||||
}
|
||||
|
||||
return entries as MetadataRoute.Sitemap;
|
||||
}
|
||||
@@ -1,12 +1,67 @@
|
||||
import StopView from "@/components/views/StopView";
|
||||
import PageRuntime from "@/components/PageRuntime";
|
||||
import { BusStopJsonLd, BreadcrumbJsonLd } from "@/components/JsonLd";
|
||||
import { SITE_NAME, SITE_DESCRIPTION } from "@/lib/site";
|
||||
import { api } from "@/lib/api";
|
||||
import type { Metadata } from "next";
|
||||
|
||||
export const metadata = { title: "รายละเอียดป้าย" };
|
||||
type Params = { params: Promise<{ code: string }> };
|
||||
|
||||
export default async function Page({ params }: { params: Promise<{ code: string }> }) {
|
||||
/** ดึงข้อมูลป้าย (ทน backend ล่ม — คืน null) */
|
||||
async function loadStop(code: string) {
|
||||
try {
|
||||
return await api.stop(decodeURIComponent(code));
|
||||
} catch {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
export async function generateMetadata({ params }: Params): Promise<Metadata> {
|
||||
const { code } = await params;
|
||||
const stop = await loadStop(code);
|
||||
if (!stop) {
|
||||
return { title: "รายละเอียดป้าย", alternates: { canonical: `/stops/${code}` } };
|
||||
}
|
||||
const name = stop.name_th || stop.name_en || `ป้าย ${code}`;
|
||||
const place = [stop.city_th, stop.province_th].filter(Boolean).join(" · ");
|
||||
const title = `${name} (${code})`;
|
||||
const description = place
|
||||
? `${name} ${place} — สายรถที่ผ่าน จุดจอด และเวลาเดินรถถัดไป ดูได้ที่ ${SITE_NAME}`
|
||||
: `${name} — สายรถที่ผ่าน จุดจอด และเวลาเดินรถ ดูได้ที่ ${SITE_NAME}`;
|
||||
|
||||
return {
|
||||
title,
|
||||
description,
|
||||
alternates: { canonical: `/stops/${encodeURIComponent(stop.code || code)}` },
|
||||
openGraph: { type: "article", title, description, url: `/stops/${encodeURIComponent(stop.code || code)}` },
|
||||
};
|
||||
}
|
||||
|
||||
export default async function Page({ params }: Params) {
|
||||
const { code } = await params;
|
||||
const stop = await loadStop(code);
|
||||
|
||||
return (
|
||||
<>
|
||||
{stop ? (
|
||||
<>
|
||||
<BreadcrumbJsonLd
|
||||
items={[
|
||||
{ name: "หน้าแรก", path: "/" },
|
||||
{ name: "ป้ายหยุดรถ", path: "/stops" },
|
||||
{ name: stop.name_th || `ป้าย ${code}`, path: `/stops/${stop.code}` },
|
||||
]}
|
||||
/>
|
||||
<BusStopJsonLd
|
||||
name={stop.name_th || stop.name_en || `ป้าย ${code}`}
|
||||
code={stop.code || code}
|
||||
city={stop.city_th}
|
||||
province={stop.province_th}
|
||||
lat={stop.lat}
|
||||
lng={stop.lng}
|
||||
/>
|
||||
</>
|
||||
) : null}
|
||||
<StopView />
|
||||
<PageRuntime page="stop" params={{ code: decodeURIComponent(code) }} />
|
||||
</>
|
||||
|
||||
@@ -1,7 +1,11 @@
|
||||
import StopsView from "@/components/views/StopsView";
|
||||
import PageRuntime from "@/components/PageRuntime";
|
||||
|
||||
export const metadata = { title: "ป้ายหยุดรถ" };
|
||||
export const metadata = {
|
||||
title: "ป้ายหยุดรถ",
|
||||
description: "ค้นหาป้ายหยุดรถด้วยรหัส หรือค้นหาตามชื่อ จังหวัด และเส้นทางที่ผ่าน",
|
||||
alternates: { canonical: "/stops" },
|
||||
};
|
||||
|
||||
export default function Page() {
|
||||
return (
|
||||
|
||||
@@ -0,0 +1,148 @@
|
||||
/**
|
||||
* JSON-LD (structured data) — ให้บอทเข้าใจว่าเว็บนี้คืออะไร
|
||||
*
|
||||
* ทำไมสำคัญ
|
||||
* Google / Bing / Brave อ่าน JSON-LD เพื่อสร้าง rich result
|
||||
* (sitelinks searchbox, breadcrumb, ชื่อเว็บใต้ลิงก์)
|
||||
* DuckDuckGo อ่านผ่าน index ของ Bing
|
||||
*
|
||||
* กฎ
|
||||
* - ต้องเป็น server component (ไม่ใส่ "use client")
|
||||
* - ใช้ค่าจาก lib/site.ts เท่านั้น — เปลี่ยนชื่อเว็บที่ env ที่เดียว
|
||||
*/
|
||||
|
||||
import { SITE_URL, SITE_NAME, SITE_TITLE, SITE_DESCRIPTION, SITE_OG_IMAGE, absUrl } from "@/lib/site";
|
||||
|
||||
type Json = Record<string, unknown>;
|
||||
|
||||
function Script({ data }: { data: Json | Json[] }) {
|
||||
return (
|
||||
<script
|
||||
type="application/ld+json"
|
||||
// eslint-disable-next-line react/no-danger
|
||||
dangerouslySetInnerHTML={{ __html: JSON.stringify(data) }}
|
||||
/>
|
||||
);
|
||||
}
|
||||
|
||||
/** เว็บไซต์ + ช่องค้นหา + องค์กร — ใส่ครั้งเดียวใน layout */
|
||||
export function SiteJsonLd() {
|
||||
return (
|
||||
<Script
|
||||
data={[
|
||||
{
|
||||
"@context": "https://schema.org",
|
||||
"@type": "WebSite",
|
||||
"@id": `${SITE_URL}/#website`,
|
||||
url: SITE_URL,
|
||||
name: SITE_NAME,
|
||||
description: SITE_DESCRIPTION,
|
||||
inLanguage: "th-TH",
|
||||
publisher: { "@id": `${SITE_URL}/#organization` },
|
||||
// ช่องค้นหาบนหน้าเว็บ (Google sitelinks searchbox)
|
||||
potentialAction: {
|
||||
"@type": "SearchAction",
|
||||
target: {
|
||||
"@type": "EntryPoint",
|
||||
urlTemplate: `${SITE_URL}/stops?q={search_term_string}`,
|
||||
},
|
||||
"query-input": "required name=search_term_string",
|
||||
},
|
||||
},
|
||||
{
|
||||
"@context": "https://schema.org",
|
||||
"@type": "Organization",
|
||||
"@id": `${SITE_URL}/#organization`,
|
||||
name: SITE_NAME,
|
||||
url: SITE_URL,
|
||||
logo: {
|
||||
"@type": "ImageObject",
|
||||
url: absUrl("/image/icons/minibus-512x512.png"),
|
||||
width: 512,
|
||||
height: 512,
|
||||
},
|
||||
image: absUrl(SITE_OG_IMAGE),
|
||||
description: SITE_TITLE,
|
||||
},
|
||||
]}
|
||||
/>
|
||||
);
|
||||
}
|
||||
|
||||
/** ทางเดินหน้า (breadcrumb) — ขึ้นใน SERP แทน URL ดิบ */
|
||||
export function BreadcrumbJsonLd({ items }: { items: Array<{ name: string; path: string }> }) {
|
||||
return (
|
||||
<Script
|
||||
data={{
|
||||
"@context": "https://schema.org",
|
||||
"@type": "BreadcrumbList",
|
||||
itemListElement: items.map((it, i) => ({
|
||||
"@type": "ListItem",
|
||||
position: i + 1,
|
||||
name: it.name,
|
||||
item: absUrl(it.path),
|
||||
})),
|
||||
}}
|
||||
/>
|
||||
);
|
||||
}
|
||||
|
||||
/** ป้ายหยุดรถ */
|
||||
export function BusStopJsonLd(props: {
|
||||
name: string;
|
||||
code: string;
|
||||
city?: string | null;
|
||||
province?: string | null;
|
||||
lat?: number | null;
|
||||
lng?: number | null;
|
||||
}) {
|
||||
const { name, code, city, province, lat, lng } = props;
|
||||
const data: Json = {
|
||||
"@context": "https://schema.org",
|
||||
"@type": "BusStop",
|
||||
"@id": absUrl(`/stops/${encodeURIComponent(code)}`),
|
||||
name,
|
||||
identifier: code,
|
||||
url: absUrl(`/stops/${encodeURIComponent(code)}`),
|
||||
};
|
||||
if (city || province) {
|
||||
data.address = {
|
||||
"@type": "PostalAddress",
|
||||
addressLocality: city || undefined,
|
||||
addressRegion: province || undefined,
|
||||
addressCountry: "TH",
|
||||
};
|
||||
}
|
||||
if (typeof lat === "number" && typeof lng === "number") {
|
||||
data.geo = { "@type": "GeoCoordinates", latitude: lat, longitude: lng };
|
||||
}
|
||||
return <Script data={data} />;
|
||||
}
|
||||
|
||||
/** สายรถ */
|
||||
export function BusRouteJsonLd(props: {
|
||||
routeId: string;
|
||||
name: string;
|
||||
description?: string | null;
|
||||
stops?: number;
|
||||
provinces?: number;
|
||||
}) {
|
||||
const { routeId, name, description, stops, provinces } = props;
|
||||
return (
|
||||
<Script
|
||||
data={{
|
||||
"@context": "https://schema.org",
|
||||
"@type": "Service",
|
||||
"@id": absUrl(`/routes/${encodeURIComponent(routeId)}`),
|
||||
name: `สาย ${routeId} ${name}`.trim(),
|
||||
serviceType: "รถโดยสารประจำทาง",
|
||||
description: description || undefined,
|
||||
provider: { "@id": `${SITE_URL}/#organization` },
|
||||
areaServed: { "@type": "AdministrativeArea", name: "จังหวัดอ่างทอง" },
|
||||
url: absUrl(`/routes/${encodeURIComponent(routeId)}`),
|
||||
...(typeof stops === "number" ? { additionalProperty: { "@type": "PropertyValue", name: "จุดจอดหลัก", value: stops } } : {}),
|
||||
...(typeof provinces === "number" ? {} : {}),
|
||||
}}
|
||||
/>
|
||||
);
|
||||
}
|
||||
@@ -55,6 +55,14 @@ export default function CheckView() {
|
||||
</div>
|
||||
</div>
|
||||
</section>
|
||||
{/* ปุ่มแชร์หน้านี้ — ลิงก์สั้น ใช้ path ปัจจุบัน ไม่ฝังชื่อเว็บ */}
|
||||
<div className="mu-share-row">
|
||||
<button type="button" className="mu-share-btn" id="share-btn">
|
||||
<svg className="ic" aria-hidden="true"><use href="#ic-share-2" /></svg>
|
||||
<span data-i18n="share.label">แชร์หน้านี้</span>
|
||||
</button>
|
||||
<p className="mu-share-status" id="share-status" aria-live="polite" />
|
||||
</div>
|
||||
|
||||
</>
|
||||
);
|
||||
|
||||
@@ -75,11 +75,11 @@ export default function HomeView() {
|
||||
{/* หมวดเส้นทางทั้งหมด: สร้างจาก resource/data/route_groups.json + routes.json (+ routes_municipal.json)
|
||||
ที่มา: ui/partials/home.init.js → initRouteZones() — ห้าม hardcode การ์ดในไฟล์นี้ */}
|
||||
<div id="route-zones" />
|
||||
{/* ปุ่มแชร์ลิงก์สั้น (มุมล่างขวา ต่อจากการ์ดหมวดเส้นทางภายในจังหวัด) */}
|
||||
{/* ปุ่มแชร์หน้านี้ (มุมล่างขวา ต่อจากการ์ดหมวดเส้นทางภายในจังหวัด) */}
|
||||
<div className="mu-share-row">
|
||||
<button type="button" className="mu-share-btn" id="share-btn">
|
||||
<svg className="ic" aria-hidden="true"><use href="#ic-share-2" /></svg>
|
||||
<span data-i18n="share.label">แชร์ลิงก์สั้น</span>
|
||||
<span data-i18n="share.label">แชร์หน้านี้</span>
|
||||
</button>
|
||||
<p className="mu-share-status" id="share-status" aria-live="polite" />
|
||||
</div>
|
||||
|
||||
@@ -48,6 +48,14 @@ export default function RouteView() {
|
||||
</div>
|
||||
</div>
|
||||
</section>
|
||||
{/* ปุ่มแชร์หน้านี้ — ลิงก์สั้น ใช้ path ปัจจุบัน ไม่ฝังชื่อเว็บ */}
|
||||
<div className="mu-share-row">
|
||||
<button type="button" className="mu-share-btn" id="share-btn">
|
||||
<svg className="ic" aria-hidden="true"><use href="#ic-share-2" /></svg>
|
||||
<span data-i18n="share.label">แชร์หน้านี้</span>
|
||||
</button>
|
||||
<p className="mu-share-status" id="share-status" aria-live="polite" />
|
||||
</div>
|
||||
</div>
|
||||
</main>
|
||||
|
||||
|
||||
@@ -47,6 +47,15 @@ export default function StopView() {
|
||||
<div id="stop-chips" style={{display: 'flex', flexWrap: 'wrap', gap: 8, marginTop: 14}} />
|
||||
</aside>
|
||||
</section>
|
||||
<div id="share-probe-marker" />
|
||||
{/* ปุ่มแชร์หน้านี้ — จำตัวกรองสายรถที่เลือกอยู่ลงลิงก์ */}
|
||||
<div className="mu-share-row">
|
||||
<button type="button" className="mu-share-btn" id="share-btn">
|
||||
<svg className="ic" aria-hidden="true"><use href="#ic-share-2" /></svg>
|
||||
<span data-i18n="share.label">แชร์หน้านี้</span>
|
||||
</button>
|
||||
<p className="mu-share-status" id="share-status" aria-live="polite" />
|
||||
</div>
|
||||
</div>
|
||||
</main>
|
||||
|
||||
|
||||
@@ -89,7 +89,7 @@
|
||||
"home.lead": "Browse routes, find stops, and preview a route right from this page",
|
||||
"home.chooseProvince": "Select Province",
|
||||
"home.chooseStation": "Select Terminal",
|
||||
"share.label": "Share short link",
|
||||
"share.label": "Share this page",
|
||||
"share.copied": "Link copied",
|
||||
"share.short": "Short link",
|
||||
"share.line": "Share on LINE",
|
||||
|
||||
@@ -89,7 +89,7 @@
|
||||
"home.lead": "ดูสายรถ, ค้นหาป้าย และเปิดตัวอย่างเส้นทางได้ทันทีจากหน้าแรก",
|
||||
"home.chooseProvince": "เลือกจังหวัด",
|
||||
"home.chooseStation": "เลือกสถานีขนส่งผู้โดยสาร",
|
||||
"share.label": "แชร์ลิงก์สั้น",
|
||||
"share.label": "แชร์หน้านี้",
|
||||
"share.copied": "คัดลอกลิงก์แล้ว",
|
||||
"share.short": "ลิงก์สั้น",
|
||||
"share.line": "แชร์ผ่าน LINE",
|
||||
|
||||
@@ -29,6 +29,11 @@ export function ensureRuntime(): Promise<void> {
|
||||
await import("./ui/schedules");
|
||||
await import("./ui/otherStop");
|
||||
|
||||
/* ตัวกลางลิงก์แชร์ — ต้องพร้อมก่อนหน้าไหนจะกดแชร์ */
|
||||
const share = await import("./share");
|
||||
(window as unknown as { AtShare?: unknown }).AtShare = share;
|
||||
await import("./ui/share.init");
|
||||
|
||||
const w = window as unknown as {
|
||||
I18N?: { ready?: Promise<unknown>; apply?: () => void };
|
||||
};
|
||||
@@ -69,4 +74,6 @@ export async function mountPage(
|
||||
const mod = await load();
|
||||
mod.default();
|
||||
w.I18N?.apply?.();
|
||||
/* ผูกปุ่ม "แชร์หน้านี้" หลัง DOM ของหน้าเรนเดอร์เสร็จ */
|
||||
(window as unknown as { AtShareInit?: () => void }).AtShareInit?.();
|
||||
}
|
||||
@@ -0,0 +1,88 @@
|
||||
/**
|
||||
* Atroute — ลิงก์แชร์ (ตัวกลาง)
|
||||
*
|
||||
* เป้าหมาย
|
||||
* 1) สั้น — ใช้ querystring key สั้น ไม่ยัด JSON/base64
|
||||
* 2) ไม่ฝังชื่อเว็บ — ใช้ location.origin + location.pathname
|
||||
* → ปีหน้าเปลี่ยนชื่อเว็บ/โดเมน ลิงก์เก่าที่แชร์ไปแล้วยังเปิดได้ที่โดเมนเดิม
|
||||
* และลิงก์ใหม่สร้างจากโดเมนที่ผู้ใช้กำลังเปิดอยู่โดยอัตโนมัติ
|
||||
* 3) จำสถานะ — เก็บ "ตัวกรองที่ผู้ใช้เลือกอยู่" ณ ขณะกดแชร์ลงในลิงก์
|
||||
*
|
||||
* กติกา key ต่อหน้า (สั้น อ่านรู้เรื่อง)
|
||||
* / ?s=<station_code> เลือกสถานีอยู่
|
||||
* ?p=<province_id> เลือกจังหวัดอยู่
|
||||
* /stops/:code ?q=<ข้อความค้นหา> กรองสายรถในป้ายนั้น
|
||||
* /routes/:id — อยู่ใน path แล้ว
|
||||
* /check/:id — อยู่ใน path แล้ว
|
||||
*
|
||||
* หมายเหตุ: ค่าที่เป็นค่าเริ่มต้น (ว่าง/0/'all') จะไม่ถูกใส่ลิงก์ → ลิงก์สั้นที่สุด
|
||||
*/
|
||||
|
||||
export type ShareState = Record<string, string | number | null | undefined>;
|
||||
|
||||
/** key ที่ยอมรับได้ต่อหน้า — กันไม่ให้ query แปลกปลอมหลุดเข้า state */
|
||||
export const SHARE_KEYS = ["s", "p", "q"] as const;
|
||||
export type ShareKey = (typeof SHARE_KEYS)[number];
|
||||
|
||||
/** ค่าที่ถือว่า "ไม่มีอะไรต้องแชร์" → ไม่ต้องใส่ใน query */
|
||||
function isEmpty(v: unknown): boolean {
|
||||
if (v === null || v === undefined) return true;
|
||||
const s = String(v).trim();
|
||||
return s === "" || s === "all" || s === "0";
|
||||
}
|
||||
|
||||
/**
|
||||
* สร้างลิงก์แชร์จากที่อยู่ปัจจุบัน + state ที่ส่งมา
|
||||
* - ใช้ origin/pathname ของผู้ใช้ → เปลี่ยนชื่อเว็บแล้วไม่พัง
|
||||
* - ตัด trailing `/index.html` เผื่อรันแบบ static
|
||||
*/
|
||||
export function buildShareUrl(state?: ShareState): string {
|
||||
const origin = typeof window !== "undefined" ? window.location.origin : "";
|
||||
const path =
|
||||
typeof window !== "undefined"
|
||||
? window.location.pathname.replace(/\/index\.html$/, "")
|
||||
: "/";
|
||||
|
||||
const parts: string[] = [];
|
||||
if (state) {
|
||||
for (const k of SHARE_KEYS) {
|
||||
const v = state[k];
|
||||
if (isEmpty(v)) continue;
|
||||
parts.push(encodeURIComponent(k) + "=" + encodeURIComponent(String(v).trim()));
|
||||
}
|
||||
}
|
||||
|
||||
const qs = parts.length ? "?" + parts.join("&") : "";
|
||||
return origin + (path || "/") + qs;
|
||||
}
|
||||
|
||||
/** อ่าน state จาก query ปัจจุบัน — คืนเฉพาะ key ที่รู้จัก */
|
||||
export function readShareState(): Partial<Record<ShareKey, string>> {
|
||||
if (typeof window === "undefined") return {};
|
||||
const out: Partial<Record<ShareKey, string>> = {};
|
||||
try {
|
||||
const sp = new URLSearchParams(window.location.search);
|
||||
for (const k of SHARE_KEYS) {
|
||||
const v = sp.get(k);
|
||||
if (v != null && v !== "") out[k] = v;
|
||||
}
|
||||
} catch {
|
||||
/* เพิกเฉย — query เพี้ยน */
|
||||
}
|
||||
return out;
|
||||
}
|
||||
|
||||
/**
|
||||
* เขียน state ลง URL แบบไม่ reload ไม่เพิ่ม history
|
||||
* ใช้เมื่อผู้ใช้เปลี่ยนตัวกรอง → แชร์/บุ๊กมาร์กได้ตรงสถานะล่าสุด
|
||||
* และคัดลอกลิงก์จาก omnibox ได้ด้วย
|
||||
*/
|
||||
export function syncShareState(state: ShareState): void {
|
||||
if (typeof window === "undefined" || !window.history?.replaceState) return;
|
||||
try {
|
||||
const url = buildShareUrl(state);
|
||||
window.history.replaceState(window.history.state, "", url);
|
||||
} catch {
|
||||
/* เพิกเฉย */
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,51 @@
|
||||
/**
|
||||
* Atroute — ค่าคงที่ของเว็บ (SEO / meta / sitemap / robots)
|
||||
*
|
||||
* ทำไมต้องมีไฟล์นี้
|
||||
* ปีหน้าจะเปลี่ยนชื่อเว็บ — ทุกอย่างที่อ้างชื่อ/โดเมนให้ดึงจากที่นี่ที่เดียว
|
||||
* เปลี่ยนชื่อ = แก้ `NEXT_PUBLIC_SITE_NAME` + `NEXT_PUBLIC_SITE_URL` ใน .env
|
||||
* ไม่ต้องแก้โค้ด (สอดคล้องกับระบบลิงก์แชร์ที่ไม่ฝังชื่อเว็บไว้ใน URL)
|
||||
*/
|
||||
|
||||
const rawUrl = (process.env.NEXT_PUBLIC_SITE_URL || "").replace(/\/+$/, "");
|
||||
|
||||
/** โดเมนจริงของเว็บ — ใช้ทำ canonical / OG / sitemap */
|
||||
export const SITE_URL = rawUrl || "http://localhost:3100";
|
||||
|
||||
/** ชื่อแบรนด์ — เปลี่ยนได้ที่ env */
|
||||
export const SITE_NAME = process.env.NEXT_PUBLIC_SITE_NAME || "Atroute";
|
||||
|
||||
/** ชื่อเต็มที่ขึ้นใน <title> และ OG */
|
||||
export const SITE_TITLE = `${SITE_NAME} — สถานีขนส่งผู้โดยสารจังหวัดอ่างทอง`;
|
||||
|
||||
/** คำอธิบายมาตรฐาน (ความยาว ~150 ตัวอักษร เหมาะกับ SERP) */
|
||||
export const SITE_DESCRIPTION =
|
||||
"ตารางเดินรถ รหัสป้าย จุดจอด และเส้นทางรถโดยสารในจังหวัดอ่างทองและจังหวัดใกล้เคียง ดูเวลาเที่ยวถัดไปได้ทันที";
|
||||
|
||||
/** ภาษาหลักของหน้า (หน้าเว็บสลับ TH/EN ด้วยตัวเอง ไม่มี path แยก) */
|
||||
export const SITE_LOCALE = "th_TH";
|
||||
|
||||
/** รูป OG มาตรฐาน (1200×630) */
|
||||
export const SITE_OG_IMAGE = "/og-image.png";
|
||||
|
||||
/** พาธที่ไม่อยากให้บอทเก็บ (API + ไฟล์ไบนารี + หน้าดิบ) */
|
||||
export const DISALLOW_PATHS = ["/api/", "/files/", "/offline.html"];
|
||||
|
||||
/** หน้าคงที่ที่ควรอยู่ใน sitemap (path, changefreq, priority) */
|
||||
export const STATIC_PAGES: Array<{
|
||||
path: string;
|
||||
changeFrequency: "daily" | "weekly" | "monthly";
|
||||
priority: number;
|
||||
}> = [
|
||||
{ path: "/", changeFrequency: "daily", priority: 1.0 },
|
||||
{ path: "/routes", changeFrequency: "daily", priority: 0.9 },
|
||||
{ path: "/stops", changeFrequency: "daily", priority: 0.9 },
|
||||
{ path: "/blog", changeFrequency: "weekly", priority: 0.6 },
|
||||
{ path: "/about", changeFrequency: "monthly", priority: 0.5 },
|
||||
{ path: "/credits", changeFrequency: "monthly", priority: 0.3 },
|
||||
];
|
||||
|
||||
/** ต่อ path กับโดเมนให้เป็น URL เต็ม */
|
||||
export function absUrl(path: string): string {
|
||||
return SITE_URL + (path.startsWith("/") ? path : "/" + path);
|
||||
}
|
||||
@@ -317,7 +317,8 @@ function nm(o: any, base: string): string {
|
||||
host.appendChild(zoneSection(g, mine, ZDATA.timesByRoute, tr));
|
||||
});
|
||||
|
||||
if (shareRefresh) shareRefresh(); /* อัปเดตลิงก์สั้นตามที่เลือก */
|
||||
refreshShareLink(); /* อัปเดตลิงก์แชร์ตามที่เลือก */
|
||||
syncHomeUrl(); /* เขียนสถานะลง URL ตรง ๆ */
|
||||
if (!zoneTimer && chipSlots.length) {
|
||||
zoneTimer = setInterval(refreshChips, 60000);
|
||||
document.addEventListener('visibilitychange', function () {
|
||||
@@ -328,7 +329,7 @@ function nm(o: any, base: string): string {
|
||||
}
|
||||
|
||||
var zoneTimer = null;
|
||||
var shareRefresh = null;
|
||||
/* ตัวอัปเดตลิงก์แชร์ — ใช้ AtShare.refresh() จาก share.init.ts */
|
||||
|
||||
function zoneSection(group, allRoutes, timesByRoute, tr) {
|
||||
var meta = GROUP_META[group.route_group] || {};
|
||||
@@ -421,55 +422,35 @@ function nm(o: any, base: string): string {
|
||||
}
|
||||
|
||||
/* ============================================================
|
||||
ลิงก์สั้นสำหรับแชร์ (ส่งไลน์หากัน)
|
||||
#/?s=<รหัสสถานี> = เปิดหน้าแรกพร้อมเลือกสถานีนั้น
|
||||
#/?p=<province_id> = เปิดพร้อมเลือกจังหวัด
|
||||
ลิงก์แชร์ — ใช้ตัวกลาง lib/ui/share.init.ts
|
||||
หน้านี้แค่บอกสถานะที่ผู้ใช้เลือกอยู่ (สถานี/จังหวัด)
|
||||
รูปแบบลิงก์: <origin>/ ? s=<รหัสสถานี> หรือ ? p=<province_id>
|
||||
ไม่ฝังชื่อเว็บ → เปลี่ยนชื่อเว็บปีหน้าแล้วลิงก์ยังใช้ได้
|
||||
============================================================ */
|
||||
function shortUrl() {
|
||||
var base = location.origin + location.pathname.replace(/index\.html$/, '');
|
||||
var q = state.stationCode ? 's=' + encodeURIComponent(state.stationCode)
|
||||
: (state.provinceId ? 'p=' + state.provinceId : '');
|
||||
return base + (q ? '/?' + q : '/');
|
||||
(window as any).AtHomeState = function () {
|
||||
var out = {};
|
||||
if (state.stationCode) out.s = state.stationCode;
|
||||
else if (state.provinceId) out.p = state.provinceId;
|
||||
return out;
|
||||
};
|
||||
|
||||
/* เขียนตัวเลือกที่ใช้อยู่ลง URL (ไม่ reload) → คัดลอกลิงก์จาก omnibox ได้ตรงสถานะ */
|
||||
function syncHomeUrl() {
|
||||
var S = (window as any).AtShare;
|
||||
if (S && S.syncShareState) S.syncShareState((window as any).AtHomeState());
|
||||
}
|
||||
|
||||
function initShare() {
|
||||
var btn = document.getElementById('share-btn');
|
||||
var status = document.getElementById('share-status');
|
||||
if (!btn) return;
|
||||
var tr = window.I18N ? window.I18N.t : function (k) { return k; };
|
||||
|
||||
function paint(msg) {
|
||||
if (!status) return;
|
||||
status.innerHTML = esc(msg) + ' <code class="mu-share-url">' + esc(shortUrl()) + '</code> ' +
|
||||
'<a class="mu-share-line" href="https://social-plugins.line.me/lineit/share?url=' +
|
||||
encodeURIComponent(shortUrl()) + '" target="_blank" rel="noopener">' + esc(tr('share.line')) + '</a>';
|
||||
}
|
||||
|
||||
shareRefresh = function () { if (status && status.dataset.shown) paint(status.dataset.msg || ''); };
|
||||
|
||||
btn.addEventListener('click', function () {
|
||||
var url = shortUrl();
|
||||
if (navigator.share) {
|
||||
navigator.share({ title: document.title, url: url }).catch(function () { /* ผู้ใช้ยกเลิก */ });
|
||||
}
|
||||
if (navigator.clipboard && navigator.clipboard.writeText) {
|
||||
navigator.clipboard.writeText(url).then(function () {
|
||||
status.dataset.shown = '1'; status.dataset.msg = tr('share.copied'); paint(tr('share.copied'));
|
||||
}, function () {
|
||||
status.dataset.shown = '1'; status.dataset.msg = tr('share.short'); paint(tr('share.short'));
|
||||
});
|
||||
} else {
|
||||
status.dataset.shown = '1'; status.dataset.msg = tr('share.short'); paint(tr('share.short'));
|
||||
}
|
||||
});
|
||||
function refreshShareLink() {
|
||||
var S = (window as any).AtShare;
|
||||
if (S && S.refresh) S.refresh();
|
||||
}
|
||||
|
||||
initHomeSelectors();
|
||||
initHomeSelectors();
|
||||
initSponsors().then(initMarquee); /* เติมไทล์จาก JSON ก่อน แล้วค่อย clone (ไม่งั้นไทล์ที่เพิ่มจะไม่ถูก clone) */
|
||||
initShare();
|
||||
refreshShareLink();
|
||||
|
||||
export default function mount(): void {
|
||||
initHomeSelectors();
|
||||
initSponsors().then(initMarquee);
|
||||
initShare();
|
||||
refreshShareLink();
|
||||
}
|
||||
@@ -0,0 +1,141 @@
|
||||
/**
|
||||
* Atroute — ปุ่ม "แชร์หน้านี้" (ใช้ร่วมทุกหน้า)
|
||||
*
|
||||
* หลักการ
|
||||
* - ปุ่มคือ [id="share-btn"] ในหน้านั้น (มีหลายหน้าวางปุ่มตัวเดียวกัน)
|
||||
* - ตอนกด จะรวบรวม "สถานะที่ผู้ใช้กำลังเลือกอยู่" ของหน้านั้น แล้วสร้างลิงก์สั้น
|
||||
* - ใช้ navigator.share ถ้ามี (มือถือ) + คัดลอกลงคลิปบอร์ดพร้อมกัน
|
||||
*
|
||||
* สถานะที่เก็บต่อหน้า
|
||||
* / → s = รหัสสถานีที่เลือก, p = province_id
|
||||
* /stops/:code → q = ข้อความในช่องค้นหาสายรถ
|
||||
* /routes/:id → อยู่ใน path แล้ว ไม่ต้องใส่ query
|
||||
* /check/:id → อยู่ใน path แล้ว ไม่ต้องใส่ query
|
||||
*
|
||||
* ดึง buildShareUrl/readShareState/syncShareState จาก lib/share.ts ผ่าน window.AtShare
|
||||
* (ตั้งค่าไว้ใน lib/runtime.ts)
|
||||
*/
|
||||
export {}; /* ทำให้ไฟล์นี้เป็น ES module (runtime.ts import ได้) */
|
||||
|
||||
(function () {
|
||||
"use strict";
|
||||
|
||||
var AtShare = (window as any).AtShare;
|
||||
if (!AtShare) return;
|
||||
|
||||
function t(key: string): string {
|
||||
return (window as any).I18N ? (window as any).I18N.t(key) : key;
|
||||
}
|
||||
function esc(v: unknown): string {
|
||||
return String(v == null ? "" : v)
|
||||
.replace(/&/g, "&")
|
||||
.replace(/</g, "<")
|
||||
.replace(/>/g, ">")
|
||||
.replace(/"/g, """)
|
||||
.replace(/'/g, "'");
|
||||
}
|
||||
|
||||
/** หน้าแรก: อ่านสถานี/จังหวัดที่ผู้ใช้เลือกอยู่จริงจาก DOM */
|
||||
function homeState(): Record<string, string> {
|
||||
/* หน้าแรกประกาศ getter ไว้แล้ว (home.init.ts) — ใช้ก่อนเสมอ */
|
||||
if (typeof (window as any).AtHomeState === "function") {
|
||||
return (window as any).AtHomeState() || {};
|
||||
}
|
||||
var out: Record<string, string> = {};
|
||||
var sel = document.querySelector("[data-home-station].is-active, #home-station-select") as HTMLElement | null;
|
||||
var code = sel && (sel as any).dataset ? (sel as any).dataset.homeStation : "";
|
||||
if (code) out.s = String(code);
|
||||
|
||||
var prov = document.querySelector("[data-home-province].is-active") as HTMLElement | null;
|
||||
var pid = prov && (prov as any).dataset ? (prov as any).dataset.homeProvince : "";
|
||||
if (pid) out.p = String(pid);
|
||||
return out;
|
||||
}
|
||||
|
||||
/** /stops/:code: เก็บข้อความค้นหาสายรถ */
|
||||
function stopsState(): Record<string, string> {
|
||||
var out: Record<string, string> = {};
|
||||
var input = document.getElementById("mu-route-filter") as HTMLInputElement | null;
|
||||
if (input && input.value.trim()) out.q = input.value.trim();
|
||||
return out;
|
||||
}
|
||||
|
||||
/** เลือกชุด state ตาม path ปัจจุบัน — ไม่ผูกกับชื่อโดเมน */
|
||||
function collectState(): Record<string, string> {
|
||||
var path = window.location.pathname.replace(/\/index\.html$/, "");
|
||||
if (/^\/stops\/[^/]+/.test(path)) return stopsState();
|
||||
if (path === "/" || path === "") return homeState();
|
||||
return {}; /* routes/:id, check/:id → path พอแล้ว */
|
||||
}
|
||||
|
||||
function shareUrlNow(): string {
|
||||
return AtShare.buildShareUrl(collectState());
|
||||
}
|
||||
|
||||
function initShare(): void {
|
||||
var btn = document.getElementById("share-btn");
|
||||
var status = document.getElementById("share-status");
|
||||
if (!btn) return;
|
||||
|
||||
function paint(msg: string): void {
|
||||
if (!status) return;
|
||||
var url = shareUrlNow();
|
||||
status.innerHTML =
|
||||
esc(msg) +
|
||||
' <code class="mu-share-url">' + esc(url) + "</code> " +
|
||||
'<a class="mu-share-line" href="https://social-plugins.line.me/lineit/share?url=' +
|
||||
encodeURIComponent(url) +
|
||||
'" target="_blank" rel="noopener">' + esc(t("share.line")) + "</a>";
|
||||
status.dataset.shown = "1";
|
||||
status.dataset.msg = msg;
|
||||
}
|
||||
|
||||
/* ให้หน้าอื่นเรียกอัปเดตได้เมื่อตัวกรองเปลี่ยน */
|
||||
(window as any).AtShare.refresh = function () {
|
||||
if (status && status.dataset.shown) paint(status.dataset.msg || "");
|
||||
};
|
||||
|
||||
btn.addEventListener("click", function () {
|
||||
var url = shareUrlNow();
|
||||
|
||||
if ((navigator as any).share) {
|
||||
(navigator as any).share({ title: document.title, url: url }).catch(function () {
|
||||
/* ผู้ใช้ยกเลิก — ไม่ต้องแจ้ง */
|
||||
});
|
||||
}
|
||||
|
||||
function done(ok: boolean): void {
|
||||
paint(ok ? t("share.copied") : t("share.short"));
|
||||
}
|
||||
|
||||
if (navigator.clipboard && navigator.clipboard.writeText) {
|
||||
navigator.clipboard.writeText(url).then(
|
||||
function () { done(true); },
|
||||
function () { legacyCopy(url); done(false); }
|
||||
);
|
||||
} else {
|
||||
legacyCopy(url);
|
||||
done(false);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
/* คัดลอกแบบเก่า — เบราว์เซอร์ไม่รองรับ Clipboard API หรือไม่ได้ https */
|
||||
function legacyCopy(text: string): void {
|
||||
try {
|
||||
var ta = document.createElement("textarea");
|
||||
ta.value = text;
|
||||
ta.setAttribute("readonly", "");
|
||||
ta.style.position = "fixed";
|
||||
ta.style.top = "-1000px";
|
||||
document.body.appendChild(ta);
|
||||
ta.select();
|
||||
document.execCommand("copy");
|
||||
document.body.removeChild(ta);
|
||||
} catch {
|
||||
/* เพิกเฉย */
|
||||
}
|
||||
}
|
||||
|
||||
(window as any).AtShareInit = initShare;
|
||||
})();
|
||||
@@ -346,8 +346,27 @@ function nm(o: any, base: string): string {
|
||||
var input = $('mu-route-filter');
|
||||
if (input && !input.dataset.bound) {
|
||||
input.dataset.bound = '1';
|
||||
input.addEventListener('input', applyFilter);
|
||||
input.addEventListener('input', function () {
|
||||
applyFilter();
|
||||
/* จำคำค้นหาลง URL → แชร์/บุ๊กมาร์กได้ตรงสถานะล่าสุด */
|
||||
var S = (window as any).AtShare;
|
||||
if (S && S.syncShareState) S.syncShareState({ q: input.value.trim() });
|
||||
if (S && S.refresh) S.refresh();
|
||||
});
|
||||
}
|
||||
restoreFilterFromUrl();
|
||||
}
|
||||
|
||||
/* อ่าน ?q= จากลิงก์ที่แชร์มา แล้วเติมช่องค้นหา + กรองทันที */
|
||||
function restoreFilterFromUrl() {
|
||||
var input = $('mu-route-filter');
|
||||
if (!input) return;
|
||||
var S = (window as any).AtShare;
|
||||
if (!S || !S.readShareState) return;
|
||||
var st = S.readShareState();
|
||||
if (!st || !st.q) return;
|
||||
input.value = st.q;
|
||||
applyFilter();
|
||||
}
|
||||
|
||||
/* ---------- ไฮไลต์เที่ยวถัดไป + นาฬิกา (เดิมอยู่ใน partial) ---------- */
|
||||
|
||||
@@ -1 +1 @@
|
||||
{"fileNames":["./node_modules/typescript/lib/lib.es5.d.ts","./node_modules/typescript/lib/lib.es2015.d.ts","./node_modules/typescript/lib/lib.es2016.d.ts","./node_modules/typescript/lib/lib.es2017.d.ts","./node_modules/typescript/lib/lib.es2018.d.ts","./node_modules/typescript/lib/lib.es2019.d.ts","./node_modules/typescript/lib/lib.es2020.d.ts","./node_modules/typescript/lib/lib.es2021.d.ts","./node_modules/typescript/lib/lib.es2022.d.ts","./node_modules/typescript/lib/lib.es2023.d.ts","./node_modules/typescript/lib/lib.es2024.d.ts","./node_modules/typescript/lib/lib.esnext.d.ts","./node_modules/typescript/lib/lib.dom.d.ts","./node_modules/typescript/lib/lib.dom.iterable.d.ts","./node_modules/typescript/lib/lib.es2015.core.d.ts","./node_modules/typescript/lib/lib.es2015.collection.d.ts","./node_modules/typescript/lib/lib.es2015.generator.d.ts","./node_modules/typescript/lib/lib.es2015.iterable.d.ts","./node_modules/typescript/lib/lib.es2015.promise.d.ts","./node_modules/typescript/lib/lib.es2015.proxy.d.ts","./node_modules/typescript/lib/lib.es2015.reflect.d.ts","./node_modules/typescript/lib/lib.es2015.symbol.d.ts","./node_modules/typescript/lib/lib.es2015.symbol.wellknown.d.ts","./node_modules/typescript/lib/lib.es2016.array.include.d.ts","./node_modules/typescript/lib/lib.es2016.intl.d.ts","./node_modules/typescript/lib/lib.es2017.arraybuffer.d.ts","./node_modules/typescript/lib/lib.es2017.date.d.ts","./node_modules/typescript/lib/lib.es2017.object.d.ts","./node_modules/typescript/lib/lib.es2017.sharedmemory.d.ts","./node_modules/typescript/lib/lib.es2017.string.d.ts","./node_modules/typescript/lib/lib.es2017.intl.d.ts","./node_modules/typescript/lib/lib.es2017.typedarrays.d.ts","./node_modules/typescript/lib/lib.es2018.asyncgenerator.d.ts","./node_modules/typescript/lib/lib.es2018.asynciterable.d.ts","./node_modules/typescript/lib/lib.es2018.intl.d.ts","./node_modules/typescript/lib/lib.es2018.promise.d.ts","./node_modules/typescript/lib/lib.es2018.regexp.d.ts","./node_modules/typescript/lib/lib.es2019.array.d.ts","./node_modules/typescript/lib/lib.es2019.object.d.ts","./node_modules/typescript/lib/lib.es2019.string.d.ts","./node_modules/typescript/lib/lib.es2019.symbol.d.ts","./node_modules/typescript/lib/lib.es2019.intl.d.ts","./node_modules/typescript/lib/lib.es2020.bigint.d.ts","./node_modules/typescript/lib/lib.es2020.date.d.ts","./node_modules/typescript/lib/lib.es2020.promise.d.ts","./node_modules/typescript/lib/lib.es2020.sharedmemory.d.ts","./node_modules/typescript/lib/lib.es2020.string.d.ts","./node_modules/typescript/lib/lib.es2020.symbol.wellknown.d.ts","./node_modules/typescript/lib/lib.es2020.intl.d.ts","./node_modules/typescript/lib/lib.es2020.number.d.ts","./node_modules/typescript/lib/lib.es2021.promise.d.ts","./node_modules/typescript/lib/lib.es2021.string.d.ts","./node_modules/typescript/lib/lib.es2021.weakref.d.ts","./node_modules/typescript/lib/lib.es2021.intl.d.ts","./node_modules/typescript/lib/lib.es2022.array.d.ts","./node_modules/typescript/lib/lib.es2022.error.d.ts","./node_modules/typescript/lib/lib.es2022.intl.d.ts","./node_modules/typescript/lib/lib.es2022.object.d.ts","./node_modules/typescript/lib/lib.es2022.string.d.ts","./node_modules/typescript/lib/lib.es2022.regexp.d.ts","./node_modules/typescript/lib/lib.es2023.array.d.ts","./node_modules/typescript/lib/lib.es2023.collection.d.ts","./node_modules/typescript/lib/lib.es2023.intl.d.ts","./node_modules/typescript/lib/lib.es2024.arraybuffer.d.ts","./node_modules/typescript/lib/lib.es2024.collection.d.ts","./node_modules/typescript/lib/lib.es2024.object.d.ts","./node_modules/typescript/lib/lib.es2024.promise.d.ts","./node_modules/typescript/lib/lib.es2024.regexp.d.ts","./node_modules/typescript/lib/lib.es2024.sharedmemory.d.ts","./node_modules/typescript/lib/lib.es2024.string.d.ts","./node_modules/typescript/lib/lib.esnext.array.d.ts","./node_modules/typescript/lib/lib.esnext.collection.d.ts","./node_modules/typescript/lib/lib.esnext.intl.d.ts","./node_modules/typescript/lib/lib.esnext.disposable.d.ts","./node_modules/typescript/lib/lib.esnext.promise.d.ts","./node_modules/typescript/lib/lib.esnext.decorators.d.ts","./node_modules/typescript/lib/lib.esnext.iterator.d.ts","./node_modules/typescript/lib/lib.esnext.float16.d.ts","./node_modules/typescript/lib/lib.esnext.error.d.ts","./node_modules/typescript/lib/lib.esnext.sharedmemory.d.ts","./node_modules/typescript/lib/lib.decorators.d.ts","./node_modules/typescript/lib/lib.decorators.legacy.d.ts","./node_modules/@types/react/global.d.ts","./node_modules/csstype/index.d.ts","./node_modules/@types/prop-types/index.d.ts","./node_modules/@types/react/index.d.ts","./node_modules/next/dist/styled-jsx/types/css.d.ts","./node_modules/next/dist/styled-jsx/types/macro.d.ts","./node_modules/next/dist/styled-jsx/types/style.d.ts","./node_modules/next/dist/styled-jsx/types/global.d.ts","./node_modules/next/dist/styled-jsx/types/index.d.ts","./node_modules/next/dist/server/get-page-fLine truncated
|
||||
{"fileNames":["./node_modules/typescript/lib/lib.es5.d.ts","./node_modules/typescript/lib/lib.es2015.d.ts","./node_modules/typescript/lib/lib.es2016.d.ts","./node_modules/typescript/lib/lib.es2017.d.ts","./node_modules/typescript/lib/lib.es2018.d.ts","./node_modules/typescript/lib/lib.es2019.d.ts","./node_modules/typescript/lib/lib.es2020.d.ts","./node_modules/typescript/lib/lib.es2021.d.ts","./node_modules/typescript/lib/lib.es2022.d.ts","./node_modules/typescript/lib/lib.es2023.d.ts","./node_modules/typescript/lib/lib.es2024.d.ts","./node_modules/typescript/lib/lib.esnext.d.ts","./node_modules/typescript/lib/lib.dom.d.ts","./node_modules/typescript/lib/lib.dom.iterable.d.ts","./node_modules/typescript/lib/lib.es2015.core.d.ts","./node_modules/typescript/lib/lib.es2015.collection.d.ts","./node_modules/typescript/lib/lib.es2015.generator.d.ts","./node_modules/typescript/lib/lib.es2015.iterable.d.ts","./node_modules/typescript/lib/lib.es2015.promise.d.ts","./node_modules/typescript/lib/lib.es2015.proxy.d.ts","./node_modules/typescript/lib/lib.es2015.reflect.d.ts","./node_modules/typescript/lib/lib.es2015.symbol.d.ts","./node_modules/typescript/lib/lib.es2015.symbol.wellknown.d.ts","./node_modules/typescript/lib/lib.es2016.array.include.d.ts","./node_modules/typescript/lib/lib.es2016.intl.d.ts","./node_modules/typescript/lib/lib.es2017.arraybuffer.d.ts","./node_modules/typescript/lib/lib.es2017.date.d.ts","./node_modules/typescript/lib/lib.es2017.object.d.ts","./node_modules/typescript/lib/lib.es2017.sharedmemory.d.ts","./node_modules/typescript/lib/lib.es2017.string.d.ts","./node_modules/typescript/lib/lib.es2017.intl.d.ts","./node_modules/typescript/lib/lib.es2017.typedarrays.d.ts","./node_modules/typescript/lib/lib.es2018.asyncgenerator.d.ts","./node_modules/typescript/lib/lib.es2018.asynciterable.d.ts","./node_modules/typescript/lib/lib.es2018.intl.d.ts","./node_modules/typescript/lib/lib.es2018.promise.d.ts","./node_modules/typescript/lib/lib.es2018.regexp.d.ts","./node_modules/typescript/lib/lib.es2019.array.d.ts","./node_modules/typescript/lib/lib.es2019.object.d.ts","./node_modules/typescript/lib/lib.es2019.string.d.ts","./node_modules/typescript/lib/lib.es2019.symbol.d.ts","./node_modules/typescript/lib/lib.es2019.intl.d.ts","./node_modules/typescript/lib/lib.es2020.bigint.d.ts","./node_modules/typescript/lib/lib.es2020.date.d.ts","./node_modules/typescript/lib/lib.es2020.promise.d.ts","./node_modules/typescript/lib/lib.es2020.sharedmemory.d.ts","./node_modules/typescript/lib/lib.es2020.string.d.ts","./node_modules/typescript/lib/lib.es2020.symbol.wellknown.d.ts","./node_modules/typescript/lib/lib.es2020.intl.d.ts","./node_modules/typescript/lib/lib.es2020.number.d.ts","./node_modules/typescript/lib/lib.es2021.promise.d.ts","./node_modules/typescript/lib/lib.es2021.string.d.ts","./node_modules/typescript/lib/lib.es2021.weakref.d.ts","./node_modules/typescript/lib/lib.es2021.intl.d.ts","./node_modules/typescript/lib/lib.es2022.array.d.ts","./node_modules/typescript/lib/lib.es2022.error.d.ts","./node_modules/typescript/lib/lib.es2022.intl.d.ts","./node_modules/typescript/lib/lib.es2022.object.d.ts","./node_modules/typescript/lib/lib.es2022.string.d.ts","./node_modules/typescript/lib/lib.es2022.regexp.d.ts","./node_modules/typescript/lib/lib.es2023.array.d.ts","./node_modules/typescript/lib/lib.es2023.collection.d.ts","./node_modules/typescript/lib/lib.es2023.intl.d.ts","./node_modules/typescript/lib/lib.es2024.arraybuffer.d.ts","./node_modules/typescript/lib/lib.es2024.collection.d.ts","./node_modules/typescript/lib/lib.es2024.object.d.ts","./node_modules/typescript/lib/lib.es2024.promise.d.ts","./node_modules/typescript/lib/lib.es2024.regexp.d.ts","./node_modules/typescript/lib/lib.es2024.sharedmemory.d.ts","./node_modules/typescript/lib/lib.es2024.string.d.ts","./node_modules/typescript/lib/lib.esnext.array.d.ts","./node_modules/typescript/lib/lib.esnext.collection.d.ts","./node_modules/typescript/lib/lib.esnext.intl.d.ts","./node_modules/typescript/lib/lib.esnext.disposable.d.ts","./node_modules/typescript/lib/lib.esnext.promise.d.ts","./node_modules/typescript/lib/lib.esnext.decorators.d.ts","./node_modules/typescript/lib/lib.esnext.iterator.d.ts","./node_modules/typescript/lib/lib.esnext.float16.d.ts","./node_modules/typescript/lib/lib.esnext.error.d.ts","./node_modules/typescript/lib/lib.esnext.sharedmemory.d.ts","./node_modules/typescript/lib/lib.decorators.d.ts","./node_modules/typescript/lib/lib.decorators.legacy.d.ts","./node_modules/@types/react/global.d.ts","./node_modules/csstype/index.d.ts","./node_modules/@types/prop-types/index.d.ts","./node_modules/@types/react/index.d.ts","./node_modules/next/dist/styled-jsx/types/css.d.ts","./node_modules/next/dist/styled-jsx/types/macro.d.ts","./node_modules/next/dist/styled-jsx/types/style.d.ts","./node_modules/next/dist/styled-jsx/types/global.d.ts","./node_modules/next/dist/styled-jsx/types/index.d.ts","./node_modules/next/dist/server/get-page-fLine truncated
|
||||
Reference in new issue
Block a user