后台:站点设置新增社交链接与自定义 JS 字段

social_links 以 JSON 数组存进 settings KV([{label,url}]),解码容错:
空串 / 坏 JSON / 缺 label 或 url 的条目一律丢弃,前台拿到空数组时区块
自动隐藏。custom_js 原样存取——它是站主自己的代码(统计脚本等),
做转义只会把脚本洗坏。后台表单与前台展示在下一笔前端提交里。
This commit is contained in:
Sakurasan
2026-09-27 03:34:43 +08:00
parent 75737034d9
commit 5dfa1550fb
3 changed files with 54 additions and 2 deletions
+15
View File
@@ -120,6 +120,13 @@ type MonthBucket struct {
Count int `json:"count"`
}
// SocialLink 是站主在后台填写的社交 / 源码入口(label + url),
// 前台渲染成图标或文字链接。icon 不入库 —— 由前端按 url 域名推导。
type SocialLink struct {
Label string `json:"label"`
URL string `json:"url"`
}
type Settings struct {
SiteTitle string `json:"site_title"`
SiteDesc string `json:"site_desc"`
@@ -128,6 +135,9 @@ type Settings struct {
FooterNote string `json:"footer_note"`
ICPLicense string `json:"icp"`
PostsPerPage int `json:"posts_per_page"`
// SocialLinks 以 JSON 数组形式存在 settings KV 里(key: social_links),
// 解析失败/为空时前台拿到空数组,区块自动隐藏。
SocialLinks []SocialLink `json:"social_links"`
// LightSkinID is the front-end skin used when the client (or system)
// prefers light. Valid values: paper / sage / rose.
// Dark side is fixed to ink for now — kept implicit so we can add
@@ -147,4 +157,9 @@ type Settings struct {
// Only injected for the vivid UI, and never on /admin. Always non-nil so
// the JSON response is {} rather than null.
CustomCSS map[string]string `json:"custom_css"`
// CustomJS holds owner-authored JavaScript (analytics snippets like
// Google Analytics / Plausible / Umami). Injected on every public page
// of either UI, never on /admin. Stored raw — it's the owner's own code,
// sanitizing it would only break the snippet.
CustomJS string `json:"custom_js"`
}