Skip to content
This repository has been archived by the owner on Jul 17, 2024. It is now read-only.

Commit

Permalink
[CARE-5740] Fix media gallery page meta description
Browse files Browse the repository at this point in the history
  • Loading branch information
e1himself committed Jul 12, 2024
1 parent fde2900 commit fce77a4
Show file tree
Hide file tree
Showing 3 changed files with 59 additions and 34 deletions.
54 changes: 27 additions & 27 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 3 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -34,9 +34,9 @@
"@prezly/content-renderer-react-js": "0.38.4",
"@prezly/sdk": "21.0.0",
"@prezly/story-content-format": "0.65.1",
"@prezly/theme-kit-core": "7.4.0",
"@prezly/theme-kit-intl": "7.4.0",
"@prezly/theme-kit-nextjs": "7.4.2",
"@prezly/theme-kit-core": "7.5.1",
"@prezly/theme-kit-intl": "7.5.1",
"@prezly/theme-kit-nextjs": "7.5.1",
"@prezly/uploadcare": "2.4.3",
"@prezly/uploadcare-image": "0.3.2",
"@react-hookz/web": "14.7.1",
Expand Down
33 changes: 29 additions & 4 deletions pages/media/album/[uuid].tsx
Original file line number Diff line number Diff line change
@@ -1,8 +1,11 @@
/* eslint-disable @typescript-eslint/no-use-before-define */
import { NewsroomGallery } from '@prezly/sdk';
import { getAssetsUrl, getGalleryThumbnail } from '@prezly/theme-kit-core';
import { translations } from '@prezly/theme-kit-intl';
import type { GalleryAlbumPageProps } from '@prezly/theme-kit-nextjs/server';
import { getGalleryAlbumPageServerSideProps } from '@prezly/theme-kit-nextjs/server';
import dynamic from 'next/dynamic';
import type { FunctionComponent } from 'react';
import { useIntl } from 'react-intl';

import Layout from '@/modules/Layout';
import { importMessages, isTrackingEnabled } from '@/utils';
Expand All @@ -12,19 +15,21 @@ const Gallery = dynamic(() => import('@/modules/Gallery'), { ssr: true });

type Props = BasePageProps & GalleryAlbumPageProps;

const GalleryPage: FunctionComponent<Props> = ({ gallery }) => {
export default function GalleryPage({ gallery }: Props) {
const { name } = gallery;
const galleryThumbnail = getGalleryThumbnail(gallery);
const metaDescription = useGalleryPageMetaDescription(gallery);

return (
<Layout
title={name}
imageUrl={galleryThumbnail ? getAssetsUrl(galleryThumbnail.uuid) : undefined}
description={metaDescription}
>
<Gallery gallery={gallery} />
</Layout>
);
};
}

export const getServerSideProps = getGalleryAlbumPageServerSideProps<BasePageProps>(
async (context, { newsroomContextProps }) => ({
Expand All @@ -33,4 +38,24 @@ export const getServerSideProps = getGalleryAlbumPageServerSideProps<BasePagePro
}),
);

export default GalleryPage;
function useGalleryPageMetaDescription(gallery: NewsroomGallery) {
const { formatMessage } = useIntl();
const description = gallery.description?.trim() ?? '';

if (gallery.type === NewsroomGallery.Type.IMAGE) {
const imagesCount = formatMessage(translations.mediaGallery.imagesCount, {
imagesCount: gallery.images_number,
});

return [imagesCount, description].filter(Boolean).join(' - ');
}

if (gallery.type === NewsroomGallery.Type.VIDEO) {
const videosCount = formatMessage(translations.mediaGallery.videosCount, {
videosCount: gallery.videos_number,
});
return [videosCount, description].filter(Boolean).join(' - ');
}

return description;
}

0 comments on commit fce77a4

Please sign in to comment.