feat: 后台管理系统(Admin Backend + 全量 CMS)
- 内容迁入数据库:articles/works 表(中英双语 + 内容块), server/utils/seed.ts 灌入现有 6 动态 + 6 作品,站点初始内容不变 - 前台内容 API:/api/news、/api/work(列表/详情,仅已发布), 页面/首页组件改为 useFetch 拉取并按 locale 选 zh/en 字段 - 后台管理 /admin(admin 中间件守卫): - Dashboard 统计、动态/作品增删改(块编辑器、图片上传 /api/admin/upload) - 用户管理(角色切换/删除)、评论审核、联系/订阅管理(导出 CSV) - 预置管理员:NUXT_ADMIN_INITIAL_PASSWORD 首次初始化创建 admin 账号 - 图片自托管:上传存 PVC /data/uploads,/uploads/[...] 路由服务 - sitemap 改查 DB;i18n 移除内容键(305 键对齐);删除 app/data 冗余模块 - 角色以数据库为准(后台可切换);admin 中间件 + 客户端会话恢复插件
This commit is contained in:
@@ -0,0 +1,49 @@
|
||||
import type { ArticleBlock } from './db'
|
||||
|
||||
/**
|
||||
* 后台内容校验/归一化(articles / works 的 post/patch 共用)。
|
||||
*/
|
||||
|
||||
export const ARTICLE_CATEGORIES = ['insights', 'projects', 'announcements']
|
||||
export const WORK_CATEGORIES = ['webDesign', 'branding', 'development']
|
||||
export const BLOCK_TYPES = ['paragraph', 'heading', 'quote', 'image']
|
||||
|
||||
export function normalizeSlug(value: unknown): string {
|
||||
return String(value ?? '').trim()
|
||||
}
|
||||
|
||||
export function isValidSlug(slug: string): boolean {
|
||||
return /^[a-z0-9-]{2,64}$/.test(slug)
|
||||
}
|
||||
|
||||
export function isValidArticleCategory(value: unknown): boolean {
|
||||
return typeof value === 'string' && ARTICLE_CATEGORIES.includes(value)
|
||||
}
|
||||
|
||||
export function isValidWorkCategory(value: unknown): boolean {
|
||||
return typeof value === 'string' && WORK_CATEGORIES.includes(value)
|
||||
}
|
||||
|
||||
/** 归一化内容块数组(过滤非法块) */
|
||||
export function normalizeBlocks(value: unknown): ArticleBlock[] {
|
||||
if (!Array.isArray(value)) return []
|
||||
return value
|
||||
.filter(
|
||||
(b): b is ArticleBlock =>
|
||||
!!b &&
|
||||
typeof b === 'object' &&
|
||||
BLOCK_TYPES.includes((b as ArticleBlock).type) &&
|
||||
typeof (b as ArticleBlock).text === 'string',
|
||||
)
|
||||
.map((b) => ({ type: b.type, text: b.text.slice(0, 20000) }))
|
||||
}
|
||||
|
||||
export function normalizeTags(value: unknown): string[] {
|
||||
if (!Array.isArray(value)) return []
|
||||
return value.filter((t): t is string => typeof t === 'string' && t.trim()).map((t) => t.trim()).slice(0, 20)
|
||||
}
|
||||
|
||||
export function normalizeGallery(value: unknown): string[] {
|
||||
if (!Array.isArray(value)) return []
|
||||
return value.filter((u): u is string => typeof u === 'string' && u.trim()).map((u) => u.trim()).slice(0, 20)
|
||||
}
|
||||
Reference in New Issue
Block a user