- index.css 以 Tailwind 4 @theme 落地设计令牌,全部页面按新设计稿重写 样式:首页/笔记详情/标签页/登录/后台列表/编辑/回收站/设置/404 - Layout 重构导航与主题切换;新增 Toast 轻提示组件 - 移除 vite 手动 codeSplitting:分组 chunk 会被提升进入口静态依赖并对 HTML 发出 modulepreload,lazy 路由的 CodeMirror 在所有页面被预加载 (Lighthouse unused-javascript 549KiB 的根因) - vite dev 代理补 changeOrigin:false,保留浏览器原始 Host,避免后端 Origin 校验误判跨源 403
47 lines
1.6 KiB
TypeScript
47 lines
1.6 KiB
TypeScript
export function cn(...parts: Array<string | false | null | undefined>): string {
|
|
return parts.filter(Boolean).join(' ')
|
|
}
|
|
|
|
export function formatDate(unix: number): string {
|
|
return new Date(unix * 1000).toLocaleDateString('zh-CN', {
|
|
year: 'numeric',
|
|
month: 'long',
|
|
day: 'numeric',
|
|
})
|
|
}
|
|
|
|
export function formatDateTime(unix: number): string {
|
|
return new Date(unix * 1000).toLocaleString('zh-CN', {
|
|
year: 'numeric',
|
|
month: '2-digit',
|
|
day: '2-digit',
|
|
hour: '2-digit',
|
|
minute: '2-digit',
|
|
})
|
|
}
|
|
|
|
// 设计稿统一使用 YYYY-MM-DD 等宽日期
|
|
export function formatDateISO(unix: number): string {
|
|
const d = new Date(unix * 1000)
|
|
const p = (n: number) => String(n).padStart(2, '0')
|
|
return `${d.getFullYear()}-${p(d.getMonth() + 1)}-${p(d.getDate())}`
|
|
}
|
|
|
|
// 阅读时长估算:中文约 400 字/分钟
|
|
export function readingMinutes(content: string): number {
|
|
return Math.max(1, Math.round(content.length / 400))
|
|
}
|
|
|
|
// 回收站剩余保留天数(30 天保留期)
|
|
export function daysRemaining(deletedAt: number): number {
|
|
const elapsedDays = Math.floor((Date.now() / 1000 - deletedAt) / 86400)
|
|
return Math.max(0, 30 - elapsedDays)
|
|
}
|
|
|
|
// 前端 slug 预览:与服务端 slugify 同规则(ASCII 部分),纯非 ASCII 时提示将自动生成
|
|
export function slugPreview(title: string, date: Date): string {
|
|
const t = title.trim().toLowerCase().replace(/_/g, '-').replace(/[^a-z0-9]+/g, '-').replace(/^-+|-+$/g, '').replace(/^-+|-+$/g, '')
|
|
if (t === '') return `post-${date.getFullYear()}${String(date.getMonth() + 1).padStart(2, '0')}${String(date.getDate()).padStart(2, '0')}`
|
|
return t.slice(0, 80).replace(/-+$/g, '')
|
|
}
|