Calendar: redirect to the corresponding ranking page instead of the 1st artwork

This commit is contained in:
VnPower
2024-11-03 13:12:48 +07:00
parent 8ea8526ec3
commit 1f592060f8
2 changed files with 7 additions and 4 deletions
+3 -2
View File
@@ -2,6 +2,8 @@
{{- import "blocks/underlinenav" }}
{{- block body() }}
{{- Mode := isset(Queries.mode) ? Queries.mode : "daily" }}
<div class="d-none">
<p>Daily</p>
<p>Weekly</p>
@@ -58,7 +60,7 @@
<div class="d-flex thumbnail-wrapper bg-neutral-900 rounded overflow-hidden">
{{ if day.DayNumber > 0 }}
{{ if day.ImageURL }}
<a href="{{ day.ArtworkLink }}" class="text-decoration-none w-100 h-100 position-relative">
<a href="/ranking?date={{ day.DateString }}&mode={{ Mode }}" class="text-decoration-none w-100 h-100 position-relative">
<img src="{{ day.ImageURL }}" alt="Day {{ day.DayNumber }}" class="w-100 h-100 object-fit-cover" />
<div class="position-absolute top-0 start-0 p-2">
<span class="text-white fw-bold bg-dark bg-opacity-75 rounded-pill px-2 py-1">{{ day.DayNumber }}</span>
@@ -106,7 +108,6 @@
</div>
</div>
{{- Mode := isset(Queries.mode) ? Queries.mode : "daily" }}
{{- url := "/rankingCalendar?date=" + .ThisMonth.Link + "&mode=" }}
<div class="row border-bottom border-2 mb-4">
<div class="col-12 mb-4">
+4 -2
View File
@@ -17,6 +17,7 @@ import (
// DayCalendar represents the data for a single day in the ranking calendar
type DayCalendar struct {
DayNumber int // The day of the month
DateString string // Pixiv-compatible string that represents the date (format: YYYYMMDD)
ImageURL string // Proxy URL to the image (optional, can be empty when no image is available)
ArtworkLink string // The link to the artwork page for this day
}
@@ -63,7 +64,7 @@ func GetRankingCalendar(auditor *audit.Auditor, r *http.Request, mode string, ye
numDays := daysIn(time.Month(month), year)
// Add days of the month
calendar, dayCount = addDaysOfMonth(calendar, links, dayCount, numDays)
calendar, dayCount = addDaysOfMonth(calendar, links, dayCount, numDays, year, month)
// Add empty days after the last day to complete the week
calendar, dayCount = addEmptyDaysAfter(calendar, dayCount)
@@ -99,7 +100,7 @@ func addEmptyDaysBefore(calendar []DayCalendar, firstDay time.Time, dayCount int
}
// addDaysOfMonth adds the actual days of the month to the calendar.
func addDaysOfMonth(calendar []DayCalendar, links []string, dayCount int, numDays int) ([]DayCalendar, int) {
func addDaysOfMonth(calendar []DayCalendar, links []string, dayCount, numDays, year, month int) ([]DayCalendar, int) {
for i := 0; i < numDays; i++ {
day := DayCalendar{
DayNumber: i + 1,
@@ -111,6 +112,7 @@ func addDaysOfMonth(calendar []DayCalendar, links []string, dayCount int, numDay
day.ArtworkLink = fmt.Sprintf("/artworks/%s", artworkID)
}
}
day.DateString = fmt.Sprintf("%d%02d%02d", year, month, i + 1)
calendar = append(calendar, day)
dayCount++
}