diff --git a/app/(main)/Headline.tsx b/app/(main)/Headline.tsx index ab8c0ee1..de5a189f 100644 --- a/app/(main)/Headline.tsx +++ b/app/(main)/Headline.tsx @@ -19,12 +19,12 @@ function Developer() { function Designer() { return ( - + - - - - + + + + 设计师 diff --git a/app/admin/comments/page.tsx b/app/admin/comments/page.tsx index 210ec1ac..e5b68ed0 100644 --- a/app/admin/comments/page.tsx +++ b/app/admin/comments/page.tsx @@ -19,7 +19,7 @@ import { db } from '~/db' import { comments } from '~/db/schema' import { url } from '~/lib' import { truncate } from '~/lib/string' -import { clientFetch } from '~/sanity/lib/client' +import { client } from '~/sanity/lib/client' export default async function AdminCommentsPage() { const { @@ -42,12 +42,13 @@ export default async function AdminCommentsPage() { .limit(15) // get unique post IDs from comments const postIds = [...new Set(latestComments.map((comment) => comment.postId))] - const posts: { _id: string; title: string; slug: string }[] = - await clientFetch( - `*[_type == "post" && (_id in [${postIds - .map((v) => `"${v}"`) - .join(',')}])]{ _id, title, "slug":slug.current }` - ) + const posts = await client.fetch< + { _id: string; title: string; slug: string }[] + >( + `*[_type == "post" && (_id in [${postIds + .map((v) => `"${v}"`) + .join(',')}])]{ _id, title, "slug":slug.current }` + ) // define a map with key of post IDs to posts const postMap = new Map(posts.map((post) => [post._id, post])) diff --git a/sanity/lib/client.ts b/sanity/lib/client.ts index 7e047d66..afeedd07 100644 --- a/sanity/lib/client.ts +++ b/sanity/lib/client.ts @@ -1,5 +1,4 @@ import { createClient } from 'next-sanity' -import { cache } from 'react' import { apiVersion, dataset, projectId, useCdn } from '../env' @@ -8,8 +7,5 @@ export const client = createClient({ dataset, projectId, useCdn, - perspective: 'published', + // perspective: 'published', }) - -// Wrap the cache function in a way that reuses the TypeScript definitions -export const clientFetch = cache(client.fetch.bind(client)) diff --git a/sanity/queries.ts b/sanity/queries.ts index a9cca3a6..de02658a 100644 --- a/sanity/queries.ts +++ b/sanity/queries.ts @@ -1,7 +1,7 @@ import { groq } from 'next-sanity' import { getDate } from '~/lib/date' -import { clientFetch } from '~/sanity/lib/client' +import { client } from '~/sanity/lib/client' import { type Post, type PostDetail } from '~/sanity/schemas/post' import { type Project } from '~/sanity/schemas/project' @@ -12,8 +12,8 @@ export const getAllLatestBlogPostSlugsQuery = () => && defined(slug.current)] | order(publishedAt desc).slug.current ` -export const getAllLatestBlogPostSlugs = (): Promise => { - return clientFetch(getAllLatestBlogPostSlugsQuery()) +export const getAllLatestBlogPostSlugs = () => { + return client.fetch(getAllLatestBlogPostSlugsQuery()) } type GetBlogPostsOptions = { @@ -47,9 +47,8 @@ export const getLatestBlogPostsQuery = ({ } } }` -export const getLatestBlogPosts = ( - options: GetBlogPostsOptions -): Promise => clientFetch(getLatestBlogPostsQuery(options)) +export const getLatestBlogPosts = (options: GetBlogPostsOptions) => + client.fetch(getLatestBlogPostsQuery(options)) export const getBlogPostQuery = groq` *[_type == "post" && slug.current == $slug && !(_id in path("drafts.**"))][0] { @@ -95,8 +94,10 @@ export const getBlogPostQuery = groq` }, } }` -export const getBlogPost = (slug: string): Promise => - clientFetch(getBlogPostQuery, { slug }) +export const getBlogPost = (slug: string) => + client.fetch(getBlogPostQuery, { + slug, + }) export const getSettingsQuery = () => groq` @@ -117,16 +118,17 @@ export const getSettingsQuery = () => "logo": logo.asset->url } }` -export const getSettings = (): Promise<{ - projects: Project[] | null - heroPhotos?: string[] | null - resume?: - | { - company: string - title: string - logo: string - start: string - end?: string - }[] - | null -}> => clientFetch(getSettingsQuery()) +export const getSettings = () => + client.fetch<{ + projects: Project[] | null + heroPhotos?: string[] | null + resume?: + | { + company: string + title: string + logo: string + start: string + end?: string + }[] + | null + }>(getSettingsQuery())