diff --git a/frontend/src/app/admin/ArticleManager.tsx b/frontend/src/app/admin/ArticleManager.tsx index 9f8cd61..62dd69a 100644 --- a/frontend/src/app/admin/ArticleManager.tsx +++ b/frontend/src/app/admin/ArticleManager.tsx @@ -5,9 +5,9 @@ import { FormEvent, useEffect, useMemo, useState } from 'react'; type Row = { content_id: string; title: string; publish_status: string; created_at: string; updated_at: string; category?: string | null; tags?: string | null; author?: string | null; published_at?: string | null; - source: 'content_system' | 'manual'; public_path: string; + source: 'content_system' | 'manual'; public_path: string; summary?: string | null; }; -type Draft = { content_id: string; title: string; body: string; publish_status: string; category: string; tags: string; author: string; published_at: string; source?: Row['source'] }; +type Draft = { content_id: string; title: string; body: string; publish_status: string; category: string; tags: string; author: string; published_at: string; summary: string; source?: Row['source'] }; type Request = (path: string, options?: RequestInit) => Promise; const STATUS: Record = { published: '已发布', draft: '草稿', review: '审核中', unpublished: '已下线', historical: '历史版本' }; @@ -26,7 +26,7 @@ function toText(value?: string | null) { const date = new Date(value); return Number.isNaN(date.getTime()) ? value : date.toLocaleString('zh-CN', { year: 'numeric', month: '2-digit', day: '2-digit', hour: '2-digit', minute: '2-digit' }); } -const empty = (): Draft => ({ content_id: '', title: '', body: '', publish_status: 'draft', category: '', tags: '', author: '阿美巴', published_at: '' }); +const empty = (): Draft => ({ content_id: '', title: '', body: '', publish_status: 'draft', category: '', tags: '', author: '阿美巴', published_at: '', summary: '' }); /** Articles: search, filter, publish or take offline, edit, and delete one or many. */ export function ArticleManager({ request, onMessage, onError }: { request: Request; onMessage: (text: string) => void; onError: (text: string) => void }) { @@ -72,23 +72,24 @@ export function ArticleManager({ request, onMessage, onError }: { request: Reque function toggle(row: Row) { const next = row.publish_status === 'published' ? 'unpublished' : 'published'; void run(() => request(`/api/admin/contents/article/${row.content_id}`, { method: 'PUT', body: JSON.stringify({ publish_status: next }) }), - next === 'published' ? '文章已上线。' : '文章已下线,网站上不再显示。'); + next === 'published' ? '文章已上线,网站约 1 分钟内显示。' : '文章已下线,网站约 1 分钟内不再显示。'); } async function edit(row: Row) { try { const full = await request(`/api/admin/contents/article/${row.content_id}`); setEditing({ content_id: row.content_id, title: full.title || '', body: full.body || '', publish_status: full.publish_status || 'draft', - category: full.category || '', tags: full.tags || '', author: full.author || '', published_at: toInput(full.published_at), source: row.source }); + category: full.category || '', tags: full.tags || '', author: full.author || '', published_at: toInput(full.published_at), summary: row.summary || '', source: row.source }); } catch (e: any) { onError(e.message); } } async function save(event: FormEvent) { event.preventDefault(); if (!editing) return; const data = { title: editing.title.trim(), body: editing.body, publish_status: editing.publish_status, category: editing.category, - tags: editing.tags, author: editing.author, published_at: editing.published_at ? `${editing.published_at.replace('T', ' ')}:00` : '' }; + tags: editing.tags, author: editing.author, published_at: editing.published_at ? `${editing.published_at.replace('T', ' ')}:00` : '', + ...(editing.source === 'content_system' ? { summary: editing.summary } : {}) }; const path = editing.content_id ? `/api/admin/contents/article/${editing.content_id}` : '/api/admin/contents/article'; await run(async () => { await request(path, { method: editing.content_id ? 'PUT' : 'POST', body: JSON.stringify(data) }); setEditing(null); }, - editing.content_id ? '修改已保存,网站上立即生效。' : '文章已新增。'); + editing.content_id ? '修改已保存,网站约 1 分钟内更新。' : '文章已新增。'); } return
@@ -134,8 +135,9 @@ export function ArticleManager({ request, onMessage, onError }: { request: Reque {editing &&
{ if (e.target === e.currentTarget) setEditing(null); }}>

{editing.content_id ? '编辑文章' : '新增文章'}

- {editing.source === 'content_system' &&

这篇文章来自内容系统。这里的修改会立即生效,但内容系统再次发布同一篇文章时会覆盖这里的修改。

} + {editing.source === 'content_system' &&

这篇文章来自内容系统。这里的修改约 1 分钟内在网站生效,但内容系统再次发布同一篇文章时会覆盖这里的修改。

} + {editing.source === 'content_system' &&