diff options
Diffstat (limited to 'src/components/ScheduleInteractive.astro')
| -rw-r--r-- | src/components/ScheduleInteractive.astro | 54 |
1 files changed, 54 insertions, 0 deletions
diff --git a/src/components/ScheduleInteractive.astro b/src/components/ScheduleInteractive.astro index cb33ce9..129b38a 100644 --- a/src/components/ScheduleInteractive.astro +++ b/src/components/ScheduleInteractive.astro @@ -529,6 +529,59 @@ }); } + // 検索エンジン向けに、これからのイベントを構造化データ(JSON-LD)で出力する。 + function emitEventStructuredData() { + const upcoming = entries + .filter((e) => e.type === 'event' && e.dates.some((d) => d >= todayKey)) + .map((e) => { + const future = e.dates.filter((d) => d >= todayKey).sort(); + const name = e.name.startsWith(e.category) + ? e.name.slice(e.category.length).trim() + : e.name; + const parts = e.time.split('/'); + const venue = (parts[1] ?? '').trim(); + return { + '@type': 'Event', + name, + startDate: future[0], + eventStatus: 'https://schema.org/EventScheduled', + eventAttendanceMode: 'https://schema.org/OfflineEventAttendanceMode', + location: { + '@type': 'Place', + name: venue || '小平市', + address: { + '@type': 'PostalAddress', + addressLocality: '東京都小平市', + addressCountry: 'JP', + }, + }, + description: e.time, + url: `https://yasutakeyohei.com/kodaira-data/hp-archive/schedule/#${e.rowId}`, + }; + }) + .sort((a, b) => a.startDate.localeCompare(b.startDate)) + .slice(0, 40); + + const existing = document.getElementById('schedule-event-ldjson'); + if (existing) existing.remove(); + if (upcoming.length === 0) return; + + const script = document.createElement('script'); + script.type = 'application/ld+json'; + script.id = 'schedule-event-ldjson'; + script.textContent = JSON.stringify({ + '@context': 'https://schema.org', + '@type': 'ItemList', + name: '小平市のこれからのイベント', + itemListElement: upcoming.map((item, index) => ({ + '@type': 'ListItem', + position: index + 1, + item, + })), + }); + document.head.appendChild(script); + } + // 件数はフィルターのボタンには出さず、ページ下部にまとめて表示する。 function renderCategorySummary() { const summaryEl = document.getElementById('schedule-category-summary'); @@ -543,6 +596,7 @@ buildFilters(); renderCategorySummary(); + emitEventStructuredData(); applyFilter(); renderCalendar(); if (selectedDate) showDayDetails(selectedDate); |
