diff --git a/app/globals.css b/app/globals.css index b5c61c9..13bbf1e 100644 --- a/app/globals.css +++ b/app/globals.css @@ -1,3 +1,7 @@ @tailwind base; @tailwind components; @tailwind utilities; + +.zoomist-wrapper { + background: transparent !important; +} diff --git a/app/information/[id]/page.tsx b/app/information/[id]/page.tsx index 16abde1..3529cf1 100644 --- a/app/information/[id]/page.tsx +++ b/app/information/[id]/page.tsx @@ -29,6 +29,14 @@ const INFO_DIRECTORY: { [id: string]: InfoMeta } = { } }; +export async function generateMetadata({ params }: { params: { id: string } }) { + const info = INFO_DIRECTORY[params.id]; + + return { + title: info?.title, + } +} + export default function InfoPage({ params }: { params: { id: string } }) { const info = INFO_DIRECTORY[params.id]; diff --git a/app/posts/[id]/page.tsx b/app/posts/[id]/page.tsx index 7b4e3b0..15c3fee 100644 --- a/app/posts/[id]/page.tsx +++ b/app/posts/[id]/page.tsx @@ -3,6 +3,18 @@ import { client } from "@/sanity/lib/client"; import PostContent from "@/components/posts/PostContent"; import Image from "next/image"; +export async function generateMetadata({ params }: { params: { id: string } }) { + const post = await client.fetch(`*[_type == "post" && slug.current == $slug][0] { + title, description + }`, { slug: params.id }); + + + return { + title: post.title, + description: post.description + }; +} + export default async function PostDetailPage({ params }: { params: { id: string } }) { const post = await client.fetch(`*[_type == "post" && slug.current == $slug][0] { title, description, slug, body, author, publishedAt, diff --git a/app/posts/page.tsx b/app/posts/page.tsx index c707f49..6ff7fa2 100644 --- a/app/posts/page.tsx +++ b/app/posts/page.tsx @@ -3,6 +3,10 @@ import { client } from "@/sanity/lib/client"; import Image from "next/image"; import Link from "next/link"; +export const metadata = { + title: "博客" +} + export default async function PostList() { const posts = await client.fetch(`*[_type == "post"] { title, description, slug, author, publishedAt, diff --git a/components/NavigationDrawer.tsx b/components/NavigationDrawer.tsx index 6f220f0..1a8b169 100644 --- a/components/NavigationDrawer.tsx +++ b/components/NavigationDrawer.tsx @@ -38,7 +38,7 @@ export interface NavigationItem { export const DRAWER_WIDTH = 320; export const NAVIGATION_ITEMS: NavigationItem[] = [ { icon: , title: "首页", link: "/" }, - { icon: , title: "新闻", link: "/posts" }, + { icon: , title: "博客", link: "/posts" }, { icon: , title: "信息中心", children: [ { icon: , title: "用户协议", link: "/i/user-agreement" }, diff --git a/components/articles/ImageViewer.tsx b/components/articles/ImageViewer.tsx new file mode 100644 index 0000000..8c6a65f --- /dev/null +++ b/components/articles/ImageViewer.tsx @@ -0,0 +1,30 @@ +"use client"; + +import { useEffect, useRef } from "react"; +import Zoomist from "zoomist"; + +import "zoomist/css"; + +export default function ImageViewer({ src, alt }: { src: string, alt: string }) { + const container = useRef(null); + + useEffect(() => { + if (container.current) { + new Zoomist(container.current, { + maxScale: 5, + bounds: true, + pinchable: true, + }); + } + }); + + return ( +
+
+
+ {alt} +
+
+
+ ); +} \ No newline at end of file diff --git a/components/posts/PostContent.tsx b/components/posts/PostContent.tsx index 5e847a0..3512bc0 100644 --- a/components/posts/PostContent.tsx +++ b/components/posts/PostContent.tsx @@ -1,7 +1,30 @@ -"use client"; - import { PortableText } from "@portabletext/react"; +import { client } from "@/sanity/lib/client"; +import imageUrlBuilder from "@sanity/image-url"; +import Link from "next/link"; +import ImageViewer from "@/components/articles/ImageViewer"; export default function PostContent({ content }: { content: any }) { - return ; + const imageBuilder = imageUrlBuilder(client); + + const componentSet = { + types: { + image: ({ value }: any) => { + const image = imageBuilder.image(value); + return ; + } + }, + marks: { + link: ({ children, value }: any) => { + const rel = !value.href.startsWith("/") ? "noreferrer noopener" : undefined; + return ( + + {children} + + ); + } + } + }; + + return ; } diff --git a/package.json b/package.json index 516b20e..03032df 100644 --- a/package.json +++ b/package.json @@ -37,7 +37,8 @@ "react-dom": "^18", "react-markdown": "^9.0.1", "sanity": "^3.25", - "styled-components": "^6.0" + "styled-components": "^6.0", + "zoomist": "^2.0.11" }, "devDependencies": { "@tailwindcss/typography": "^0.5.10",