All files / src/lib/metadata profile.ts

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

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                                                                                                                                             
import { Metadata } from 'next';
import { headers } from 'next/headers';

import { API } from '@/api';

export const generateProfileMetadata = async (userId: number): Promise<Metadata> => {
  const headersList = headers();
  const host = (await headersList).get('host') || process.env.DOMAIN;
  const currentUrl = `https://${host}/profile/${userId}`;

  try {
    const userProfile = await API.userService.getUser({ userId });

    const { nickName, followersCnt, profileImage, profileMessage } = userProfile;

    const metaTitle = `${nickName}님의 프로필 | WeGo`;
    const metaDescription = `${nickName}님의 프로필 | 팔로워 ${followersCnt}명\n\n${profileMessage}`;

    return {
      title: metaTitle,
      description: metaDescription,
      keywords: [nickName, '프로필', 'WeGo'],
      openGraph: {
        title: metaTitle,
        description: metaDescription,
        siteName: 'WeGo',
        locale: 'ko_KR',
        type: 'profile',
        url: currentUrl,
        images: profileImage
          ? [
              {
                url: profileImage,
                width: 400,
                height: 400,
                alt: `${nickName}님의 프로필 사진`,
              },
            ]
          : [],
      },
      twitter: {
        card: 'summary',
        title: metaTitle,
        description: metaDescription,
        images: profileImage ? [profileImage] : undefined,
      },
      robots: {
        index: true,
        follow: true,
      },
      alternates: {
        canonical: currentUrl,
      },
    };
  } catch {
    return {
      title: `사용자 프로필 | WeGo`,
      description: '사용자의 프로필과 리뷰를 확인해보세요.',
      openGraph: {
        title: '사용자 프로필 | WeGo',
        description: '사용자의 프로필과 리뷰를 확인해보세요.',
        url: currentUrl,
        type: 'profile',
      },
      twitter: {
        card: 'summary',
      },
    };
  }
};