Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
56 changes: 52 additions & 4 deletions src/lib/metadata/home.ts
Original file line number Diff line number Diff line change
@@ -1,18 +1,39 @@
import { Metadata } from 'next';
import { headers } from 'next/headers';

import { API } from '@/api';
import { GROUP_LIST_PAGE_SIZE } from '@/lib/constants/group-list';

export const generateHomeMetadata = async (keyword?: string): Promise<Metadata> => {
const headersList = headers();
const host = (await headersList).get('host') || process.env.DOMAIN;
const headersList = await headers();
const host = headersList.get('host') || process.env.DOMAIN || 'wego.monster';
const protocol =
headersList.get('x-forwarded-proto') || (host.includes('localhost') ? 'http' : 'https');
const currentUrl = keyword
? `https://${host}/?keyword=${encodeURIComponent(keyword)}`
: `https://${host}/`;
? `${protocol}://${host}/?keyword=${encodeURIComponent(keyword)}`
: `${protocol}://${host}/`;
const logoImageUrl = `${protocol}://${host}/icons/resizable/icon-wego-logo.svg`;

try {
if (keyword) {
const metaTitle = `${keyword} 검색결과 | WeGo`;
const metaDescription = `"${keyword}"에 대한 모임 검색 결과를 확인해보세요.`;

let searchImageUrl = logoImageUrl;
try {
const searchResponse = await API.groupService.getGroups({
size: GROUP_LIST_PAGE_SIZE,
keyword,
});
const firstGroupImage = searchResponse.items[0]?.images?.[0];
if (firstGroupImage) {
searchImageUrl = firstGroupImage;
}
} catch (error) {
// 실패 시 기본 로고 이미지 사용
console.error('이미지를 가져오는데 실패했습니다:', error);
}

return {
title: metaTitle,
description: metaDescription,
Expand All @@ -24,11 +45,20 @@ export const generateHomeMetadata = async (keyword?: string): Promise<Metadata>
locale: 'ko_KR',
type: 'website',
url: currentUrl,
images: [
{
url: searchImageUrl,
width: 400,
height: 400,
alt: `${keyword} 검색 결과 모임 이미지`,
},
],
},
twitter: {
card: 'summary',
title: metaTitle,
description: metaDescription,
images: [searchImageUrl],
},
robots: {
index: true,
Expand All @@ -54,11 +84,20 @@ export const generateHomeMetadata = async (keyword?: string): Promise<Metadata>
locale: 'ko_KR',
type: 'website',
url: currentUrl,
images: [
{
url: logoImageUrl,
width: 400,
height: 400,
alt: 'WeGo 로고',
},
],
},
twitter: {
card: 'summary',
title: metaTitle,
description: metaDescription,
images: [logoImageUrl],
},
robots: {
index: true,
Expand All @@ -78,9 +117,18 @@ export const generateHomeMetadata = async (keyword?: string): Promise<Metadata>
description: 'WeGo에서 함께할 다양한 모임을 탐색하고 참여하세요.',
url: currentUrl,
type: 'website',
images: [
{
url: logoImageUrl,
width: 400,
height: 400,
alt: 'WeGo 로고',
},
],
},
twitter: {
card: 'summary',
images: [logoImageUrl],
},
};
}
Expand Down