Add thumbnailing for photo grids
This commit is contained in:
@@ -283,16 +283,17 @@ func computeCalendarWidget(diaryRootFS, diaryRootURL, fsPath string, depth int)
|
||||
|
||||
// diaryPhoto is a photo file whose name starts with a YYYY-MM-DD date prefix.
|
||||
type diaryPhoto struct {
|
||||
Date time.Time
|
||||
Name string
|
||||
URL string
|
||||
Date time.Time
|
||||
Name string
|
||||
URL string
|
||||
ThumbURL string
|
||||
}
|
||||
|
||||
type diaryMonthSummary struct {
|
||||
ID string
|
||||
Name string
|
||||
URL string
|
||||
PhotoCount int
|
||||
ID string
|
||||
Name string
|
||||
URL string
|
||||
Photos []diaryPhoto
|
||||
}
|
||||
|
||||
type diaryDaySection struct {
|
||||
@@ -376,10 +377,16 @@ func yearPhotos(yearFsPath, yearURLPath string) []diaryPhoto {
|
||||
if err != nil {
|
||||
continue
|
||||
}
|
||||
photoURL := path.Join(yearURLPath, url.PathEscape(name))
|
||||
thumb := photoURL
|
||||
if hasThumbnail(name) {
|
||||
thumb = thumbURL(photoURL, 300)
|
||||
}
|
||||
photos = append(photos, diaryPhoto{
|
||||
Date: t,
|
||||
Name: name,
|
||||
URL: path.Join(yearURLPath, url.PathEscape(name)),
|
||||
Date: t,
|
||||
Name: name,
|
||||
URL: photoURL,
|
||||
ThumbURL: thumb,
|
||||
})
|
||||
}
|
||||
return photos
|
||||
@@ -408,18 +415,18 @@ func renderDiaryYear(fsPath, urlPath string) template.HTML {
|
||||
if err != nil || monthNum < 1 || monthNum > 12 {
|
||||
continue
|
||||
}
|
||||
count := 0
|
||||
var monthPhotos []diaryPhoto
|
||||
for _, p := range photos {
|
||||
if p.Date.Year() == year && int(p.Date.Month()) == monthNum {
|
||||
count++
|
||||
monthPhotos = append(monthPhotos, p)
|
||||
}
|
||||
}
|
||||
monthDate := time.Date(year, time.Month(monthNum), 1, 0, 0, 0, 0, time.UTC)
|
||||
months = append(months, diaryMonthSummary{
|
||||
ID: monthDate.Format("2006-01"),
|
||||
Name: monthDate.Format("January 2006"),
|
||||
URL: path.Join(urlPath, e.Name()) + "/",
|
||||
PhotoCount: count,
|
||||
ID: monthDate.Format("2006-01"),
|
||||
Name: fmt.Sprintf("%s %d", germanMonths[monthDate.Month()], year),
|
||||
URL: path.Join(urlPath, e.Name()) + "/",
|
||||
Photos: monthPhotos,
|
||||
})
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user