Add support for multiple images from Twitter links
- Fetch all images from Twitter syndication API (photos array) - Store images with unified 'image' media type (first = thumbnail by ID order) - Display multi-image tweets in grid layout on detail page - Add hover cycling through images on home grid (2s interval) - Show image count indicator on multi-image items - Extract shared downloadAndStoreImages() helper for create/refresh - Add migration to convert existing thumbnail/gallery types to image - Make images clickable to open in new tab on detail page
This commit is contained in:
parent
e917e67930
commit
007e167707
9 changed files with 625 additions and 403 deletions
|
|
@ -31,6 +31,8 @@ type homeItem struct {
|
|||
ThumbnailID *int64
|
||||
MediaID *int64
|
||||
HasVideo bool
|
||||
GalleryIDs []int64 // Additional images for multi-image embeds
|
||||
ImageCount int // Total image count (1 + len(GalleryIDs))
|
||||
}
|
||||
|
||||
func (h homeContent) Render(sw *ssr.Writer) error {
|
||||
|
|
@ -57,6 +59,12 @@ func (h homeContent) Render(sw *ssr.Writer) error {
|
|||
<blockquote>{{.Description}}</blockquote>
|
||||
{{if .Title}}<cite>— {{.Title}}</cite>{{end}}
|
||||
</div>
|
||||
{{else if .GalleryIDs}}
|
||||
<div class="grid-item-images" data-gallery="true" data-count="{{.ImageCount}}">
|
||||
<img src="/media/{{.ThumbnailID}}" alt="{{if .Title}}{{.Title}}{{else}}Image{{end}}" loading="lazy" class="active">
|
||||
{{range .GalleryIDs}}<img src="/media/{{.}}" alt="Image" loading="lazy">{{end}}
|
||||
</div>
|
||||
<div class="gallery-indicator">{{.ImageCount}}</div>
|
||||
{{else if .ThumbnailID}}
|
||||
<img src="/media/{{.ThumbnailID}}" alt="{{if .Title}}{{.Title}}{{else}}Image{{end}}" loading="lazy">
|
||||
{{if or .HasVideo (eq .ItemType "video")}}<div class="play-indicator">▶</div>{{end}}
|
||||
|
|
@ -189,20 +197,31 @@ func HandleHome(rc *RequestContext, w http.ResponseWriter, r *http.Request) erro
|
|||
}
|
||||
|
||||
// Get media
|
||||
// Media is ordered by ID, so first "image" is the thumbnail, rest are gallery
|
||||
mediaList, err := media.QFindByItemID(ctx, rc.DB, it.ID)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
firstImage := true
|
||||
for _, m := range mediaList {
|
||||
if m.MediaType == "thumbnail" {
|
||||
hi.ThumbnailID = &m.ID
|
||||
} else if m.MediaType == "original" {
|
||||
if m.MediaType == "original" {
|
||||
hi.MediaID = &m.ID
|
||||
if strings.HasPrefix(m.ContentType, "video/") {
|
||||
hi.HasVideo = true
|
||||
}
|
||||
} else if m.MediaType == "image" {
|
||||
if firstImage {
|
||||
hi.ThumbnailID = &m.ID
|
||||
firstImage = false
|
||||
} else {
|
||||
hi.GalleryIDs = append(hi.GalleryIDs, m.ID)
|
||||
}
|
||||
}
|
||||
}
|
||||
// Calculate total image count (thumbnail + gallery images)
|
||||
if len(hi.GalleryIDs) > 0 {
|
||||
hi.ImageCount = 1 + len(hi.GalleryIDs)
|
||||
}
|
||||
|
||||
// Also check for embed video URL
|
||||
if it.EmbedVideoURL.Valid && it.EmbedVideoURL.V != "" {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue