Add caption, semantic description conditionally to photo meta

This commit is contained in:
Sam Becker 2025-06-01 00:22:11 -05:00
parent bab2c623ee
commit 28823ed334
10 changed files with 56 additions and 9 deletions

34
__tests__/photo.test.ts Normal file
View File

@ -0,0 +1,34 @@
import { descriptionForPhoto, Photo } from '@/photo';
const PHOTO: Partial<Photo> = {
takenAt: new Date('2025-01-01 12:00:00'),
};
const PHOTO_SEMANTIC: Partial<Photo> = {
...PHOTO,
semanticDescription: 'Semantic Description',
};
const PHOTO_CAPTION: Partial<Photo> = {
...PHOTO_SEMANTIC,
caption: 'Caption',
};
describe('Should generate photo description', () => {
it('with caption', () => {
expect(descriptionForPhoto(PHOTO_CAPTION as Photo))
.toBe('Caption');
});
it('with semantic description (disabled)', () => {
expect(descriptionForPhoto(PHOTO_SEMANTIC as Photo))
.toBe('01 JAN 2025 12:00PM');
});
it('with semantic description (enabled)', () => {
expect(descriptionForPhoto(PHOTO_SEMANTIC as Photo, true))
.toBe('Semantic Description');
});
it('with date', () => {
expect(descriptionForPhoto(PHOTO as Photo))
.toBe('01 JAN 2025 12:00PM');
});
});

View File

@ -41,12 +41,13 @@ export async function generateMetadata({
const title = titleForPhoto(photo);
const description = descriptionForPhoto(photo);
const descriptionHtml = descriptionForPhoto(photo, true);
const images = absolutePathForPhotoImage(photo);
const url = absolutePathForPhoto({ photo, film: film });
return {
title,
description,
description: descriptionHtml,
openGraph: {
title,
images,

View File

@ -38,12 +38,13 @@ export async function generateMetadata({
const title = titleForPhoto(photo);
const description = descriptionForPhoto(photo);
const descriptionHtml = descriptionForPhoto(photo, true);
const images = absolutePathForPhotoImage(photo);
const url = absolutePathForPhoto({ photo, focal });
return {
title,
description,
description: descriptionHtml,
openGraph: {
title,
images,

View File

@ -46,6 +46,7 @@ export async function generateMetadata({
const title = titleForPhoto(photo);
const description = descriptionForPhoto(photo);
const descriptionHtml = descriptionForPhoto(photo, true);
const images = absolutePathForPhotoImage(photo);
const url = absolutePathForPhoto({
photo,
@ -54,7 +55,7 @@ export async function generateMetadata({
return {
title,
description,
description: descriptionHtml,
openGraph: {
title,
images,

View File

@ -38,12 +38,13 @@ export async function generateMetadata({
const title = titleForPhoto(photo);
const description = descriptionForPhoto(photo);
const descriptionHtml = descriptionForPhoto(photo, true);
const images = absolutePathForPhotoImage(photo);
const url = absolutePathForPhoto({ photo });
return {
title,
description,
description: descriptionHtml,
openGraph: {
title,
images,

View File

@ -40,12 +40,13 @@ export async function generateMetadata({
const title = titleForPhoto(photo);
const description = descriptionForPhoto(photo);
const descriptionHtml = descriptionForPhoto(photo, true);
const images = absolutePathForPhotoImage(photo);
const url = absolutePathForPhoto({ photo, recipe });
return {
title,
description,
description: descriptionHtml,
openGraph: {
title,
images,

View File

@ -45,6 +45,7 @@ export async function generateMetadata({
const title = titleForPhoto(photo);
const description = descriptionForPhoto(photo);
const descriptionHtml = descriptionForPhoto(photo, true);
const images = absolutePathForPhotoImage(photo);
const url = absolutePathForPhoto({
photo,
@ -53,7 +54,7 @@ export async function generateMetadata({
return {
title,
description,
description: descriptionHtml,
openGraph: {
title,
images,

View File

@ -37,12 +37,13 @@ export async function generateMetadata({
const title = titleForPhoto(photo);
const description = descriptionForPhoto(photo);
const descriptionHtml = descriptionForPhoto(photo, true);
const images = absolutePathForPhotoImage(photo);
const url = absolutePathForPhoto({ photo, tag });
return {
title,
description,
description: descriptionHtml,
openGraph: {
title,
images,

View File

@ -35,11 +35,12 @@ export async function generateMetadata({
const title = titleForPhoto(photo);
const description = descriptionForPhoto(photo);
const descriptionHtml = descriptionForPhoto(photo, true);
const url = absolutePathForPhoto({ photo, tag: TAG_HIDDEN });
return {
title,
description,
description: descriptionHtml,
openGraph: {
title,
description,

View File

@ -171,7 +171,12 @@ export const photoStatsAsString = (photo: Photo) => [
photo.isoFormatted,
].join(' ');
export const descriptionForPhoto = (photo: Photo) =>
export const descriptionForPhoto = (
photo: Photo,
includeSemanticDescription?: boolean,
) =>
photo.caption ||
(includeSemanticDescription && photo.semanticDescription) ||
formatDate({ date: photo.takenAt }).toLocaleUpperCase();
export const getPreviousPhoto = (photo: Photo, photos: Photo[]) => {