link to artwork page instead on ranking calendar

This commit is contained in:
perennial
2024-10-01 20:48:48 +10:00
parent edb19880b1
commit 3ed93fa6bc
2 changed files with 18 additions and 5 deletions
+1 -1
View File
@@ -70,7 +70,7 @@
<div class="card h-100">
{{ if day.DayNumber > 0 }}
{{ if day.ImageURL }}
<a href="{{ day.RankingLink }}" class="text-decoration-none">
<a href="{{ day.ArtworkLink }}" class="text-decoration-none">
<img src="{{ day.ImageURL }}" alt="Day {{ day.DayNumber }}" class="card-img-top img-fluid object-fit-cover h-100" />
<div class="card-img-overlay d-flex align-items-start rounded p-2">
<p class="card-text text-white fw-bold bg-dark bg-opacity-75 rounded-pill px-2 py-1 mb-0">{{ day.DayNumber }}</p>
+17 -4
View File
@@ -3,6 +3,7 @@ package core
import (
"fmt"
"net/http"
"regexp"
"strings"
"time"
@@ -16,7 +17,7 @@ import (
type DayCalendar struct {
DayNumber int // The day of the month
ImageURL string // Proxy URL to the image (optional, can be empty when no image is available)
RankingLink string // The link to the ranking page for this day
ArtworkLink string // The link to the artwork page for this day
}
// get_weekday converts a time.Weekday to an integer representation.
@@ -44,6 +45,16 @@ func get_weekday(n time.Weekday) int {
// selector_img is a pre-compiled CSS selector for finding <img> tags in HTML.
var selector_img = cascadia.MustCompile("img")
// extractArtworkID extracts the artwork ID from the image URL
func extractArtworkID(imageURL string) string {
re := regexp.MustCompile(`/(\d+)_p0_(custom|square)1200\.jpg`)
matches := re.FindStringSubmatch(imageURL)
if len(matches) > 1 {
return matches[1]
}
return ""
}
// GetRankingCalendar retrieves and processes the ranking calendar data from Pixiv.
// It returns a slice of DayCalendar structs and any error encountered.
//
@@ -92,13 +103,15 @@ func GetRankingCalendar(r *http.Request, mode string, year, month int) ([]DayCal
// Add data for each day of the month
for i := 0; i < thisMonth.Day(); i++ {
date := fmt.Sprintf("%d%02d%02d", year, month, i+1)
day := DayCalendar{
DayNumber: i + 1,
RankingLink: fmt.Sprintf("/ranking?mode=%s&date=%s", mode, date),
DayNumber: i + 1,
}
if len(links) > i {
day.ImageURL = links[i]
artworkID := extractArtworkID(links[i])
if artworkID != "" {
day.ArtworkLink = fmt.Sprintf("/artworks/%s", artworkID)
}
}
calendar = append(calendar, day)
dayCount++