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 title = titleForPhoto(photo);
|
||||||
const description = descriptionForPhoto(photo);
|
const description = descriptionForPhoto(photo);
|
||||||
|
const descriptionHtml = descriptionForPhoto(photo, true);
|
||||||
const images = absolutePathForPhotoImage(photo);
|
const images = absolutePathForPhotoImage(photo);
|
||||||
const url = absolutePathForPhoto({ photo, film: film });
|
const url = absolutePathForPhoto({ photo, film: film });
|
||||||
|
|
||||||
return {
|
return {
|
||||||
title,
|
title,
|
||||||
description,
|
description: descriptionHtml,
|
||||||
openGraph: {
|
openGraph: {
|
||||||
title,
|
title,
|
||||||
images,
|
images,
|
||||||
|
|||||||
@ -38,12 +38,13 @@ export async function generateMetadata({
|
|||||||
|
|
||||||
const title = titleForPhoto(photo);
|
const title = titleForPhoto(photo);
|
||||||
const description = descriptionForPhoto(photo);
|
const description = descriptionForPhoto(photo);
|
||||||
|
const descriptionHtml = descriptionForPhoto(photo, true);
|
||||||
const images = absolutePathForPhotoImage(photo);
|
const images = absolutePathForPhotoImage(photo);
|
||||||
const url = absolutePathForPhoto({ photo, focal });
|
const url = absolutePathForPhoto({ photo, focal });
|
||||||
|
|
||||||
return {
|
return {
|
||||||
title,
|
title,
|
||||||
description,
|
description: descriptionHtml,
|
||||||
openGraph: {
|
openGraph: {
|
||||||
title,
|
title,
|
||||||
images,
|
images,
|
||||||
|
|||||||
@ -46,6 +46,7 @@ export async function generateMetadata({
|
|||||||
|
|
||||||
const title = titleForPhoto(photo);
|
const title = titleForPhoto(photo);
|
||||||
const description = descriptionForPhoto(photo);
|
const description = descriptionForPhoto(photo);
|
||||||
|
const descriptionHtml = descriptionForPhoto(photo, true);
|
||||||
const images = absolutePathForPhotoImage(photo);
|
const images = absolutePathForPhotoImage(photo);
|
||||||
const url = absolutePathForPhoto({
|
const url = absolutePathForPhoto({
|
||||||
photo,
|
photo,
|
||||||
@ -54,7 +55,7 @@ export async function generateMetadata({
|
|||||||
|
|
||||||
return {
|
return {
|
||||||
title,
|
title,
|
||||||
description,
|
description: descriptionHtml,
|
||||||
openGraph: {
|
openGraph: {
|
||||||
title,
|
title,
|
||||||
images,
|
images,
|
||||||
|
|||||||
@ -38,12 +38,13 @@ export async function generateMetadata({
|
|||||||
|
|
||||||
const title = titleForPhoto(photo);
|
const title = titleForPhoto(photo);
|
||||||
const description = descriptionForPhoto(photo);
|
const description = descriptionForPhoto(photo);
|
||||||
|
const descriptionHtml = descriptionForPhoto(photo, true);
|
||||||
const images = absolutePathForPhotoImage(photo);
|
const images = absolutePathForPhotoImage(photo);
|
||||||
const url = absolutePathForPhoto({ photo });
|
const url = absolutePathForPhoto({ photo });
|
||||||
|
|
||||||
return {
|
return {
|
||||||
title,
|
title,
|
||||||
description,
|
description: descriptionHtml,
|
||||||
openGraph: {
|
openGraph: {
|
||||||
title,
|
title,
|
||||||
images,
|
images,
|
||||||
|
|||||||
@ -40,12 +40,13 @@ export async function generateMetadata({
|
|||||||
|
|
||||||
const title = titleForPhoto(photo);
|
const title = titleForPhoto(photo);
|
||||||
const description = descriptionForPhoto(photo);
|
const description = descriptionForPhoto(photo);
|
||||||
|
const descriptionHtml = descriptionForPhoto(photo, true);
|
||||||
const images = absolutePathForPhotoImage(photo);
|
const images = absolutePathForPhotoImage(photo);
|
||||||
const url = absolutePathForPhoto({ photo, recipe });
|
const url = absolutePathForPhoto({ photo, recipe });
|
||||||
|
|
||||||
return {
|
return {
|
||||||
title,
|
title,
|
||||||
description,
|
description: descriptionHtml,
|
||||||
openGraph: {
|
openGraph: {
|
||||||
title,
|
title,
|
||||||
images,
|
images,
|
||||||
|
|||||||
@ -45,6 +45,7 @@ export async function generateMetadata({
|
|||||||
|
|
||||||
const title = titleForPhoto(photo);
|
const title = titleForPhoto(photo);
|
||||||
const description = descriptionForPhoto(photo);
|
const description = descriptionForPhoto(photo);
|
||||||
|
const descriptionHtml = descriptionForPhoto(photo, true);
|
||||||
const images = absolutePathForPhotoImage(photo);
|
const images = absolutePathForPhotoImage(photo);
|
||||||
const url = absolutePathForPhoto({
|
const url = absolutePathForPhoto({
|
||||||
photo,
|
photo,
|
||||||
@ -53,7 +54,7 @@ export async function generateMetadata({
|
|||||||
|
|
||||||
return {
|
return {
|
||||||
title,
|
title,
|
||||||
description,
|
description: descriptionHtml,
|
||||||
openGraph: {
|
openGraph: {
|
||||||
title,
|
title,
|
||||||
images,
|
images,
|
||||||
|
|||||||
@ -37,12 +37,13 @@ export async function generateMetadata({
|
|||||||
|
|
||||||
const title = titleForPhoto(photo);
|
const title = titleForPhoto(photo);
|
||||||
const description = descriptionForPhoto(photo);
|
const description = descriptionForPhoto(photo);
|
||||||
|
const descriptionHtml = descriptionForPhoto(photo, true);
|
||||||
const images = absolutePathForPhotoImage(photo);
|
const images = absolutePathForPhotoImage(photo);
|
||||||
const url = absolutePathForPhoto({ photo, tag });
|
const url = absolutePathForPhoto({ photo, tag });
|
||||||
|
|
||||||
return {
|
return {
|
||||||
title,
|
title,
|
||||||
description,
|
description: descriptionHtml,
|
||||||
openGraph: {
|
openGraph: {
|
||||||
title,
|
title,
|
||||||
images,
|
images,
|
||||||
|
|||||||
@ -35,11 +35,12 @@ export async function generateMetadata({
|
|||||||
|
|
||||||
const title = titleForPhoto(photo);
|
const title = titleForPhoto(photo);
|
||||||
const description = descriptionForPhoto(photo);
|
const description = descriptionForPhoto(photo);
|
||||||
|
const descriptionHtml = descriptionForPhoto(photo, true);
|
||||||
const url = absolutePathForPhoto({ photo, tag: TAG_HIDDEN });
|
const url = absolutePathForPhoto({ photo, tag: TAG_HIDDEN });
|
||||||
|
|
||||||
return {
|
return {
|
||||||
title,
|
title,
|
||||||
description,
|
description: descriptionHtml,
|
||||||
openGraph: {
|
openGraph: {
|
||||||
title,
|
title,
|
||||||
description,
|
description,
|
||||||
|
|||||||
@ -171,7 +171,12 @@ export const photoStatsAsString = (photo: Photo) => [
|
|||||||
photo.isoFormatted,
|
photo.isoFormatted,
|
||||||
].join(' ');
|
].join(' ');
|
||||||
|
|
||||||
export const descriptionForPhoto = (photo: Photo) =>
|
export const descriptionForPhoto = (
|
||||||
|
photo: Photo,
|
||||||
|
includeSemanticDescription?: boolean,
|
||||||
|
) =>
|
||||||
|
photo.caption ||
|
||||||
|
(includeSemanticDescription && photo.semanticDescription) ||
|
||||||
formatDate({ date: photo.takenAt }).toLocaleUpperCase();
|
formatDate({ date: photo.takenAt }).toLocaleUpperCase();
|
||||||
|
|
||||||
export const getPreviousPhoto = (photo: Photo, photos: Photo[]) => {
|
export const getPreviousPhoto = (photo: Photo, photos: Photo[]) => {
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user