💄 Better UX
This commit is contained in:
@@ -38,7 +38,7 @@ export interface NavigationItem {
|
||||
export const DRAWER_WIDTH = 320;
|
||||
export const NAVIGATION_ITEMS: NavigationItem[] = [
|
||||
{ icon: <HomeIcon />, title: "首页", link: "/" },
|
||||
{ icon: <ArticleIcon />, title: "新闻", link: "/posts" },
|
||||
{ icon: <ArticleIcon />, title: "博客", link: "/posts" },
|
||||
{
|
||||
icon: <InfoIcon />, title: "信息中心", children: [
|
||||
{ icon: <GavelIcon />, title: "用户协议", link: "/i/user-agreement" },
|
||||
|
30
components/articles/ImageViewer.tsx
Normal file
30
components/articles/ImageViewer.tsx
Normal file
@@ -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<HTMLDivElement>(null);
|
||||
|
||||
useEffect(() => {
|
||||
if (container.current) {
|
||||
new Zoomist(container.current, {
|
||||
maxScale: 5,
|
||||
bounds: true,
|
||||
pinchable: true,
|
||||
});
|
||||
}
|
||||
});
|
||||
|
||||
return (
|
||||
<div ref={container} className="zoomist-container h-fit">
|
||||
<div className="zoomist-wrapper">
|
||||
<div className="zoomist-image h-fit">
|
||||
<img src={src} alt={alt} />
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
);
|
||||
}
|
@@ -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 <PortableText value={content} />;
|
||||
const imageBuilder = imageUrlBuilder(client);
|
||||
|
||||
const componentSet = {
|
||||
types: {
|
||||
image: ({ value }: any) => {
|
||||
const image = imageBuilder.image(value);
|
||||
return <ImageViewer src={image.url()} alt={value.alt} />;
|
||||
}
|
||||
},
|
||||
marks: {
|
||||
link: ({ children, value }: any) => {
|
||||
const rel = !value.href.startsWith("/") ? "noreferrer noopener" : undefined;
|
||||
return (
|
||||
<Link href={value.href} rel={rel}>
|
||||
{children}
|
||||
</Link>
|
||||
);
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
return <PortableText value={content} components={componentSet} />;
|
||||
}
|
||||
|
Reference in New Issue
Block a user