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

Commit

Permalink
Merge pull request #953 from prezly/fix/care-5740-media-gallery-bookm…
Browse files Browse the repository at this point in the history
…arks-show-null-where-gallery-has-no

[CARE-5740] Fix media gallery page meta description
  • Loading branch information
e1himself authored Jul 12, 2024
2 parents c811078 + c96b946 commit c60cfed
Show file tree
Hide file tree
Showing 3 changed files with 57 additions and 31 deletions.
32 changes: 29 additions & 3 deletions modules/Gallery/Gallery.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
import type { NewsroomGallery } from '@prezly/sdk';
/* eslint-disable @typescript-eslint/no-use-before-define */
import { NewsroomGallery } from '@prezly/sdk';
import { getAssetsUrl, getGalleryThumbnail, getUploadcareGroupUrl } from '@prezly/theme-kit-core';
import { translations } from '@prezly/theme-kit-intl';
import { useEffect, useState } from 'react';
import { useIntl } from 'react-intl';

import { ContentRenderer, StoryLinks } from '@/components';

Expand All @@ -14,7 +17,7 @@ interface Props {
gallery: NewsroomGallery;
}

function Gallery({ gallery }: Props) {
export default function Gallery({ gallery }: Props) {
const { content, name, uploadcare_group_uuid, description } = gallery;
const galleryThumbnail = getGalleryThumbnail(gallery);

Expand All @@ -26,10 +29,13 @@ function Gallery({ gallery }: Props) {
}
}, []);

const metaDescription = useGalleryPageMetaDescription(gallery);

return (
<Layout
title={name}
imageUrl={galleryThumbnail ? getAssetsUrl(galleryThumbnail.uuid) : undefined}
description={metaDescription}
>
<div className={styles.container}>
<h1 className={styles.title}>{name}</h1>
Expand All @@ -48,4 +54,24 @@ function Gallery({ gallery }: Props) {
);
}

export default Gallery;
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;
}
50 changes: 25 additions & 25 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.6.0",
"@prezly/story-content-format": "0.65.1",
"@prezly/theme-kit-core": "7.5.0",
"@prezly/theme-kit-intl": "7.5.0",
"@prezly/theme-kit-nextjs": "7.5.0",
"@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.4",
"@prezly/uploadcare-image": "0.3.2",
"@react-hookz/web": "14.7.1",
Expand Down

0 comments on commit c60cfed

Please sign in to comment.