Skip to content

Commit 8ca4021

Browse files
committed
feat: add blogName to metadata generation across various pages and implement ScrollToTop component
1 parent f28b8a5 commit 8ca4021

13 files changed

Lines changed: 39 additions & 10 deletions

File tree

app/[locale]/about/page.tsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ export async function generateMetadata({
2121
description: dictionary.about.pageDescription,
2222
url: `/${locale}/about`,
2323
locale,
24+
blogName: dictionary.meta.blogName,
2425
})
2526
}
2627

app/[locale]/books/[slug]/page.tsx

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,12 +49,14 @@ export const generateMetadata = async ({
4949

5050
if (!book) throw new Error(`Book not found for slug: ${slug}`)
5151

52+
const dictionary = await getDictionary(locale)
5253
return createMetadata({
5354
title: book.title,
5455
description: sliceDesc(book.summary, 160),
5556
image: book.cover_url,
5657
url: localePath(`/books/${book.slug}`, locale),
5758
locale,
59+
blogName: dictionary.meta.blogName,
5860
})
5961
}
6062

app/[locale]/books/page.tsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ export async function generateMetadata({
2323
description: dictionary.books.pageDescription,
2424
url: `/${locale}/books`,
2525
locale,
26+
blogName: dictionary.meta.blogName,
2627
})
2728
}
2829

app/[locale]/page.tsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ export async function generateMetadata({
2424
description: dictionary.meta.blogDescription,
2525
url: `/${locale}`,
2626
locale,
27+
blogName: dictionary.meta.blogName,
2728
})
2829
}
2930

app/[locale]/posts/[slug]/page.tsx

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import GitHubGiscus from '@/app/ui/GitHubGiscus'
77
import Line from '@/app/ui/Line'
88
import MobileToc from '@/app/ui/MobileToc'
99
import ScrollProgress from '@/app/ui/ScrollProgress'
10+
import ScrollToTop from '@/app/ui/ScrollToTop'
1011
import { BlogPostStructuredData } from '@/app/ui/StructuredData'
1112
import ToastPostal from '@/app/ui/ToastPostal'
1213
import Toc from '@/app/ui/Toc'
@@ -42,7 +43,11 @@ export const generateMetadata = async ({
4243
const dictionary = await getDictionary(locale)
4344

4445
if (!post) {
45-
return createMetadata({ title: dictionary.posts.notFound, locale })
46+
return createMetadata({
47+
title: dictionary.posts.notFound,
48+
locale,
49+
blogName: dictionary.meta.blogName,
50+
})
4651
}
4752

4853
return createMetadata({
@@ -55,6 +60,7 @@ export const generateMetadata = async ({
5560
modifiedTime: post.date,
5661
tags: post.tags,
5762
locale,
63+
blogName: dictionary.meta.blogName,
5864
})
5965
}
6066

@@ -72,15 +78,18 @@ export default async function LocalePost({
7278
if (!post) throw new Error(`Post not found for slug: ${slug}`)
7379

7480
const availableTranslations = getPostTranslations(slug, locale)
75-
const koPosts = getPostsByLocale('ko')
76-
const otherPosts = koPosts
81+
const localePosts = getPostsByLocale(locale)
82+
const otherPosts = (
83+
localePosts.length > 0 ? localePosts : getPostsByLocale('ko')
84+
)
7785
.filter((other) => other.slug !== slug && other.date < post.date)
7886
.slice(0, 3)
7987

8088
const { date, title, body, tags, toc } = post
8189

8290
return (
8391
<div className="min-w-0 overflow-x-clip">
92+
<ScrollToTop />
8493
<BlogPostStructuredData
8594
title={title}
8695
description={post.summary}

app/[locale]/tags/page.tsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ export async function generateMetadata({
2222
description: dictionary.tags.pageDescription,
2323
url: `/${locale}/tags`,
2424
locale,
25+
blogName: dictionary.meta.blogName,
2526
})
2627
}
2728

app/lib/metadata.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ interface GenerateMetadataProps {
1818
tags?: string[]
1919
author?: string
2020
locale?: string
21+
blogName?: string
2122
}
2223

2324
/** Build hreflang alternates for a given path (without locale prefix) */
@@ -59,8 +60,10 @@ export function generateMetadata({
5960
tags,
6061
author = blog_name,
6162
locale = 'ko',
63+
blogName,
6264
}: GenerateMetadataProps): Metadata {
63-
const fullTitle = title ? `${title} - ${blog_name}` : blog_title
65+
const siteName = blogName ?? blog_name
66+
const fullTitle = title ? `${title} - ${siteName}` : blog_title
6467
const fullUrl = `${BASE_URL}${url}`
6568
const fullImageUrl = image.startsWith('http') ? image : `${BASE_URL}${image}`
6669
const ogLocale = ogLocaleMap[locale] ?? 'ko_KR'

app/posts/[slug]/page.tsx

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import GitHubGiscus from '@/app/ui/GitHubGiscus'
77
import Line from '@/app/ui/Line'
88
import MobileToc from '@/app/ui/MobileToc'
99
import ScrollProgress from '@/app/ui/ScrollProgress'
10+
import ScrollToTop from '@/app/ui/ScrollToTop'
1011
import { BlogPostStructuredData } from '@/app/ui/StructuredData'
1112
import ToastPostal from '@/app/ui/ToastPostal'
1213
import Toc from '@/app/ui/Toc'
@@ -71,6 +72,7 @@ export default async function Post({
7172

7273
return (
7374
<div className="min-w-0 overflow-x-clip">
75+
<ScrollToTop />
7476
<BlogPostStructuredData
7577
title={title}
7678
description={post.summary}

app/ui/ScrollToTop.tsx

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
'use client'
2+
3+
import { useEffect } from 'react'
4+
5+
export default function ScrollToTop() {
6+
useEffect(() => {
7+
window.scrollTo({ top: 0, behavior: 'instant' })
8+
}, [])
9+
10+
return null
11+
}

app/ui/home/AnotherPost.tsx

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
'use client'
22

3-
import { localePath } from '@/app/i18n/config'
43
import { useDictionary } from '@/app/i18n/use-dictionary'
54
import PostDate from '@/app/ui/home/post/PostDate'
65
import { Post } from 'contentlayer/generated'
@@ -11,7 +10,7 @@ export default function AnotherPost({ post }: { post: Post }) {
1110
const { locale } = useDictionary()
1211
const { push } = useRouter()
1312
const { title, date, body, cover_image } = post
14-
const localeUrl = localePath(post.url, locale)
13+
const localeUrl = post.url
1514

1615
return (
1716
<div

0 commit comments

Comments
 (0)