fix: 首页默认排序改为最近活动时间线
reply 按发帖与最后评论的较晚时间混排,零回复新帖不再沉底;默认文案改为「最新」。 Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
@@ -224,7 +224,7 @@ export interface FeedSortTab {
|
|||||||
}
|
}
|
||||||
|
|
||||||
export const DEFAULT_FEED_SORT_TABS: FeedSortTab[] = [
|
export const DEFAULT_FEED_SORT_TABS: FeedSortTab[] = [
|
||||||
{ id: 'reply', label: '新评论', enabled: true },
|
{ id: 'reply', label: '最新', enabled: true },
|
||||||
{ id: 'latest', label: '新帖子', enabled: true },
|
{ id: 'latest', label: '新帖子', enabled: true },
|
||||||
{ id: 'hot', label: '推荐帖', enabled: true },
|
{ id: 'hot', label: '推荐帖', enabled: true },
|
||||||
];
|
];
|
||||||
|
|||||||
@@ -15,7 +15,7 @@ import type { FeedSortTab } from '../api/types';
|
|||||||
export type FeedSort = 'latest' | 'reply' | 'hot';
|
export type FeedSort = 'latest' | 'reply' | 'hot';
|
||||||
|
|
||||||
const SORT_META: Record<FeedSort, { hint: string; icon: typeof Clock }> = {
|
const SORT_META: Record<FeedSort, { hint: string; icon: typeof Clock }> = {
|
||||||
reply: { hint: '最近有人评论', icon: MessageCircle },
|
reply: { hint: '按最近活动(发帖或评论)', icon: MessageCircle },
|
||||||
latest: { hint: '按发帖时间', icon: Clock },
|
latest: { hint: '按发帖时间', icon: Clock },
|
||||||
hot: { hint: '仅展示推荐帖', icon: BadgeCheck },
|
hot: { hint: '仅展示推荐帖', icon: BadgeCheck },
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -5,7 +5,7 @@ import type { FeedSortId, FeedSortTab } from '../../api/types';
|
|||||||
import { normalizeFeedSortTabs } from '../../utils/feedSortTabs';
|
import { normalizeFeedSortTabs } from '../../utils/feedSortTabs';
|
||||||
|
|
||||||
const TAB_META: Record<FeedSortId, { hint: string; placeholder: string }> = {
|
const TAB_META: Record<FeedSortId, { hint: string; placeholder: string }> = {
|
||||||
reply: { hint: '按最后评论时间', placeholder: '新评论' },
|
reply: { hint: '按最近活动(发帖或评论)', placeholder: '最新' },
|
||||||
latest: { hint: '按发帖时间', placeholder: '新帖子' },
|
latest: { hint: '按发帖时间', placeholder: '新帖子' },
|
||||||
hot: { hint: '仅展示推荐帖', placeholder: '推荐帖' },
|
hot: { hint: '仅展示推荐帖', placeholder: '推荐帖' },
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -952,7 +952,7 @@ export default function AdminSettingsPage() {
|
|||||||
<div className="admin-settings-subsection">
|
<div className="admin-settings-subsection">
|
||||||
<h4 className="admin-settings-subsection-title">首页排序标签</h4>
|
<h4 className="admin-settings-subsection-title">首页排序标签</h4>
|
||||||
<p className="admin-settings-subsection-desc">
|
<p className="admin-settings-subsection-desc">
|
||||||
拖拽调整顺序;在「显示名称」框中改首页文案;右侧开关控制启停。第一个启用项为默认排序
|
拖拽调整顺序;在「显示名称」框中改首页文案;右侧开关控制启停。第一个启用项为默认排序。「最新」按发帖与评论的最近时间混排
|
||||||
</p>
|
</p>
|
||||||
<FeedSortTabList
|
<FeedSortTabList
|
||||||
tabs={normalizeFeedSortTabs(limits.feed_sort_tabs ?? DEFAULT_FEED_SORT_TABS)}
|
tabs={normalizeFeedSortTabs(limits.feed_sort_tabs ?? DEFAULT_FEED_SORT_TABS)}
|
||||||
|
|||||||
@@ -4,7 +4,7 @@ import { DEFAULT_FEED_SORT_TABS } from '../api/types';
|
|||||||
const FEED_SORT_IDS: FeedSortId[] = ['reply', 'latest', 'hot'];
|
const FEED_SORT_IDS: FeedSortId[] = ['reply', 'latest', 'hot'];
|
||||||
|
|
||||||
const DEFAULT_LABELS: Record<FeedSortId, string> = {
|
const DEFAULT_LABELS: Record<FeedSortId, string> = {
|
||||||
reply: '新评论',
|
reply: '最新',
|
||||||
latest: '新帖子',
|
latest: '新帖子',
|
||||||
hot: '推荐帖',
|
hot: '推荐帖',
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -553,7 +553,7 @@ func writeSSRFeed(b *strings.Builder, boot homeBootPayload, meta homeSSRMeta) {
|
|||||||
tabs := boot.Limits.FeedSortTabs
|
tabs := boot.Limits.FeedSortTabs
|
||||||
if len(tabs) == 0 {
|
if len(tabs) == 0 {
|
||||||
tabs = []service.FeedSortTab{
|
tabs = []service.FeedSortTab{
|
||||||
{ID: service.FeedSortReply, Label: "新评论", Enabled: true},
|
{ID: service.FeedSortReply, Label: "最新", Enabled: true},
|
||||||
{ID: service.FeedSortLatest, Label: "新帖子", Enabled: true},
|
{ID: service.FeedSortLatest, Label: "新帖子", Enabled: true},
|
||||||
{ID: service.FeedSortHot, Label: "推荐帖", Enabled: true},
|
{ID: service.FeedSortHot, Label: "推荐帖", Enabled: true},
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -357,18 +357,12 @@ func (s *PostService) List(q PostListQuery) ([]model.Post, int64, error) {
|
|||||||
}
|
}
|
||||||
switch sortKey {
|
switch sortKey {
|
||||||
case "reply":
|
case "reply":
|
||||||
// 有回复的帖子优先,按最后回复时间倒序;无回复的帖子沉底(仅计已公开评论)
|
// 最近活动:按最后公开评论时间与发帖时间的较晚者倒序(零回复新帖也能靠前)
|
||||||
db = db.Order(`(
|
db = db.Order(`COALESCE((
|
||||||
SELECT COUNT(*) FROM comments
|
|
||||||
WHERE comments.post_id = posts.id AND comments.deleted_at IS NULL
|
|
||||||
AND comments.status = 'published'
|
|
||||||
) > 0 DESC`)
|
|
||||||
db = db.Order(`(
|
|
||||||
SELECT MAX(created_at) FROM comments
|
SELECT MAX(created_at) FROM comments
|
||||||
WHERE comments.post_id = posts.id AND comments.deleted_at IS NULL
|
WHERE comments.post_id = posts.id AND comments.deleted_at IS NULL
|
||||||
AND comments.status = 'published'
|
AND comments.status = 'published'
|
||||||
) DESC`)
|
), posts.created_at) DESC`)
|
||||||
db = db.Order("posts.created_at DESC")
|
|
||||||
case "hot":
|
case "hot":
|
||||||
// 仅推荐帖:按互动再按 id
|
// 仅推荐帖:按互动再按 id
|
||||||
db = db.Order("like_count desc, view_count desc")
|
db = db.Order("like_count desc, view_count desc")
|
||||||
@@ -384,7 +378,7 @@ func normalizePostSort(sort string) string {
|
|||||||
case "latest", "hot":
|
case "latest", "hot":
|
||||||
return sort
|
return sort
|
||||||
default:
|
default:
|
||||||
// 含空串 / reply:默认新评论
|
// 含空串 / reply:默认最近活动
|
||||||
return "reply"
|
return "reply"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -206,7 +206,7 @@ var feedSortTabDefaultOrder = []string{
|
|||||||
}
|
}
|
||||||
|
|
||||||
var feedSortTabDefaultLabels = map[string]string{
|
var feedSortTabDefaultLabels = map[string]string{
|
||||||
FeedSortReply: "新评论",
|
FeedSortReply: "最新",
|
||||||
FeedSortLatest: "新帖子",
|
FeedSortLatest: "新帖子",
|
||||||
FeedSortHot: "推荐帖",
|
FeedSortHot: "推荐帖",
|
||||||
}
|
}
|
||||||
@@ -287,7 +287,7 @@ var forumSettingDefs = []settingDef{
|
|||||||
|
|
||||||
var feedSettingDefaults = map[string]string{
|
var feedSettingDefaults = map[string]string{
|
||||||
SettingFeedListStyle: "title",
|
SettingFeedListStyle: "title",
|
||||||
SettingFeedSortTabs: `[{"id":"reply","label":"新评论","enabled":true},{"id":"latest","label":"新帖子","enabled":true},{"id":"hot","label":"推荐帖","enabled":true}]`,
|
SettingFeedSortTabs: `[{"id":"reply","label":"最新","enabled":true},{"id":"latest","label":"新帖子","enabled":true},{"id":"hot","label":"推荐帖","enabled":true}]`,
|
||||||
}
|
}
|
||||||
|
|
||||||
var asideSettingDefaults = map[string]string{
|
var asideSettingDefaults = map[string]string{
|
||||||
|
|||||||
Reference in New Issue
Block a user