feat(website): 对齐官网文章配置与展示顺序
This commit is contained in:
@@ -30,8 +30,8 @@ import {
|
||||
TextArea,
|
||||
Typography,
|
||||
} from '@/components/ui';
|
||||
import { articleErrors } from './insightsModel';
|
||||
import { articleContentInfo, sanitizeArticleHtml } from './insightsContent';
|
||||
import { articleErrors, RELATED_LIMIT } from './insightsModel';
|
||||
import { articleHeadings, sanitizeArticleHtml } from './insightsContent';
|
||||
import ArticleRichEditor from './ArticleRichEditor';
|
||||
|
||||
export default function ArticleEditor({ initial, insights, onApply, onClose }) {
|
||||
@@ -53,8 +53,7 @@ export default function ArticleEditor({ initial, insights, onApply, onClose }) {
|
||||
setErrors((previous) => ({ ...previous, [name]: '' }));
|
||||
};
|
||||
const close = () => {
|
||||
if (JSON.stringify(draft) === JSON.stringify(initial) && !processingImage)
|
||||
onClose();
|
||||
if (!hasDraftChanges && !processingImage) onClose();
|
||||
else
|
||||
Modal.confirm({
|
||||
title: '放弃本次编辑?',
|
||||
@@ -67,7 +66,7 @@ export default function ArticleEditor({ initial, insights, onApply, onClose }) {
|
||||
const apply = () => {
|
||||
if (processingImage) return;
|
||||
const article = { ...draft, body: sanitizeArticleHtml(draft.body) };
|
||||
for (const key of ['title', 'summary', 'subtitle', 'tag'])
|
||||
for (const key of ['title', 'summary', 'tag'])
|
||||
article[key] = article[key].trim();
|
||||
const nextErrors = articleErrors(article, insights);
|
||||
setErrors(nextErrors);
|
||||
@@ -83,7 +82,10 @@ export default function ArticleEditor({ initial, insights, onApply, onClose }) {
|
||||
{children}
|
||||
</Form.Slot>
|
||||
);
|
||||
const info = articleContentInfo(draft.body);
|
||||
const categoryName = (id) =>
|
||||
insights.categories.find((c) => c.id === id)?.name ?? '';
|
||||
const headings = articleHeadings(draft.body);
|
||||
const candidates = insights.articles.filter((a) => a.id !== draft.id);
|
||||
return (
|
||||
<SideSheet
|
||||
visible
|
||||
@@ -110,6 +112,59 @@ export default function ArticleEditor({ initial, insights, onApply, onClose }) {
|
||||
>
|
||||
基础信息
|
||||
</Typography.Title>
|
||||
<div className='grid grid-cols-1 gap-x-6 md:grid-cols-2'>
|
||||
{field(
|
||||
'category',
|
||||
'所属分类',
|
||||
<Select
|
||||
aria-label='所属分类'
|
||||
validateStatus={errors.category ? 'error' : 'default'}
|
||||
aria-invalid={Boolean(errors.category)}
|
||||
value={
|
||||
insights.categories.some((c) => c.id === draft.category)
|
||||
? draft.category
|
||||
: undefined
|
||||
}
|
||||
placeholder='请选择文章分类'
|
||||
style={{ width: '100%' }}
|
||||
optionList={insights.categories.map((c) => ({
|
||||
label: c.name,
|
||||
value: c.id,
|
||||
}))}
|
||||
onChange={(value) => change('category', value)}
|
||||
/>,
|
||||
true,
|
||||
)}
|
||||
{field(
|
||||
'date',
|
||||
'发布日期',
|
||||
<DatePicker
|
||||
aria-label='发布日期'
|
||||
status={errors.date ? 'error' : undefined}
|
||||
aria-invalid={Boolean(errors.date)}
|
||||
type='date'
|
||||
format='YYYY-MM-DD'
|
||||
placeholder='请选择发布日期'
|
||||
style={{ width: '100%' }}
|
||||
value={draft.date || undefined}
|
||||
onChange={(value) => change('date', value)}
|
||||
/>,
|
||||
true,
|
||||
)}
|
||||
{field(
|
||||
'tag',
|
||||
'角标标签',
|
||||
<Input
|
||||
aria-label='角标标签'
|
||||
validateStatus={errors.tag ? 'error' : 'default'}
|
||||
aria-invalid={Boolean(errors.tag)}
|
||||
value={draft.tag}
|
||||
maxLength={12}
|
||||
placeholder='例如 NEW、推荐,留空不展示'
|
||||
onChange={(value) => change('tag', value)}
|
||||
/>,
|
||||
)}
|
||||
</div>
|
||||
{field(
|
||||
'title',
|
||||
'文章标题',
|
||||
@@ -126,86 +181,21 @@ export default function ArticleEditor({ initial, insights, onApply, onClose }) {
|
||||
/>,
|
||||
true,
|
||||
)}
|
||||
<div className='grid grid-cols-1 gap-x-6 md:grid-cols-2'>
|
||||
{field(
|
||||
'category',
|
||||
'所属分类',
|
||||
<Select
|
||||
aria-label='所属分类'
|
||||
validateStatus={errors.category ? 'error' : 'default'}
|
||||
aria-invalid={Boolean(errors.category)}
|
||||
value={draft.category || undefined}
|
||||
placeholder='请选择文章分类'
|
||||
style={{ width: '100%' }}
|
||||
optionList={[
|
||||
{ label: '全部内容', value: 'all' },
|
||||
...insights.categories.map((c) => ({
|
||||
label: c.name,
|
||||
value: c.id,
|
||||
})),
|
||||
]}
|
||||
onChange={(value) => change('category', value)}
|
||||
/>,
|
||||
true,
|
||||
)}
|
||||
{field(
|
||||
'date',
|
||||
'发布日期',
|
||||
<DatePicker
|
||||
aria-label='发布日期'
|
||||
status={errors.date ? 'error' : undefined}
|
||||
aria-invalid={Boolean(errors.date)}
|
||||
type='dateTime'
|
||||
format='YYYY-MM-DD HH:mm:ss'
|
||||
placeholder='请选择发布日期'
|
||||
style={{ width: '100%' }}
|
||||
value={draft.date || undefined}
|
||||
onChange={(value) => change('date', value)}
|
||||
/>,
|
||||
true,
|
||||
)}
|
||||
</div>
|
||||
{field(
|
||||
'subtitle',
|
||||
'详情副标题',
|
||||
<Input
|
||||
aria-label='详情副标题'
|
||||
validateStatus={errors.subtitle ? 'error' : 'default'}
|
||||
aria-invalid={Boolean(errors.subtitle)}
|
||||
value={draft.subtitle}
|
||||
maxLength={160}
|
||||
placeholder='留空时使用卡片摘要作为副标题'
|
||||
onChange={(value) => change('subtitle', value)}
|
||||
/>,
|
||||
)}
|
||||
{field(
|
||||
'summary',
|
||||
'卡片摘要',
|
||||
'文章描述',
|
||||
<TextArea
|
||||
aria-label='卡片摘要'
|
||||
aria-label='文章描述'
|
||||
validateStatus={errors.summary ? 'error' : 'default'}
|
||||
aria-invalid={Boolean(errors.summary)}
|
||||
value={draft.summary}
|
||||
placeholder='请输入卡片摘要'
|
||||
placeholder='请输入文章描述,用于列表卡片摘要与详情页标题下方'
|
||||
maxCount={200}
|
||||
rows={3}
|
||||
onChange={(value) => change('summary', value)}
|
||||
/>,
|
||||
true,
|
||||
)}
|
||||
{field(
|
||||
'tag',
|
||||
'角标标签',
|
||||
<Input
|
||||
aria-label='角标标签'
|
||||
validateStatus={errors.tag ? 'error' : 'default'}
|
||||
aria-invalid={Boolean(errors.tag)}
|
||||
value={draft.tag}
|
||||
maxLength={12}
|
||||
placeholder='例如 NEW、推荐'
|
||||
onChange={(value) => change('tag', value)}
|
||||
/>,
|
||||
)}
|
||||
<Typography.Title
|
||||
heading={5}
|
||||
className='website-insights-section-title website-insights-detail-title'
|
||||
@@ -226,58 +216,46 @@ export default function ArticleEditor({ initial, insights, onApply, onClose }) {
|
||||
</div>
|
||||
<aside className='website-insights-aside'>
|
||||
<Card title='文章目录'>
|
||||
<Checkbox
|
||||
checked={draft.toc}
|
||||
onChange={(e) => change('toc', e.target.checked)}
|
||||
>
|
||||
根据正文标题自动生成
|
||||
</Checkbox>
|
||||
<div className='website-insights-toc'>
|
||||
{!draft.toc ? (
|
||||
<Typography.Text type='tertiary'>
|
||||
已关闭目录展示
|
||||
</Typography.Text>
|
||||
) : info.headings.length ? (
|
||||
info.headings.map((h, i) => (
|
||||
<div
|
||||
key={i}
|
||||
style={{ paddingLeft: h.level === 'H3' ? 12 : 0 }}
|
||||
>
|
||||
{h.text}
|
||||
</div>
|
||||
))
|
||||
) : (
|
||||
<Typography.Text type='tertiary'>
|
||||
添加 H2 / H3 标题后自动生成目录
|
||||
</Typography.Text>
|
||||
)}
|
||||
</div>
|
||||
<Typography.Text type='tertiary'>
|
||||
根据正文 H2 标题自动生成,官网点击目录定位到对应标题。
|
||||
</Typography.Text>
|
||||
<ol className='website-insights-toc'>
|
||||
{headings.map((text, i) => (
|
||||
<li key={i}>{text}</li>
|
||||
))}
|
||||
</ol>
|
||||
{!headings.length && (
|
||||
<Typography.Text type='tertiary'>
|
||||
正文暂无 H2 标题,官网将不展示目录项
|
||||
</Typography.Text>
|
||||
)}
|
||||
</Card>
|
||||
<Card title={`相关推荐(${draft.related.length} / 3)`}>
|
||||
<Card
|
||||
title={`相关推荐(${draft.related.length} / ${RELATED_LIMIT})`}
|
||||
>
|
||||
<div className='website-insights-related'>
|
||||
{insights.articles
|
||||
.filter((a) => a.id !== draft.id)
|
||||
.map((a) => (
|
||||
<Checkbox
|
||||
key={a.id}
|
||||
checked={draft.related.includes(a.id)}
|
||||
disabled={
|
||||
!draft.related.includes(a.id) && draft.related.length >= 3
|
||||
}
|
||||
onChange={(e) =>
|
||||
change(
|
||||
'related',
|
||||
e.target.checked
|
||||
? [...draft.related, a.id]
|
||||
: draft.related.filter((id) => id !== a.id),
|
||||
)
|
||||
}
|
||||
>
|
||||
{a.title}
|
||||
</Checkbox>
|
||||
))}
|
||||
{candidates.map((a) => (
|
||||
<Checkbox
|
||||
key={a.id}
|
||||
checked={draft.related.includes(a.id)}
|
||||
disabled={
|
||||
!draft.related.includes(a.id) &&
|
||||
draft.related.length >= RELATED_LIMIT
|
||||
}
|
||||
onChange={(e) =>
|
||||
change(
|
||||
'related',
|
||||
e.target.checked
|
||||
? [...draft.related, a.id]
|
||||
: draft.related.filter((id) => id !== a.id),
|
||||
)
|
||||
}
|
||||
>
|
||||
{`${categoryName(a.category)} · ${a.title}`}
|
||||
</Checkbox>
|
||||
))}
|
||||
</div>
|
||||
{!insights.articles.some((a) => a.id !== draft.id) && (
|
||||
{!candidates.length && (
|
||||
<Typography.Text type='tertiary'>
|
||||
暂无可推荐的其他文章
|
||||
</Typography.Text>
|
||||
@@ -288,10 +266,15 @@ export default function ArticleEditor({ initial, insights, onApply, onClose }) {
|
||||
</Card>
|
||||
<Card title='展示说明'>
|
||||
<Typography.Paragraph type='tertiary'>
|
||||
列表页:标题、摘要、分类、日期、角标。
|
||||
列表页:分类、发布日期、角标、标题、文章描述,按列表顺序展示。
|
||||
</Typography.Paragraph>
|
||||
<Typography.Paragraph type='tertiary'>
|
||||
详情页:分类、标题、文章描述、正文、目录(正文
|
||||
H2),不展示发布日期。
|
||||
</Typography.Paragraph>
|
||||
<Typography.Text type='tertiary'>
|
||||
详情页:副标题(留空时使用摘要)、正文、目录和推荐。
|
||||
相关推荐按勾选顺序展示,最多 {RELATED_LIMIT}{' '}
|
||||
篇;不勾选则官网不展示相关推荐。
|
||||
</Typography.Text>
|
||||
</Card>
|
||||
</aside>
|
||||
|
||||
Reference in New Issue
Block a user