/** * 本地视觉预览页:加载 WordPress 官方 dist 脚本 + Creator Studio 构建产物, * 用一份模拟的 bootstrap 数据渲染工作台,便于在不登录的情况下截图核对视觉。 * 仅用于本机视觉验收,不进入主题运行时。 */ const fs = require('fs'); const path = require('path'); const [srcArg, outArg] = process.argv.slice(2); const src = srcArg || '/tmp/studio-preview.html'; const out = outArg || 'C:/Users/Xing/Desktop/WP-Date/data/wordpress/jio-preview.html'; let html = fs.readFileSync(src, 'utf8'); const mockBootstrap = { sourceId: 0, versionId: 0, versionRev: 0, status: '', reviewNote: '', title: '', excerpt: '', content: '
这是正文的第一段。微信公众号式的编辑体验强调沉浸感:大面积留白、克制的工具栏、只在需要时才出现的设置面板。
', permalink: '', isPublished: false, categories: { items: [ { id: 1, name: '未分类' }, { id: 4, name: '分类一' }, { id: 5, name: '分类二' }, ], selected: [1], }, tags: { items: ['写作', '产品'], enabled: true }, custom: {}, customDefs: [], featured: { type: '', data: {}, canImage: true, canSlide: false, canVideo: false }, pay: { enabled: false, canPay: true, canDownload: true, payModo: 'cash', price: '0.00', points: 0, vip1Price: '0.00', vip2Price: '0.00', payLimit: 0, downloads: [], freeAllowed: true, priceMin: 0, priceMax: 0, pointsMin: 0, pointsMax: 0, privateStorage: false, }, capabilities: { canUploadImage: true, canUploadVideo: true, canUploadFile: true, canEmbed: true, canHide: true, canPay: true, canPayDownload: true, canPublishNow: true, canEdit: true, isLoggedIn: true, }, limits: { titleMin: 5, titleMax: 30, titlePlaceholder: '请输入标题', contentPlaceholder: '开始写作…' }, author: { name: '预览作者', avatar: '', meta: '' }, privateUploads: [], privateStorage: false, media: { maxBytes: 5242880, batch: 6 }, rest: { root: 'https://localhost/wp-json/', nonce: 'preview' }, urls: { submit: '#', newPost: '#', center: '#' }, captcha: { enabled: false }, creator: { saveUrl: '#', submitUrl: '#', previewUrl: '#', privateUrl: '#', bootstrapUrl: '#', }, blocks: { mediaUploadUrl: '#', mediaListUrl: '#' }, nonce: 'preview', }; // 换成模拟数据。WP 的 wp_add_inline_script 会在结尾追加 sourceURL 注释, // 所以只匹配到 JSON 的结束分号,保留其后的注释。 const before = html.length; html = html.replace( /window\.jioCreatorStudio = \{[\s\S]*?\};\n/, `window.jioCreatorStudio = ${JSON.stringify(mockBootstrap)};\n` ); if (html.length === before) { console.error('WARN: bootstrap 替换未生效'); } // 追加一个 banner 说明这是预览 html = html.replace( '