feat(settings): 后台可配置 Markdown 代码块自动折叠与阈值行数
支持开关与 0–100 行阈值(0 为无预览),经站点设置与 WS 热更新;短代码在视口内收起时不再回滚浏览位置。 Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
@@ -226,6 +226,13 @@ export interface Post {
|
||||
poll?: PollState | null;
|
||||
bounty?: BountyState | null;
|
||||
lottery?: LotteryState | null;
|
||||
/** 软删专用页标记 */
|
||||
tombstone?: boolean;
|
||||
delete_type?: string;
|
||||
delete_reason?: string;
|
||||
deleted_by?: number;
|
||||
staff_deleted?: boolean;
|
||||
deleted_at?: string;
|
||||
}
|
||||
|
||||
export interface QuestionState {
|
||||
@@ -306,6 +313,8 @@ export interface Comment {
|
||||
status: string;
|
||||
created_at: string;
|
||||
user: User;
|
||||
/** 软删占位 */
|
||||
deleted?: boolean;
|
||||
}
|
||||
|
||||
// 评论树节点:主评论为根,replies 为其全部子回复(时间正序,全量 SSR 直出)
|
||||
@@ -373,7 +382,7 @@ export interface NotificationItem {
|
||||
id: number;
|
||||
user_id: number;
|
||||
actor_id: number;
|
||||
type: "comment" | "reply" | "like" | "approved" | "rejected" | "mention" | "pending_review";
|
||||
type: "comment" | "reply" | "like" | "approved" | "rejected" | "mention" | "pending_review" | "deleted";
|
||||
post_id: number;
|
||||
comment_id: number;
|
||||
room_id?: number;
|
||||
@@ -539,6 +548,10 @@ export interface PublicSettings {
|
||||
site_description: string;
|
||||
allow_register: boolean;
|
||||
post_cooldown_hours: number;
|
||||
/** 超过 N 行的代码块是否默认折叠;缺省 true */
|
||||
code_block_auto_fold: boolean;
|
||||
/** 折叠阈值行数(超过则折叠;0=无预览);缺省 5 */
|
||||
code_block_fold_lines: number;
|
||||
}
|
||||
|
||||
const DEFAULT_PUBLIC_SETTINGS: PublicSettings = {
|
||||
@@ -548,6 +561,8 @@ const DEFAULT_PUBLIC_SETTINGS: PublicSettings = {
|
||||
site_description: "姜十三论坛 - 技术分享与讨论社区",
|
||||
allow_register: true,
|
||||
post_cooldown_hours: 24,
|
||||
code_block_auto_fold: true,
|
||||
code_block_fold_lines: 5,
|
||||
};
|
||||
|
||||
function normalizePublicSettings(data: Partial<PublicSettings> | null | undefined): PublicSettings {
|
||||
@@ -564,6 +579,13 @@ function normalizePublicSettings(data: Partial<PublicSettings> | null | undefine
|
||||
typeof data?.post_cooldown_hours === "number" && data.post_cooldown_hours >= 0
|
||||
? data.post_cooldown_hours
|
||||
: DEFAULT_PUBLIC_SETTINGS.post_cooldown_hours,
|
||||
code_block_auto_fold: data?.code_block_auto_fold !== false,
|
||||
code_block_fold_lines:
|
||||
typeof data?.code_block_fold_lines === "number" &&
|
||||
data.code_block_fold_lines >= 0 &&
|
||||
data.code_block_fold_lines <= 100
|
||||
? Math.round(data.code_block_fold_lines)
|
||||
: DEFAULT_PUBLIC_SETTINGS.code_block_fold_lines,
|
||||
};
|
||||
}
|
||||
|
||||
@@ -1464,6 +1486,8 @@ export type UpdateSiteSettingsBody = {
|
||||
site_description?: string;
|
||||
allow_register?: boolean;
|
||||
post_cooldown_hours?: number;
|
||||
code_block_auto_fold?: boolean;
|
||||
code_block_fold_lines?: number;
|
||||
};
|
||||
|
||||
// 更新站点设置(字段可选);accent 传空串恢复默认主题色
|
||||
|
||||
Reference in New Issue
Block a user