Skip to content

Commit

Permalink
fix: 修复批量分发属性错误问题
Browse files Browse the repository at this point in the history
  • Loading branch information
terwer committed Aug 24, 2023
1 parent c085f76 commit 1101caf
Show file tree
Hide file tree
Showing 9 changed files with 61 additions and 93 deletions.
12 changes: 6 additions & 6 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -72,14 +72,14 @@
"vue-i18n": "^9.2.2",
"vue-router": "^4.2.4",
"xmlbuilder2": "^3.1.1",
"zhi-blog-api": "^1.34.2",
"zhi-common": "^1.23.1",
"zhi-blog-api": "^1.34.6",
"zhi-common": "^1.23.2",
"zhi-device": "^2.3.1",
"zhi-fetch-middleware": "^0.3.5",
"zhi-github-middleware": "^0.3.5",
"zhi-fetch-middleware": "^0.3.6",
"zhi-github-middleware": "^0.3.6",
"zhi-lib-base": "^0.4.4",
"zhi-notion-markdown": "^0.1.4",
"zhi-siyuan-api": "^2.5.5",
"zhi-xmlrpc-middleware": "^0.5.5"
"zhi-siyuan-api": "^2.5.9",
"zhi-xmlrpc-middleware": "^0.5.6"
}
}
64 changes: 32 additions & 32 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion src/adaptors/api/base/baseBlogApi.ts
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ export class BaseBlogApi extends BlogApi {
}

public getYamlAdaptor(): YamlConvertAdaptor {
return this.baseExtendApi.getYamlAdaptor()
return null
}

