Add caption, semantic description conditionally to photo meta
This commit is contained in:
parent
bab2c623ee
commit
28823ed334
34
__tests__/photo.test.ts
Normal file
34
__tests__/photo.test.ts
Normal 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');
|
||||
});
|
||||
});
|
||||
@ -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,
|
||||
|
||||
@ -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,
|
||||
|
||||
@ -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,
|
||||
|
||||
@ -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,
|
||||
|
||||
@ -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,
|
||||
|
||||
@ -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,
|
||||
|
||||
@ -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,
|
||||
|
||||
@ -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,
|
||||
|
||||
@ -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[]) => {
|
||||
|
||||
Loading…
Reference in New Issue
Block a user