You've already forked immich
mirror of
https://github.com/immich-app/immich.git
synced 2025-06-27 05:11:11 +02:00
feat(web): improve alt text (#7596)
* alt text * memory lane alt text * revert sql generator change * use getAltText * oops * handle large number of people in asset * nit * add aria-label to search button * update api * fixed tests * fixed typing * fixed spacing * fix displaying null
This commit is contained in:
@ -1,3 +1,6 @@
|
||||
import type { AssetResponseDto } from '@immich/sdk';
|
||||
import { fromLocalDateTime } from './timeline-util';
|
||||
|
||||
/**
|
||||
* Calculate thumbnail size based on number of assets and viewport width
|
||||
* @param assetCount Number of assets in the view
|
||||
@ -31,3 +34,30 @@ export function getThumbnailSize(assetCount: number, viewWidth: number): number
|
||||
|
||||
return 300;
|
||||
}
|
||||
|
||||
export function getAltText(asset: AssetResponseDto) {
|
||||
if (asset.exifInfo?.description) {
|
||||
return asset.exifInfo.description;
|
||||
}
|
||||
|
||||
let altText = 'Image taken';
|
||||
if (asset.exifInfo?.city && asset.exifInfo.country) {
|
||||
altText += ` in ${asset.exifInfo.city}, ${asset.exifInfo.country}`;
|
||||
}
|
||||
|
||||
const names = asset.people?.filter((p) => p.name).map((p) => p.name) ?? [];
|
||||
if (names.length == 1) {
|
||||
altText += ` with ${names[0]}`;
|
||||
}
|
||||
if (names.length > 1 && names.length <= 3) {
|
||||
altText += ` with ${names.slice(0, -1).join(', ')} and ${names.at(-1)}`;
|
||||
}
|
||||
if (names.length > 3) {
|
||||
altText += ` with ${names.slice(0, 2).join(', ')}, and ${names.length - 2} others`;
|
||||
}
|
||||
|
||||
const date = fromLocalDateTime(asset.localDateTime).toLocaleString({ dateStyle: 'long' });
|
||||
altText += ` on ${date}`;
|
||||
|
||||
return altText;
|
||||
}
|
||||
|
Reference in New Issue
Block a user