You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
74 lines
2.7 KiB
Plaintext
74 lines
2.7 KiB
Plaintext
---
|
|
const { selectedCourseLabel, courses } = Astro.props
|
|
|
|
const years = await Astro.glob('../pages/archivio/*/index.md')
|
|
const yearLabels = years.map(module => module.file.split('/').at(-2)).toSorted()
|
|
|
|
/** Get the current year using the latest year label */
|
|
const currentYear = yearLabels.at(-1)
|
|
|
|
/** Get the selected year using the courses array */
|
|
const selectedYear = courses
|
|
.find(module => module.file.includes('index.md'))
|
|
.file.split('/')
|
|
.at(-2)
|
|
|
|
const selectedYearIndex = yearLabels.indexOf(selectedYear)
|
|
const previousYear = selectedYearIndex > 0 ? yearLabels[selectedYearIndex - 1] : null
|
|
const nextYear = selectedYearIndex < yearLabels.length - 1 ? yearLabels[selectedYearIndex + 1] : null
|
|
|
|
const isCurrentYear = currentYear == selectedYear
|
|
const coursesWithoutIndex = courses.filter(m => !m.file.includes('index.md'))
|
|
|
|
function yearLink(year: string) {
|
|
return year === currentYear ? '/' : `/archivio/${year}`
|
|
}
|
|
---
|
|
|
|
<header>
|
|
<h1>
|
|
<a href="/">Tutorato Matematica</a>
|
|
</h1>
|
|
<nav>
|
|
<!-- <ul>
|
|
{
|
|
yearLabels.slice(0, -1).map(year => (
|
|
<li class:list={{ active: year === selectedYear }}>
|
|
<a href={`/archivio/${year}`}>{year}</a>
|
|
</li>
|
|
))
|
|
}
|
|
<li class:list={{ active: currentYear === selectedYear }}>
|
|
<a href={'/'}>{currentYear}</a>
|
|
</li>
|
|
</ul> -->
|
|
<div class="year-navigation">
|
|
<!-- <div class="mobile-only"></div> -->
|
|
<div class="row desktop-only">
|
|
<a class:list={['link', { disabled: previousYear === null }]} href={yearLink(previousYear)}>
|
|
<div class="gg-chevron-left"></div>
|
|
</a>
|
|
<a href={currentYear === selectedYear ? '/' : `/archivio/${selectedYear}`}>{selectedYear}</a>
|
|
<a class:list={['link', { disabled: nextYear === null }]} href={yearLink(nextYear)}>
|
|
<div class="gg-chevron-right"></div>
|
|
</a>
|
|
</div>
|
|
</div>
|
|
<div class="course-navigation">
|
|
{
|
|
coursesWithoutIndex.map(course => (
|
|
<a
|
|
class:list={{
|
|
active: selectedCourseLabel === course.file.split('/').at(-1),
|
|
last: course.frontmatter['header-position'] === 'last',
|
|
}}
|
|
href={isCurrentYear ? '/' + course.url.split('/').at(-1) : course.url}
|
|
>
|
|
{course.frontmatter.title}
|
|
</a>
|
|
))
|
|
}
|
|
</div>
|
|
</nav>
|
|
</header>
|