Skip to content

Commit 24bcbef

Browse files
committed
Build and deploy
1 parent de79188 commit 24bcbef

9 files changed

Lines changed: 85 additions & 149 deletions

File tree

app/[locale]/SearchProvider.tsx

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -15,17 +15,21 @@ export const CustomSearchProvider = ({ children }: { children: React.ReactNode }
1515
const locale = getLocaleFromPath(pathname) || defaultLocale
1616
const t = (key: string) => getTranslation(key, locale)
1717

18-
// 使用类型断言来访问 kbarConfig,避免 TypeScript 类型检查错误
19-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
20-
const searchConfig = siteMetadata.search as any
21-
const searchDocumentsPath = searchConfig?.kbarConfig?.searchDocumentsPath || 'search.json'
18+
// Type assertion for search config
19+
interface SearchConfigWithKBar {
20+
kbarConfig?: {
21+
searchDocumentsPath?: string
22+
}
23+
}
24+
const searchConfig = siteMetadata.search as SearchConfigWithKBar | undefined
25+
const kbarConfig = searchConfig?.kbarConfig
2226

2327
return (
2428
<>
2529
<KBarEscButton />
2630
<KBarSearchProvider
2731
kbarConfig={{
28-
searchDocumentsPath: searchDocumentsPath,
32+
searchDocumentsPath: kbarConfig?.searchDocumentsPath || 'search.json',
2933
defaultActions: [],
3034
onSearchDocumentsLoad(json) {
3135
return json.map((post: CoreContent<Blog>) => ({

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

Lines changed: 25 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,14 @@ import siteMetadata from '@/data/siteMetadata'
1515
import { notFound } from 'next/navigation'
1616
import type { Locale } from '@/lib/i18n'
1717

18+
interface BlogWithTitleZh extends Blog {
19+
titleZh?: string
20+
}
21+
22+
interface AuthorWithNameEn extends Authors {
23+
nameEn?: string
24+
}
25+
1826
const defaultLayout = 'PostLayout'
1927
const layouts = {
2028
PostSimple,
@@ -39,16 +47,17 @@ export async function generateMetadata(props: {
3947
}
4048

4149
// 根据语言选择标题
50+
const postWithTitleZh = post as BlogWithTitleZh
4251
const displayTitle =
43-
locale === 'zh' && (post as Blog & { titleZh?: string }).titleZh
44-
? (post as Blog & { titleZh?: string }).titleZh
45-
: post.title
52+
locale === 'zh' && postWithTitleZh.titleZh ? postWithTitleZh.titleZh : post.title
4653

4754
// 根据语言选择作者名
4855
const authors = authorDetails.map((author) => {
49-
return locale === 'zh'
50-
? author.name
51-
: (author as Authors & { nameEn?: string }).nameEn || author.name
56+
if (locale === 'zh') {
57+
return author.name
58+
}
59+
const authorWithNameEn = author as AuthorWithNameEn
60+
return authorWithNameEn.nameEn || author.name
5261
})
5362

5463
const publishedAt = new Date(post.date).toISOString()
@@ -132,19 +141,18 @@ export default async function Page(props: { params: Promise<{ slug: string[]; lo
132141
const Layout = layouts[post.layout || defaultLayout]
133142

134143
// 根据语言选择标题
144+
const postWithTitleZh = post as BlogWithTitleZh
135145
const displayTitle =
136-
locale === 'zh' && (post as Blog & { titleZh?: string }).titleZh
137-
? (post as Blog & { titleZh?: string }).titleZh
138-
: post.title
146+
locale === 'zh' && postWithTitleZh.titleZh ? postWithTitleZh.titleZh : post.title
139147

140148
// 根据语言选择作者名
141-
const displayAuthorDetails = authorDetails.map((author) => ({
142-
...author,
143-
displayName:
144-
locale === 'zh'
145-
? author.name
146-
: (author as Authors & { nameEn?: string }).nameEn || author.name,
147-
}))
149+
const displayAuthorDetails = authorDetails.map((author) => {
150+
const authorWithNameEn = author as AuthorWithNameEn
151+
return {
152+
...author,
153+
displayName: locale === 'zh' ? author.name : authorWithNameEn.nameEn || author.name,
154+
}
155+
})
148156

149157
return (
150158
<>
@@ -154,7 +162,7 @@ export default async function Page(props: { params: Promise<{ slug: string[]; lo
154162
/>
155163
<Layout
156164
content={{ ...mainContent, title: displayTitle } as CoreContent<Blog>}
157-
authorDetails={displayAuthorDetails as (CoreContent<Authors> & { displayName?: string })[]}
165+
authorDetails={displayAuthorDetails}
158166
next={next}
159167
prev={prev}
160168
locale={locale}

app/[locale]/blog/page.tsx

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,13 @@ import { genPageMetadata } from 'app/seo'
44
import SimpleBlogLayout from '@/layouts/SimpleBlogLayout'
55
import { getTranslation } from '@/data/translations'
66
import type { Locale } from '@/lib/i18n'
7+
import { locales } from '@/lib/i18n'
8+
9+
export async function generateStaticParams() {
10+
return locales.map((locale) => ({
11+
locale,
12+
}))
13+
}
714

815
export async function generateMetadata(props: {
916
params: Promise<{ locale: string }>

app/[locale]/joinus/page.tsx

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,13 @@ import { genPageMetadata } from 'app/seo'
22
import Link from '@/components/Link'
33
import { getTranslation } from '@/data/translations'
44
import type { Locale } from '@/lib/i18n'
5+
import { locales } from '@/lib/i18n'
6+
7+
export async function generateStaticParams() {
8+
return locales.map((locale) => ({
9+
locale,
10+
}))
11+
}
512

613
export async function generateMetadata(props: {
714
params: Promise<{ locale: string }>

app/[locale]/page.tsx

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,13 @@ import { sortPosts, allCoreContent } from 'pliny/utils/contentlayer'
22
import { allBlogs } from 'contentlayer/generated'
33
import Main from './Main'
44
import type { Locale } from '@/lib/i18n'
5+
import { locales } from '@/lib/i18n'
6+
7+
export async function generateStaticParams() {
8+
return locales.map((locale) => ({
9+
locale,
10+
}))
11+
}
512

613
export default async function Page(props: { params: Promise<{ locale: string }> }) {
714
const params = await props.params

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

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,19 @@ import Image from '@/components/Image'
55
import Link from '@/components/Link'
66
import { getTranslation } from '@/data/translations'
77
import type { Locale } from '@/lib/i18n'
8+
import { locales } from '@/lib/i18n'
89

910
export async function generateStaticParams() {
10-
return productsData.map((product) => ({
11-
slug: product.slug,
12-
}))
11+
const params: { slug: string; locale: string }[] = []
12+
for (const locale of locales) {
13+
for (const product of productsData) {
14+
params.push({
15+
slug: product.slug,
16+
locale,
17+
})
18+
}
19+
}
20+
return params
1321
}
1422

1523
export async function generateMetadata(props: {

app/[locale]/products/page.tsx

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,13 @@ import Image from '@/components/Image'
44
import { genPageMetadata } from 'app/seo'
55
import { getTranslation } from '@/data/translations'
66
import type { Locale } from '@/lib/i18n'
7+
import { locales } from '@/lib/i18n'
8+
9+
export async function generateStaticParams() {
10+
return locales.map((locale) => ({
11+
locale,
12+
}))
13+
}
714

815
export async function generateMetadata(props: {
916
params: Promise<{ locale: string }>

app/blog/[...slug]/page.tsx

Lines changed: 0 additions & 120 deletions
This file was deleted.

layouts/SimpleBlogLayout.tsx

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,14 @@ import { coreContent } from 'pliny/utils/contentlayer'
88
import type { Authors } from 'contentlayer/generated'
99
import type { Locale } from '@/lib/i18n'
1010

11+
interface BlogWithTitleZh extends CoreContent<Blog> {
12+
titleZh?: string
13+
}
14+
15+
interface AuthorWithNameEn extends Authors {
16+
nameEn?: string
17+
}
18+
1119
interface SimpleBlogLayoutProps {
1220
posts: CoreContent<Blog>[]
1321
title: string
@@ -40,9 +48,8 @@ export default function SimpleBlogLayout({
4048
<div className="max-w-4xl">
4149
<ul className="space-y-0">
4250
{posts.map((post) => {
43-
const { path, date, title, titleZh, authors } = post as CoreContent<Blog> & {
44-
titleZh?: string
45-
}
51+
const postWithTitleZh = post as BlogWithTitleZh
52+
const { path, date, title, titleZh, authors } = postWithTitleZh
4653
const authorList = authors || ['default']
4754
const authorDetails = authorList.map((author) => {
4855
const authorResults = allAuthors.find((p) => p.slug === author)
@@ -55,7 +62,8 @@ export default function SimpleBlogLayout({
5562
if (locale === 'zh') {
5663
return author.name || ''
5764
} else {
58-
return (author as Authors & { nameEn?: string }).nameEn || author.name || ''
65+
const authorWithNameEn = author as AuthorWithNameEn
66+
return authorWithNameEn.nameEn || author.name || ''
5967
}
6068
})
6169
.filter(Boolean)

0 commit comments

Comments
 (0)