Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[meta-tags] 앱라우터용 메타태그 및 QaPageScript, DiscussionForumPostingScript를 추가합니다. #3500

Merged
merged 8 commits into from
Dec 20, 2024
Merged
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
import { Metadata } from 'next'

import { DEFAULT_APP_ID } from '../constants'

export function generateAppleSmartBannerMeta({
appId = DEFAULT_APP_ID,
appPath = '/',
}: {
appId?: string
appPath?: string
} = {}): Metadata {
const appUrlScheme = process.env.NEXT_PUBLIC_APP_URL_SCHEME || ''

return {
itunes: {
appId,
appArgument: `${appUrlScheme}://${appPath}`,
},
}
}
10 changes: 10 additions & 0 deletions packages/meta-tags/src/app-router/generate-common-meta.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
import { Metadata } from 'next'

export function generateCommonMeta(): Metadata {
return {
icons: {
apple: 'https://triple.guide/icons/favicon-152x152.png',
},
manifest: '/manifest.json',
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
import { Metadata } from 'next'

export function generateEssentialContentMeta({
title,
description,
canonicalUrl,
}: {
title?: string
description?: string
canonicalUrl?: string
} = {}): Metadata {
return {
title: title || process.env.NEXT_PUBLIC_DEFAULT_PAGE_TITLE || '',
description:
description || process.env.NEXT_PUBLIC_DEFAULT_PAGE_DESCRIPTION || '',
alternates: {
canonical: canonicalUrl,
},
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
import { Metadata } from 'next'

import { DEFAULT_APP_ID, DEFAULT_APP_PACKAGE_NAME } from '../constants'

export function generateFacebookAppLinkMeta({
appName: appNameFromProps,
appId = DEFAULT_APP_ID,
appPath = '/',
appPackageName = DEFAULT_APP_PACKAGE_NAME,
}: {
appName?: string
appId?: string
appPath?: string
appPackageName?: string
} = {}): Metadata {
const appName = appNameFromProps ?? '트리플'
const appUrlScheme = process.env.NEXT_PUBLIC_APP_URL_SCHEME || ''
const url = `${appUrlScheme}://${appPath}`

return {
appLinks: {
ios: {
app_name: appName,
url,
app_store_id: appId,
},
android: {
app_name: appName,
url,
package: appPackageName,
},
},
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
import { Metadata } from 'next'
import { OpenGraphType } from 'next/dist/lib/metadata/types/opengraph-types'

import { DEFAULT_OG_IMAGE } from '../constants'

export function generateFacebookOpenGraphMeta({
title: titleFromProps,
description: descriptionFromProps,
canonicalUrl,
type = 'website',
locale = 'ko_KR',
image = DEFAULT_OG_IMAGE,
}: {
title?: string
description?: string
canonicalUrl?: string
type?: OpenGraphType
locale?: string
image?: { url: string; width?: number; height?: number }
} = {}): Metadata {
const title = titleFromProps || process.env.NEXT_PUBLIC_DEFAULT_PAGE_TITLE
const description =
descriptionFromProps || process.env.NEXT_PUBLIC_DEFAULT_PAGE_DESCRIPTION
const url =
canonicalUrl ||
(process.env.NEXT_PUBLIC_WEB_URL_BASE
? `${process.env.NEXT_PUBLIC_WEB_URL_BASE}/auth-web`
: undefined)

return {
openGraph: {
title,
description,
url,
type,
locale,
images: image,
},
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
import { Metadata } from 'next'

import { generateCommonMeta } from './generate-common-meta'
import { generateEssentialContentMeta } from './generate-essential-content-meta'
import { generateFacebookOpenGraphMeta } from './generate-facebook-open-graph-meta'
import { generateFacebookAppLinkMeta } from './generate-facebook-app-link-meta'
import { generateAppleSmartBannerMeta } from './generate-apple-smart-banner-meta'

export function generateTripleDefaultMeta(): Metadata {
return {
...generateCommonMeta(),
...generateEssentialContentMeta(),
...generateFacebookOpenGraphMeta(),
...generateFacebookAppLinkMeta(),
...generateAppleSmartBannerMeta(),
}
}
6 changes: 6 additions & 0 deletions packages/meta-tags/src/app-router/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
export * from './generate-common-meta'
export * from './generate-apple-smart-banner-meta'
export * from './generate-essential-content-meta'
export * from './generate-facebook-app-link-meta'
export * from './generate-facebook-open-graph-meta'
export * from './generate-triple-default-meta'
16 changes: 0 additions & 16 deletions packages/meta-tags/src/article-script.tsx

This file was deleted.

16 changes: 0 additions & 16 deletions packages/meta-tags/src/breadcrumb-list-script.tsx

This file was deleted.

16 changes: 4 additions & 12 deletions packages/meta-tags/src/index.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,4 @@
export { ItemAvailability } from './types'
export { EssentialContentMeta } from './essential-content-meta'
export { CommonMeta } from './common-meta'
export { AppleSmartBannerMeta } from './apple-smart-banner-meta'
export { FacebookAppLinkMeta } from './facebook-app-link-meta'
export { FacebookOpenGraphMeta } from './facebook-open-graph-meta'
export { ThemeColorMeta } from './theme-color-meta'
export { ArticleScript } from './article-script'
export { BreadcrumbListScript } from './breadcrumb-list-script'
export { ProductScript } from './product-script'
export { LocalBusinessScript } from './local-business-script'
export { ReviewScript } from './review-script'
export * from './types'
export * from './app-router'
export * from './pages-router'
export * from './structured-data'
19 changes: 0 additions & 19 deletions packages/meta-tags/src/local-business-script.tsx

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import Head from 'next/head'
import { useEnv } from '@titicaca/triple-web'

import { DEFAULT_APP_ID } from './constants'
import { DEFAULT_APP_ID } from '../constants'

export function AppleSmartBannerMeta({
appId = DEFAULT_APP_ID,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import Head from 'next/head'
import { useEnv, useTranslation } from '@titicaca/triple-web'

import { DEFAULT_APP_ID, DEFAULT_APP_PACKAGE_NAME } from './constants'
import { DEFAULT_APP_ID, DEFAULT_APP_PACKAGE_NAME } from '../constants'

export function FacebookAppLinkMeta({
appName,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import Head from 'next/head'
import { useEnv } from '@titicaca/triple-web'

import { DEFAULT_OG_IMAGE } from './constants'
import { DEFAULT_OG_IMAGE } from '../constants'

export function FacebookOpenGraphMeta({
title: titleFromProps,
Expand Down
6 changes: 6 additions & 0 deletions packages/meta-tags/src/pages-router/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
export { EssentialContentMeta } from './essential-content-meta'
export { CommonMeta } from './common-meta'
export { AppleSmartBannerMeta } from './apple-smart-banner-meta'
export { FacebookAppLinkMeta } from './facebook-app-link-meta'
export { FacebookOpenGraphMeta } from './facebook-open-graph-meta'
export { ThemeColorMeta } from './theme-color-meta'
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import Head from 'next/head'

import { ThemeColor } from './types'
import { DEFAULT_THEME_COLOR } from './constants'
import { ThemeColor } from '../types'
import { DEFAULT_THEME_COLOR } from '../constants'

export function ThemeColorMeta({
content = DEFAULT_THEME_COLOR,
Expand Down
16 changes: 0 additions & 16 deletions packages/meta-tags/src/product-script.tsx

This file was deleted.

14 changes: 0 additions & 14 deletions packages/meta-tags/src/review-script.tsx

This file was deleted.

18 changes: 18 additions & 0 deletions packages/meta-tags/src/structured-data/article-script.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
import Script from 'next/script'

import { createScript } from '../utils'
import { ArticleScriptProps } from '../types'

export function ArticleScript(props: ArticleScriptProps) {
const articleScript = createScript(props, 'Article')

return (
<Script
Copy link
Contributor Author

@dongoc dongoc Dec 17, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

  • 기존 코드에서 head 태그 제거(nextjs 앱라우터는 head 태그를 지원하지 않습니다)
  • 일반 script 태그를 next/script 태그로 변경
  • 간혹 파싱 오류가 있어 dangerouslySetInnerHtml로 주입합니다. (관련 스레드)

id="article-script"
type="application/ld+json"
dangerouslySetInnerHTML={{
__html: JSON.stringify(articleScript, null, '\t'),
}}
/>
)
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
import Script from 'next/script'

import { createScript } from '../utils'
import { BreadcrumbListScriptProps } from '../types'

export function BreadcrumbListScript(props: BreadcrumbListScriptProps) {
const breadcrumbScript = createScript(props, 'BreadcrumbList')

return (
<Script
id="breadcrumb-list-script"
type="application/ld+json"
dangerouslySetInnerHTML={{
__html: JSON.stringify(breadcrumbScript, null, '\t'),
}}
/>
)
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
import Script from 'next/script'

import { createScript } from '../utils'
import { DiscussionForumPostingScriptProps } from '../types'

export function DiscussionForumPostingScript(
props: DiscussionForumPostingScriptProps,
) {
const discussionForumPosting = createScript(props, 'DiscussionForumPosting')

return (
<Script
id="discussion-forum-posting-script"
type="application/ld+json"
dangerouslySetInnerHTML={{
__html: JSON.stringify(discussionForumPosting, null, '\t'),
}}
/>
)
}
7 changes: 7 additions & 0 deletions packages/meta-tags/src/structured-data/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
export { ArticleScript } from './article-script'
export { BreadcrumbListScript } from './breadcrumb-list-script'
export { ProductScript } from './product-script'
export { LocalBusinessScript } from './local-business-script'
export { ReviewScript } from './review-script'
export { QaPageScript } from './qa-page-script'
export { DiscussionForumPostingScript } from './discussion-forum-posting-script'
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
import Script from 'next/script'

import { SCHEMA_SCRIPT_TYPE_MAP, createScript } from '../utils'
import { LocalBusinessScriptProps } from '../types'

export function LocalBusinessScript({
type,
...props
}: LocalBusinessScriptProps) {
const localBusinessScript = createScript(props, SCHEMA_SCRIPT_TYPE_MAP[type])

return (
<Script
id="local-business-script"
type="application/ld+json"
dangerouslySetInnerHTML={{
__html: JSON.stringify(localBusinessScript, null, '\t'),
}}
/>
)
}
Loading
Loading