fix: 修复 CMS 发布时未读取文章正文的问题 - #215
Open
Zw-awa wants to merge 1 commit into
Open
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
问题说明
在文章编辑器中将文章同步到 WordPress、MetaWeblog 或 Typecho 时,CMS 连接测试可以正常通过,但实际保存草稿会失败。
界面显示以下错误:
复现步骤
undefined.length。原因分析
当前文章同步流程传给平台适配器的正文主要位于:
article.html:预处理后的 HTML。article.markdown:转换后的 Markdown。这与
CodeAdapter中约定的文章数据结构一致。但是 WordPress、MetaWeblog 和 Typecho 适配器仍然只读取旧的
article.content:当编辑器传入的文章没有
content字段时,适配器会将undefined传给后续的图片和正文处理流程,最终在解析正文时产生异常。连接测试不涉及文章正文,因此连接测试仍然可以成功。
解决思路
在三个 CMS 适配器中按照以下顺序选择可用的文章正文:
content,保持对原有调用方的兼容。content不存在时,使用编辑器提供的html。markdown。undefined传入正文处理流程。同时更新适配器的文章参数类型,使
content、html和markdown与实际可能收到的数据结构一致。本次修改覆盖:
修复效果
修改前
从编辑器同步文章到 WordPress 时失败:
修改后
使用相同文章和同一个
ZWAWA BlogCMS 账户重新同步,可以正常保存为草稿。同步历史中也可以看到成功记录:
验证结果