Use album cover for og:image

Co-authored-by: Pierre KELBERT <root@mout.ch>
This commit is contained in:
Alan Grainger
2026-05-30 10:36:09 +08:00
parent 1906f3ceeb
commit 356486bb75
4 changed files with 15 additions and 4 deletions
+1
View File
@@ -240,6 +240,7 @@ class Immich {
} }
// Replace the empty link.assets array with the array of assets from the album // Replace the empty link.assets array with the array of assets from the album
link.assets = album.assets link.assets = album.assets
if (link.album) link.album.albumThumbnailAssetId = album.albumThumbnailAssetId
} }
link.password = password link.password = password
+5
View File
@@ -280,6 +280,10 @@ class Render {
})) }))
const downloadAllowed = canDownload(share) const downloadAllowed = canDownload(share)
// Prefer the album's owner-chosen cover for og:image; fall back to first
// item if the cover asset has been filtered out (e.g. trashed).
const coverId = share.album?.albumThumbnailAssetId
const ogImageItem = (coverId && items.find(i => i.id === coverId)) || items[0]
const props: GalleryProps = { const props: GalleryProps = {
items, items,
title: this.title(share), title: this.title(share),
@@ -289,6 +293,7 @@ class Render {
showDownload: downloadAllowed, showDownload: downloadAllowed,
showTitle: !!getConfigOption('ipp.gallery.showTitle', true), showTitle: !!getConfigOption('ipp.gallery.showTitle', true),
openItem, openItem,
ogImageItem,
lightboxConfig: { lightboxConfig: {
// Show download button only if downloading is allowed AND configured. // Show download button only if downloading is allowed AND configured.
showDownload: downloadAllowed && !!getConfigOption('ipp.lightbox.showDownload', true), showDownload: downloadAllowed && !!getConfigOption('ipp.lightbox.showDownload', true),
+2
View File
@@ -42,6 +42,7 @@ export interface Asset {
export interface Album { export interface Album {
id: string; id: string;
assets: Asset[]; assets: Asset[];
albumThumbnailAssetId?: string;
} }
export interface SharedLink { export interface SharedLink {
@@ -57,6 +58,7 @@ export interface SharedLink {
albumName?: string; albumName?: string;
order?: string; order?: string;
description?: string; description?: string;
albumThumbnailAssetId?: string;
} }
expiresAt: string | null; expiresAt: string | null;
} }
+7 -4
View File
@@ -38,6 +38,7 @@ export interface GalleryProps {
showDownload: boolean showDownload: boolean
showTitle: boolean showTitle: boolean
openItem?: number openItem?: number
ogImageItem?: GalleryItem
lightboxConfig: LightboxConfig lightboxConfig: LightboxConfig
groupByDate: boolean groupByDate: boolean
} }
@@ -50,11 +51,13 @@ export function Gallery (props: GalleryProps) {
groupByDate: props.groupByDate groupByDate: props.groupByDate
}) })
const firstItem = props.items[0] const firstItem = props.items[0]
// For videos, previewUrl points to the .mp4; use thumbnailUrl so og:image is always a still JPEG. // og:image prefers the album cover (passed via props); for videos, previewUrl
const ogImageAsset = firstItem // points to the .mp4, so use thumbnailUrl to keep og:image a still JPEG.
? (firstItem.type === AssetType.video ? firstItem.thumbnailUrl : firstItem.previewUrl) const ogItem = props.ogImageItem || firstItem
const ogImageAsset = ogItem
? (ogItem.type === AssetType.video ? ogItem.thumbnailUrl : ogItem.previewUrl)
: '' : ''
const ogImageUrl = firstItem ? props.publicBaseUrl + ogImageAsset : '' const ogImageUrl = ogItem ? props.publicBaseUrl + ogImageAsset : ''
return ( return (
<html lang="en"> <html lang="en">