feat: 完善内容管理通用富文本编辑器
This commit is contained in:
@@ -3,6 +3,7 @@ import { hashSync } from 'bcryptjs'
|
||||
import { createHash } from 'node:crypto'
|
||||
import { copyFileSync, existsSync, mkdirSync, readFileSync, readdirSync, statSync } from 'node:fs'
|
||||
import { dirname, resolve } from 'node:path'
|
||||
import { sanitizeRichText } from './rich-text'
|
||||
import { defaultSiteDocument, siteDocumentSchema } from './site-schema'
|
||||
|
||||
let database: Database.Database | undefined
|
||||
@@ -92,6 +93,9 @@ export function readSiteDocument(mode: 'draft' | 'published' = 'published') {
|
||||
function normalizeLegacyDocument(input: unknown) {
|
||||
if (!input || typeof input !== 'object') return input
|
||||
const document = structuredClone(input) as Record<string, any>
|
||||
if (document.hero?.backgroundImage === '/images/hero-bg-v1.png') {
|
||||
document.hero.backgroundImage = '/images/hero-bg-v3.webp'
|
||||
}
|
||||
if (Array.isArray(document.products)) {
|
||||
document.products = document.products.map((product: Record<string, any>, index: number) => {
|
||||
const fallback = defaultSiteDocument.products[index]
|
||||
@@ -102,7 +106,7 @@ function normalizeLegacyDocument(input: unknown) {
|
||||
subtitle: product.subtitle || '',
|
||||
type: product.type || fallback?.type || 'course',
|
||||
summary: product.summary || fallback?.summary || '',
|
||||
content: product.content || fallback?.content || '',
|
||||
content: sanitizeRichText(product.content || fallback?.content || ''),
|
||||
image: product.image || fallback?.image || '/images/hero-bg-v3.webp',
|
||||
href: product.href || `/products/${slug}`,
|
||||
status: product.status || 'published',
|
||||
@@ -110,7 +114,15 @@ function normalizeLegacyDocument(input: unknown) {
|
||||
})
|
||||
}
|
||||
document.articles ??= structuredClone(defaultSiteDocument.articles)
|
||||
document.articles = document.articles.map((article: Record<string, any>) => ({
|
||||
...article,
|
||||
content: sanitizeRichText(article.content || ''),
|
||||
}))
|
||||
document.team ??= structuredClone(defaultSiteDocument.team)
|
||||
document.team = document.team.map((member: Record<string, any>) => ({
|
||||
...member,
|
||||
summary: sanitizeRichText(member.summary || ''),
|
||||
}))
|
||||
document.channels ??= structuredClone(defaultSiteDocument.channels)
|
||||
document.legal ??= structuredClone(defaultSiteDocument.legal)
|
||||
document.brand = { ...defaultSiteDocument.brand, ...(document.brand || {}) }
|
||||
|
||||
Reference in New Issue
Block a user