aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/components/ScheduleMonthLinks.astro
blob: 61f1ae17fc9325c70cb771dab1f39151df5c660b (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
---
// 月別・年度別アーカイブのリンク一覧。行事予定ページの下部に置く。
// アーカイブは前々月以前の月だけ(前月以降はメインページに掲載している)。
import {
  archiveFiscalYearKeys,
  archiveMonthKeys,
  fiscalYearLabel,
  fiscalYearOf,
  monthCounts,
  monthLabel,
} from '@/lib/schedule-months';
import { scheduleUrl } from '@/data/schedule/config';

const groups = [...new Set(archiveMonthKeys.map((month) => fiscalYearOf(month)))].map((fy) => ({
  key: fy,
  label: fiscalYearLabel(fy),
  hasPage: archiveFiscalYearKeys.includes(fy),
  months: archiveMonthKeys.filter((month) => fiscalYearOf(month) === fy),
}));
---

{
  groups.length === 0 ? (
    <p class="schedule-archive-empty">
      前々月より前に終了した予定はまだありません。月が進むと、ここに過去の予定が表示されます。
    </p>
  ) : (
    <div class="schedule-archive">
      {groups.map((group) => (
        <section class="schedule-archive-year">
          <h3 class="schedule-archive-year-title">
            {group.hasPage ? (
              <a href={scheduleUrl(`${group.key}/`)}>{group.label}の予定</a>
            ) : (
              group.label
            )}
          </h3>
          <ul class="schedule-archive-months">
            {group.months.map((key) => (
              <li>
                <a href={scheduleUrl(`${key}/`)}>
                  <span>{monthLabel(key)}</span>
                  <span class="schedule-archive-count">{monthCounts[key]}件</span>
                </a>
              </li>
            ))}
          </ul>
        </section>
      ))}
    </div>
  )
}