Skip to content

Commit

Permalink
fix: seo error
Browse files Browse the repository at this point in the history
Signed-off-by: Innei <i@innei.in>
  • Loading branch information
Innei committed Jul 12, 2023
1 parent a6fb8bd commit ee3f5db
Show file tree
Hide file tree
Showing 5 changed files with 42 additions and 26 deletions.
21 changes: 21 additions & 0 deletions src/app/config.d.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,26 @@
import type { ScriptProps } from 'next/script'

export interface LinkSection {
name: string
links: {
name: string
href: string
external?: boolean
}[]
}

export interface OtherInfo {
date: string
icp?: {
text: string
link: string
}
}
export interface AppThemeConfig {
config: AppConfig
footer: FooterConfig
}

export interface AppConfig {
site: Site
hero: Hero
Expand Down
23 changes: 16 additions & 7 deletions src/app/layout.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,14 @@ import '../styles/index.css'

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

import { ClerkProvider } from '@clerk/nextjs'

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

export const revalidate = 60

let aggregationData: (AggregateRoot & { theme: any }) | null = null
export const generateMetadata = defineMetadata(async (_, getData) => {
const fetchedData = aggregationData ?? (await getData())
// @ts-ignore
let aggregationData: (AggregateRoot & { theme: AppThemeConfig }) | null = null
export const generateMetadata = async () => {
const queryClient = await getQueryClient()

const fetchedData =
aggregationData ??
(await queryClient.fetchQuery(queries.aggregation.root()))

aggregationData = fetchedData
const { seo, url, user, theme: config } = fetchedData
const {
seo,
url,
user,
theme: { config },
} = fetchedData

return {
metadataBase: new URL(url.webUrl),
Expand Down Expand Up @@ -86,7 +95,7 @@ export const generateMetadata = defineMetadata(async (_, getData) => {
description: seo.description,
},
}
})
}

type Props = {
children: React.ReactNode
Expand Down
3 changes: 2 additions & 1 deletion src/components/layout/footer/FooterInfo.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import Link from 'next/link'
import type { FooterConfig } from './config'

import { SubscribeTextButton } from '~/components/widgets/subscribe/SubscribeTextButton'
import { clsxm } from '~/lib/helper'
Expand All @@ -24,7 +25,7 @@ const FooterLinkSection = async () => {
const queryClient = await getQueryClient()
const data = await queryClient.fetchQuery(queries.aggregation.root())
const { footer } = data.theme
const footerConfig = footer || {
const footerConfig: FooterConfig = footer || {
linkSections: defaultLinkSections,
}

Expand Down
16 changes: 1 addition & 15 deletions src/components/layout/footer/config.ts
Original file line number Diff line number Diff line change
@@ -1,19 +1,5 @@
export interface LinkSection {
name: string
links: {
name: string
href: string
external?: boolean
}[]
}
import type { LinkSection, OtherInfo } from '~/app/config'

export interface OtherInfo {
date: string
icp?: {
text: string
link: string
}
}
export const defaultLinkSections: LinkSection[] = [
{
name: '关于',
Expand Down
5 changes: 2 additions & 3 deletions src/queries/definition/aggregation.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import { isServer } from '@tanstack/react-query'
import type { AggregateRoot } from '@mx-space/api-client'
import type { AppConfig } from '~/app/config'
import type { FooterConfig } from '~/components/layout/footer/config'
import type { AppThemeConfig } from '~/app/config'

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

Expand All @@ -15,7 +14,7 @@ export const aggregation = {
apiClient.aggregate.getAggregateData('shiro').then(
(res) =>
res.$serialized as AggregateRoot & {
theme: { footer: FooterConfig; config: AppConfig }
theme: AppThemeConfig
},
),
cacheTime: 1000 * 60 * 10,
Expand Down

1 comment on commit ee3f5db

@vercel
Copy link

@vercel vercel bot commented on ee3f5db Jul 12, 2023

Choose a reason for hiding this comment

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

Successfully deployed to the following URLs:

shiro – ./

innei.in
springtide.vercel.app
shiro-innei.vercel.app
shiro-git-main-innei.vercel.app

Please sign in to comment.