diff options
| author | Yasutake Yohei <61961825+yasutakeyohei@users.noreply.github.com> | 2026-11-07 12:29:10 +0900 |
|---|---|---|
| committer | Yasutake Yohei <61961825+yasutakeyohei@users.noreply.github.com> | 2026-11-07 12:29:10 +0900 |
| commit | 5c56c4f74225ef9f8a5e992228cdab17eb029bea (patch) | |
| tree | b0a27be02e3fdc8b3d90ac9bc3fb7c13fb5cded7 /src/components/ScheduleInteractive.astro | |
| parent | 919976ee778a1898816dc0df21cd25d5e2cdaf87 (diff) | |
events: 行のアンカーIDを日付と名称から作るよう変更
行番号から作っていたため、予定を追加すると共有リンクが別の予定を
指していた。日付と名称のハッシュに変え、追加しても変わらないように
した。
Diffstat (limited to 'src/components/ScheduleInteractive.astro')
| -rw-r--r-- | src/components/ScheduleInteractive.astro | 14 |
1 files changed, 12 insertions, 2 deletions
diff --git a/src/components/ScheduleInteractive.astro b/src/components/ScheduleInteractive.astro index 19a3f59..4c31d99 100644 --- a/src/components/ScheduleInteractive.astro +++ b/src/components/ScheduleInteractive.astro @@ -26,6 +26,16 @@ const escapeHtml = (s) => s.replace(/[&<>"']/g, (c) => ({ '&': '&', '<': '<', '>': '>', '"': '"', "'": ''' }[c])); + // 行番号ではなく、日付と名称からアンカーIDを作る(予定を追加してもリンクが変わらないように)。 + function stableId(input: string): string { + let hash = 2166136261; + for (let i = 0; i < input.length; i++) { + hash ^= input.charCodeAt(i); + hash = Math.imul(hash, 16777619); + } + return (hash >>> 0).toString(36); + } + function initSchedule() { const calendarEl = document.getElementById('schedule-calendar'); const detailsEl = document.getElementById('schedule-day-details'); @@ -39,7 +49,7 @@ const entries = []; function collect(table, type) { - table.querySelectorAll('tbody tr').forEach((row, i) => { + table.querySelectorAll('tbody tr').forEach((row) => { const cells = row.querySelectorAll('td'); if (cells.length < 3) return; const dateText = cells[0].textContent.trim(); @@ -47,7 +57,7 @@ const timeText = cells[2].textContent.trim(); // 出典欄はリンク先URLで判定するため、HTML を保持する(textContent には href が入らない)。 const source = cells[4] ? cells[4].innerHTML : ''; - const rowId = `${type}-row-${i}`; + const rowId = `${type}-${stableId(`${dateText}|${name}`)}`; row.id = rowId; let category = MEETING_ICON; |
