social_links 以 JSON 数组存进 settings KV([{label,url}]),解码容错:
空串 / 坏 JSON / 缺 label 或 url 的条目一律丢弃,前台拿到空数组时区块
自动隐藏。custom_js 原样存取——它是站主自己的代码(统计脚本等),
做转义只会把脚本洗坏。后台表单与前台展示在下一笔前端提交里。
166 lines
5.8 KiB
Go
166 lines
5.8 KiB
Go
package model
|
|
|
|
// Post kinds. "long" is a normal article; "short" is a Twitter-like note
|
|
// with no title shown in the timeline.
|
|
const (
|
|
KindLong = "long"
|
|
KindShort = "short"
|
|
)
|
|
|
|
const (
|
|
StatusDraft = "draft"
|
|
StatusPublished = "published"
|
|
)
|
|
|
|
type Post struct {
|
|
ID int64 `json:"id"`
|
|
Kind string `json:"kind"`
|
|
Title string `json:"title"`
|
|
Slug string `json:"slug"`
|
|
Summary string `json:"summary"`
|
|
CoverURL string `json:"cover_url"`
|
|
ContentMd string `json:"content_md,omitempty"`
|
|
ContentHTML string `json:"content_html"`
|
|
Status string `json:"status"`
|
|
PublishedAt string `json:"published_at"`
|
|
CreatedAt string `json:"created_at"`
|
|
UpdatedAt string `json:"updated_at"`
|
|
ReadingMinutes int `json:"reading_minutes"`
|
|
// ContentLen 是正文字符数:列表接口不返回全文,但后台列表要显示字数。
|
|
ContentLen int64 `json:"content_len"`
|
|
Tags []string `json:"tags"`
|
|
}
|
|
|
|
type PostInput struct {
|
|
Kind string `json:"kind"`
|
|
Title string `json:"title"`
|
|
Slug string `json:"slug"`
|
|
Summary string `json:"summary"`
|
|
CoverURL string `json:"cover_url"`
|
|
ContentMd string `json:"content_md"`
|
|
Status string `json:"status"`
|
|
PublishedAt string `json:"published_at"`
|
|
Tags []string `json:"tags"`
|
|
ReadingMinutes *int `json:"reading_minutes"`
|
|
}
|
|
|
|
type Tag struct {
|
|
ID int64 `json:"id"`
|
|
Name string `json:"name"`
|
|
Slug string `json:"slug"`
|
|
Color string `json:"color"`
|
|
Count int `json:"count"`
|
|
}
|
|
|
|
// Project is a showcase entry rendered on the public /projects page. It links
|
|
// out to an external homepage and (optionally) a source repository.
|
|
type Project struct {
|
|
ID int64 `json:"id"`
|
|
Title string `json:"title"`
|
|
Slug string `json:"slug"`
|
|
Summary string `json:"summary"`
|
|
CoverURL string `json:"cover_url"`
|
|
URL string `json:"url"`
|
|
RepoURL string `json:"repo_url"`
|
|
Status string `json:"status"`
|
|
Position int `json:"position"`
|
|
CreatedAt string `json:"created_at"`
|
|
UpdatedAt string `json:"updated_at"`
|
|
}
|
|
|
|
// ProjectInput carries the editable fields for a project. A blank Slug or
|
|
// Status is filled in by the store (slug from Title, status defaults to
|
|
// published) so the admin UI can omit them.
|
|
type ProjectInput struct {
|
|
Title string `json:"title"`
|
|
Slug string `json:"slug"`
|
|
Summary string `json:"summary"`
|
|
CoverURL string `json:"cover_url"`
|
|
URL string `json:"url"`
|
|
RepoURL string `json:"repo_url"`
|
|
Status string `json:"status"`
|
|
Position int `json:"position"`
|
|
}
|
|
|
|
type ArchiveMonth struct {
|
|
Month string `json:"month"`
|
|
Posts []Post `json:"posts"`
|
|
}
|
|
|
|
type ArchiveYear struct {
|
|
Year string `json:"year"`
|
|
Months []ArchiveMonth `json:"months"`
|
|
Count int `json:"count"`
|
|
}
|
|
|
|
type Page struct {
|
|
Items []Post `json:"items"`
|
|
Total int `json:"total"`
|
|
Page int `json:"page"`
|
|
Size int `json:"size"`
|
|
}
|
|
|
|
// Dashboard is the snapshot rendered on /admin (homepage).
|
|
type Dashboard struct {
|
|
TotalPosts int `json:"total_posts"`
|
|
PublishedPosts int `json:"published_posts"`
|
|
DraftPosts int `json:"draft_posts"`
|
|
ShortPosts int `json:"short_posts"`
|
|
LongPosts int `json:"long_posts"`
|
|
TotalTags int `json:"total_tags"`
|
|
TotalWords int `json:"total_words"`
|
|
RecentPosts []Post `json:"recent_posts"`
|
|
RecentDrafts []Post `json:"recent_drafts"`
|
|
TopTags []Tag `json:"top_tags"`
|
|
PublishedByMonth []MonthBucket `json:"published_by_month"`
|
|
}
|
|
|
|
type MonthBucket struct {
|
|
Month string `json:"month"` // "YYYY-MM"
|
|
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"`
|
|
AuthorName string `json:"author_name"`
|
|
AuthorBio string `json:"author_bio"`
|
|
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
|
|
// dark variants later without breaking clients.
|
|
LightSkinID string `json:"light_skin_id"`
|
|
// ThemeID is kept for backward compatibility with older clients that
|
|
// only know about a single skin. settingsFromMap falls back to it
|
|
// when LightSkinID is empty.
|
|
ThemeID string `json:"theme_id,omitempty"`
|
|
// UIID selects which front-end UI the whole site renders. Valid values
|
|
// are "classic" (the original minimalist layout) and "vivid" (the
|
|
// livelier one). The admin UI is unaffected by this — it always uses the
|
|
// --admin-* tokens.
|
|
UIID string `json:"ui_id"`
|
|
// CustomCSS holds owner-authored stylesheets keyed by page section
|
|
// ("global", "home", "post", "archive", "tags", "projects", "about").
|
|
// 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"`
|
|
}
|