public async preEditPost(post: Post, id?: string, publishCfg?: any): Promise<Post> {
Expand Down
1 change: 1 addition & 0 deletions src/adaptors/api/hexo/hexoYamlConverterAdaptor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,7 @@ export class HexoYamlConverterAdaptor extends YamlConvertAdaptor {
yamlFormatObj.mdFullContent = YamlUtil.addYamlToMd(yamlFormatObj.formatter, yamlFormatObj.mdContent)
yamlFormatObj.htmlContent = post.html
this.logger.info("生成默认的YAML")

return yamlFormatObj
}

Expand Down
13 changes: 4 additions & 9 deletions src/adaptors/base/baseExtendApi.ts
Original file line number Diff line number Diff line change
Expand Up @@ -71,11 +71,6 @@ class BaseExtendApi extends WebApi implements IBlogApi, IWebApi {
this.kernelApi = kernelApi
}

public getYamlAdaptor(): YamlConvertAdaptor {
this.logger.info("return default yaml adaptor null, you may implement it in sub class for custom")
return null
}

/**
* 在保存前编辑文章
*
Expand All @@ -97,7 +92,7 @@ class BaseExtendApi extends WebApi implements IBlogApi, IWebApi {
// ================
private async handleYaml(post: Post, id?: string, publishCfg?: any) {
const cfg: BlogConfig = publishCfg?.cfg
const yamlAdaptor: YamlConvertAdaptor = this.getYamlAdaptor()
const yamlAdaptor: YamlConvertAdaptor = this.api.getYamlAdaptor()
if (null !== yamlAdaptor) {
// 先生成对应平台的yaml
const yamlObj: YamlFormatObj = yamlAdaptor.convertToYaml(post, cfg)
Expand All @@ -110,10 +105,10 @@ class BaseExtendApi extends WebApi implements IBlogApi, IWebApi {
// 同步发布内容
const yamlObj = post.toYamlObj()
const yaml = YamlUtil.obj2Yaml(yamlObj)
const md = post.markdown
const md = YamlUtil.extractMarkdown(post.markdown)
post.yaml = yaml
post.markdown = YamlUtil.addYamlToMd(yaml, md)
post.html = LuteUtil.mdToHtml(post.markdown)
post.markdown = md
post.html = LuteUtil.mdToHtml(md)
this.logger.info("yaml adaptor not found, using default")
}

Expand Down
2 changes: 1 addition & 1 deletion src/adaptors/web/base/baseWebApi.ts
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ class BaseWebApi extends WebApi {
}

public getYamlAdaptor(): YamlConvertAdaptor {
return this.baseExtendApi.getYamlAdaptor()
return null
}

public async preEditPost(post: Post, id?: string, publishCfg?: any): Promise<Post> {
Expand Down
41 changes: 15 additions & 26 deletions src/components/publish/BatchPublishIndex.vue
Original file line number Diff line number Diff line change
Expand Up @@ -103,8 +103,6 @@ const formData = reactive({
// =========================
// sync attrs end
// =========================
distriPattern: DistributionPattern.Override,
actionEnable: true,
})
Expand Down Expand Up @@ -134,15 +132,6 @@ const handlePublish = async () => {
// 平台相关的元数据初始化
batchItemPost = await initPublishMethods.assignInitAttrs(siyuanPost, id, formData.publishCfg)
// 合并属性
if (formData.distriPattern === DistributionPattern.Merge) {
batchItemPost = initPublishMethods.doMergeBatchPost(siyuanPost, batchItemPost)
logger.debug("批量分发模式文章已合并", {
siyuanPost: toRaw(siyuanPost),
mergedPost: toRaw(batchItemPost),
})
}
}
const batchResult = await doSinglePublish(key, id, formData.publishCfg, batchItemPost)
Expand All @@ -162,8 +151,13 @@ const handlePublish = async () => {
} else {
ElMessage.error(`多平台文章分发失败,失败个数:${formData.errCount}`)
}
} catch (error) {
ElMessage.error(error.message)
} catch (e) {
const errMsg = t("main.opt.failure") + "=>" + e
logger.error(t("main.opt.failure") + "=>", e)
await kernelApi.pushErrMsg({
msg: errMsg,
timeout: 7000,
})
} finally {
formData.isPublishLoading = false
}
Expand Down Expand Up @@ -221,8 +215,13 @@ const doDelete = async () => {
} else {
ElMessage.error(`多平台文章删除失败,失败个数:${formData.errCount}`)
}
} catch (error) {
ElMessage.error(error.message)
} catch (e) {
const errMsg = t("main.opt.failure") + "=>" + e
logger.error(t("main.opt.failure") + "=>", e)
await kernelApi.pushErrMsg({
msg: errMsg,
timeout: 7000,
})
} finally {
formData.isDeleteLoading = false
}
Expand Down Expand Up @@ -275,7 +274,7 @@ const syncDesc = (val: string) => {
}
const syncTags = (val: string[]) => {
formData.siyuanPost.mt_keywords = val.join(",")
formData.siyuanPost.mt_keywords = val?.join(",")
logger.debug("syncTags in batch publish")
}
Expand Down Expand Up @@ -391,16 +390,6 @@ onMounted(async () => {
v-model:md="formData.siyuanPost.markdown"
v-model:html="formData.siyuanPost.html"
/>

<!-- 分发模式 -->
<div class="distri-type">
<el-form-item label="分发模式">
<el-radio-group v-model="formData.distriPattern" class="ml-4">
<el-radio :label="DistributionPattern.Override" size="large">覆盖</el-radio>
<el-radio :label="DistributionPattern.Merge" size="large">合并</el-radio>
</el-radio-group>
</el-form-item>
</div>
<el-divider border-style="dashed" />

<div v-if="formData.editType === PageEditMode.EditMode_complex" class="complex-mode">
Expand Down
2 changes: 1 addition & 1 deletion src/components/publish/SinglePublishDoPublish.vue
Original file line number Diff line number Diff line change
Expand Up @@ -291,7 +291,7 @@ const syncDesc = (val: string) => {
}
const syncTags = (val: string[]) => {
formData.mergedPost.mt_keywords = val.join(",")
formData.mergedPost.mt_keywords = val?.join(",")
logger.debug("syncTags in single publish")
}
Expand Down
17 changes: 0 additions & 17 deletions src/composables/usePublish.ts
Original file line number Diff line number Diff line change
Expand Up @@ -471,23 +471,6 @@ const usePublish = () => {
postPreviewUrl,
}
},

doMergeBatchPost: (post: Post, newPost: Post): Post => {
// 复制原始 post 对象以避免直接修改它
const mergedPost = _.cloneDeep(post) as Post

const postKeywords = post.mt_keywords.split(",")
const newPostKeywords = newPost.mt_keywords.split(",")
// 合并并去重关键词
const mergedKeywords = [...new Set([...postKeywords, ...newPostKeywords])]
mergedPost.mt_keywords = mergedKeywords.join(",")

// 合并并去重分类
const mergedCategories = [...new Set([...post.categories, ...newPost.categories])]
mergedPost.categories = mergedCategories

return mergedPost
},
}

return {
Expand Down

0 comments on commit 1101caf

Please sign in to comment.