Refine tag folder metadata
This commit is contained in:
parent
7649323a28
commit
1e8c4c839f
@ -1,12 +1,9 @@
|
|||||||
import SiteGrid from '@/components/SiteGrid';
|
import SiteGrid from '@/components/SiteGrid';
|
||||||
|
import { dateRangeForPhotos } from '@/photo';
|
||||||
import PhotoGrid from '@/photo/PhotoGrid';
|
import PhotoGrid from '@/photo/PhotoGrid';
|
||||||
import { getPhotos } from '@/services/postgres';
|
import { getPhotos } from '@/services/postgres';
|
||||||
import { absolutePathForTag, absolutePathForTagImage } from '@/site/paths';
|
import { absolutePathForTag, absolutePathForTagImage } from '@/site/paths';
|
||||||
import {
|
import { descriptionForTaggedPhotos, titleForTag } from '@/tag';
|
||||||
descriptionForTaggedPhotos,
|
|
||||||
ogTitleForTag,
|
|
||||||
pageTitleForTag,
|
|
||||||
} from '@/tag';
|
|
||||||
import PhotoTag from '@/tag/PhotoTag';
|
import PhotoTag from '@/tag/PhotoTag';
|
||||||
import { cc } from '@/utility/css';
|
import { cc } from '@/utility/css';
|
||||||
import { Metadata } from 'next';
|
import { Metadata } from 'next';
|
||||||
@ -21,15 +18,14 @@ export async function generateMetadata({
|
|||||||
const photos = await getPhotos(undefined, undefined, undefined, tag);
|
const photos = await getPhotos(undefined, undefined, undefined, tag);
|
||||||
|
|
||||||
const url = absolutePathForTag(tag);
|
const url = absolutePathForTag(tag);
|
||||||
const titlePage = pageTitleForTag(tag);
|
const title = titleForTag(tag, photos);
|
||||||
const titleOg = ogTitleForTag(tag);
|
const description = descriptionForTaggedPhotos(photos, true);
|
||||||
const description = descriptionForTaggedPhotos(photos);
|
|
||||||
const images = absolutePathForTagImage(tag);
|
const images = absolutePathForTagImage(tag);
|
||||||
|
|
||||||
return {
|
return {
|
||||||
title: titlePage,
|
title,
|
||||||
openGraph: {
|
openGraph: {
|
||||||
title: titleOg,
|
title,
|
||||||
description,
|
description,
|
||||||
images,
|
images,
|
||||||
url,
|
url,
|
||||||
@ -46,8 +42,7 @@ export async function generateMetadata({
|
|||||||
export default async function TagPage({ params: { tag } }: TagProps) {
|
export default async function TagPage({ params: { tag } }: TagProps) {
|
||||||
const photos = await getPhotos(undefined, undefined, undefined, tag);
|
const photos = await getPhotos(undefined, undefined, undefined, tag);
|
||||||
|
|
||||||
const dateStart = photos[0].takenAtNaiveFormattedShort;
|
const { start, end } = dateRangeForPhotos(photos);
|
||||||
const dateEnd = photos[photos.length - 1].takenAtNaiveFormattedShort;
|
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<SiteGrid
|
<SiteGrid
|
||||||
@ -68,9 +63,9 @@ export default async function TagPage({ params: { tag } }: TagProps) {
|
|||||||
'text-right uppercase',
|
'text-right uppercase',
|
||||||
'text-gray-400 dark:text-gray-500',
|
'text-gray-400 dark:text-gray-500',
|
||||||
)}>
|
)}>
|
||||||
{dateStart === dateEnd
|
{start === end
|
||||||
? dateStart
|
? start
|
||||||
: <>{dateStart}<br />– {dateEnd}</>}
|
: <>{start}<br />– {end}</>}
|
||||||
</span>
|
</span>
|
||||||
</div>
|
</div>
|
||||||
<PhotoGrid photos={photos} />
|
<PhotoGrid photos={photos} />
|
||||||
|
|||||||
@ -63,8 +63,8 @@ export interface Photo extends PhotoDb {
|
|||||||
isoFormatted?: string
|
isoFormatted?: string
|
||||||
exposureTimeFormatted?: string
|
exposureTimeFormatted?: string
|
||||||
exposureCompensationFormatted?: string
|
exposureCompensationFormatted?: string
|
||||||
takenAtNaiveFormatted?: string
|
takenAtNaiveFormatted: string
|
||||||
takenAtNaiveFormattedShort?: string
|
takenAtNaiveFormattedShort: string
|
||||||
}
|
}
|
||||||
|
|
||||||
export const parsePhotoFromDb = (photoDbRaw: PhotoDb): Photo => {
|
export const parsePhotoFromDb = (photoDbRaw: PhotoDb): Photo => {
|
||||||
@ -178,3 +178,12 @@ export const translatePhotoId = (shortId: string) => {
|
|||||||
|
|
||||||
export const titleForPhoto = (photo: Photo) =>
|
export const titleForPhoto = (photo: Photo) =>
|
||||||
photo.title || 'Untitled';
|
photo.title || 'Untitled';
|
||||||
|
|
||||||
|
export const dateRangeForPhotos = (photos: Photo[]) => {
|
||||||
|
const start = photos[0].takenAtNaiveFormattedShort;
|
||||||
|
const end = photos[photos.length - 1].takenAtNaiveFormattedShort;
|
||||||
|
const description = start === end
|
||||||
|
? start
|
||||||
|
: `${start}–${end}`;
|
||||||
|
return { start, end, description };
|
||||||
|
};
|
||||||
|
|||||||
@ -1,11 +1,13 @@
|
|||||||
import { Photo } from '@/photo';
|
import { Photo, dateRangeForPhotos } from '@/photo';
|
||||||
import { capitalizeWords } from '@/utility/string';
|
import { capitalizeWords } from '@/utility/string';
|
||||||
|
|
||||||
export const pageTitleForTag = (tag: string) =>
|
export const titleForTag = (tag: string, photos:Photo[]) =>
|
||||||
`${capitalizeWords(tag.replaceAll('-', ' '))} Photos`;
|
`${capitalizeWords(tag.replaceAll('-', ' '))} (${photos.length})`;
|
||||||
|
|
||||||
export const ogTitleForTag = (tag: string) =>
|
export const descriptionForTaggedPhotos = (
|
||||||
`🏷️ ${capitalizeWords(tag.replaceAll('-', ' '))}`;
|
photos:Photo[],
|
||||||
|
dateBased?: boolean,
|
||||||
export const descriptionForTaggedPhotos = (photos:Photo[]) =>
|
) =>
|
||||||
`${photos.length} tagged ${photos.length === 1 ? 'photo' : 'photos'}`;
|
dateBased
|
||||||
|
? dateRangeForPhotos(photos).description.toUpperCase()
|
||||||
|
: `${photos.length} tagged ${photos.length === 1 ? 'photo' : 'photos'}`;
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user