重构:更新API基础URL并增强内容解析逻辑
- 更改了API基础URL,以便在开发和生产环境之间切换。 - 添加了assetBase参数,以提高内容解析中图像源的分辨率。 - 增强了阅读页面的配置,将assetBase纳入图像URL的配置中。 - 更新了OpenPlatformPage,以便正确导航至设置和API文档。 - 对ContentPage进行了重构,以包含额外的webhook配置检索功能。 - 改进了DashboardPage,使其能更有效地处理用户交互。 - 清理了未使用的导入,并优化了AdminLayout,以提高可读性。
This commit is contained in:
@@ -27,6 +27,35 @@ function decodeEntities(str) {
|
||||
.replace(/'/g, "'")
|
||||
}
|
||||
|
||||
/**
|
||||
* 正文里 img 的 src:管理端常见为 /uploads/...(相对 API 根),浏览器会自动补全域名;
|
||||
* 小程序 <image> 不会拼接 baseUrl,需在此用 assetBase 转成可请求的绝对地址。
|
||||
* @param {string} src
|
||||
* @param {string} [assetBase] - 如 https://soulapi.example.com(无末尾 /)
|
||||
*/
|
||||
function resolveArticleImageSrc(src, assetBase) {
|
||||
if (!src || typeof src !== 'string') return src
|
||||
const s = src.trim()
|
||||
if (!s) return s
|
||||
if (/^(https?:|wxfile:|data:|blob:)/i.test(s)) return s
|
||||
if (s.startsWith('//')) return 'https:' + s
|
||||
if (s.startsWith('/')) {
|
||||
const base = String(assetBase || '').replace(/\/$/, '')
|
||||
if (!base) return s
|
||||
return base + s
|
||||
}
|
||||
return s
|
||||
}
|
||||
|
||||
/** 从 <img ...> 标签取出 src(双引号/单引号) */
|
||||
function extractImgSrcFromTag(tag) {
|
||||
const d = tag.match(/src\s*=\s*"([^"]*)"/i)
|
||||
if (d && d[1] != null) return d[1]
|
||||
const q = tag.match(/src\s*=\s*'([^']*)'/i)
|
||||
if (q && q[1] != null) return q[1]
|
||||
return ''
|
||||
}
|
||||
|
||||
/**
|
||||
* 单行展示用:昵称、#标签文案、章节外标题类字段 — 合并换行、<br>、连续空白(避免 TipTap/粘贴带入异常断行)
|
||||
*/
|
||||
@@ -118,11 +147,16 @@ function parseBlockToSegments(block, config) {
|
||||
segs.push({ type: 'linkTag', label: label || '#', url, tagType: '', pagePath: '', tagId: '' })
|
||||
|
||||
} else if (/^<img /i.test(tag)) {
|
||||
// 图片
|
||||
const srcMatch = tag.match(/src="([^"]*)"/)
|
||||
const altMatch = tag.match(/alt="([^"]*)"/)
|
||||
if (srcMatch) {
|
||||
segs.push({ type: 'image', src: srcMatch[1], alt: altMatch ? altMatch[1] : '' })
|
||||
// 图片(src 可能为相对路径,需结合 config.assetBase)
|
||||
const rawSrc = extractImgSrcFromTag(tag)
|
||||
const altMatch = tag.match(/alt\s*=\s*"([^"]*)"/i) || tag.match(/alt\s*=\s*'([^']*)'/i)
|
||||
if (rawSrc) {
|
||||
const decoded = decodeEntities(rawSrc)
|
||||
const src =
|
||||
config && config.assetBase
|
||||
? resolveArticleImageSrc(decoded, config.assetBase)
|
||||
: resolveArticleImageSrc(decoded, '')
|
||||
segs.push({ type: 'image', src, alt: altMatch ? decodeEntities(altMatch[1]) : '' })
|
||||
}
|
||||
}
|
||||
|
||||
@@ -139,7 +173,7 @@ function parseBlockToSegments(block, config) {
|
||||
/**
|
||||
* 从 HTML 中解析出 lines(纯文本行)和 segments(含富文本片段)
|
||||
* @param {string} html
|
||||
* @param {object} [config] - { persons: [], linkTags: [] },用于对 text 段自动匹配 @人名 / #标签
|
||||
* @param {object} [config] - { persons: [], linkTags: [], assetBase?: string },用于对 text 段自动匹配 @人名 / #标签;assetBase 用于补全图片相对 URL
|
||||
*/
|
||||
function parseHtmlToSegments(html, config) {
|
||||
const lines = []
|
||||
|
||||
Reference in New Issue
Block a user