fix: 首页默认排序改为最近活动时间线

reply 按发帖与最后评论的较晚时间混排,零回复新帖不再沉底;默认文案改为「最新」。

Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
2026-09-01 21:54:44 +08:00
parent ea9e0058d4
commit dff60dde6a
8 changed files with 12 additions and 18 deletions

View File

@@ -224,7 +224,7 @@ export interface FeedSortTab {
}
export const DEFAULT_FEED_SORT_TABS: FeedSortTab[] = [
{ id: 'reply', label: '新评论', enabled: true },
{ id: 'reply', label: '新', enabled: true },
{ id: 'latest', label: '新帖子', enabled: true },
{ id: 'hot', label: '推荐帖', enabled: true },
];

View File

@@ -15,7 +15,7 @@ import type { FeedSortTab } from '../api/types';
export type FeedSort = 'latest' | 'reply' | 'hot';
const SORT_META: Record<FeedSort, { hint: string; icon: typeof Clock }> = {
reply: { hint: '最近有人评论', icon: MessageCircle },
reply: { hint: '最近活动(发帖或评论', icon: MessageCircle },
latest: { hint: '按发帖时间', icon: Clock },
hot: { hint: '仅展示推荐帖', icon: BadgeCheck },
};

View File

@@ -5,7 +5,7 @@ import type { FeedSortId, FeedSortTab } from '../../api/types';
import { normalizeFeedSortTabs } from '../../utils/feedSortTabs';
const TAB_META: Record<FeedSortId, { hint: string; placeholder: string }> = {
reply: { hint: '按最后评论时间', placeholder: '新评论' },
reply: { hint: '按最近活动(发帖或评论)', placeholder: '新' },
latest: { hint: '按发帖时间', placeholder: '新帖子' },
hot: { hint: '仅展示推荐帖', placeholder: '推荐帖' },
};

View File

@@ -952,7 +952,7 @@ export default function AdminSettingsPage() {
<div className="admin-settings-subsection">
<h4 className="admin-settings-subsection-title"></h4>
<p className="admin-settings-subsection-desc">
</p>
<FeedSortTabList
tabs={normalizeFeedSortTabs(limits.feed_sort_tabs ?? DEFAULT_FEED_SORT_TABS)}

View File

@@ -4,7 +4,7 @@ import { DEFAULT_FEED_SORT_TABS } from '../api/types';
const FEED_SORT_IDS: FeedSortId[] = ['reply', 'latest', 'hot'];
const DEFAULT_LABELS: Record<FeedSortId, string> = {
reply: '新评论',
reply: '新',
latest: '新帖子',
hot: '推荐帖',
};

View File

@@ -553,7 +553,7 @@ func writeSSRFeed(b *strings.Builder, boot homeBootPayload, meta homeSSRMeta) {
tabs := boot.Limits.FeedSortTabs
if len(tabs) == 0 {
tabs = []service.FeedSortTab{
{ID: service.FeedSortReply, Label: "新评论", Enabled: true},
{ID: service.FeedSortReply, Label: "新", Enabled: true},
{ID: service.FeedSortLatest, Label: "新帖子", Enabled: true},
{ID: service.FeedSortHot, Label: "推荐帖", Enabled: true},
}

View File

@@ -357,18 +357,12 @@ func (s *PostService) List(q PostListQuery) ([]model.Post, int64, error) {
}
switch sortKey {
case "reply":
// 有回复的帖子优先,按最后回复时间倒序;无回复的帖子沉底(仅计已公开评论
db = db.Order(`(
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(`(
// 最近活动:按最后公开评论时间与发帖时间的较晚者倒序(零回复新帖也能靠前
db = db.Order(`COALESCE((
SELECT MAX(created_at) FROM comments
WHERE comments.post_id = posts.id AND comments.deleted_at IS NULL
AND comments.status = 'published'
) DESC`)
db = db.Order("posts.created_at DESC")
), posts.created_at) DESC`)
case "hot":
// 仅推荐帖:按互动再按 id
db = db.Order("like_count desc, view_count desc")
@@ -384,7 +378,7 @@ func normalizePostSort(sort string) string {
case "latest", "hot":
return sort
default:
// 含空串 / reply默认新评论
// 含空串 / reply默认最近活动
return "reply"
}
}

View File

@@ -206,7 +206,7 @@ var feedSortTabDefaultOrder = []string{
}
var feedSortTabDefaultLabels = map[string]string{
FeedSortReply: "新评论",
FeedSortReply: "新",
FeedSortLatest: "新帖子",
FeedSortHot: "推荐帖",
}
@@ -287,7 +287,7 @@ var forumSettingDefs = []settingDef{
var feedSettingDefaults = map[string]string{
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{