feat(admin): 增加背景管理

- settings 新增 background.light / background.dark,留空使用内置图
- 后台首页管理新增「背景管理」,两栏 URL 输入与实时预览,可一键恢复内置图
- 前台按设置覆盖明暗背景图,仍保留 65vh 与交叉淡入
- 保存/撤销沿用现有设置乐观锁流程
This commit is contained in:
2026-11-03 20:23:57 +08:00
parent b9005dd514
commit 5439ebf3be
6 changed files with 166 additions and 5 deletions
+20
View File
@@ -110,6 +110,15 @@ pub struct SidebarSettings {
pub show_nav: bool,
}
#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq, Default)]
#[serde(default)]
pub struct BackgroundSettings {
/// 亮色背景图地址;空表示用内置图
pub light: String,
/// 暗色背景图地址;空表示用内置图
pub dark: String,
}
#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq)]
#[serde(default)]
pub struct ProfileSettings {
@@ -220,6 +229,7 @@ impl Default for SiteMetaSettings {
pub struct Settings {
pub header: HeaderSettings,
pub sidebar: SidebarSettings,
pub background: BackgroundSettings,
pub profile: ProfileSettings,
pub site: SiteMetaSettings,
}
@@ -275,6 +285,16 @@ pub fn validate(settings: &Settings) -> Result<(), StashError> {
if settings.profile.location.chars().count() > 40 {
return Err(StashError::InvalidDirectory("位置最多 40 个字".into()));
}
if settings.background.light.chars().count() > 500 {
return Err(StashError::InvalidDirectory(
"亮色背景地址最多 500 个字符".into(),
));
}
if settings.background.dark.chars().count() > 500 {
return Err(StashError::InvalidDirectory(
"暗色背景地址最多 500 个字符".into(),
));
}
if settings.site.title.chars().count() > 120 {
return Err(StashError::InvalidDirectory("页面标题最多 120 个字".into()));
}