Skip to content

Commit ee3f5db

Browse files
committed
fix: seo error
Signed-off-by: Innei <[email protected]>
1 parent a6fb8bd commit ee3f5db

File tree

5 files changed

+42
-26
lines changed

5 files changed

+42
-26
lines changed

src/app/config.d.ts

+21
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,26 @@
11
import type { ScriptProps } from 'next/script'
22

3+
export interface LinkSection {
4+
name: string
5+
links: {
6+
name: string
7+
href: string
8+
external?: boolean
9+
}[]
10+
}
11+
12+
export interface OtherInfo {
13+
date: string
14+
icp?: {
15+
text: string
16+
link: string
17+
}
18+
}
19+
export interface AppThemeConfig {
20+
config: AppConfig
21+
footer: FooterConfig
22+
}
23+
324
export interface AppConfig {
425
site: Site
526
hero: Hero

src/app/layout.tsx

+16-7
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,14 @@ import '../styles/index.css'
22

33
import { Analytics } from '@vercel/analytics/react'
44
import type { AggregateRoot } from '@mx-space/api-client'
5+
import type { AppThemeConfig } from './config'
56

67
import { ClerkProvider } from '@clerk/nextjs'
78

89
import PKG from '~/../package.json'
910
import { Root } from '~/components/layout/root/Root'
1011
import { TocAutoScroll } from '~/components/widgets/toc/TocAutoScroll'
1112
import { attachUA } from '~/lib/attach-ua'
12-
import { defineMetadata } from '~/lib/define-metadata'
1313
import { sansFont, serifFont } from '~/lib/fonts'
1414
import { getQueryClient } from '~/lib/query-client.server'
1515
import { AggregationProvider } from '~/providers/root/aggregation-data-provider'
@@ -25,12 +25,21 @@ init()
2525

2626
export const revalidate = 60
2727

28-
let aggregationData: (AggregateRoot & { theme: any }) | null = null
29-
export const generateMetadata = defineMetadata(async (_, getData) => {
30-
const fetchedData = aggregationData ?? (await getData())
31-
// @ts-ignore
28+
let aggregationData: (AggregateRoot & { theme: AppThemeConfig }) | null = null
29+
export const generateMetadata = async () => {
30+
const queryClient = await getQueryClient()
31+
32+
const fetchedData =
33+
aggregationData ??
34+
(await queryClient.fetchQuery(queries.aggregation.root()))
35+
3236
aggregationData = fetchedData
33-
const { seo, url, user, theme: config } = fetchedData
37+
const {
38+
seo,
39+
url,
40+
user,
41+
theme: { config },
42+
} = fetchedData
3443

3544
return {
3645
metadataBase: new URL(url.webUrl),
@@ -86,7 +95,7 @@ export const generateMetadata = defineMetadata(async (_, getData) => {
8695
description: seo.description,
8796
},
8897
}
89-
})
98+
}
9099

91100
type Props = {
92101
children: React.ReactNode

src/components/layout/footer/FooterInfo.tsx

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import Link from 'next/link'
2+
import type { FooterConfig } from './config'
23

34
import { SubscribeTextButton } from '~/components/widgets/subscribe/SubscribeTextButton'
45
import { clsxm } from '~/lib/helper'
@@ -24,7 +25,7 @@ const FooterLinkSection = async () => {
2425
const queryClient = await getQueryClient()
2526
const data = await queryClient.fetchQuery(queries.aggregation.root())
2627
const { footer } = data.theme
27-
const footerConfig = footer || {
28+
const footerConfig: FooterConfig = footer || {
2829
linkSections: defaultLinkSections,
2930
}
3031

src/components/layout/footer/config.ts

+1-15
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,5 @@
1-
export interface LinkSection {
2-
name: string
3-
links: {
4-
name: string
5-
href: string
6-
external?: boolean
7-
}[]
8-
}
1+
import type { LinkSection, OtherInfo } from '~/app/config'
92

10-
export interface OtherInfo {
11-
date: string
12-
icp?: {
13-
text: string
14-
link: string
15-
}
16-
}
173
export const defaultLinkSections: LinkSection[] = [
184
{
195
name: '关于',

src/queries/definition/aggregation.ts

+2-3
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
import { isServer } from '@tanstack/react-query'
22
import type { AggregateRoot } from '@mx-space/api-client'
3-
import type { AppConfig } from '~/app/config'
4-
import type { FooterConfig } from '~/components/layout/footer/config'
3+
import type { AppThemeConfig } from '~/app/config'
54

65
import { apiClient } from '~/lib/request'
76

@@ -15,7 +14,7 @@ export const aggregation = {
1514
apiClient.aggregate.getAggregateData('shiro').then(
1615
(res) =>
1716
res.$serialized as AggregateRoot & {
18-
theme: { footer: FooterConfig; config: AppConfig }
17+
theme: AppThemeConfig
1918
},
2019
),
2120
cacheTime: 1000 * 60 * 10,

0 commit comments

Comments
 (0)