All files / src/lib/metadata group.ts

0% Statements 0/74
0% Branches 0/1
0% Functions 0/1
0% Lines 0/74

Press n or j to go to the next uncovered block, b, p or k for the previous block.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75                                                                                                                                                     
import { Metadata } from 'next';
import { headers } from 'next/headers';

import { API } from '@/api';

export const generateGroupMetadata = async (groupId: string): Promise<Metadata> => {
  const headersList = headers();
  const host = (await headersList).get('host') || process.env.DOMAIN;
  const currentUrl = `https://${host}/group/${groupId}`;

  try {
    const {
      createdBy: { nickName },
      title,
      images,
    } = await API.groupService.getGroupDetails({ groupId });

    const metaTitle = `${nickName}님의 모임 | WeGo`;
    const metaDescription = title;

    const thumbnails = images[0]?.variants ? images[0].variants[0].imageUrl : '';

    return {
      title: metaTitle,
      description: metaDescription,
      keywords: [nickName, '모임', 'WeGo'],
      openGraph: {
        title: metaTitle,
        description: metaDescription,
        siteName: 'WeGo',
        locale: 'ko_KR',
        type: 'website',
        url: currentUrl,
        images: thumbnails
          ? [
              {
                url: thumbnails,
                width: 400,
                height: 400,
                alt: `${nickName}님의 모임 사진`,
              },
            ]
          : [],
      },
      twitter: {
        card: 'summary',
        title: metaTitle,
        description: metaDescription,
        images: thumbnails ? [thumbnails] : undefined,
      },
      robots: {
        index: true,
        follow: true,
      },
      alternates: {
        canonical: currentUrl,
      },
    };
  } catch {
    return {
      title: `모임 상세 정보 | WeGo`,
      description: '사용자의 모임을 확인해보세요.',
      openGraph: {
        title: '사용자 모임 | WeGo',
        description: '사용자의 모임을 확인해보세요.',
        url: currentUrl,
        type: 'website',
      },
      twitter: {
        card: 'summary',
      },
    };
  }
};