import { Link, useNavigate, useParams } from 'react-router' import { useQuery } from '@tanstack/react-query' import { ArrowLeft, ArrowRight, Clock, Eye } from 'lucide-react' import { Alert, Button, Card, Empty, Skeleton, Tag } from 'antd' import { api } from '../lib/api' import type { NoteDetail } from '../lib/api' import { useAuth } from '../lib/auth' import { useDocumentTitle } from '../features/site' import MarkdownViewer from '../components/MarkdownViewer' import { formatDateISO, readingMinutes } from '../lib/utils' export default function Note() { const { slug = '' } = useParams() const navigate = useNavigate() const { authenticated } = useAuth() const { data: note, isLoading, error } = useQuery({ queryKey: ['note', slug], queryFn: () => api(`/api/notes/${encodeURIComponent(slug)}`), retry: false, }) useDocumentTitle(note?.title) if (isLoading) { return (
) } if (error || !note) { return (
) } const privatePreview = note.status === 'private' return (
{privatePreview && authenticated && ( 私有预览:此笔记未公开,仅管理员可见 } /> )}

{note.title}

· 约 {readingMinutes(note.content)} 分钟阅读 {note.tags.length > 0 && ( <> · {note.tags.map((t) => ( {t} ))} )}
) }