Add proper meta to tag share page
This commit is contained in:
parent
907561d1fa
commit
459785ceeb
@ -2,8 +2,7 @@ import { getPhotosCached } from '@/cache';
|
|||||||
import SiteGrid from '@/components/SiteGrid';
|
import SiteGrid from '@/components/SiteGrid';
|
||||||
import PhotoGrid from '@/photo/PhotoGrid';
|
import PhotoGrid from '@/photo/PhotoGrid';
|
||||||
import { getUniqueTags } from '@/services/postgres';
|
import { getUniqueTags } from '@/services/postgres';
|
||||||
import { absolutePathForTag, absolutePathForTagImage } from '@/site/paths';
|
import { generateMetaForTag } from '@/tag';
|
||||||
import { descriptionForTaggedPhotos, titleForTag } from '@/tag';
|
|
||||||
import TagHeader from '@/tag/TagHeader';
|
import TagHeader from '@/tag/TagHeader';
|
||||||
import { Metadata } from 'next';
|
import { Metadata } from 'next';
|
||||||
|
|
||||||
@ -23,10 +22,12 @@ export async function generateMetadata({
|
|||||||
}: TagProps): Promise<Metadata> {
|
}: TagProps): Promise<Metadata> {
|
||||||
const photos = await getPhotosCached({ tag });
|
const photos = await getPhotosCached({ tag });
|
||||||
|
|
||||||
const url = absolutePathForTag(tag);
|
const {
|
||||||
const title = titleForTag(tag, photos);
|
url,
|
||||||
const description = descriptionForTaggedPhotos(photos, true);
|
title,
|
||||||
const images = absolutePathForTagImage(tag);
|
description,
|
||||||
|
images,
|
||||||
|
} = generateMetaForTag(tag, photos);
|
||||||
|
|
||||||
return {
|
return {
|
||||||
title,
|
title,
|
||||||
|
|||||||
@ -2,8 +2,14 @@ import { getPhotosCached } from '@/cache';
|
|||||||
import SiteGrid from '@/components/SiteGrid';
|
import SiteGrid from '@/components/SiteGrid';
|
||||||
import PhotoGrid from '@/photo/PhotoGrid';
|
import PhotoGrid from '@/photo/PhotoGrid';
|
||||||
import { getUniqueTags } from '@/services/postgres';
|
import { getUniqueTags } from '@/services/postgres';
|
||||||
|
import { generateMetaForTag } from '@/tag';
|
||||||
import TagHeader from '@/tag/TagHeader';
|
import TagHeader from '@/tag/TagHeader';
|
||||||
import TagShareModal from '@/tag/TagShareModal';
|
import TagShareModal from '@/tag/TagShareModal';
|
||||||
|
import { Metadata } from 'next';
|
||||||
|
|
||||||
|
interface TagProps {
|
||||||
|
params: { tag: string }
|
||||||
|
}
|
||||||
|
|
||||||
export async function generateStaticParams() {
|
export async function generateStaticParams() {
|
||||||
const tags = await getUniqueTags();
|
const tags = await getUniqueTags();
|
||||||
@ -12,6 +18,35 @@ export async function generateStaticParams() {
|
|||||||
}));
|
}));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export async function generateMetadata({
|
||||||
|
params: { tag },
|
||||||
|
}: TagProps): Promise<Metadata> {
|
||||||
|
const photos = await getPhotosCached({ tag });
|
||||||
|
|
||||||
|
const {
|
||||||
|
url,
|
||||||
|
title,
|
||||||
|
description,
|
||||||
|
images,
|
||||||
|
} = generateMetaForTag(tag, photos);
|
||||||
|
|
||||||
|
return {
|
||||||
|
title,
|
||||||
|
openGraph: {
|
||||||
|
title,
|
||||||
|
description,
|
||||||
|
images,
|
||||||
|
url,
|
||||||
|
},
|
||||||
|
twitter: {
|
||||||
|
images,
|
||||||
|
description,
|
||||||
|
card: 'summary_large_image',
|
||||||
|
},
|
||||||
|
description,
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
export default async function Share({
|
export default async function Share({
|
||||||
params: { tag },
|
params: { tag },
|
||||||
}: {
|
}: {
|
||||||
|
|||||||
@ -1,4 +1,5 @@
|
|||||||
import { Photo, dateRangeForPhotos } from '@/photo';
|
import { Photo, dateRangeForPhotos } from '@/photo';
|
||||||
|
import { absolutePathForTag, absolutePathForTagImage } from '@/site/paths';
|
||||||
import { capitalizeWords } from '@/utility/string';
|
import { capitalizeWords } from '@/utility/string';
|
||||||
|
|
||||||
const labelForPhotos = (photos: Photo[]) =>
|
const labelForPhotos = (photos: Photo[]) =>
|
||||||
@ -16,3 +17,10 @@ export const descriptionForTaggedPhotos = (
|
|||||||
dateBased
|
dateBased
|
||||||
? dateRangeForPhotos(photos).description.toUpperCase()
|
? dateRangeForPhotos(photos).description.toUpperCase()
|
||||||
: `${photos.length} Tagged ${labelForPhotos(photos)}`;
|
: `${photos.length} Tagged ${labelForPhotos(photos)}`;
|
||||||
|
|
||||||
|
export const generateMetaForTag = (tag: string, photos: Photo[]) => ({
|
||||||
|
url: absolutePathForTag(tag),
|
||||||
|
title: titleForTag(tag, photos),
|
||||||
|
description: descriptionForTaggedPhotos(photos, true),
|
||||||
|
images: absolutePathForTagImage(tag),
|
||||||
|
});
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user