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
@@ -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();
|
||||
}
|
||||
Reference in new issue
Block a user